[cfe-commits] r110592 - in /cfe/trunk: lib/Checker/SimpleSValuator.cpp test/Analysis/misc-ps.m
Jordy Rose
jediknil at belkadan.com
Mon Aug 9 13:31:57 PDT 2010
Author: jrose
Date: Mon Aug 9 15:31:57 2010
New Revision: 110592
URL: http://llvm.org/viewvc/llvm-project?rev=110592&view=rev
Log:
Allow EvalBinOpNN to handle expressions of the form $a+$b if $b can be reduced to a constant.
Modified:
cfe/trunk/lib/Checker/SimpleSValuator.cpp
cfe/trunk/test/Analysis/misc-ps.m
Modified: cfe/trunk/lib/Checker/SimpleSValuator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/SimpleSValuator.cpp?rev=110592&r1=110591&r2=110592&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/SimpleSValuator.cpp (original)
+++ cfe/trunk/lib/Checker/SimpleSValuator.cpp Mon Aug 9 15:31:57 2010
@@ -461,10 +461,12 @@
case nonloc::SymbolValKind: {
nonloc::SymbolVal *slhs = cast<nonloc::SymbolVal>(&lhs);
SymbolRef Sym = slhs->getSymbol();
-
+
+ ASTContext& Ctx = ValMgr.getContext();
+
// Does the symbol simplify to a constant? If so, "fold" the constant
// by setting 'lhs' to a ConcreteInt and try again.
- if (Sym->getType(ValMgr.getContext())->isIntegerType())
+ if (Sym->getType(Ctx)->isIntegerType())
if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
// The symbol evaluates to a constant. If necessary, promote the
// folded constant (LHS) to the result type.
@@ -474,7 +476,7 @@
// Also promote the RHS (if necessary).
- // For shifts, it necessary promote the RHS to the result type.
+ // For shifts, it is not necessary to promote the RHS.
if (BinaryOperator::isShiftOp(op))
continue;
@@ -486,7 +488,20 @@
continue;
}
-
+
+ // Is the RHS a symbol we can simplify?
+ if (const nonloc::SymbolVal *srhs = dyn_cast<nonloc::SymbolVal>(&rhs)) {
+ SymbolRef RSym = srhs->getSymbol();
+ if (RSym->getType(Ctx)->isIntegerType()) {
+ if (const llvm::APSInt *Constant = state->getSymVal(RSym)) {
+ // The symbol evaluates to a constant.
+ BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
+ const llvm::APSInt &rhs_I = BVF.Convert(resultTy, *Constant);
+ rhs = nonloc::ConcreteInt(rhs_I);
+ }
+ }
+ }
+
if (isa<nonloc::ConcreteInt>(rhs)) {
return MakeSymIntVal(slhs->getSymbol(), op,
cast<nonloc::ConcreteInt>(rhs).getValue(),
Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=110592&r1=110591&r2=110592&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Aug 9 15:31:57 2010
@@ -1027,3 +1027,21 @@
return __real l0 + __imag l0;
}
+
+//===----------------------------------------------------------------------===
+// Test that we can reduce symbols to constants whether they are on the left
+// or right side of an expression.
+//===----------------------------------------------------------------------===
+
+void reduce_to_constant(int x, int y) {
+ if (x != 20)
+ return;
+
+ int a = x + y;
+ int b = y + x;
+
+ if (y == -20 && a != 0)
+ (void)*(char*)0; // no-warning
+ if (y == -20 && b != 0)
+ (void)*(char*)0; // no-warning
+}
More information about the cfe-commits
mailing list