]> granicus.if.org Git - clang/commitdiff
Throw the switch to exclusively use Evaluate (along with the small
authorEli Friedman <eli.friedman@gmail.com>
Sun, 22 Feb 2009 06:45:27 +0000 (06:45 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 22 Feb 2009 06:45:27 +0000 (06:45 +0000)
helper isConstantInitializer) to check whether an initializer is
constant.  This passes tests, but it's possible that it'll cause
regressions with real-world code.

Future work:
1. The diagnostics obtained this way are lower quality at the moment;
some work both here and in Evaluate is needed for accurate diagnostics.
2. We probably need some extra code when we're in -pedantic mode so we
can strictly enforce the rules in C99 6.6p7.
3. Dead code cleanup (this should wait until after 2, because we might
want to re-use some of the code).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65265 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/const-ptr-int-ptr-cast.c
test/Sema/static-init.c

index 3130f02bef3b910dc0e114d8942edee5f51b1a08..4ec2dc6968b5004c7bfb3fa51b6886c31c25a2f2 100644 (file)
@@ -2371,6 +2371,12 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
 }
 
 bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
+  if (Init->isConstantInitializer(Context)) {
+    return false;
+  }
+  InitializerElementNotConstant(Init);
+  return true;
+
   if (DesignatedInitExpr *DIE = dyn_cast<DesignatedInitExpr>(Init))
     Init = DIE->getInit();
 
index 6bf44b05b358fe17dbe3bafe435dacb7bd9f5077..3590583cd5ea43350d24354e24511200a89bd300 100644 (file)
@@ -1,3 +1,5 @@
 // RUN: clang -fsyntax-only -verify %s
 
-char *a = (void*)(unsigned long long)(void*)&a;
+#include <stdint.h>
+
+char *a = (void*)(uintptr_t)(void*)&a;
index f7648a6d358ffec472282717639816c78fd49018..9ab3146ee76e21fa8ccc8f9cfce410ca82196980 100644 (file)
@@ -1,9 +1,12 @@
 // RUN: clang -arch i386 -fsyntax-only -verify %s
+
+#include <stdint.h>
+
 static int f = 10;
 static int b = f; // expected-error {{initializer element is not a compile-time constant}}
 
-float r  = (float) &r; // FIXME: should give an error: ptr value used where a float was expected
-long long s = (long long) &s;
+float r  = (float) &r; // expected-error {{initializer element is not a compile-time constant}}
+intptr_t s = (intptr_t) &s;
 _Bool t = &t;
 
 
@@ -16,5 +19,5 @@ struct foo {
 };
 
 union bar u[1];
-struct foo x = {(long) u}; // no-error
+struct foo x = {(intptr_t) u}; // no-error
 struct foo y = {(char) u}; // expected-error {{initializer element is not a compile-time constant}}