Add -fobjc-default-synthesized-properties flag
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
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index 04288a2..33b8053 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -176,6 +176,12 @@
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;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 9df276d..cee00ed 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1484,6 +1484,13 @@
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,
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index ba91510..29aac8a 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -550,6 +550,8 @@
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 @@
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);
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index d199911..8c66588 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1095,7 +1095,8 @@
// 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 @@
}
}
- if (LangOpts.ObjCNonFragileABI2)
+ if (LangOpts.ObjCDefaultSynthProperties &&
+ LangOpts.ObjCNonFragileABI2)
DefaultSynthesizeProperties(S, IC, IDecl);
ImplMethodsVsClassMethods(S, IC, IDecl);
AtomicPropertySetterGetterRules(IC, IDecl);
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 72360e7..084778d 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -84,6 +84,8 @@
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 @@
PARSE_LANGOPT(ObjC2);
PARSE_LANGOPT(ObjCNonFragileABI);
PARSE_LANGOPT(ObjCNonFragileABI2);
+ PARSE_LANGOPT(ObjCDefaultSynthProperties);
PARSE_LANGOPT(NoConstantCFStrings);
PARSE_LANGOPT(PascalStrings);
PARSE_LANGOPT(WritableStrings);
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index bf07c52..8c0fb42 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -860,6 +860,8 @@
// 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