Skip to content

Commit c3e6120

Browse files
committed
convert named to anonymous structs when creating target ext types
1 parent 3a1bdba commit c3e6120

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// RUN: %clang_cc1 -triple dxil-unknown-shadermodel6.6-compute -S -finclude-default-header -o - %s | FileCheck %s
22

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-
3+
// The purpose of this test is to ensure that the target
4+
// extension type associated with the structured buffer only
5+
// contains anonymous struct types, rather than named
6+
// struct types
77

88
// note that "{ <4 x float> }" in the check below is a struct type, but only the
99
// body is emitted on the RHS because we are already in the context of a
1010
// target extension type definition (class.hlsl::StructuredBuffer)
11+
1112
// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 x float> }, 0, 0), %struct.mystruct }
1213
// CHECK: %struct.mystruct = type { <4 x float> }
1314
// CHECK: %dx.types.Handle = type { ptr }

llvm/lib/IR/Type.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,17 @@ TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
794794
// Parameter storage immediately follows the class in allocation.
795795
Type **Params = reinterpret_cast<Type **>(this + 1);
796796
ContainedTys = Params;
797-
for (Type *T : Types)
798-
*Params++ = T;
797+
for (Type *T : Types) {
798+
// target ext type parameters may not be named struct types
799+
// so we should convert any named struct types to anonymous
800+
// struct types in the parameter list
801+
Type *ConvertedTy = T;
802+
if (auto *STy = dyn_cast<StructType>(T)) {
803+
if (STy->hasName())
804+
ConvertedTy = StructType::get(C, STy->elements(), /*isPacked=*/false);
805+
}
806+
*Params++ = ConvertedTy;
807+
}
799808

800809
setSubclassData(Ints.size());
801810
unsigned *IntParamSpace = reinterpret_cast<unsigned *>(Params);

0 commit comments

Comments
 (0)