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

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 31 06:44:53 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);
----------------
NagyDonat wrote:

I agree that further investigations may be warranted (and perhaps I'll spend some time on it).

However, this is a nice self-contained fix for a crash, so I think it is nice to merge it as a stand-alone commit (leaving further more general changes for follow-up changes).

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


More information about the cfe-commits mailing list