diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h index 72038b92f8edf..7cfb24e5e649d 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h @@ -175,9 +175,9 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager { const llvm::APSInt *LHS, *RHS; if (const SymIntExpr *SIE = dyn_cast(BSE)) { LHS = getSymVal(State, SIE->getLHS()); - RHS = &SIE->getRHS(); + RHS = SIE->getRHS().get(); } else if (const IntSymExpr *ISE = dyn_cast(BSE)) { - LHS = &ISE->getLHS(); + LHS = ISE->getLHS().get(); RHS = getSymVal(State, ISE->getRHS()); } else if (const SymSymExpr *SSM = dyn_cast(BSE)) { // Early termination to avoid expensive call diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index ec2b2b2456948..54430d426a82a 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -329,11 +329,10 @@ class SValBuilder { } nonloc::SymbolVal makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, - const llvm::APSInt &rhs, QualType type); + APSIntPtr rhs, QualType type); - nonloc::SymbolVal makeNonLoc(const llvm::APSInt &rhs, - BinaryOperator::Opcode op, const SymExpr *lhs, - QualType type); + nonloc::SymbolVal makeNonLoc(APSIntPtr rhs, BinaryOperator::Opcode op, + const SymExpr *lhs, QualType type); nonloc::SymbolVal makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType type); diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h index 3b64d38ee2b23..73732d532f630 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h @@ -18,6 +18,7 @@ #include "clang/AST/Type.h" #include "clang/Analysis/AnalysisDeclContext.h" #include "clang/Basic/LLVM.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntPtr.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" #include "clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" @@ -410,9 +411,7 @@ class BinarySymExpr : public SymExpr { return 1; } - static const llvm::APSInt *getPointer(const llvm::APSInt &Value) { - return &Value; - } + static const llvm::APSInt *getPointer(APSIntPtr Value) { return Value.get(); } static const SymExpr *getPointer(const SymExpr *Value) { return Value; } static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value); @@ -468,11 +467,11 @@ class BinarySymExprImpl : public BinarySymExpr { }; /// Represents a symbolic expression like 'x' + 3. -using SymIntExpr = BinarySymExprImpl; /// Represents a symbolic expression like 3 - 'x'. -using IntSymExpr = BinarySymExprImpl; /// Represents a symbolic expression like 'x' + 'y'. @@ -537,15 +536,14 @@ class SymbolManager { QualType From, QualType To); const SymIntExpr *getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, - const llvm::APSInt& rhs, QualType t); + APSIntPtr rhs, QualType t); const SymIntExpr *getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, - const llvm::APSInt& rhs, QualType t) { + APSIntPtr rhs, QualType t) { return getSymIntExpr(&lhs, op, rhs, t); } - const IntSymExpr *getIntSymExpr(const llvm::APSInt& lhs, - BinaryOperator::Opcode op, + const IntSymExpr *getIntSymExpr(APSIntPtr lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t); const SymSymExpr *getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp index 3096999e9fd16..5534ef86a7bef 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp @@ -486,8 +486,8 @@ class SymbolExpressor return Str; if (std::optional Str = Visit(S->getLHS())) return (*Str + " " + BinaryOperator::getOpcodeStr(S->getOpcode()) + " " + - std::to_string(S->getRHS().getLimitedValue()) + - (S->getRHS().isUnsigned() ? "U" : "")) + std::to_string(S->getRHS()->getLimitedValue()) + + (S->getRHS()->isUnsigned() ? "U" : "")) .str(); return std::nullopt; } diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index 6fbdc956313d5..2b85580186381 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -76,17 +76,13 @@ DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) { nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, - const llvm::APSInt &rhs, - QualType type) { - // The Environment ensures we always get a persistent APSInt in - // BasicValueFactory, so we don't need to get the APSInt from - // BasicValueFactory again. + APSIntPtr rhs, QualType type) { assert(lhs); assert(!Loc::isLocType(type)); return nonloc::SymbolVal(SymMgr.getSymIntExpr(lhs, op, rhs, type)); } -nonloc::SymbolVal SValBuilder::makeNonLoc(const llvm::APSInt &lhs, +nonloc::SymbolVal SValBuilder::makeNonLoc(APSIntPtr lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType type) { assert(rhs); diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index 136b1729c9469..455621739f693 100644 --- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -349,7 +349,7 @@ static NonLoc doRearrangeUnchecked(ProgramStateRef State, return nonloc::SymbolVal(ResultSym); } } - const llvm::APSInt &PersistentResultInt = BV.getValue(ResultInt); + APSIntPtr PersistentResultInt = BV.getValue(ResultInt); return nonloc::SymbolVal( SymMgr.getSymIntExpr(ResultSym, ResultOp, PersistentResultInt, ResultTy)); } diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp index 9025e11a3f51a..f21e5c3ad7bd7 100644 --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -261,8 +261,7 @@ SymbolManager::getCastSymbol(const SymExpr *Op, const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, - const llvm::APSInt& v, - QualType t) { + APSIntPtr v, QualType t) { llvm::FoldingSetNodeID ID; SymIntExpr::Profile(ID, lhs, op, v, t); void *InsertPos; @@ -276,10 +275,9 @@ const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs, return cast(data); } -const IntSymExpr *SymbolManager::getIntSymExpr(const llvm::APSInt& lhs, +const IntSymExpr *SymbolManager::getIntSymExpr(APSIntPtr lhs, BinaryOperator::Opcode op, - const SymExpr *rhs, - QualType t) { + const SymExpr *rhs, QualType t) { llvm::FoldingSetNodeID ID; IntSymExpr::Profile(ID, lhs, op, rhs, t); void *InsertPos;