Author: Vince Bridgers Date: 2021-08-10T16:12:52-05:00 New Revision: d39ebdae674c8efc84ebe8dc32716ec353220530
URL: https://github.com/llvm/llvm-project/commit/d39ebdae674c8efc84ebe8dc32716ec353220530 DIFF: https://github.com/llvm/llvm-project/commit/d39ebdae674c8efc84ebe8dc32716ec353220530.diff LOG: [analyzer] Cleanup a FIXME in SValBuilder.cpp This change follows up on a FIXME submitted with D105974. This change simply let's the reference case fall through to return a concrete 'true' instead of a nonloc pointer of appropriate length set to NULL. Reviewed By: NoQ Differential Revision: https://reviews.llvm.org/D107720 Added: clang/test/Analysis/solver-sym-simplification-bool.cpp Modified: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index b459b5adb5110..8d27ba3e65c46 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -725,16 +725,12 @@ SVal SValBuilder::evalCastSubKind(loc::MemRegionVal V, QualType CastTy, // 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); diff --git a/clang/test/Analysis/solver-sym-simplification-bool.cpp b/clang/test/Analysis/solver-sym-simplification-bool.cpp new file mode 100644 index 0000000000000..0e7633dfb87e0 --- /dev/null +++ b/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}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits