[clang] [analyzer] Retain address space information in getElementRegion (PR #151370)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 31 03:09:05 PDT 2025


================
@@ -1219,6 +1219,16 @@ MemRegionManager::getElementRegion(QualType elementType, NonLoc Idx,
                                    const ASTContext &Ctx) {
   QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType();
 
+  // The address space must be preserved because some target-specific address
+  // spaces influence the size of the pointer value which is represented by the
+  // element region.
+  LangAS AS = elementType.getAddressSpace();
+  if (AS != LangAS::Default) {
+    Qualifiers Quals;
+    Quals.setAddressSpace(AS);
----------------
steakhal wrote:

My next question would be, is this the only place that deserves this check?
I'm thinking of the lack of proper cast modeling may not always trigger the creation of an element region thus avoids this code path. WDYT?

Personally, I'm not too concerned. This patch isn't too intrusive and the use cases are narrow, and this patch strictly improves the status quo so I think I'm fine with this.
It this problem comes up again, we should investigate more what could we do to generally avoid this issue.

https://github.com/llvm/llvm-project/pull/151370


More information about the cfe-commits mailing list