[clang] [analyzer] Fix getElementRegion to retain address space information (PR #151249)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 30 06:09:59 PDT 2025
================
@@ -8274,6 +8275,15 @@ inline void QualType::removeLocalVolatile() {
removeLocalFastQualifiers(Qualifiers::Volatile);
}
+inline QualType QualType::removeNonAddressSpaceQualifiers() {
+ if (getQualifiers().hasTargetSpecificAddressSpace()) {
+ removeLocalFastQualifiers();
+ } else {
+ return getCanonicalType().getUnqualifiedType();
+ }
+ return *this;
+}
----------------
steakhal wrote:
I'm not sure how broadly this function is useful for anyone else.
If only the static analyzer uses this, then probably we should just have this as a static helper there instead.
```suggestion
inline QualType QualType::removeNonAddressSpaceQualifiers() {
if (getQualifiers().hasTargetSpecificAddressSpace()) {
removeLocalFastQualifiers();
return *this;
}
return getCanonicalType().getUnqualifiedType();
}
```
BTW I'm not really familiar with the QualType methods, but I was not expecting mutations if we anyway return a value. What I'd expect when calling this function that this would not mutate (and have side effect) the object itself but just return the right value instead.
This semantic is usually achieved by taking a copy of self, apply the mutation on the copy and return the mutated copy.
Alternatively, you could decide to have a `void` return type to solve this inconsistency, and clearly admit that calling this has side effects.
https://github.com/llvm/llvm-project/pull/151249
More information about the cfe-commits
mailing list