Skip to content

Commit ffda105

Browse files
committed
[analyzer][NFC] Migrate {SymInt,IntSym}Expr to use APSIntPtr (4/4)
1 parent 81c7a28 commit ffda105

File tree

7 files changed

+20
-29
lines changed

7 files changed

+20
-29
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ class SMTConstraintManager : public clang::ento::SimpleConstraintManager {
175175
const llvm::APSInt *LHS, *RHS;
176176
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(BSE)) {
177177
LHS = getSymVal(State, SIE->getLHS());
178-
RHS = &SIE->getRHS();
178+
RHS = SIE->getRHS().get();
179179
} else if (const IntSymExpr *ISE = dyn_cast<IntSymExpr>(BSE)) {
180-
LHS = &ISE->getLHS();
180+
LHS = ISE->getLHS().get();
181181
RHS = getSymVal(State, ISE->getRHS());
182182
} else if (const SymSymExpr *SSM = dyn_cast<SymSymExpr>(BSE)) {
183183
// Early termination to avoid expensive call

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,10 @@ class SValBuilder {
329329
}
330330

331331
nonloc::SymbolVal makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
332-
const llvm::APSInt &rhs, QualType type);
332+
APSIntPtr rhs, QualType type);
333333

334-
nonloc::SymbolVal makeNonLoc(const llvm::APSInt &rhs,
335-
BinaryOperator::Opcode op, const SymExpr *lhs,
336-
QualType type);
334+
nonloc::SymbolVal makeNonLoc(APSIntPtr rhs, BinaryOperator::Opcode op,
335+
const SymExpr *lhs, QualType type);
337336

338337
nonloc::SymbolVal makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
339338
const SymExpr *rhs, QualType type);

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/AST/Type.h"
1919
#include "clang/Analysis/AnalysisDeclContext.h"
2020
#include "clang/Basic/LLVM.h"
21+
#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntPtr.h"
2122
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
2223
#include "clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h"
2324
#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
@@ -410,9 +411,7 @@ class BinarySymExpr : public SymExpr {
410411
return 1;
411412
}
412413

413-
static const llvm::APSInt *getPointer(const llvm::APSInt &Value) {
414-
return &Value;
415-
}
414+
static const llvm::APSInt *getPointer(APSIntPtr Value) { return Value.get(); }
416415
static const SymExpr *getPointer(const SymExpr *Value) { return Value; }
417416

418417
static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value);
@@ -468,11 +467,11 @@ class BinarySymExprImpl : public BinarySymExpr {
468467
};
469468

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

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

478477
/// Represents a symbolic expression like 'x' + 'y'.
@@ -537,15 +536,14 @@ class SymbolManager {
537536
QualType From, QualType To);
538537

539538
const SymIntExpr *getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op,
540-
const llvm::APSInt& rhs, QualType t);
539+
APSIntPtr rhs, QualType t);
541540

542541
const SymIntExpr *getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op,
543-
const llvm::APSInt& rhs, QualType t) {
542+
APSIntPtr rhs, QualType t) {
544543
return getSymIntExpr(&lhs, op, rhs, t);
545544
}
546545

547-
const IntSymExpr *getIntSymExpr(const llvm::APSInt& lhs,
548-
BinaryOperator::Opcode op,
546+
const IntSymExpr *getIntSymExpr(APSIntPtr lhs, BinaryOperator::Opcode op,
549547
const SymExpr *rhs, QualType t);
550548

551549
const SymSymExpr *getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op,

clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ class SymbolExpressor
486486
return Str;
487487
if (std::optional<std::string> Str = Visit(S->getLHS()))
488488
return (*Str + " " + BinaryOperator::getOpcodeStr(S->getOpcode()) + " " +
489-
std::to_string(S->getRHS().getLimitedValue()) +
490-
(S->getRHS().isUnsigned() ? "U" : ""))
489+
std::to_string(S->getRHS()->getLimitedValue()) +
490+
(S->getRHS()->isUnsigned() ? "U" : ""))
491491
.str();
492492
return std::nullopt;
493493
}

clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,13 @@ DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
7676

7777
nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *lhs,
7878
BinaryOperator::Opcode op,
79-
const llvm::APSInt &rhs,
80-
QualType type) {
81-
// The Environment ensures we always get a persistent APSInt in
82-
// BasicValueFactory, so we don't need to get the APSInt from
83-
// BasicValueFactory again.
79+
APSIntPtr rhs, QualType type) {
8480
assert(lhs);
8581
assert(!Loc::isLocType(type));
8682
return nonloc::SymbolVal(SymMgr.getSymIntExpr(lhs, op, rhs, type));
8783
}
8884

89-
nonloc::SymbolVal SValBuilder::makeNonLoc(const llvm::APSInt &lhs,
85+
nonloc::SymbolVal SValBuilder::makeNonLoc(APSIntPtr lhs,
9086
BinaryOperator::Opcode op,
9187
const SymExpr *rhs, QualType type) {
9288
assert(rhs);

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static NonLoc doRearrangeUnchecked(ProgramStateRef State,
349349
return nonloc::SymbolVal(ResultSym);
350350
}
351351
}
352-
const llvm::APSInt &PersistentResultInt = BV.getValue(ResultInt);
352+
APSIntPtr PersistentResultInt = BV.getValue(ResultInt);
353353
return nonloc::SymbolVal(
354354
SymMgr.getSymIntExpr(ResultSym, ResultOp, PersistentResultInt, ResultTy));
355355
}

clang/lib/StaticAnalyzer/Core/SymbolManager.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ SymbolManager::getCastSymbol(const SymExpr *Op,
261261

262262
const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs,
263263
BinaryOperator::Opcode op,
264-
const llvm::APSInt& v,
265-
QualType t) {
264+
APSIntPtr v, QualType t) {
266265
llvm::FoldingSetNodeID ID;
267266
SymIntExpr::Profile(ID, lhs, op, v, t);
268267
void *InsertPos;
@@ -276,10 +275,9 @@ const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs,
276275
return cast<SymIntExpr>(data);
277276
}
278277

279-
const IntSymExpr *SymbolManager::getIntSymExpr(const llvm::APSInt& lhs,
278+
const IntSymExpr *SymbolManager::getIntSymExpr(APSIntPtr lhs,
280279
BinaryOperator::Opcode op,
281-
const SymExpr *rhs,
282-
QualType t) {
280+
const SymExpr *rhs, QualType t) {
283281
llvm::FoldingSetNodeID ID;
284282
IntSymExpr::Profile(ID, lhs, op, rhs, t);
285283
void *InsertPos;

0 commit comments

Comments
 (0)