[clang] [clang][analyzer] Add StoreToImmutable checker (PR #150417)
Endre Fülöp via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 29 11:58:51 PDT 2025
================
@@ -62,22 +57,33 @@ bool StoreToImmutableChecker::isConstVariable(const MemRegion *MR,
return true;
}
- // Check if this is an ElementRegion accessing a const array
- if (const ElementRegion *ER = dyn_cast<ElementRegion>(MR)) {
- return isConstQualifiedType(ER->getSuperRegion(), C);
- }
+ // NOTE: The only kind of region that is not checked by the above branches is
+ // AllocaRegion. We do not need to check AllocaRegion, as it models untyped
+ // memory, that is allocated on the stack.
return false;
}
-bool StoreToImmutableChecker::isConstQualifiedType(const MemRegion *MR,
- CheckerContext &C) const {
- // Check if the region has a const-qualified type
- if (const TypedValueRegion *TVR = dyn_cast<TypedValueRegion>(MR)) {
- QualType Ty = TVR->getValueType();
- return Ty.isConstQualified();
+bool StoreToImmutableChecker::isEffectivelyConstRegion(
+ const MemRegion *MR, CheckerContext &C) const {
+ // If the region is an ElementRegion, we need to check if any of the super
+ // regions have const-qualified type.
+ if (const ElementRegion *ER = dyn_cast<ElementRegion>(MR)) {
----------------
gamesh411 wrote:
True, fixed
https://github.com/llvm/llvm-project/pull/150417
More information about the cfe-commits
mailing list