Skip to content

Commit 0daf63e

Browse files
committed
[analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr (3/4)
1 parent 09aa29d commit 0daf63e

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,12 @@ class MemRegionVal : public Loc {
514514

515515
class ConcreteInt : public Loc {
516516
public:
517-
explicit ConcreteInt(const llvm::APSInt &V) : Loc(ConcreteIntKind, &V) {}
517+
explicit ConcreteInt(APSIntPtr V) : Loc(ConcreteIntKind, V.get()) {}
518518

519-
const llvm::APSInt &getValue() const { return *castDataAs<llvm::APSInt>(); }
519+
APSIntPtr getValue() const {
520+
// This is safe because in the ctor we take a safe APSIntPtr.
521+
return APSIntPtr::unsafeConstructor(castDataAs<llvm::APSInt>());
522+
}
520523

521524
static bool classof(SVal V) { return V.getKind() == ConcreteIntKind; }
522525
};

clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class EvalCastVisitor : public SValVisitor<EvalCastVisitor, SVal> {
671671
SVal VisitConcreteInt(loc::ConcreteInt V) {
672672
// Pointer to bool.
673673
if (CastTy->isBooleanType())
674-
return VB.makeTruthVal(V.getValue().getBoolValue(), CastTy);
674+
return VB.makeTruthVal(V.getValue()->getBoolValue(), CastTy);
675675

676676
// Pointer to integer.
677677
if (CastTy->isIntegralOrEnumerationType()) {

clang/lib/StaticAnalyzer/Core/SVals.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const llvm::APSInt *SVal::getAsInteger() const {
113113
if (auto CI = getAs<nonloc::ConcreteInt>())
114114
return CI->getValue().get();
115115
if (auto CI = getAs<loc::ConcreteInt>())
116-
return &CI->getValue();
116+
return CI->getValue().get();
117117
return nullptr;
118118
}
119119

@@ -249,7 +249,7 @@ bool SVal::isConstant() const {
249249

250250
bool SVal::isConstant(int I) const {
251251
if (std::optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
252-
return LV->getValue() == I;
252+
return *LV->getValue().get() == I;
253253
if (std::optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
254254
return *NV->getValue().get() == I;
255255
return false;
@@ -380,7 +380,7 @@ void NonLoc::dumpToStream(raw_ostream &os) const {
380380
void Loc::dumpToStream(raw_ostream &os) const {
381381
switch (getKind()) {
382382
case loc::ConcreteIntKind:
383-
os << castAs<loc::ConcreteInt>().getValue().getZExtValue() << " (Loc)";
383+
os << castAs<loc::ConcreteInt>().getValue()->getZExtValue() << " (Loc)";
384384
break;
385385
case loc::GotoLabelKind:
386386
os << "&&" << castAs<loc::GotoLabel>().getLabel()->getName();

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ const llvm::APSInt *SimpleSValBuilder::getConstValue(ProgramStateRef state,
12101210

12111211
const llvm::APSInt *SimpleSValBuilder::getConcreteValue(SVal V) {
12121212
if (std::optional<loc::ConcreteInt> X = V.getAs<loc::ConcreteInt>())
1213-
return &X->getValue();
1213+
return X->getValue().get();
12141214

12151215
if (std::optional<nonloc::ConcreteInt> X = V.getAs<nonloc::ConcreteInt>())
12161216
return X->getValue().get();

0 commit comments

Comments
 (0)