[cfe-commits] r57795 - in /cfe/trunk: include/clang/Parse/DeclSpec.h lib/Parse/ParseDecl.cpp test/Parser/attributes.c
Chris Lattner
sabre at nondot.org
Sun Oct 19 21:57:38 PDT 2008
Author: lattner
Date: Sun Oct 19 23:57:38 2008
New Revision: 57795
URL: http://llvm.org/viewvc/llvm-project?rev=57795&view=rev
Log:
Support attributes in *yet another* place. Is there any place you
can't stick an attributes?
Modified:
cfe/trunk/include/clang/Parse/DeclSpec.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Parser/attributes.c
Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=57795&r1=57794&r2=57795&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Sun Oct 19 23:57:38 2008
@@ -718,17 +718,20 @@
}
/// AddAttributes - simply adds the attribute list to the Declarator.
- /// Unlike AddAttributes on DeclSpec, this routine should never have to
- /// concatenate two lists. The following syntax adds 3 attributes to "var":
- ///
- /// short int var __attribute__((aligned(16),common,deprecated));
+ /// These examples both add 3 attributes to "var":
+ /// short int var __attribute__((aligned(16),common,deprecated));
+ /// short int x, __attribute__((aligned(16)) var
+ /// __attribute__((common,deprecated));
///
void AddAttributes(AttributeList *alist) {
if (!alist)
return; // we parsed __attribute__(()) or had a syntax error
- assert((AttrList == 0) && "Declarator already has an attribute list");
+
+ if (AttrList)
+ alist->addAttributeList(AttrList);
AttrList = alist;
}
+
const AttributeList *getAttributes() const { return AttrList; }
AttributeList *getAttributes() { return AttrList; }
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=57795&r1=57794&r2=57795&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Oct 19 23:57:38 2008
@@ -321,6 +321,17 @@
// Parse the next declarator.
D.clear();
+
+ // Accept attributes in an init-declarator. In the first declarator in a
+ // declaration, these would be part of the declspec. In subsequent
+ // declarators, they become part of the declarator itself, so that they
+ // don't apply to declarators after *this* one. Examples:
+ // short __attribute__((common)) var; -> declspec
+ // short var __attribute__((common)); -> declarator
+ // short x, __attribute__((common)) var; -> declarator
+ if (Tok.is(tok::kw___attribute))
+ D.AddAttributes(ParseAttributes());
+
ParseDeclarator(D);
}
Modified: cfe/trunk/test/Parser/attributes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/attributes.c?rev=57795&r1=57794&r2=57795&view=diff
==============================================================================
--- cfe/trunk/test/Parser/attributes.c (original)
+++ cfe/trunk/test/Parser/attributes.c Sun Oct 19 23:57:38 2008
@@ -43,3 +43,15 @@
void (*h3)(void (*f3)(attribute(()) x)); // expected-warning {{defaults to 'int'}}
void (*h4)(void (*f4)(attribute(()))); // expected-error {{expected parameter declarator}}
+
+
+
+// rdar://6131260
+int foo42(void) {
+ int x, attribute((unused)) y, z;
+ return 0;
+}
+
+// rdar://6096491
+void attribute((noreturn)) d0(void), attribute((noreturn)) d1(void);
+
More information about the cfe-commits
mailing list