[PATCH] D107720: [analyzer] Cleanup a FIXME in SValBuilder.cpp

Vince Bridgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 10 11:01:51 PDT 2021


vabridgers updated this revision to Diff 365546.
vabridgers added a comment.

add test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107720/new/

https://reviews.llvm.org/D107720

Files:
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
  clang/test/Analysis/solver-sym-simplification-bool.cpp
  clang/test/Analysis/solver-sym-simplification-bool2.cpp


Index: clang/test/Analysis/solver-sym-simplification-bool2.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool2.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -Wno-unused-value -verify %s
+
+void clang_analyzer_dump(bool);
+
+void fee(int *p) {
+  int *q = p - 1;
+  q &&q;
+  q &&q;
+  clang_analyzer_dump(q && q);
+  // expected-warning at -1{{((reg_$0<int * p>) != 0U) != 0U}}}
+  // expected-warning at -2{{0 U1b}}
+  (void)q;
+}
Index: clang/test/Analysis/solver-sym-simplification-bool.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/solver-sym-simplification-bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core \
+// RUN: -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_dump(bool);
+
+void foo(int &x) {
+  int *p = &x; // 'p' is the same SVal as 'x'
+  bool b = p;
+  clang_analyzer_dump(b); // expected-warning {{1 U1b}}
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -725,16 +725,12 @@
       // This change is needed for architectures with varying
       // pointer widths. See the amdgcn opencl reproducer with
       // this change as an example: solver-sym-simplification-ptr-bool.cl
-      // FIXME: We could encounter a reference here,
-      //        try returning a concrete 'true' since it might
-      //        be easier on the solver.
       // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
       //        and `getIntWithPtrWidth()` functions to prevent future
       //        confusion
-      const llvm::APSInt &Zero = Ty->isReferenceType()
-                                     ? BasicVals.getZeroWithPtrWidth()
-                                     : BasicVals.getZeroWithTypeSize(Ty);
-      return makeNonLoc(Sym, BO_NE, Zero, CastTy);
+      if (!Ty->isReferenceType())
+        return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
+                          CastTy);
     }
     // Non-symbolic memory regions are always true.
     return makeTruthVal(true, CastTy);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107720.365546.patch
Type: text/x-patch
Size: 2388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210810/e9b841e3/attachment-0001.bin>


More information about the cfe-commits mailing list