aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/AST/ExprConstant.cpp5
-rw-r--r--test/CodeGen/fold-const-declref.c9
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 175fd85a24..7347f5a43e 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -1008,8 +1008,11 @@ bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
VD->setEvaluatingValue();
- if (Visit(const_cast<Expr*>(Init))) {
+ Expr::EvalResult EResult;
+ if (Init->Evaluate(EResult, Info.Ctx) && !EResult.HasSideEffects &&
+ EResult.Val.isInt()) {
// Cache the evaluated value in the variable declaration.
+ Result = EResult.Val;
VD->setEvaluatedValue(Result);
return true;
}
diff --git a/test/CodeGen/fold-const-declref.c b/test/CodeGen/fold-const-declref.c
new file mode 100644
index 0000000000..5a7ba8e26a
--- /dev/null
+++ b/test/CodeGen/fold-const-declref.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -emit-llvm-only
+
+// PR7242: Check that this doesn't crash.
+int main(void)
+{
+ int __negative = 1;
+ const int __max = __negative && 0 ;
+ __max / 0;
+}