aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-05 05:09:56 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-05 05:09:56 +0000
commit9e09f5d361c50373435b9e142da8538034d84601 (patch)
tree72623acabd9feb8355e4383dee9d3b82a0c65250
parent96f560b96ba3fb7b9a5408db22b481206b211f1c (diff)
Make Sema::CheckForConstantInitializer use Expr::Evaluate. This fixes PR3130.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60580 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp8
-rw-r--r--test/CodeGen/PR3130-cond-constant.c3
-rw-r--r--test/Sema/constant-builtins.c3
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 65abc36cb0..411307522b 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1651,8 +1651,13 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) {
}
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 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
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()) {
diff --git a/test/CodeGen/PR3130-cond-constant.c b/test/CodeGen/PR3130-cond-constant.c
new file mode 100644
index 0000000000..7aa2ce1bc0
--- /dev/null
+++ b/test/CodeGen/PR3130-cond-constant.c
@@ -0,0 +1,3 @@
+// RUN: clang -emit-llvm %s -o -
+
+int a = 2.0 ? 1 : 2;
diff --git a/test/Sema/constant-builtins.c b/test/Sema/constant-builtins.c
index d6cf45755d..b1c5e2af10 100644
--- a/test/Sema/constant-builtins.c
+++ b/test/Sema/constant-builtins.c
@@ -19,5 +19,6 @@ int h0 = __builtin_types_compatible_p(int,float); // expected-warning {{extensio
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();
+