[llvm-branch-commits] [clang] [analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr (3/4) (PR #120437)
Balazs Benics via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 19 02:11:50 PST 2024
https://github.com/steakhal updated https://github.com/llvm/llvm-project/pull/120437
>From 9841a76e62ad9d9bcdea3ff8c066c19f113c2615 Mon Sep 17 00:00:00 2001
From: Balazs Benics <benicsbalazs at gmail.com>
Date: Wed, 18 Dec 2024 15:57:26 +0100
Subject: [PATCH] [analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr
(3/4)
---
.../clang/StaticAnalyzer/Core/PathSensitive/SVals.h | 7 +++++--
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 2 +-
clang/lib/StaticAnalyzer/Core/SVals.cpp | 6 +++---
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 2 +-
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index 57d7514280f10f..aeb57b28077c61 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -514,9 +514,12 @@ class MemRegionVal : public Loc {
class ConcreteInt : public Loc {
public:
- explicit ConcreteInt(const llvm::APSInt &V) : Loc(ConcreteIntKind, &V) {}
+ explicit ConcreteInt(APSIntPtr V) : Loc(ConcreteIntKind, V.get()) {}
- const llvm::APSInt &getValue() const { return *castDataAs<llvm::APSInt>(); }
+ APSIntPtr getValue() const {
+ // This is safe because in the ctor we take a safe APSIntPtr.
+ return APSIntPtr::unsafeConstructor(castDataAs<llvm::APSInt>());
+ }
static bool classof(SVal V) { return V.getKind() == ConcreteIntKind; }
};
diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 5741fff0cc12f7..6fbdc956313d57 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -671,7 +671,7 @@ class EvalCastVisitor : public SValVisitor<EvalCastVisitor, SVal> {
SVal VisitConcreteInt(loc::ConcreteInt V) {
// Pointer to bool.
if (CastTy->isBooleanType())
- return VB.makeTruthVal(V.getValue().getBoolValue(), CastTy);
+ return VB.makeTruthVal(V.getValue()->getBoolValue(), CastTy);
// Pointer to integer.
if (CastTy->isIntegralOrEnumerationType()) {
diff --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp b/clang/lib/StaticAnalyzer/Core/SVals.cpp
index ec88f52a2b3c58..3ab01a04dcec4c 100644
--- a/clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -113,7 +113,7 @@ const llvm::APSInt *SVal::getAsInteger() const {
if (auto CI = getAs<nonloc::ConcreteInt>())
return CI->getValue().get();
if (auto CI = getAs<loc::ConcreteInt>())
- return &CI->getValue();
+ return CI->getValue().get();
return nullptr;
}
@@ -249,7 +249,7 @@ bool SVal::isConstant() const {
bool SVal::isConstant(int I) const {
if (std::optional<loc::ConcreteInt> LV = getAs<loc::ConcreteInt>())
- return LV->getValue() == I;
+ return *LV->getValue().get() == I;
if (std::optional<nonloc::ConcreteInt> NV = getAs<nonloc::ConcreteInt>())
return *NV->getValue().get() == I;
return false;
@@ -380,7 +380,7 @@ void NonLoc::dumpToStream(raw_ostream &os) const {
void Loc::dumpToStream(raw_ostream &os) const {
switch (getKind()) {
case loc::ConcreteIntKind:
- os << castAs<loc::ConcreteInt>().getValue().getZExtValue() << " (Loc)";
+ os << castAs<loc::ConcreteInt>().getValue()->getZExtValue() << " (Loc)";
break;
case loc::GotoLabelKind:
os << "&&" << castAs<loc::GotoLabel>().getLabel()->getName();
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index d2e6870ad17079..136b1729c94691 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -1210,7 +1210,7 @@ const llvm::APSInt *SimpleSValBuilder::getConstValue(ProgramStateRef state,
const llvm::APSInt *SimpleSValBuilder::getConcreteValue(SVal V) {
if (std::optional<loc::ConcreteInt> X = V.getAs<loc::ConcreteInt>())
- return &X->getValue();
+ return X->getValue().get();
if (std::optional<nonloc::ConcreteInt> X = V.getAs<nonloc::ConcreteInt>())
return X->getValue().get();
More information about the llvm-branch-commits
mailing list