Author: rsmith Date: Thu Dec 3 21:00:44 2015 New Revision: 254699 URL: http://llvm.org/viewvc/llvm-project?rev=254699&view=rev Log: 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).
Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/SemaCXX/constant-expression.cpp Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=254699&r1=254698&r2=254699&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Dec 3 21:00:44 2015 @@ -9408,7 +9408,11 @@ bool Expr::isIntegerConstantExpr(llvm::A 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; } Modified: cfe/trunk/test/SemaCXX/constant-expression.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression.cpp?rev=254699&r1=254698&r2=254699&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/constant-expression.cpp (original) +++ cfe/trunk/test/SemaCXX/constant-expression.cpp Thu Dec 3 21:00:44 2015 @@ -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}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits