From b659b7b860e586f38438b12eeaa417d41028fe63 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 4 Dec 2015 03:00:44 +0000 Subject: [PATCH] Don't assert if evaluation of an expression that we're syntactically required to treat as an ICE results in undefined behavior. Instead, return the "natural" result of the operation (signed wraparound / inf / nan). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254699 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 6 +++++- test/SemaCXX/constant-expression.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index d80f466d99..ffaf742030 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -9408,7 +9408,11 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Value, const ASTContext &Ctx, if (!isIntegerConstantExpr(Ctx, Loc)) return false; - if (!EvaluateAsInt(Value, Ctx)) + // The only possible side-effects here are due to UB discovered in the + // evaluation (for instance, INT_MAX + 1). In such a case, we are still + // required to treat the expression as an ICE, so we produce the folded + // value. + if (!EvaluateAsInt(Value, Ctx, SE_AllowSideEffects)) llvm_unreachable("ICE cannot be evaluated!"); return true; } diff --git a/test/SemaCXX/constant-expression.cpp b/test/SemaCXX/constant-expression.cpp index e01acdd46f..f82a692093 100644 --- a/test/SemaCXX/constant-expression.cpp +++ b/test/SemaCXX/constant-expression.cpp @@ -141,3 +141,5 @@ namespace rdar16064952 { unsigned w = ({int a = b.val[sizeof(0)]; 0; }); // expected-warning {{use of GNU statement expression extension}} } } + +char PR17381_ice = 1000000 * 1000000; // expected-warning {{overflow}} expected-warning {{changes value}} -- 2.40.0