[cfe-commits] r56351 - /cfe/trunk/lib/Analysis/GRSimpleVals.cpp

Ted Kremenek kremenek at apple.com
Fri Sep 19 10:31:14 PDT 2008


Author: kremenek
Date: Fri Sep 19 12:31:13 2008
New Revision: 56351

URL: http://llvm.org/viewvc/llvm-project?rev=56351&view=rev
Log:
When we have a binary expression 'int operator symbol', properly rewrite this as
'symbol operator-reverse int'. This patch is a combination of code from
Zhongxing Xu and myself (Zhongxing noticed this bug for the cases of
relational operators).

Modified:
    cfe/trunk/lib/Analysis/GRSimpleVals.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Fri Sep 19 12:31:13 2008
@@ -126,12 +126,13 @@
 RVal GRSimpleVals::DetermEvalBinOpNN(GRStateManager& StateMgr,
                                      BinaryOperator::Opcode Op,
                                      NonLVal L, NonLVal R)  {
-  
+
   BasicValueFactory& BasicVals = StateMgr.getBasicVals();
+  unsigned subkind = L.getSubKind();
   
   while (1) {
     
-    switch (L.getSubKind()) {
+    switch (subkind) {
       default:
         return UnknownVal();
         
@@ -169,18 +170,28 @@
         
         if (isa<nonlval::ConcreteInt>(R)) {          
           const nonlval::ConcreteInt& L_CI = cast<nonlval::ConcreteInt>(L);
-          const nonlval::ConcreteInt& R_CI = cast<nonlval::ConcreteInt>(R);          
+          const nonlval::ConcreteInt& R_CI = cast<nonlval::ConcreteInt>(R);
           return L_CI.EvalBinOp(BasicVals, Op, R_CI);          
         }
         else {
+          subkind = R.getSubKind();
           NonLVal tmp = R;
           R = L;
           L = tmp;
+          
+          // Swap the operators.
+          switch (Op) {
+            case BinaryOperator::LT: Op = BinaryOperator::GT; break;
+            case BinaryOperator::GT: Op = BinaryOperator::LT; break;
+            case BinaryOperator::LE: Op = BinaryOperator::GE; break;
+            case BinaryOperator::GE: Op = BinaryOperator::LE; break;
+            default: break;
+          }
+          
           continue;
         }
         
-      case nonlval::SymbolValKind: {
-        
+      case nonlval::SymbolValKind:
         if (isa<nonlval::ConcreteInt>(R)) {
           const SymIntConstraint& C =
             BasicVals.getConstraint(cast<nonlval::SymbolVal>(L).getSymbol(), Op,
@@ -190,7 +201,6 @@
         }
         else
           return UnknownVal();
-      }
     }
   }
 }





More information about the cfe-commits mailing list