]> granicus.if.org Git - clang/commitdiff
Improve the checkUInt32Argument() helper function so that it diagnoses integer consta...
authorAaron Ballman <aaron@aaronballman.com>
Tue, 22 Jul 2014 14:09:34 +0000 (14:09 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 22 Jul 2014 14:09:34 +0000 (14:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213658 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/constructor-attribute.c

index 61683cd875797ccfd8c35c036e91fd6fd2940f2b..973b63de309288e927618c7a0ce95496f491e780 100644 (file)
@@ -192,6 +192,12 @@ static bool checkUInt32Argument(Sema &S, const AttributeList &Attr,
         << 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;
 }
index 1bb69fc4aa56b39562ecc554fb90b650a85d09da..9460c75e32a8afd6f00906b5e739e0f640e2425b 100644 (file)
@@ -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));