aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-01-03 22:52:32 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-01-03 22:52:32 +0000
commit341b8be2b8069e09eb4d928bebf5d55a50515614 (patch)
treee023d44f070813da5f1a2c49626b8a359b31f5ed
parented002bd2f9eaea6ed5030ccd90fdaa870598a16a (diff)
objc: diagnose misplacement of objc_suppress_autosynthesis
attribute. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147490 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaDeclAttr.cpp5
-rw-r--r--test/SemaObjC/default-synthesize-3.m6
3 files changed, 14 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index d97dff633b..7e5fff8ab4 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1369,6 +1369,9 @@ def err_attribute_wrong_number_arguments : Error<
":requires exactly %0 arguments}0">;
def err_attribute_too_many_arguments : Error<
"attribute takes no more than %0 argument%s0">;
+def err_suppress_autosynthesis : Error<
+ "objc_suppress_autosynthesis attribute may only be specified on a class"
+ "to a class declaration">;
def err_attribute_too_few_arguments : Error<
"attribute takes at least %0 argument%s0">;
def err_attribute_missing_parameter_name : Error<
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 4074afee1c..22a2cfe8a6 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -1581,6 +1581,11 @@ static void handleArcWeakrefUnavailableAttr(Sema &S, Decl *D,
static void handleObjCSuppressAutosynthesisAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
+ if (!isa<ObjCInterfaceDecl>(D)) {
+ S.Diag(Attr.getLoc(), diag::err_suppress_autosynthesis);
+ return;
+ }
+
unsigned NumArgs = Attr.getNumArgs();
if (NumArgs > 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 0;
diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m
index 7b07cb9aa1..20e7dd28f2 100644
--- a/test/SemaObjC/default-synthesize-3.m
+++ b/test/SemaObjC/default-synthesize-3.m
@@ -31,3 +31,9 @@ __attribute ((objc_suppress_autosynthesis)) // redundant, just for testing
- (id) DeepMustSynthProperty { return 0; }
@end
+__attribute ((objc_suppress_autosynthesis))
+@interface Deep(CAT) // expected-error {{attributes may not be specified on a category}}
+@end
+
+__attribute ((objc_suppress_autosynthesis)) // expected-error {{objc_suppress_autosynthesis attribute may only be specified on a class}}
+@protocol P @end