Author: aaronballman
Date: Tue Jul 22 09:09:34 2014
New Revision: 213658

URL: http://llvm.org/viewvc/llvm-project?rev=213658&view=rev
Log:
Improve the checkUInt32Argument() helper function so that it diagnoses integer 
constants larger than 32-bits.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/constructor-attribute.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=213658&r1=213657&r2=213658&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Jul 22 09:09:34 2014
@@ -192,6 +192,12 @@ static bool checkUInt32Argument(Sema &S,
         << Expr->getSourceRange();
     return false;
   }
+
+  if (!I.isIntN(32)) {
+    S.Diag(Expr->getExprLoc(), diag::err_integer_too_large) << 32;
+    return false;
+  }
+
   Val = (uint32_t)I.getZExtValue();
   return true;
 }

Modified: cfe/trunk/test/Sema/constructor-attribute.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constructor-attribute.c?rev=213658&r1=213657&r2=213658&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constructor-attribute.c (original)
+++ cfe/trunk/test/Sema/constructor-attribute.c Tue Jul 22 09:09:34 2014
@@ -5,6 +5,7 @@ int f() __attribute__((constructor));
 int f() __attribute__((constructor(1)));
 int f() __attribute__((constructor(1,2))); // expected-error {{'constructor' 
attribute takes no more than 1 argument}}
 int f() __attribute__((constructor(1.0))); // expected-error {{'constructor' 
attribute requires an integer constant}}
+int f() __attribute__((constructor(0x100000000))); // expected-error {{integer 
constant is larger than the largest 32-bit unsigned integer type}}
 
 int x __attribute__((destructor)); // expected-warning {{'destructor' 
attribute only applies to functions}}
 int f() __attribute__((destructor));


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to