Skip to content

Commit 8dfa651

Browse files
authored
[Clang] Fix crash when transforming a DependentAddressSpaceType (#102206)
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.
1 parent f83a89c commit 8dfa651

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Bug Fixes in This Version
166166
- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
167167
be used in C++.
168168
- Fixed a failed assertion when checking required literal types in C context. (#GH101304).
169+
- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
169170

170171
Bug Fixes to Compiler Builtins
171172
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/TreeTransform.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5840,7 +5840,8 @@ QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
58405840
TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
58415841
const DependentAddressSpaceType *T = TL.getTypePtr();
58425842

5843-
QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5843+
QualType pointeeType =
5844+
getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
58445845

58455846
if (pointeeType.isNull())
58465847
return QualType();
@@ -5873,9 +5874,7 @@ QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
58735874
NewTL.setAttrNameLoc(TL.getAttrNameLoc());
58745875

58755876
} else {
5876-
TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5877-
Result, getDerived().getBaseLocation());
5878-
TransformType(TLB, DI->getTypeLoc());
5877+
TLB.TypeWasModifiedSafely(Result);
58795878
}
58805879

58815880
return Result;

clang/test/SemaTemplate/address_space-dependent.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,16 @@ int main() {
117117

118118
return 0;
119119
}
120+
121+
namespace gh101685 {
122+
template <int AS>
123+
using ASPtrTy = void [[clang::address_space(AS)]] *;
124+
125+
template <int AS>
126+
struct EntryTy {
127+
ASPtrTy<AS> Base;
128+
};
129+
130+
ASPtrTy<1> x;
131+
EntryTy<2> y;
132+
}

0 commit comments

Comments
 (0)