vabridgers created this revision. vabridgers added reviewers: NoQ, steakhal, martong. Herald added subscribers: ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun. vabridgers requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is a NFC refactoring to change makeIntValWithPtrWidth and remove getZeroWithPtrWidth to use types when forming values to match pointer widths. Some targets may have different pointer widths depending upon address space, so this needs to be comprehended. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D120134 Files: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/lib/StaticAnalyzer/Core/SValBuilder.cpp Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -742,9 +742,6 @@ // 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: Cleanup remainder of `getZeroWithPtrWidth ()` - // and `getIntWithPtrWidth()` functions to prevent future - // confusion if (!Ty->isReferenceType()) return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty), CastTy); Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1342,8 +1342,9 @@ case Stmt::GNUNullExprClass: { // GNU __null is a pointer-width integer, not an actual pointer. ProgramStateRef state = Pred->getState(); - state = state->BindExpr(S, Pred->getLocationContext(), - svalBuilder.makeIntValWithPtrWidth(0, false)); + state = state->BindExpr( + S, Pred->getLocationContext(), + svalBuilder.makeIntValWithPtrWidth(getContext().VoidPtrTy, 0)); Bldr.generateNode(S, Pred, state); break; } Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2565,9 +2565,9 @@ return nullptr; // Compare the size argument to 0. - DefinedOrUnknownSVal SizeZero = - svalBuilder.evalEQ(State, TotalSize.castAs<DefinedOrUnknownSVal>(), - svalBuilder.makeIntValWithPtrWidth(0, false)); + DefinedOrUnknownSVal SizeZero = svalBuilder.evalEQ( + State, TotalSize.castAs<DefinedOrUnknownSVal>(), + svalBuilder.makeIntValWithPtrWidth(Arg1->getType(), 0)); ProgramStateRef StatePtrIsNull, StatePtrNotNull; std::tie(StatePtrIsNull, StatePtrNotNull) = State->assume(PtrEQ); Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -332,9 +332,8 @@ return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned)); } - NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) { - return nonloc::ConcreteInt( - BasicVals.getIntWithPtrWidth(integer, isUnsigned)); + NonLoc makeIntValWithPtrWidth(QualType ptrType, uint64_t integer) { + return nonloc::ConcreteInt(BasicVals.getValue(integer, ptrType)); } NonLoc makeLocAsInteger(Loc loc, unsigned bits) { Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h @@ -220,14 +220,6 @@ return getValue(0, Ctx.getTypeSize(T), true); } - const llvm::APSInt &getZeroWithPtrWidth(bool isUnsigned = true) { - return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned); - } - - const llvm::APSInt &getIntWithPtrWidth(uint64_t X, bool isUnsigned) { - return getValue(X, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned); - } - const llvm::APSInt &getTruthValue(bool b, QualType T) { return getValue(b ? 1 : 0, Ctx.getIntWidth(T), T->isUnsignedIntegerOrEnumerationType());
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -742,9 +742,6 @@ // 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: Cleanup remainder of `getZeroWithPtrWidth ()` - // and `getIntWithPtrWidth()` functions to prevent future - // confusion if (!Ty->isReferenceType()) return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty), CastTy); Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1342,8 +1342,9 @@ case Stmt::GNUNullExprClass: { // GNU __null is a pointer-width integer, not an actual pointer. ProgramStateRef state = Pred->getState(); - state = state->BindExpr(S, Pred->getLocationContext(), - svalBuilder.makeIntValWithPtrWidth(0, false)); + state = state->BindExpr( + S, Pred->getLocationContext(), + svalBuilder.makeIntValWithPtrWidth(getContext().VoidPtrTy, 0)); Bldr.generateNode(S, Pred, state); break; } Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -2565,9 +2565,9 @@ return nullptr; // Compare the size argument to 0. - DefinedOrUnknownSVal SizeZero = - svalBuilder.evalEQ(State, TotalSize.castAs<DefinedOrUnknownSVal>(), - svalBuilder.makeIntValWithPtrWidth(0, false)); + DefinedOrUnknownSVal SizeZero = svalBuilder.evalEQ( + State, TotalSize.castAs<DefinedOrUnknownSVal>(), + svalBuilder.makeIntValWithPtrWidth(Arg1->getType(), 0)); ProgramStateRef StatePtrIsNull, StatePtrNotNull; std::tie(StatePtrIsNull, StatePtrNotNull) = State->assume(PtrEQ); Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -332,9 +332,8 @@ return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned)); } - NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) { - return nonloc::ConcreteInt( - BasicVals.getIntWithPtrWidth(integer, isUnsigned)); + NonLoc makeIntValWithPtrWidth(QualType ptrType, uint64_t integer) { + return nonloc::ConcreteInt(BasicVals.getValue(integer, ptrType)); } NonLoc makeLocAsInteger(Loc loc, unsigned bits) { Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h @@ -220,14 +220,6 @@ return getValue(0, Ctx.getTypeSize(T), true); } - const llvm::APSInt &getZeroWithPtrWidth(bool isUnsigned = true) { - return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned); - } - - const llvm::APSInt &getIntWithPtrWidth(uint64_t X, bool isUnsigned) { - return getValue(X, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned); - } - const llvm::APSInt &getTruthValue(bool b, QualType T) { return getValue(b ? 1 : 0, Ctx.getIntWidth(T), T->isUnsignedIntegerOrEnumerationType());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits