[cfe-commits] r59946 - in /cfe/trunk: lib/AST/Expr.cpp test/CodeGen/staticinit.c
Anders Carlsson
andersca at mac.com
Sun Nov 23 21:24:00 PST 2008
Author: andersca
Date: Sun Nov 23 23:23:59 2008
New Revision: 59946
URL: http://llvm.org/viewvc/llvm-project?rev=59946&view=rev
Log:
Reimplement Expr::isConstantExpr in terms of Expr::Evaluate. This fixes PR2832.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/CodeGen/staticinit.c
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=59946&r1=59945&r2=59946&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Nov 23 23:23:59 2008
@@ -622,8 +622,32 @@
}
}
+#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 @@
case CXXDefaultArgExprClass:
return cast<CXXDefaultArgExpr>(this)->getExpr()->isConstantExpr(Ctx, Loc);
}
+#endif
}
/// isIntegerConstantExpr - this recursive routine will test if an expression is
Modified: cfe/trunk/test/CodeGen/staticinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/staticinit.c?rev=59946&r1=59945&r2=59946&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/staticinit.c (original)
+++ cfe/trunk/test/CodeGen/staticinit.c Sun Nov 23 23:23:59 2008
@@ -18,3 +18,9 @@
static char a[10];
static char *b = a;
}
+
+struct s { void *p; };
+
+void foo(void) {
+ static struct s var = {((void*)&((char*)0)[0])};
+}
More information about the cfe-commits
mailing list