]> granicus.if.org Git - clang/commitdiff
Refactored code for transfer functions for binary operators involving two LValues.
authorTed Kremenek <kremenek@apple.com>
Fri, 15 Feb 2008 23:15:23 +0000 (23:15 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 15 Feb 2008 23:15:23 +0000 (23:15 +0000)
Fixed bug in transfer functions for sizeof(*); we were incorrectly evaluating to
a value of the wrong type.

Fixed bug in transfer functions for compound assignments where we did not properly
handle assignments involving dereferences of symbolic values.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47190 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/GRExprEngine.cpp
Analysis/GRSimpleVals.cpp
Analysis/GRSimpleVals.h
Analysis/GRTransferFuncs.cpp
include/clang/Analysis/PathSensitive/GRTransferFuncs.h

index 33f7f5150439b09bf5f6c75d9bfd7e90379f73d1..4bcdd5fb70fd696487a45beafa39222b42557100 100644 (file)
@@ -473,7 +473,7 @@ void GRExprEngine::VisitSizeOfAlignOfTypeExpr(SizeOfAlignOfTypeExpr* S,
   
   Nodify(Dst, S, Pred,
          SetValue(Pred->getState(), S,
-                  NonLValue::GetValue(ValMgr, size, getContext().IntTy, L)));
+                  NonLValue::GetValue(ValMgr, size, S->getType(), L)));
   
 }
 
@@ -573,7 +573,7 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U,
                 
         Nodify(Dst, U, N1,
                SetValue(St, U, NonLValue::GetValue(ValMgr, size,
-                                                   getContext().IntTy, L)));
+                                                   U->getType(), L)));
         
         break;
       }
@@ -730,15 +730,20 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
               Result = EvalBinaryOp(ValMgr, Op, L1, L2);
             }
             else {
+              QualType T1 = B->getLHS()->getType();
+              QualType T2 = B->getRHS()->getType();
+              
               // An operation between two variables of a non-lvalue type.
               Result =
                 EvalBinaryOp(ValMgr, Op,
-                             cast<NonLValue>(GetValue(N1->getState(), L1)),
-                             cast<NonLValue>(GetValue(N2->getState(), L2)));
+                            cast<NonLValue>(GetValue(N1->getState(), L1, &T1)),
+                            cast<NonLValue>(GetValue(N2->getState(), L2, &T2)));
             }
           }
           else { // Any other operation between two Non-LValues.
-            const NonLValue& R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
+            QualType T = B->getLHS()->getType();
+            const NonLValue& R1 = cast<NonLValue>(GetValue(N1->getState(),
+                                                           L1, &T));
             const NonLValue& R2 = cast<NonLValue>(V2);
             Result = EvalBinaryOp(ValMgr, Op, R1, R2);
           }
index c9827d9d10501970656f24d49f8598fbc639ac4b..75dc256d79709157b6be18b95caeec4db8213615 100644 (file)
@@ -163,6 +163,24 @@ NonLValue GRSimpleVals::EvalBinaryOp(ValueManager& ValMgr,
 }
 
 
+// Binary Operators (except assignments and comma).
+
+RValue GRSimpleVals::EvalBinaryOp(ValueManager& ValMgr,
+                                  BinaryOperator::Opcode Op,
+                                  LValue LHS, LValue RHS) {
+  
+  switch (Op) {
+    default:
+      return UnknownVal();
+      
+    case BinaryOperator::EQ:
+      return EvalEQ(ValMgr, LHS, RHS);
+      
+    case BinaryOperator::NE:
+      return EvalNE(ValMgr, LHS, RHS);      
+  }
+}
+
 // Pointer arithmetic.
 
 LValue GRSimpleVals::EvalBinaryOp(ValueManager& ValMgr,
index b00dd3ca39d69a1100c41188e6ea8f67616e59ce..34b1d4f183cf66d24e9b00f62c2a9f5eda85d9ee 100644 (file)
@@ -44,14 +44,19 @@ public:
                                  BinaryOperator::Opcode Op,
                                  NonLValue LHS, NonLValue RHS);
   
+  virtual RValue EvalBinaryOp(ValueManager& ValMgr,
+                              BinaryOperator::Opcode Op,
+                              LValue LHS, LValue RHS);
+  
   // Pointer arithmetic.
   
   virtual LValue EvalBinaryOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
                               LValue LHS, NonLValue RHS);  
   
+protected:
   // Equality operators for LValues.
-  virtual NonLValue EvalEQ(ValueManager& ValMgr, LValue LHS, LValue RHS);
-  virtual NonLValue EvalNE(ValueManager& ValMgr, LValue LHS, LValue RHS);
+  NonLValue EvalEQ(ValueManager& ValMgr, LValue LHS, LValue RHS);
+  NonLValue EvalNE(ValueManager& ValMgr, LValue LHS, LValue RHS);
 };
   
   
index 33663d6c60dd9884a7782fe64cb5ba5e0ce55736..3716ed9691096891bedfbcfff4cbba4a9cf41731 100644 (file)
@@ -39,21 +39,3 @@ RValue GRTransferFuncs::EvalCast(ValueManager& ValMgr, RValue X,
   
   return X;
 }
-
-// Binary Operators (except assignments and comma).
-
-RValue GRTransferFuncs::EvalBinaryOp(ValueManager& ValMgr,
-                                     BinaryOperator::Opcode Op,
-                                     LValue LHS, LValue RHS) {
-  
-  switch (Op) {
-    default:
-      assert (false && "Not yet implemented.");
-      
-    case BinaryOperator::EQ:
-      return EvalEQ(ValMgr, LHS, RHS);
-      
-    case BinaryOperator::NE:
-      return EvalNE(ValMgr, LHS, RHS);
-  }
-}
\ No newline at end of file
index 19e87dcd943185b57b155faa9c4a04fbd5c3cb2f..53491d532e5e46b6fa77a6990339ed8ae8132ee2 100644 (file)
@@ -43,9 +43,9 @@ public:
                                  BinaryOperator::Opcode Op,
                                  NonLValue LHS, NonLValue RHS) = 0;
   
-  RValue EvalBinaryOp(ValueManager& ValMgr,
-                      BinaryOperator::Opcode Op,
-                      LValue LHS, LValue RHS);
+  virtual RValue EvalBinaryOp(ValueManager& ValMgr,
+                              BinaryOperator::Opcode Op,
+                              LValue LHS, LValue RHS) = 0;
   
   // Pointer arithmetic.
   
@@ -64,11 +64,6 @@ public:
     else
       return EvalBinaryOp(ValMgr, Op, cast<NonLValue>(L), cast<NonLValue>(R));
   }
-  
-  
-  // Equality operators for LValues.
-  virtual NonLValue EvalEQ(ValueManager& ValMgr, LValue LHS, LValue RHS) = 0;
-  virtual NonLValue EvalNE(ValueManager& ValMgr, LValue LHS, LValue RHS) = 0;
 };
   
 } // end clang namespace