[cfe-commits] r65265 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/const-ptr-int-ptr-cast.c test/Sema/static-init.c

Eli Friedman eli.friedman at gmail.com
Sat Feb 21 22:45:27 PST 2009


Author: efriedma
Date: Sun Feb 22 00:45:27 2009
New Revision: 65265

URL: http://llvm.org/viewvc/llvm-project?rev=65265&view=rev
Log:
Throw the switch to exclusively use Evaluate (along with the small 
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).


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/const-ptr-int-ptr-cast.c
    cfe/trunk/test/Sema/static-init.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=65265&r1=65264&r2=65265&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Feb 22 00:45:27 2009
@@ -2371,6 +2371,12 @@
 }
 
 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();
 

Modified: cfe/trunk/test/Sema/const-ptr-int-ptr-cast.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-ptr-int-ptr-cast.c?rev=65265&r1=65264&r2=65265&view=diff

==============================================================================
--- cfe/trunk/test/Sema/const-ptr-int-ptr-cast.c (original)
+++ cfe/trunk/test/Sema/const-ptr-int-ptr-cast.c Sun Feb 22 00:45:27 2009
@@ -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;

Modified: cfe/trunk/test/Sema/static-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/static-init.c?rev=65265&r1=65264&r2=65265&view=diff

==============================================================================
--- cfe/trunk/test/Sema/static-init.c (original)
+++ cfe/trunk/test/Sema/static-init.c Sun Feb 22 00:45:27 2009
@@ -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 @@
 };
 
 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}}





More information about the cfe-commits mailing list