]> granicus.if.org Git - clang/commitdiff
Don't assert if evaluation of an expression that we're syntactically required
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 4 Dec 2015 03:00:44 +0000 (03:00 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 4 Dec 2015 03:00:44 +0000 (03:00 +0000)
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
test/SemaCXX/constant-expression.cpp

index d80f466d99f5ea779eae96b21ee480a82ae49124..ffaf742030f7f5122e39f6969a7c527704dde67e 100644 (file)
@@ -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;
 }
index e01acdd46f935a79b9df456445a530137e848c30..f82a6920937962883bb71c24ab5175713fc16b31 100644 (file)
@@ -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}}