Skip to content

Commit e9c7966

Browse files
authored
[DirectX] Fix crash when naming buffers of arrays (#164553)
DXILResource was falling over trying to name a resource type that contained an array, such as `StructuredBuffer<float[3][2]>`. Handle this by walking through array types to gather the dimensions.
1 parent 0e807a4 commit e9c7966

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ static void formatTypeName(SmallString<64> &Dest, StringRef Name,
255255
if (!ContainedType)
256256
return;
257257

258+
SmallVector<uint64_t> ArrayDimensions;
259+
while (ArrayType *AT = dyn_cast<ArrayType>(ContainedType)) {
260+
ArrayDimensions.push_back(AT->getNumElements());
261+
ContainedType = AT->getElementType();
262+
}
263+
258264
StringRef ElementName;
259265
ElementType ET = toDXILElementType(ContainedType, IsSigned);
260266
if (ET != ElementType::Invalid) {
@@ -271,6 +277,8 @@ static void formatTypeName(SmallString<64> &Dest, StringRef Name,
271277
DestStream << "<" << ElementName;
272278
if (const FixedVectorType *VTy = dyn_cast<FixedVectorType>(ContainedType))
273279
DestStream << VTy->getNumElements();
280+
for (uint64_t Dim : ArrayDimensions)
281+
DestStream << "[" << Dim << "]";
274282
DestStream << ">";
275283
}
276284

llvm/test/CodeGen/DirectX/Metadata/resource-symbols.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ define void @test() {
2828
@llvm.dx.resource.handlefrombinding(i32 0, i32 10, i32 1, i32 0, ptr @SB.str)
2929
; CHECK: %"StructuredBuffer<struct.S>" = type { %struct.S }
3030

31+
; StructuredBuffer<float[3][2]>
32+
%struct1 = call target("dx.RawBuffer", [3 x [2 x float]], 0, 0)
33+
@llvm.dx.resource.handlefrombinding(i32 0, i32 12, i32 1, i32 0, ptr null)
34+
; CHECK: %"StructuredBuffer<float[3][2]>" = type { [3 x [2 x float]] }
35+
3136
; ByteAddressBuffer
3237
%byteaddr = call target("dx.RawBuffer", i8, 0, 0)
3338
@llvm.dx.resource.handlefrombinding(i32 0, i32 20, i32 1, i32 0, ptr null)
@@ -40,12 +45,14 @@ define void @test() {
4045
; CHECK-NEXT: @[[T1:.*]] = external constant %"Buffer<int32_t>"
4146
; CHECK-NEXT: @[[T2:.*]] = external constant %"Buffer<uint32_t3>"
4247
; CHECK-NEXT: @[[S0:.*]] = external constant %"StructuredBuffer<struct.S>"
48+
; CHECK-NEXT: @[[S1:.*]] = external constant %"StructuredBuffer<float[3][2]>"
4349
; CHECK-NEXT: @[[B0:.*]] = external constant %ByteAddressBuffer
4450

4551
; CHECK: !{i32 0, ptr @[[T0]], !"A"
4652
; CHECK: !{i32 1, ptr @[[T1]], !""
4753
; CHECK: !{i32 2, ptr @[[T2]], !""
4854
; CHECK: !{i32 3, ptr @[[S0]], !"SB"
49-
; CHECK: !{i32 4, ptr @[[B0]], !""
55+
; CHECK: !{i32 4, ptr @[[S1]], !""
56+
; CHECK: !{i32 5, ptr @[[B0]], !""
5057

5158
attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

0 commit comments

Comments
 (0)