[cfe-commits] r83368 - in /cfe/trunk: lib/Analysis/SimpleSValuator.cpp test/Analysis/misc-ps.m

Ted Kremenek kremenek at apple.com
Mon Oct 5 20:44:52 PDT 2009


Author: kremenek
Date: Mon Oct  5 22:44:49 2009
New Revision: 83368

URL: http://llvm.org/viewvc/llvm-project?rev=83368&view=rev
Log:
Fix crash introduced by r83358 where a symbol could be eagerly
evaluated to an APSInt with a different bitwidth than the other
operand in a binary expression.

Modified:
    cfe/trunk/lib/Analysis/SimpleSValuator.cpp
    cfe/trunk/test/Analysis/misc-ps.m

Modified: cfe/trunk/lib/Analysis/SimpleSValuator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SimpleSValuator.cpp?rev=83368&r1=83367&r2=83368&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/SimpleSValuator.cpp (original)
+++ cfe/trunk/lib/Analysis/SimpleSValuator.cpp Mon Oct  5 22:44:49 2009
@@ -349,8 +349,13 @@
       // Does the symbol simplify to a constant?
       if (Sym->getType(ValMgr.getContext())->isIntegerType())
         if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
-          lhs = nonloc::ConcreteInt(*Constant);
-          continue;
+          // What should we convert it to?
+          if (nonloc::ConcreteInt *rhs_I = dyn_cast<nonloc::ConcreteInt>(&rhs)){
+            BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
+            lhs = nonloc::ConcreteInt(BVF.Convert(rhs_I->getValue(),
+                                                  *Constant));
+            continue;
+          }
         }
       
       if (isa<nonloc::ConcreteInt>(rhs)) {

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=83368&r1=83367&r2=83368&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Oct  5 22:44:49 2009
@@ -681,3 +681,14 @@
   return 1;
 }
 
+// Test constant-folding of symbolic values, automatically handling type
+// conversions of the symbol as necessary.  Previously this would crash
+// once we started eagerly evaluating symbols whose values were constrained
+// to a single value.
+void test_constant_symbol(signed char x) {
+  while (1) {
+    if (x == ((signed char) 0)) {}
+  }
+}
+
+





More information about the cfe-commits mailing list