[cfe-commits] r106350 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/SemaCXX/init-priority-attr.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Jun 18 16:14:53 PDT 2010
Author: fjahanian
Date: Fri Jun 18 18:14:53 2010
New Revision: 106350
URL: http://llvm.org/viewvc/llvm-project?rev=106350&view=rev
Log:
More Sema Check and a test case for init_priority attr.
(radar 8076356).
Added:
cfe/trunk/test/SemaCXX/init-priority-attr.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=106350&r1=106349&r2=106350&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 18 18:14:53 2010
@@ -818,6 +818,9 @@
def err_attribute_argument_outof_range : Error<
"init_priority attribute requires integer constant between "
"101 and 65535 inclusive">;
+def err_init_priority_object_attr : Error<
+ "can only use âinit_priorityâ attribute on file-scope definitions "
+ "of objects of class type">;
def err_attribute_argument_n_not_int : Error<
"'%0' attribute requires parameter %1 to be an integer constant">;
def err_attribute_argument_n_not_string : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=106350&r1=106349&r2=106350&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jun 18 18:14:53 2010
@@ -1189,12 +1189,27 @@
return;
}
+ if (!isa<VarDecl>(d) || S.getCurFunctionOrMethodDecl()) {
+ S.Diag(Attr.getLoc(), diag::err_init_priority_object_attr);
+ Attr.setInvalid();
+ return;
+ }
+ QualType T = dyn_cast<VarDecl>(d)->getType();
+ if (S.Context.getAsArrayType(T))
+ T = S.Context.getBaseElementType(T);
+ if (!T->getAs<RecordType>()) {
+ S.Diag(Attr.getLoc(), diag::err_init_priority_object_attr);
+ Attr.setInvalid();
+ return;
+ }
+
if (Attr.getNumArgs() != 1) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
Attr.setInvalid();
return;
}
Expr *priorityExpr = static_cast<Expr *>(Attr.getArg(0));
+
llvm::APSInt priority(32);
if (priorityExpr->isTypeDependent() || priorityExpr->isValueDependent() ||
!priorityExpr->isIntegerConstantExpr(priority, S.Context)) {
Added: cfe/trunk/test/SemaCXX/init-priority-attr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/init-priority-attr.cpp?rev=106350&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/init-priority-attr.cpp (added)
+++ cfe/trunk/test/SemaCXX/init-priority-attr.cpp Fri Jun 18 18:14:53 2010
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class Two {
+private:
+ int i, j, k;
+public:
+ static int count;
+ Two( int ii, int jj ) { i = ii; j = jj; k = count++; };
+ Two( void ) { i = 0; j = 0; k = count++; };
+ int eye( void ) { return i; };
+ int jay( void ) { return j; };
+ int kay( void ) { return k; };
+};
+
+extern Two foo;
+extern Two goo;
+extern Two coo[];
+extern Two koo[];
+
+Two foo __attribute__((init_priority(101))) ( 5, 6 );
+
+Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{attribute requires 1 argument(s)}}
+
+Two coo[2] __attribute__((init_priority(3))); // expected-error {{init_priority attribute requires integer constant between 101 and 65535 inclusive}}
+
+Two koo[4] __attribute__((init_priority(1.13))); // expected-error {{'init_priority' attribute requires integer constant}}
+
+
+Two func() __attribute__((init_priority(1001))); // expected-error {{can only use âinit_priorityâ attribute on file-scope definitions of objects of class type}}
+
+int i __attribute__((init_priority(1001))); // expected-error {{can only use âinit_priorityâ attribute on file-scope definitions of objects of class type}}
+
+int main() {
+ Two foo __attribute__((init_priority(1001))); // expected-error {{can only use âinit_priorityâ attribute on file-scope definitions of objects of class type}}
+}
+
More information about the cfe-commits
mailing list