[cfe-commits] r68494 - in /cfe/trunk/lib: Basic/Targets.cpp Lex/Preprocessor.cpp

Chris Lattner sabre at nondot.org
Mon Apr 6 21:48:21 PDT 2009


Author: lattner
Date: Mon Apr  6 23:48:21 2009
New Revision: 68494

URL: http://llvm.org/viewvc/llvm-project?rev=68494&view=rev
Log:
The __weak and __strong defines are common to all darwin targets
and are even set in C mode.  As such, move them to Targets.cpp.

__OBJC_GC__ is also darwin specific, but seems reasonable to always
define it when in objc-gc mode.

This fixes rdar://6761450

Modified:
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=68494&r1=68493&r2=68494&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Apr  6 23:48:21 2009
@@ -138,11 +138,21 @@
   return true;
 }
 
-static void getDarwinDefines(std::vector<char> &Defs, const char *Triple) {
+static void getDarwinDefines(std::vector<char> &Defs, const LangOptions &Opts,
+                             const char *Triple) {
   Define(Defs, "__APPLE__");
   Define(Defs, "__MACH__");
   Define(Defs, "OBJC_NEW_PROPERTIES");
   
+  // Darwin defines __weak and __strong even in C mode.
+  if (!Opts.ObjC1 || Opts.getGCMode() == LangOptions::NonGC) {
+    Define(Defs, "__weak", "");
+    Define(Defs, "__strong", "");
+  } else {
+    Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
+    Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
+  }
+  
   // FIXME: OBJC_ZEROCOST_EXCEPTIONS when using zero cost eh.
   
   // Figure out which "darwin number" the target triple is.  "darwin9" -> 10.5.
@@ -375,7 +385,7 @@
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     PPC32TargetInfo::getTargetDefines(Opts, Defines);
-    getDarwinDefines(Defines, getTargetTriple());
+    getDarwinDefines(Defines, Opts, getTargetTriple());
   }
 
   /// getDefaultLangOptions - Allow the target to specify default settings for
@@ -394,7 +404,7 @@
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     PPC64TargetInfo::getTargetDefines(Opts, Defines);
-    getDarwinDefines(Defines, getTargetTriple());
+    getDarwinDefines(Defines, Opts, getTargetTriple());
   }
 
   /// getDefaultLangOptions - Allow the target to specify default settings for
@@ -674,7 +684,7 @@
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     X86_32TargetInfo::getTargetDefines(Opts, Defines);
-    getDarwinDefines(Defines, getTargetTriple());
+    getDarwinDefines(Defines, Opts, getTargetTriple());
   }
 
   /// getDefaultLangOptions - Allow the target to specify default settings for
@@ -835,7 +845,7 @@
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     X86_64TargetInfo::getTargetDefines(Opts, Defines);
-    getDarwinDefines(Defines, getTargetTriple());
+    getDarwinDefines(Defines, Opts, getTargetTriple());
   }
 
   /// getDefaultLangOptions - Allow the target to specify default settings for
@@ -923,7 +933,7 @@
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &Defines) const {
     ARMTargetInfo::getTargetDefines(Opts, Defines);
-    getDarwinDefines(Defines, getTargetTriple());
+    getDarwinDefines(Defines, Opts, getTargetTriple());
   }
 };
 } // end anonymous namespace.

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=68494&r1=68493&r2=68494&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Apr  6 23:48:21 2009
@@ -500,15 +500,9 @@
     if (PP.getLangOptions().ObjCNonFragileABI)
       DefineBuiltinMacro(Buf, "__OBJC2__=1");
 
-    if (PP.getLangOptions().getGCMode() == LangOptions::NonGC) {
-      DefineBuiltinMacro(Buf, "__weak=");
-      DefineBuiltinMacro(Buf, "__strong=");
-    } else {
-      DefineBuiltinMacro(Buf, "__weak=__attribute__((objc_gc(weak)))");
-      DefineBuiltinMacro(Buf, "__strong=__attribute__((objc_gc(strong)))");
+    if (PP.getLangOptions().getGCMode() != LangOptions::NonGC)
       DefineBuiltinMacro(Buf, "__OBJC_GC__=1");
-    }
-
+    
     if (PP.getLangOptions().NeXTRuntime)
       DefineBuiltinMacro(Buf, "__NEXT_RUNTIME__=1");
   }





More information about the cfe-commits mailing list