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

Ted Kremenek kremenek at apple.com
Fri Jul 18 08:46:06 PDT 2008


Author: kremenek
Date: Fri Jul 18 10:46:06 2008
New Revision: 53752

URL: http://llvm.org/viewvc/llvm-project?rev=53752&view=rev
Log:
Improve path-sensitivity when using the logical not operator.

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=53752&r1=53751&r2=53752&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Fri Jul 18 10:46:06 2008
@@ -450,6 +450,15 @@
 
 // Binary operators.
 
+static unsigned char LNotOpMap[] = {
+  (unsigned char) BinaryOperator::GE,  /* LT => GE */
+  (unsigned char) BinaryOperator::LE,  /* GT => LE */
+  (unsigned char) BinaryOperator::GT,  /* LE => GT */
+  (unsigned char) BinaryOperator::LT,  /* GE => LT */
+  (unsigned char) BinaryOperator::NE,  /* EQ => NE */
+  (unsigned char) BinaryOperator::EQ   /* NE => EQ */
+};
+
 RVal GRSimpleVals::DetermEvalBinOpNN(ValueStateManager& StateMgr,
                                      BinaryOperator::Opcode Op,
                                      NonLVal L, NonLVal R)  {
@@ -462,6 +471,31 @@
       default:
         return UnknownVal();
         
+      case nonlval::SymIntConstraintValKind: {
+        const SymIntConstraint& C =
+          cast<nonlval::SymIntConstraintVal>(L).getConstraint();
+        
+        BinaryOperator::Opcode Opc = C.getOpcode();
+
+        if (Opc < BinaryOperator::LT || Opc > BinaryOperator::NE)
+          return UnknownVal();
+
+        // For comparison operators, translate the constraint by
+        // changing the opcode.
+        
+        int idx = (unsigned) Opc - (unsigned) BinaryOperator::LT;
+        
+        assert (idx >= 0 && 
+                (unsigned) idx < sizeof(LNotOpMap)/sizeof(unsigned char));
+        
+        Opc = (BinaryOperator::Opcode) LNotOpMap[idx];
+        
+        const SymIntConstraint& CNew =
+          BasicVals.getConstraint(C.getSymbol(), Opc, C.getInt());
+        
+        return nonlval::SymIntConstraintVal(CNew);
+      }
+        
       case nonlval::ConcreteIntKind:
         
         if (isa<nonlval::ConcreteInt>(R)) {          





More information about the cfe-commits mailing list