]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix logical not for pointers with different bit width
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>
Mon, 19 Jun 2017 08:55:51 +0000 (08:55 +0000)
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>
Mon, 19 Jun 2017 08:55:51 +0000 (08:55 +0000)
Differential Revision: https://reviews.llvm.org/D31029

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

include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
lib/StaticAnalyzer/Core/ExprEngineC.cpp

index fb427f6185759be356a84e1db63442a8a32d9480..b8ec2aa6ae8d214edc361bb3f097c97eb56b6da1 100644 (file)
@@ -180,6 +180,11 @@ public:
     return getValue(X);
   }
 
+  inline const llvm::APSInt& getZeroWithTypeSize(QualType T) {
+    assert(T->isScalarType());
+    return getValue(0, Ctx.getTypeSize(T), true);
+  }
+
   inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
     return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
index 14aa3af37620acb621eb74f4a14f5047ef6fa202..d58d0a690c88eec8f055d9654f06d29b7cd15675 100644 (file)
@@ -315,6 +315,13 @@ public:
     return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
+  /// Create NULL pointer, with proper pointer bit-width for given address
+  /// space.
+  /// \param type pointer type.
+  Loc makeNullWithType(QualType type) {
+    return loc::ConcreteInt(BasicVals.getZeroWithTypeSize(type));
+  }
+
   Loc makeNull() {
     return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
   }
index 8f720a2067b153ce489669c273296295a207cecf..6f1e8391e67cf0423b31c15f18cc24946519ece8 100644 (file)
@@ -980,10 +980,9 @@ void ExprEngine::VisitUnaryOperator(const UnaryOperator* U, ExplodedNode *Pred,
           //    transfer functions as "0 == E".
           SVal Result;
           if (Optional<Loc> LV = V.getAs<Loc>()) {
-            Loc X = svalBuilder.makeNull();
+            Loc X = svalBuilder.makeNullWithType(Ex->getType());
             Result = evalBinOp(state, BO_EQ, *LV, X, U->getType());
-          }
-          else if (Ex->getType()->isFloatingType()) {
+          } else if (Ex->getType()->isFloatingType()) {
             // FIXME: handle floating point types.
             Result = UnknownVal();
           } else {