Skip to content

[analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr (3/4) #120437

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

Conversation

steakhal
Copy link
Contributor

No description provided.

Copy link
Contributor Author

steakhal commented Dec 18, 2024

@steakhal steakhal marked this pull request as ready for review December 18, 2024 15:25
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Dec 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 18, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/120437.diff

4 Files Affected:

  • (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h (+5-2)
  • (modified) clang/lib/StaticAnalyzer/Core/SValBuilder.cpp (+1-1)
  • (modified) clang/lib/StaticAnalyzer/Core/SVals.cpp (+3-3)
  • (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+1-1)
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();

@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-2 branch from bda8441 to d9ce18f Compare December 19, 2024 10:11
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-3 branch from 81c7a28 to 9841a76 Compare December 19, 2024 10:11
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-2 branch from d9ce18f to 09aa29d Compare December 19, 2024 10:19
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-3 branch from 9841a76 to 0daf63e Compare December 19, 2024 10:20
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-2 branch from 09aa29d to 75579cb Compare December 19, 2024 11:05
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-3 branch from 0daf63e to e82a47f Compare December 19, 2024 11:06
Base automatically changed from users/steakhal/bb/fix-dangling-aps-ints-2 to main December 19, 2024 11:51
@steakhal steakhal force-pushed the users/steakhal/bb/fix-dangling-aps-ints-3 branch from e82a47f to c7e3bc0 Compare December 19, 2024 11:53
@steakhal steakhal merged commit 13e20bc into main Dec 19, 2024
5 of 6 checks passed
Copy link
Contributor Author

Merge activity

  • Dec 19, 6:57 AM EST: A user merged this pull request with Graphite.

@steakhal steakhal deleted the users/steakhal/bb/fix-dangling-aps-ints-3 branch December 19, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants