From: Jordy Rose Date: Sun, 27 Jun 2010 01:20:56 +0000 (+0000) Subject: Implicitly compare symbolic expressions to zero when they're being used as constraint... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5ca129c2558a13d7d4b2b76fee8404bc07466ce9;p=clang Implicitly compare symbolic expressions to zero when they're being used as constraints. Part of PR7491. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106972 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Checker/SimpleConstraintManager.cpp b/lib/Checker/SimpleConstraintManager.cpp index a1594a9e9e..321381b045 100644 --- a/lib/Checker/SimpleConstraintManager.cpp +++ b/lib/Checker/SimpleConstraintManager.cpp @@ -174,9 +174,13 @@ const GRState *SimpleConstraintManager::AssumeAux(const GRState *state, return state; BinaryOperator::Opcode op = SE->getOpcode(); - // FIXME: We should implicitly compare non-comparison expressions to 0. - if (!BinaryOperator::isComparisonOp(op)) - return state; + // Implicitly compare non-comparison expressions to 0. + if (!BinaryOperator::isComparisonOp(op)) { + QualType T = SymMgr.getType(SE); + const llvm::APSInt &zero = BasicVals.getValue(0, T); + op = (Assumption ? BinaryOperator::NE : BinaryOperator::EQ); + return AssumeSymRel(state, SE, op, zero); + } // From here on out, op is the real comparison we'll be testing. if (!Assumption) diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m index 1beb464cd1..0de5113072 100644 --- a/test/Analysis/misc-ps.m +++ b/test/Analysis/misc-ps.m @@ -981,3 +981,21 @@ void r7979430(id x) { MAKE_TEST_FN() // expected-warning{{null pointer}} +//===----------------------------------------------------------------------=== +// PR 7491 - Test that symbolic expressions can be used as conditions. +//===----------------------------------------------------------------------=== + +void pr7491 () { + extern int getint(); + int a = getint()-1; + if (a) { + return; + } + if (!a) { + return; + } else { + // Should be unreachable + (void)*(char*)0; // no-warning + } +} +