[llvm-branch-commits] [clang] [analyzer][NFC] Determine object parameter constness for getExtraInvalidatedValues (PR #223272)

Benedek Kaibas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 14 05:11:50 PDT 2026


https://github.com/benedekaibas updated https://github.com/llvm/llvm-project/pull/223272

>From efa7e614751cf396ed6812429ec8416644c0e2e1 Mon Sep 17 00:00:00 2001
From: benedekaibas <kaibas01 at allegheny.edu>
Date: Sun, 13 Sep 2026 21:59:50 +0200
Subject: [PATCH 1/2] [analyzer][NFC] Determine object parameter constness for
 getExtraInvalidatedValues

---
 clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index b2c81be96a6bb..d797a510f110f 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -754,6 +754,16 @@ const FunctionDecl *CXXInstanceCall::getDecl() const {
   return getSVal(CE->getCallee()).getAsFunctionDecl();
 }
 
+static bool hasConstObjectParameter(const CXXMethodDecl *MD) {
+  if (!MD->isExplicitObjectMemberFunction())
+    return MD->isConst();
+
+  QualType ObjTy = MD->getParamDecl(0)->getType();
+  if (const auto *RT = ObjTy->getAs<ReferenceType>())
+    return RT->getPointeeType().isConstQualified();
+  return true;
+}
+
 void CXXInstanceCall::getExtraInvalidatedValues(
     ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const {
   SVal ThisVal = getCXXThisVal();
@@ -761,7 +771,7 @@ void CXXInstanceCall::getExtraInvalidatedValues(
 
   // Don't invalidate if the method is const and there are no mutable fields.
   if (const auto *D = cast_or_null<CXXMethodDecl>(getDecl())) {
-    if (!D->isConst())
+    if (!hasConstObjectParameter(D))
       return;
 
     // Get the record decl for the class of 'This'. D->getParent() may return

>From 87307c6834fa33b8b0b23cca568f05c6395369f9 Mon Sep 17 00:00:00 2001
From: benedekaibas <kaibas01 at allegheny.edu>
Date: Mon, 14 Sep 2026 11:37:19 +0200
Subject: [PATCH 2/2] Add comment to explicit object parameter.

---
 clang/lib/StaticAnalyzer/Core/CallEvent.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
index d797a510f110f..4cec0852c8e24 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -758,6 +758,8 @@ static bool hasConstObjectParameter(const CXXMethodDecl *MD) {
   if (!MD->isExplicitObjectMemberFunction())
     return MD->isConst();
 
+  // An explicit object parameter has its own qualifiers instead of
+  // being described by the const-qualifier of the function type.
   QualType ObjTy = MD->getParamDecl(0)->getType();
   if (const auto *RT = ObjTy->getAs<ReferenceType>())
     return RT->getPointeeType().isConstQualified();



More information about the llvm-branch-commits mailing list