[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 02:37:40 PDT 2026
https://github.com/benedekaibas updated https://github.com/llvm/llvm-project/pull/223272
>From da57c792cdcd9a423681f821298a83ca17ddcc34 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 4eed56b2963b53..9adc99d2db8fcc 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -758,6 +758,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();
@@ -765,7 +775,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 351f73349ce82f59aa6bc10e8502056de08b27d2 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 9adc99d2db8fcc..38debfecfd91a4 100644
--- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -762,6 +762,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