[cfe-commits] r63519 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/static-init.c

Nuno Lopes nunoplopes at sapo.pt
Mon Feb 2 08:07:43 PST 2009


Author: nlopes
Date: Mon Feb  2 10:07:41 2009
New Revision: 63519

URL: http://llvm.org/viewvc/llvm-project?rev=63519&view=rev
Log:
allow cast from array to int to be considered as constant

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    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=63519&r1=63518&r2=63519&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb  2 10:07:41 2009
@@ -2075,8 +2075,7 @@
     if (SubExpr->getType()->isPointerType()) {
       const Expr* Base = FindExpressionBaseAddress(SubExpr);
       // If the pointer has a null base, this is an offsetof-like construct
-      if (!Base)
-        return CheckAddressConstantExpression(SubExpr);
+      return Base ? false : CheckAddressConstantExpression(SubExpr);
     }
 
     InitializerElementNotConstant(Init);

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

==============================================================================
--- cfe/trunk/test/Sema/static-init.c (original)
+++ cfe/trunk/test/Sema/static-init.c Mon Feb  2 10:07:41 2009
@@ -2,6 +2,18 @@
 static int f = 10;
 static int b = f; // expected-error {{initializer element is not a compile-time constant}}
 
-float r  = (float) &r; // 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;
 _Bool t = &t;
+
+
+union bar {
+	int i;
+};
+
+struct foo {
+	unsigned ptr;
+};
+
+union bar u[1];
+struct foo x = {(int) u}; // no-error





More information about the cfe-commits mailing list