Skip to content

Commit 7413ceb

Browse files
committed
print struct body within target ext ty context
1 parent d2db9bd commit 7413ceb

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s
2+
3+
// The purpose of this test is to ensure that the AST writer
4+
// only emits struct bodies when within the context of a
5+
// larger object that is being outputted on the RHS.
6+
7+
8+
// note that "{ <4 x float> }" in the check below is a struct type, but only the
9+
// body is emitted on the RHS because we are already in the context of a
10+
// target extension type definition (class.hlsl::StructuredBuffer)
11+
// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 x float> }, 0, 0), %struct.mystruct }
12+
// CHECK: %struct.mystruct = type { <4 x float> }
13+
// CHECK: %dx.types.Handle = type { ptr }
14+
// CHECK: %dx.types.ResBind = type { i32, i32, i32, i8 }
15+
// CHECK: %dx.types.ResourceProperties = type { i32, i32 }
16+
17+
struct mystruct
18+
{
19+
float4 Color;
20+
};
21+
22+
StructuredBuffer<mystruct> my_buffer : register(t2, space4);
23+
24+
export float4 test()
25+
{
26+
return my_buffer[0].Color;
27+
}
28+
29+
[numthreads(1,1,1)]
30+
void main() {}

llvm/lib/IR/AsmWriter.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,14 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
649649
OS << "target(\"";
650650
printEscapedString(Ty->getTargetExtName(), OS);
651651
OS << "\"";
652-
for (Type *Inner : TETy->type_params())
653-
OS << ", " << *Inner;
652+
for (Type *Inner : TETy->type_params()) {
653+
OS << ", ";
654+
if (Inner->isStructTy()) {
655+
StructType *STy = cast<StructType>(Inner);
656+
printStructBody(STy, OS);
657+
} else
658+
OS << *Inner;
659+
}
654660
for (unsigned IntParam : TETy->int_params())
655661
OS << ", " << IntParam;
656662
OS << ")";

0 commit comments

Comments
 (0)