r178670 - Emit a nicer diagnostic for misplaced attributes on ObjC directives.
Nico Weber
nicolasweber at gmx.de
Wed Apr 3 10:36:11 PDT 2013
Author: nico
Date: Wed Apr 3 12:36:11 2013
New Revision: 178670
URL: http://llvm.org/viewvc/llvm-project?rev=178670&view=rev
Log:
Emit a nicer diagnostic for misplaced attributes on ObjC directives.
Added:
cfe/trunk/test/Parser/attributes.mm
- copied, changed from r177222, cfe/trunk/test/Parser/prefix-attributes.m
Removed:
cfe/trunk/test/Parser/prefix-attributes.m
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseObjc.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=178670&r1=178669&r2=178670&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Apr 3 12:36:11 2013
@@ -399,6 +399,8 @@ def err_objc_properties_require_objc2 :
"properties are an Objective-C 2 feature">;
def err_objc_unexpected_attr : Error<
"prefix attribute must be followed by an interface or protocol">;
+def err_objc_postfix_attribute : Error <
+ "postfix attributes are not allowed on Objective-C directives">;
def err_objc_directive_only_in_protocol : Error<
"directive may only be specified in protocols only">;
def err_missing_catch_finally : Error<
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=178670&r1=178669&r2=178670&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Apr 3 12:36:11 2013
@@ -1113,6 +1113,7 @@ private:
ExprResult ParseAsmStringLiteral();
// Objective-C External Declarations
+ void MaybeSkipAttributes();
DeclGroupPtrTy ParseObjCAtDirectives();
DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=178670&r1=178669&r2=178670&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Apr 3 12:36:11 2013
@@ -22,6 +22,14 @@
#include "llvm/ADT/StringExtras.h"
using namespace clang;
+/// Skips attributes after an Objective-C @ directive. Emits a diagnostic.
+void Parser::MaybeSkipAttributes() {
+ ParsedAttributes attrs(AttrFactory);
+ if (Tok.is(tok::kw___attribute)) {
+ Diag(Tok, diag::err_objc_postfix_attribute);
+ ParseGNUAttributes(attrs);
+ }
+}
/// ParseObjCAtDirectives - Handle parts of the external-declaration production:
/// external-declaration: [C99 6.9]
@@ -93,6 +101,7 @@ Parser::ParseObjCAtClassDeclaration(Sour
while (1) {
+ MaybeSkipAttributes();
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident);
SkipUntil(tok::semi);
@@ -179,6 +188,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclar
return 0;
}
+ MaybeSkipAttributes();
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing class or category name.
return 0;
@@ -1397,6 +1408,8 @@ Parser::ParseObjCAtProtocolDeclaration(S
return DeclGroupPtrTy();
}
+ MaybeSkipAttributes();
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing protocol name.
return DeclGroupPtrTy();
@@ -1488,6 +1501,8 @@ Parser::ParseObjCAtImplementationDeclara
return DeclGroupPtrTy();
}
+ MaybeSkipAttributes();
+
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_ident); // missing class or category name.
return DeclGroupPtrTy();
Copied: cfe/trunk/test/Parser/attributes.mm (from r177222, cfe/trunk/test/Parser/prefix-attributes.m)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attributes.mm?p2=cfe/trunk/test/Parser/attributes.mm&p1=cfe/trunk/test/Parser/prefix-attributes.m&r1=177222&r2=178670&rev=178670&view=diff
==============================================================================
--- cfe/trunk/test/Parser/prefix-attributes.m (original)
+++ cfe/trunk/test/Parser/attributes.mm Wed Apr 3 12:36:11 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -verify -fsyntax-only -Wno-objc-root-class %s
__attribute__((deprecated)) @class B; // expected-error {{prefix attribute must be followed by an interface or protocol}}
@@ -6,3 +6,20 @@ __attribute__((deprecated)) @interface A
__attribute__((deprecated)) @protocol P0;
__attribute__((deprecated)) @protocol P1
@end
+
+#define EXP __attribute__((visibility("default")))
+class EXP C {};
+EXP class C2 {}; // expected-warning {{attribute 'visibility' is ignored, place it after "class" to apply attribute to type declaration}}
+
+ at interface EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+EXP @interface I2 @end
+
+ at implementation EXP I @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+// FIXME: Prefix attribute recovery skips until ';'
+EXP @implementation I2 @end; // expected-error{{prefix attribute must be followed by an interface or protocol}}
+
+ at class EXP OC; // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+EXP @class OC2; // expected-error {{prefix attribute must be followed by an interface or protocol}}
+
+ at protocol EXP P @end // expected-error {{postfix attributes are not allowed on Objective-C directives}}
+EXP @protocol P2 @end
Removed: cfe/trunk/test/Parser/prefix-attributes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/prefix-attributes.m?rev=178669&view=auto
==============================================================================
--- cfe/trunk/test/Parser/prefix-attributes.m (original)
+++ cfe/trunk/test/Parser/prefix-attributes.m (removed)
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -verify -fsyntax-only %s
-
-__attribute__((deprecated)) @class B; // expected-error {{prefix attribute must be followed by an interface or protocol}}
-
-__attribute__((deprecated)) @interface A @end
-__attribute__((deprecated)) @protocol P0;
-__attribute__((deprecated)) @protocol P1
- at end
More information about the cfe-commits
mailing list