[cfe-commits] r60580 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGen/PR3130-cond-constant.c test/Sema/constant-builtins.c
Anders Carlsson
andersca at mac.com
Thu Dec 4 21:09:57 PST 2008
Author: andersca
Date: Thu Dec 4 23:09:56 2008
New Revision: 60580
URL: http://llvm.org/viewvc/llvm-project?rev=60580&view=rev
Log:
Make Sema::CheckForConstantInitializer use Expr::Evaluate. This fixes PR3130.
Added:
cfe/trunk/test/CodeGen/PR3130-cond-constant.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/constant-builtins.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=60580&r1=60579&r2=60580&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec 4 23:09:56 2008
@@ -1651,8 +1651,13 @@
}
bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
+ Expr::EvalResult Result;
+
Init = Init->IgnoreParens();
+ if (Init->Evaluate(Result, Context) && !Result.HasSideEffects)
+ return false;
+
// Look through CXXDefaultArgExprs; they have no meaning in this context.
if (CXXDefaultArgExpr* DAE = dyn_cast<CXXDefaultArgExpr>(Init))
return CheckForConstantInitializer(DAE->getExpr(), DclT);
@@ -1672,6 +1677,9 @@
return false;
}
+ // FIXME: We can probably remove some of this code below, now that
+ // Expr::Evaluate is doing the heavy lifting for scalars.
+
if (Init->isNullPointerConstant(Context))
return false;
if (Init->getType()->isArithmeticType()) {
Added: cfe/trunk/test/CodeGen/PR3130-cond-constant.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/PR3130-cond-constant.c?rev=60580&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/PR3130-cond-constant.c (added)
+++ cfe/trunk/test/CodeGen/PR3130-cond-constant.c Thu Dec 4 23:09:56 2008
@@ -0,0 +1,3 @@
+// RUN: clang -emit-llvm %s -o -
+
+int a = 2.0 ? 1 : 2;
Modified: cfe/trunk/test/Sema/constant-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-builtins.c?rev=60580&r1=60579&r2=60580&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins.c (original)
+++ cfe/trunk/test/Sema/constant-builtins.c Thu Dec 4 23:09:56 2008
@@ -19,5 +19,6 @@
short somefunc();
-short t = __builtin_constant_p(5353) ? 42 : somefunc(); // expected-warning {{expression is not a constant, but is accepted as one by GNU extensions}}
+short t = __builtin_constant_p(5353) ? 42 : somefunc();
+
More information about the cfe-commits
mailing list