Skip to content

[analyzer][NFC] Migrate {SymInt,IntSym}Expr to use APSIntPtr (4/4) #120438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
const llvm::APSInt *LHS, *RHS;
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(BSE)) {
LHS = getSymVal(State, SIE->getLHS());
RHS = &SIE->getRHS();
RHS = SIE->getRHS().get();
} else if (const IntSymExpr *ISE = dyn_cast<IntSymExpr>(BSE)) {
LHS = &ISE->getLHS();
LHS = ISE->getLHS().get();
RHS = getSymVal(State, ISE->getRHS());
} else if (const SymSymExpr *SSM = dyn_cast<SymSymExpr>(BSE)) {
// Early termination to avoid expensive call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -468,11 +467,11 @@ class BinarySymExprImpl : public BinarySymExpr {
};

/// Represents a symbolic expression like 'x' + 3.
using SymIntExpr = BinarySymExprImpl<const SymExpr *, const llvm::APSInt &,
using SymIntExpr = BinarySymExprImpl<const SymExpr *, APSIntPtr,
SymExpr::Kind::SymIntExprKind>;

/// Represents a symbolic expression like 3 - 'x'.
using IntSymExpr = BinarySymExprImpl<const llvm::APSInt &, const SymExpr *,
using IntSymExpr = BinarySymExprImpl<APSIntPtr, const SymExpr *,
SymExpr::Kind::IntSymExprKind>;

/// Represents a symbolic expression like 'x' + 'y'.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ class SymbolExpressor
return Str;
if (std::optional<std::string> 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;
}
Expand Down
8 changes: 2 additions & 6 deletions clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -276,10 +275,9 @@ const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs,
return cast<SymIntExpr>(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;
Expand Down
Loading