]> granicus.if.org Git - clang/commitdiff
Predefine __weak attribute when doing objective-c
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Jan 2010 18:51:17 +0000 (18:51 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 13 Jan 2010 18:51:17 +0000 (18:51 +0000)
rewriting for any target. (refixes radar 7530235).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93331 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CompilerInstance.h
include/clang/Frontend/Utils.h
lib/Basic/Targets.cpp
lib/Frontend/CompilerInstance.cpp
lib/Frontend/InitPreprocessor.cpp

index 35a983dbd7820689f3158f401b1f9ea6430c4f78..edafe623a4f6c14d45d28d4ed418979f647abaf2 100644 (file)
@@ -488,6 +488,7 @@ public:
                                           const HeaderSearchOptions &,
                                           const DependencyOutputOptions &,
                                           const TargetInfo &,
+                                          const FrontendOptions &,
                                           SourceManager &, FileManager &);
 
   /// Create the AST context.
index 2a214663bd1d0171162df61e26f52a2d19f4a087..c8df4941cc213be442a33048654b11f5eab524db 100644 (file)
@@ -39,6 +39,7 @@ class PreprocessorOutputOptions;
 class SourceManager;
 class Stmt;
 class TargetInfo;
+class FrontendOptions;
 
 class MacroBuilder {
   llvm::raw_ostream &Out;
@@ -76,7 +77,8 @@ void ApplyHeaderSearchOptions(HeaderSearch &HS,
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP,
                             const PreprocessorOptions &PPOpts,
-                            const HeaderSearchOptions &HSOpts);
+                            const HeaderSearchOptions &HSOpts,
+                            const FrontendOptions &FEOpts);
 
 /// ProcessWarningOptions - Initialize the diagnostic client and process the
 /// warning options specified on the command line.
index ef3cf89299e417e4b51817b75c3842c1944f5b7a..ac13b950752fcd313c7c232da6f9f955d9a73040 100644 (file)
@@ -994,10 +994,6 @@ public:
     DefineStd(Builder, "WIN32", Opts);
     DefineStd(Builder, "WINNT", Opts);
     Builder.defineMacro("_X86_");
-    if (Opts.ObjC1)
-      // __weak is always defined, for use in blocks and with objc pointers,
-      // even for i686-pc-win32 targets.
-      Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
   }
 };
 } // end anonymous namespace
index 9f71ec6b23561fbce3bd4f724358028d39ed43d2..19c740d17a839be78e8ead48e1e7d3afcc044957 100644 (file)
@@ -158,7 +158,8 @@ void CompilerInstance::createPreprocessor() {
   PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(),
                               getPreprocessorOpts(), getHeaderSearchOpts(),
                               getDependencyOutputOpts(), getTarget(),
-                              getSourceManager(), getFileManager()));
+                              getFrontendOpts(), getSourceManager(),
+                              getFileManager()));
 }
 
 Preprocessor *
@@ -168,6 +169,7 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
                                      const HeaderSearchOptions &HSOpts,
                                      const DependencyOutputOptions &DepOpts,
                                      const TargetInfo &Target,
+                                     const FrontendOptions &FEOpts,
                                      SourceManager &SourceMgr,
                                      FileManager &FileMgr) {
   // Create a PTH manager if we are using some form of a token cache.
@@ -189,7 +191,7 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
     PP->setPTHManager(PTHMgr);
   }
 
-  InitializePreprocessor(*PP, PPOpts, HSOpts);
+  InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts);
 
   // Handle generating dependencies, if requested.
   if (!DepOpts.OutputFile.empty())
index 841463c8e981a77c17c6a7103dbfbcdef06263c2..e4c380ae0eddcbace1670623c0d8e7d737a9b78c 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Frontend/Utils.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/FrontendOptions.h"
 #include "clang/Frontend/PreprocessorOptions.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Basic/FileManager.h"
@@ -202,6 +203,7 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty,
 
 static void InitializePredefinedMacros(const TargetInfo &TI,
                                        const LangOptions &LangOpts,
+                                       const FrontendOptions &FEOpts,
                                        MacroBuilder &Builder) {
   // Compiler version introspection macros.
   Builder.defineMacro("__llvm__");  // LLVM Backend
@@ -406,6 +408,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq)
     Builder.defineMacro("__SSP_ALL__", "2");
 
+  if (FEOpts.ProgramAction == frontend::RewriteObjC)
+    Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
   // Get other target #defines.
   TI.getTargetDefines(LangOpts, Builder);
 }
@@ -461,7 +465,8 @@ static void InitializeFileRemapping(Diagnostic &Diags,
 ///
 void clang::InitializePreprocessor(Preprocessor &PP,
                                    const PreprocessorOptions &InitOpts,
-                                   const HeaderSearchOptions &HSOpts) {
+                                   const HeaderSearchOptions &HSOpts,
+                                   const FrontendOptions &FEOpts) {
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
   llvm::raw_string_ostream Predefines(PredefineBuffer);
@@ -475,7 +480,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
   if (InitOpts.UsePredefines)
     InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
-                               Builder);
+                               FEOpts, Builder);
 
   // Add on the predefines from the driver.  Wrap in a #line directive to report
   // that they come from the command line.