]> granicus.if.org Git - clang/commitdiff
Don't crash during constant-evaluation of 1/(1/0). PR9262.
authorJohn McCall <rjmccall@apple.com>
Sat, 26 Feb 2011 08:27:17 +0000 (08:27 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 26 Feb 2011 08:27:17 +0000 (08:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126541 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/i-c-e.c

index 656bb99df98e5353eda9eca6278d0d579f5ccd68..3a5eb66ea18fa4cc23b3c30b00d1ceb245f04ffc 100644 (file)
@@ -2926,7 +2926,7 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
           Exp->getOpcode() == BO_Rem) {
         // Evaluate gives an error for undefined Div/Rem, so make sure
         // we don't evaluate one.
-        if (LHSResult.Val != 2 && RHSResult.Val != 2) {
+        if (LHSResult.Val == 0 && RHSResult.Val == 0) {
           llvm::APSInt REval = Exp->getRHS()->EvaluateAsInt(Ctx);
           if (REval == 0)
             return ICEDiag(1, E->getLocStart());
index d0a6c529c16006c938326b312a1a8059e8284e38..4d7007cd077c9d7f770db263320765221af62a78 100644 (file)
@@ -66,6 +66,8 @@ int illegaldiv1b[1 && 1/0];  // expected-warning {{division by zero is undefined
 int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \
                       // expected-warning {{division by zero is undefined}}
 int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
+// PR9262
+int illegaldiv4[0 / (1 / 0)]; // expected-warning {{division by zero is undefined}} expected-error {{variable length array declaration not allowed at file scope}}
 
 int chooseexpr[__builtin_choose_expr(1, 1, expr)];
 int realop[(__real__ 4) == 4 ? 1 : -1];