[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-06-19 Thread Daniel Marjamäki via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
danielmarjamaki marked an inline comment as done.
Closed by commit rL305669: [analyzer] Fix logical not for pointers with 
different bit width (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D31029?vs=99114=102999#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31029

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,6 +180,11 @@
 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: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,6 +315,13 @@
 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: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,6 +180,11 @@
 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: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,6 +315,13 @@
 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());
   }
___

[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-06-14 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Looks good with a nit!




Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:325
 
+  Loc makeNull() { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }
+

Formatting changes here look inconsistent with the rest of the code around.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-05-26 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-05-16 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 99114.
danielmarjamaki added a comment.

Fix review comments


Repository:
  rL LLVM

https://reviews.llvm.org/D31029

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


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,10 +315,15 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  /// 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()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,7 +180,12 @@
 return getValue(X);
   }
 
-  inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
+  inline const llvm::APSInt (QualType T) {
+assert(T->isScalarType());
+return getValue(0, Ctx.getTypeSize(T), true);
+  }
+
+  inline const llvm::APSInt (bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
 


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -315,10 +315,15 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  /// 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()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -180,7 +180,12 @@
 return getValue(X);
   }
 
-  inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
+  inline const llvm::APSInt (QualType T) {
+assert(T->isScalarType());
+return getValue(0, Ctx.getTypeSize(T), true);
+  }
+
+  inline const llvm::APSInt (bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
 
___

[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-05-10 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Sorry for the delay!!!




Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:180
+  inline const llvm::APSInt (QualType T,
+ bool isUnsigned = true) {
+return getValue(0, Ctx.getTypeSize(T), isUnsigned);

The isUnsigned parameter is not used and is not necessary as the type itself 
has this info.

Not clear if this function is expected to work for all types or only scalar 
types (maybe assert that the input is isScalarType()).


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-04-25 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

Ping


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-04-18 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

Ping


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-04-03 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

Ping


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-23 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki marked an inline comment as done.
danielmarjamaki added a comment.

In https://reviews.llvm.org/D31029#708567, @danielmarjamaki wrote:

> In https://reviews.llvm.org/D31029#703428, @zaks.anna wrote:
>
> > Are there other cases where makeNull would need to be replaced?
>
>
> There might be. As I understand it, this is the only known case at the moment.


To clarify. The static analyser runs fine on plenty of code. I ran CSA using 
this target on a 1000's of C-files project. I think it works well.. but I can't 
guarantee there won't be any more issues.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-23 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

In https://reviews.llvm.org/D31029#703428, @zaks.anna wrote:

> Are there other cases where makeNull would need to be replaced?


There might be. As I understand it, this is the only known case at the moment.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-23 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 92773.
danielmarjamaki added a comment.

Added a testcase that will crash without the fix. Used the amdgcn target as 
that happens to use different pointer bit widths for different address spaces.

Updated the comment. I am not good at english so I hope the grammar is ok.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Analysis/ptr.cl


Index: test/Analysis/ptr.cl
===
--- test/Analysis/ptr.cl
+++ test/Analysis/ptr.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -target-cpu verde 
-analyze -analyzer-checker=core %s
+
+#define __cm __attribute__((address_space(256)))
+
+// Don't crash when pointer bit-widths are different for different address 
spaces
+void dontCrash(void) {
+  __cm void *cm_p = 0;
+  if (!cm_p)
+(void)cm_p;
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -310,10 +310,15 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  /// 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()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -176,7 +176,12 @@
 return getValue(X);
   }
 
-  inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
+  inline const llvm::APSInt (QualType T,
+ bool isUnsigned = true) {
+return getValue(0, Ctx.getTypeSize(T), isUnsigned);
+  }
+
+  inline const llvm::APSInt (bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }
 


Index: test/Analysis/ptr.cl
===
--- test/Analysis/ptr.cl
+++ test/Analysis/ptr.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown -target-cpu verde -analyze -analyzer-checker=core %s
+
+#define __cm __attribute__((address_space(256)))
+
+// Don't crash when pointer bit-widths are different for different address spaces
+void dontCrash(void) {
+  __cm void *cm_p = 0;
+  if (!cm_p)
+(void)cm_p;
+}
Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -310,10 +310,15 @@
 return 

[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-16 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Are there other cases where makeNull would need to be replaced?


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-16 Thread Noel Grandin via Phabricator via cfe-commits
grandinj added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:313
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  // Pass type to accomodate for different pointer bit-witdths of different
+  // address spaces.

spelling and grammar and doxygen formatting:

/// \param type accommodate different pointer bit-widths of different address 
spaces.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-16 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

I am not sure where to look. I heard somebody say OpenCL has different pointer 
widths.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-16 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

So there is no LLVM supported target with different bit width pointer types?

In case we have such a target upstreamed, you can add a test with the 
host-triple hardcoded into the test.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31029: [analyzer] Fix logical not for pointers with different bit width

2017-03-16 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki created this revision.

The Static Analyzer assumed that all pointers had the same bit width. Now pass 
the type to the 'makeNull' method, to construct a null
pointer of the appropiate bit width.

Example code that does not work well:

  int main(void) {
    __cm void *cm_p = 0;
    if (cm_p == 0)
      (void)cm_p;
  }

Unfortunately there is no proper testcase here. The problem is seen with a 
custom target.


Repository:
  rL LLVM

https://reviews.llvm.org/D31029

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


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -310,10 +310,14 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  // Pass type to accomodate for different pointer bit-witdths of different
+  // address spaces.
+  Loc makeNullWithType(QualType type) {
+return loc::ConcreteInt(BasicVals.getZeroWithTypeSize(type));
   }
 
+  Loc makeNull() { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -176,6 +176,11 @@
 return getValue(X);
   }
 
+  inline const llvm::APSInt (QualType T,
+ bool isUnsigned = true) {
+return getValue(0, Ctx.getTypeSize(T), isUnsigned);
+  }
+
   inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) {
 return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
   }


Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -980,10 +980,9 @@
   //transfer functions as "0 == E".
   SVal Result;
   if (Optional LV = V.getAs()) {
-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 {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -310,10 +310,14 @@
 return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
   }
 
-  Loc makeNull() {
-return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+  // Pass type to accomodate for different pointer bit-witdths of different
+  // address spaces.
+  Loc makeNullWithType(QualType type) {
+return loc::ConcreteInt(BasicVals.getZeroWithTypeSize(type));
   }
 
+  Loc makeNull() { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }
+
   Loc makeLoc(SymbolRef sym) {
 return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -176,6 +176,11 @@
 return getValue(X);
   }
 
+  inline const llvm::APSInt (QualType T,
+ bool isUnsigned = true) {
+return