]> granicus.if.org Git - clang/commitdiff
Reimplement Expr::isConstantExpr in terms of Expr::Evaluate. This fixes PR2832.
authorAnders Carlsson <andersca@mac.com>
Mon, 24 Nov 2008 05:23:59 +0000 (05:23 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 24 Nov 2008 05:23:59 +0000 (05:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59946 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/CodeGen/staticinit.c

index 0ff345a1a8d957227c90db2ee03b2f1ed60d427b..6d29dd1f31983895514a7058fba37a3ae6e0f61c 100644 (file)
@@ -622,8 +622,32 @@ Expr *Expr::IgnoreParenCasts() {
   }
 }
 
+#define USE_EVALUATE
 
 bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
+#ifdef USE_EVALUATE
+  switch (getStmtClass()) {
+  default:
+    if (!isEvaluatable(Ctx)) {
+      if (Loc) *Loc = getLocStart();
+      return false;
+    }
+    break;
+  case StringLiteralClass:
+  case ObjCStringLiteralClass:
+    return true;
+  case InitListExprClass: {
+    const InitListExpr *Exp = cast<InitListExpr>(this);
+    unsigned numInits = Exp->getNumInits();
+    for (unsigned i = 0; i < numInits; i++) {
+      if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) 
+        return false;
+    }
+  }
+  }
+
+  return true;
+#else
   switch (getStmtClass()) {
   default:
     if (Loc) *Loc = getLocStart();
@@ -762,6 +786,7 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
   case CXXDefaultArgExprClass:
     return cast<CXXDefaultArgExpr>(this)->getExpr()->isConstantExpr(Ctx, Loc);
   }
+#endif
 }
 
 /// isIntegerConstantExpr - this recursive routine will test if an expression is
index 50c837a1c2f1fd7d22c40fd5aac90bfc4d30b011..196d931f64a9d36a49b5642636c92b0411859883 100644 (file)
@@ -18,3 +18,9 @@ void g() {
   static char a[10];
   static char *b = a;
 }
+
+struct s { void *p; };
+
+void foo(void) {
+  static struct s var = {((void*)&((char*)0)[0])};
+}