[cfe-commits] r106972 - in /cfe/trunk: lib/Checker/SimpleConstraintManager.cpp test/Analysis/misc-ps.m
Jordy Rose
jediknil at belkadan.com
Sat Jun 26 18:20:56 PDT 2010
Author: jrose
Date: Sat Jun 26 20:20:56 2010
New Revision: 106972
URL: http://llvm.org/viewvc/llvm-project?rev=106972&view=rev
Log:
Implicitly compare symbolic expressions to zero when they're being used as constraints. Part of PR7491.
Modified:
cfe/trunk/lib/Checker/SimpleConstraintManager.cpp
cfe/trunk/test/Analysis/misc-ps.m
Modified: cfe/trunk/lib/Checker/SimpleConstraintManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/SimpleConstraintManager.cpp?rev=106972&r1=106971&r2=106972&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/SimpleConstraintManager.cpp (original)
+++ cfe/trunk/lib/Checker/SimpleConstraintManager.cpp Sat Jun 26 20:20:56 2010
@@ -174,9 +174,13 @@
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)
Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=106972&r1=106971&r2=106972&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Sat Jun 26 20:20:56 2010
@@ -981,3 +981,21 @@
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
+ }
+}
+
More information about the cfe-commits
mailing list