[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
Sun Sep 13 13:00:46 PDT 2026
https://github.com/benedekaibas created https://github.com/llvm/llvm-project/pull/223272
None
>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] [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 4eed56b2963b5..9adc99d2db8fc 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
More information about the llvm-branch-commits
mailing list