Skip to content

Conversation

@Sirraide
Copy link
Member

@Sirraide Sirraide commented Aug 6, 2024

We were forgetting to pass the TypeLocBuilder along to TransformType, causing us to complain if we then tried to build a DependentAddressSpaceTypeLoc because the inner TypeLoc was missing from the TLB.

Fixes #101685.

@Sirraide Sirraide added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Aug 6, 2024
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-clang

Author: None (Sirraide)

Changes

We were forgetting to pass the TypeLocBuilder along to TransformType, causing us to complain if we then tried to build a DependentAddressSpaceTypeLoc because the inner TypeLoc was missing from the TLB.

Fixes #101685.


Full diff: https://github.com/llvm/llvm-project/pull/102206.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+1)
  • (modified) clang/lib/Sema/TreeTransform.h (+3-2)
  • (modified) clang/test/SemaTemplate/address_space-dependent.cpp (+13)
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;
+}

Copy link
Contributor

@mizvekov mizvekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@Sirraide Sirraide merged commit 8dfa651 into llvm:main Aug 7, 2024
@Sirraide Sirraide deleted the transform-addr-space branch August 7, 2024 00:37
@jdoerfert
Copy link
Member

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang] Crash on templated type with address space

4 participants