]> granicus.if.org Git - clang/commitdiff
Add -fobjc-default-synthesized-properties flag
authorTed Kremenek <kremenek@apple.com>
Thu, 23 Dec 2010 21:35:43 +0000 (21:35 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 23 Dec 2010 21:35:43 +0000 (21:35 +0000)
to allow us to explicitly control whether or
not Objective-C properties are default synthesized.
Currently this feature only works when using
the -fobjc-non-fragile-abi2 flag (so there is
no functionality change), but we can now turn
off this feature without turning off all the features
coupled with -fobjc-non-fragile-abi2.

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

18 files changed:
include/clang/Basic/DiagnosticFrontendKinds.td
include/clang/Basic/LangOptions.h
include/clang/Driver/CC1Options.td
include/clang/Driver/Options.td
include/clang/Driver/ToolChain.h
lib/Driver/ToolChains.h
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
test/CodeGenObjC/debug-info-default-synth-ivar.m
test/SemaObjC/default-synthesize-1.m
test/SemaObjC/default-synthesize.m
test/SemaObjC/direct-synthesized-ivar-access.m
test/SemaObjC/synth-provisional-ivars.m
test/SemaObjC/synthesized-ivar.m
test/SemaObjC/warn-implicit-atomic-property.m

index f56a2407de2cc7e2822cc232ba3b1f33a1843bbc..8ea904130cfd19b33b22336d669135efd1772793 100644 (file)
@@ -129,6 +129,9 @@ def warn_pch_nonfragile_abi2 : Error<
     "PCH file was compiled with the %select{32-bit|enhanced non-fragile}0 "
     "Objective-C ABI but the %select{32-bit|enhanced non-fragile}1 "
     "Objective-C ABI is selected">;
+def warn_pch_objc_auto_properties : Error<
+    "PCH file was compiled %select{with|without}0 support for auto-synthesized "
+    "@properties but it is currently %select{disabled|enabled}1">;
 def warn_pch_no_constant_cfstrings : Error<
     "Objctive-C NSstring generation support was %select{disabled|enabled}0 "
     "in PCH file but currently %select{disabled|enabled}1">; 
index b964ddb777d1b3778c7cf0d475c5b06e7bd922d5..a868dbd9eb4df1043134b7d1e7a2531b4959f8ce 100644 (file)
@@ -44,6 +44,7 @@ public:
   unsigned ObjC2             : 1;  // Objective-C 2 support enabled.
   unsigned ObjCNonFragileABI : 1;  // Objective-C modern abi enabled
   unsigned ObjCNonFragileABI2 : 1;  // Objective-C enhanced modern abi enabled
+  unsigned ObjCDefaultSynthProperties : 1; // Objective-C auto-synthesized properties.
 
   unsigned PascalStrings     : 1;  // Allow Pascal strings
   unsigned WritableStrings   : 1;  // Allow writable strings
@@ -155,6 +156,7 @@ public:
     GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
     HexFloats = 0;
     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
+    ObjCDefaultSynthProperties = 0;
     NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
     C99 = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0;
     CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
index 1eefc78b3a58bbefe42a1ac618711bf423c87f1b..50bfc5af36d988591aa03e30177ea1b86d8d9a7e 100644 (file)
@@ -463,6 +463,8 @@ def fobjc_gc_only : Flag<"-fobjc-gc-only">,
   HelpText<"Use GC exclusively for Objective-C related memory management">;
 def fobjc_dispatch_method_EQ : Joined<"-fobjc-dispatch-method=">,
   HelpText<"Objective-C dispatch method to use">;
+def fobjc_default_synthesize_properties : Flag<"-fobjc-default-synthesize-properties">,
+  HelpText<"enable the default synthesis of Objective-C properties">;
 def print_ivar_layout : Flag<"-print-ivar-layout">,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
 def fobjc_nonfragile_abi : Flag<"-fobjc-nonfragile-abi">,
index eeec2679117654f448814ac7ffcad9cf16608d5a..fb5cd05dd6ac9b1ec07ff9b4beb2296112717836 100644 (file)
@@ -338,6 +338,8 @@ def fno_lax_vector_conversions : Flag<"-fno-lax-vector-conversions">, Group<f_Gr
 def fno_math_errno : Flag<"-fno-math-errno">, Group<f_Group>;
 def fno_merge_all_constants : Flag<"-fno-merge-all-constants">, Group<f_Group>;
 def fno_ms_extensions : Flag<"-fno-ms-extensions">, Group<f_Group>;
+def fno_objc_default_synthesize_properties 
+  : Flag<"-fno-objc-default-synthesize-properties">, Group<f_Group>;
 def fno_objc_legacy_dispatch : Flag<"-fno-objc-legacy-dispatch">, Group<f_Group>;
 def fno_omit_frame_pointer : Flag<"-fno-omit-frame-pointer">, Group<f_Group>;
 def fno_pascal_strings : Flag<"-fno-pascal-strings">, Group<f_Group>;
@@ -357,6 +359,7 @@ def fno_working_directory : Flag<"-fno-working-directory">, Group<f_Group>;
 def fno_zero_initialized_in_bss : Flag<"-fno-zero-initialized-in-bss">, Group<f_Group>;
 def fobjc_atdefs : Flag<"-fobjc-atdefs">, Group<clang_ignored_f_Group>;
 def fobjc_call_cxx_cdtors : Flag<"-fobjc-call-cxx-cdtors">, Group<clang_ignored_f_Group>;
+def fobjc_default_synthesize_properties : Flag<"-fobjc-default-synthesize-properties">, Group<f_Group>;
 def fobjc_gc_only : Flag<"-fobjc-gc-only">, Group<f_Group>;
 def fobjc_gc : Flag<"-fobjc-gc">, Group<f_Group>;
 def fobjc_legacy_dispatch : Flag<"-fobjc-legacy-dispatch">, Group<f_Group>;
index 47dabb03d33113946a6a8105257e85202ea110f1..dfd39bc594ed842a5c0dcfaeb2b65099a83568ef 100644 (file)
@@ -108,11 +108,15 @@ public:
 
   /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
   virtual bool IsBlocksDefault() const { return false; }
-
+  
   /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
   /// by default.
   virtual bool IsIntegratedAssemblerDefault() const { return false; }
 
+  /// IsObjCDefaultSynthPropertiesDefault - Does this tool chain enable
+  /// -fobjc-default-synthesize-properties by default.
+  virtual bool IsObjCDefaultSynthPropertiesDefault() const { return false; }
+
   /// IsObjCNonFragileABIDefault - Does this tool chain set
   /// -fobjc-nonfragile-abi by default.
   virtual bool IsObjCNonFragileABIDefault() const { return false; }
index 04288a2ee06a0d233d5ca40e2aa53da98a2df1e9..33b805345321b1cca716c3f6e6ee155faf457ba0 100644 (file)
@@ -176,6 +176,12 @@ public:
             getTriple().getArch() == llvm::Triple::x86_64);
 #endif
   }
+  
+  virtual bool IsObjCDefaultSynthPropertiesDefault() const {
+    // Always allow default synthesized properties on Darwin.
+    return true;
+  }
+
   virtual bool IsObjCNonFragileABIDefault() const {
     // Non-fragile ABI is default for everything but i386.
     return getTriple().getArch() != llvm::Triple::x86;
index 9df276d9c24a1135f42a123da033ed167959d65a..cee00edd2dfa4e026fdd452cfa2bb2fcc2d9901c 100644 (file)
@@ -1484,6 +1484,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
           CmdArgs.push_back("-fobjc-dispatch-method=non-legacy");
       }
     }
+    
+    // -fobjc-default-synthesize-properties=0 is default.
+    if (Args.hasFlag(options::OPT_fobjc_default_synthesize_properties,
+                     options::OPT_fno_objc_default_synthesize_properties,
+                     getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
+      CmdArgs.push_back("-fobjc-default-synthesize-properties");
+    }
   }
 
   if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
index ba9151019722b5d6d1b97eeb6516f32e3f18905c..29aac8a9daa9d96f194c21eb5c7f09329b50b698 100644 (file)
@@ -550,6 +550,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
     Res.push_back("-fobjc-nonfragile-abi");
   if (Opts.ObjCNonFragileABI2)
     Res.push_back("-fobjc-nonfragile-abi2");
+  if (Opts.ObjCDefaultSynthProperties)
+    Res.push_back("-fobjc-default-synthesize-properties");
   // NoInline is implicit.
   if (!Opts.CXXOperatorNames)
     Res.push_back("-fno-operator-names");
@@ -1424,6 +1426,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   Opts.ObjCNonFragileABI2 = Args.hasArg(OPT_fobjc_nonfragile_abi2);
   if (Opts.ObjCNonFragileABI2)
     Opts.ObjCNonFragileABI = true;
+  Opts.ObjCDefaultSynthProperties =
+    Args.hasArg(OPT_fobjc_default_synthesize_properties);
   Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
   Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
   Opts.PICLevel = Args.getLastArgIntValue(OPT_pic_level, 0, Diags);
index d19991138eee30d42bdf65baa51d8257e2b4595c..8c66588da29061cb0b483b0ce8075d18f38982f6 100644 (file)
@@ -1095,7 +1095,8 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
   // Check and see if properties declared in the interface have either 1)
   // an implementation or 2) there is a @synthesize/@dynamic implementation
   // of the property in the @implementation.
-  if (isa<ObjCInterfaceDecl>(CDecl) && !LangOpts.ObjCNonFragileABI2)
+  if (isa<ObjCInterfaceDecl>(CDecl) &&
+        !(LangOpts.ObjCDefaultSynthProperties && LangOpts.ObjCNonFragileABI2))
     DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap);
       
   llvm::DenseSet<Selector> ClsMap;
@@ -1587,7 +1588,8 @@ void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd,
         }
       }
       
-      if (LangOpts.ObjCNonFragileABI2)
+      if (LangOpts.ObjCDefaultSynthProperties &&
+          LangOpts.ObjCNonFragileABI2)
         DefaultSynthesizeProperties(S, IC, IDecl);
       ImplMethodsVsClassMethods(S, IC, IDecl);
       AtomicPropertySetterGetterRules(IC, IDecl);
index 72360e7416d7aa7ae4f2a759e05b09d678ba262e..084778d856cd1a1cade43143b9c7738856819b7b 100644 (file)
@@ -84,6 +84,8 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
   PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2);
   PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi);
   PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2);
+  PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties,
+                          diag::warn_pch_objc_auto_properties);
   PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings,
                           diag::warn_pch_no_constant_cfstrings);
   PARSE_LANGOPT_BENIGN(PascalStrings);
@@ -2598,6 +2600,7 @@ bool ASTReader::ParseLanguageOptions(
     PARSE_LANGOPT(ObjC2);
     PARSE_LANGOPT(ObjCNonFragileABI);
     PARSE_LANGOPT(ObjCNonFragileABI2);
+    PARSE_LANGOPT(ObjCDefaultSynthProperties);
     PARSE_LANGOPT(NoConstantCFStrings);
     PARSE_LANGOPT(PascalStrings);
     PARSE_LANGOPT(WritableStrings);
index bf07c52335b0fdd7c66b835e420d009c7c6f462d..8c0fb42f5f89eecd3461d7ada33cb76d2f9d7dc4 100644 (file)
@@ -860,6 +860,8 @@ void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
                                                  // modern abi enabled.
   Record.push_back(LangOpts.ObjCNonFragileABI2); // Objective-C enhanced
                                                  // modern abi enabled.
+  Record.push_back(LangOpts.ObjCDefaultSynthProperties); // Objective-C auto-synthesized
+                                                      // properties enabled.
   Record.push_back(LangOpts.NoConstantCFStrings); // non cfstring generation enabled..
 
   Record.push_back(LangOpts.PascalStrings);  // Allow Pascal strings
index c1f7f5dbd90593e855feaa33c87e100642a8ba88..a74ee3416881ecf48fedfe3339d85f44ff2edc89 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi2 -emit-llvm -g %s -o %t 
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -emit-llvm -g %s -o %t 
 // RUN: grep DW_TAG_member %t | count 5
 // rdar://8493239
 
index 374fa8314bfdd0d9c6d1e4e59c423cab7d767256..c364c41fc78669b8b92ae76f4fafbba7534632b1 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 
 @interface NSObject 
 - (void) release;
index be3ef08117141a4990daf7b5031c84a17e80162d..1477478dfb82d16facc1bf6507f100bc3258b337 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 
 @interface NSString @end
 
index e59fa81662d2973e4a68c81fd1dc3711e7caf89b..4dedafc29ed1db6211c57a61b411445947c1b694 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -Wnonfragile-abi2 -fsyntax-only -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 // rdar://8673791
 
 @interface I {
index 1fb1abb7ce0831df2208bb4c3d36002e84e0a6b4..482ccc1e64707287038c545c0df8135624df4c60 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 
 int bar;
 
index 6d7e4e7ff209c288d2bc408be323497a40953bf3..06530144b85f3f2c3e65f7172ea33d5d7328ba55 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 @interface I
 {
 }
index b0a6597989e1123b96abd02a2fe965b514714e9f..ad9cbd60678ac8b67cfc80db89d8d40151de4263 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wimplicit-atomic-properties -fobjc-nonfragile-abi2 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wimplicit-atomic-properties -fobjc-nonfragile-abi2 -fobjc-default-synthesize-properties -verify %s
 // rdar://8774580
 
 @interface Super