[clang] [Clang] Fix crash when transforming a `DependentAddressSpaceType` (PR #102206)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 6 13:17:13 PDT 2024


https://github.com/Sirraide updated https://github.com/llvm/llvm-project/pull/102206

>From 07db2e9c85dd15a948b969be3c3d32579f790d74 Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Tue, 6 Aug 2024 21:42:23 +0200
Subject: [PATCH 1/2] [Clang] Fix crash when transforming a
 DependentAddressSpaceType

---
 clang/docs/ReleaseNotes.rst                         |  1 +
 clang/lib/Sema/TreeTransform.h                      |  5 +++--
 clang/test/SemaTemplate/address_space-dependent.cpp | 13 +++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f50ab07f1fc0..3ad87c68e28d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,7 @@ Bug Fixes in This Version
 - Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
   be used in C++.
 - Fixed a failed assertion when checking required literal types in C context. (#GH101304).
+- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 540e1e0cb8df0..fd96ebd812343 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5803,7 +5803,8 @@ QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
     TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
   const DependentAddressSpaceType *T = TL.getTypePtr();
 
-  QualType pointeeType = getDerived().TransformType(T->getPointeeType());
+  QualType pointeeType =
+      getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
 
   if (pointeeType.isNull())
     return QualType();
@@ -5838,7 +5839,7 @@ QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
   } else {
     TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
         Result, getDerived().getBaseLocation());
-    TransformType(TLB, DI->getTypeLoc());
+    TLB.TypeWasModifiedSafely(DI->getType());
   }
 
   return Result;
diff --git a/clang/test/SemaTemplate/address_space-dependent.cpp b/clang/test/SemaTemplate/address_space-dependent.cpp
index c8cc67ef45211..2ca9b8007ab41 100644
--- a/clang/test/SemaTemplate/address_space-dependent.cpp
+++ b/clang/test/SemaTemplate/address_space-dependent.cpp
@@ -117,3 +117,16 @@ int main() {
 
   return 0;
 }
+
+namespace gh101685 {
+template <int AS>
+using ASPtrTy = void [[clang::address_space(AS)]] *;
+
+template <int AS>
+struct EntryTy {
+  ASPtrTy<AS> Base;
+};
+
+ASPtrTy<1> x;
+EntryTy<2> y;
+}

>From ed7bd413da79ce173dd4d081adce00293bddcd15 Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Tue, 6 Aug 2024 22:17:01 +0200
Subject: [PATCH 2/2] Remove call to getTrivialTypeSourceInfo

---
 clang/lib/Sema/TreeTransform.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index fd96ebd812343..14333e515caaa 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5837,9 +5837,7 @@ QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
     NewTL.setAttrNameLoc(TL.getAttrNameLoc());
 
   } else {
-    TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
-        Result, getDerived().getBaseLocation());
-    TLB.TypeWasModifiedSafely(DI->getType());
+    TLB.TypeWasModifiedSafely(Result);
   }
 
   return Result;



More information about the cfe-commits mailing list