Skip to content

Commit 97b0745

Browse files
committed
add test to typestest.cpp
1 parent e3f9344 commit 97b0745

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

clang/lib/CodeGen/Targets/DirectX.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
4343
if (ContainedTy.isNull())
4444
return nullptr;
4545

46+
// convert element type
4647
llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
4748

4849
llvm::StringRef TypeName =

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -S -finclude-default-header -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -emit-llvm -finclude-default-header -o - %s | FileCheck %s
22

33
// The purpose of this test is to ensure that the target
44
// extension type associated with the structured buffer only
@@ -11,9 +11,6 @@
1111

1212
// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", %struct.mystruct, 0, 0), %struct.mystruct }
1313
// CHECK: %struct.mystruct = type { <4 x float> }
14-
// CHECK: %dx.types.Handle = type { ptr }
15-
// CHECK: %dx.types.ResBind = type { i32, i32, i32, i8 }
16-
// CHECK: %dx.types.ResourceProperties = type { i32, i32 }
1714

1815
struct mystruct
1916
{

llvm/unittests/IR/TypesTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,43 @@ TEST(TypesTest, TargetExtType) {
4040
Type *A = TargetExtType::get(Context, "typea");
4141
Type *Aparam = TargetExtType::get(Context, "typea", {}, {0, 1});
4242
Type *Aparam2 = TargetExtType::get(Context, "typea", {}, {0, 1});
43+
4344
// Opaque types with same parameters are identical...
4445
EXPECT_EQ(Aparam, Aparam2);
4546
// ... but just having the same name is not enough.
4647
EXPECT_NE(A, Aparam);
48+
49+
// ensure struct types in targest extension types
50+
// only show the struct name, not the struct body
51+
Type *Int32Type = Type::getInt32Ty(Context);
52+
Type *FloatType = Type::getFloatTy(Context);
53+
std::vector<Type *> OriginalElements = {Int32Type, FloatType};
54+
StructType *Struct = llvm::StructType::create(Context, "MyStruct");
55+
Struct->setBody(OriginalElements);
56+
57+
// the other struct is different only in that it's an anonymous struct,
58+
// without a name
59+
StructType *OtherStruct =
60+
StructType::get(Context, Struct->elements(), /*isPacked=*/false);
61+
62+
Type *TargetExtensionType =
63+
TargetExtType::get(Context, "structTET", {Struct}, {0, 1});
64+
Type *OtherTargetExtensionType =
65+
TargetExtType::get(Context, "structTET", {OtherStruct}, {0, 1});
66+
67+
SmallVector<char, 50> TETV;
68+
SmallVector<char, 50> OtherTETV;
69+
70+
llvm::raw_svector_ostream TETStream(TETV);
71+
TargetExtensionType->print(TETStream);
72+
73+
llvm::raw_svector_ostream OtherTETStream(OtherTETV);
74+
OtherTargetExtensionType->print(OtherTETStream);
75+
76+
EXPECT_STREQ(TETStream.str().str().data(),
77+
"target(\"structTET\", %MyStruct, 0, 1)");
78+
EXPECT_STREQ(OtherTETStream.str().str().data(),
79+
"target(\"structTET\", { i32, float }, 0, 1)");
4780
}
4881

4982
TEST(TypedPointerType, PrintTest) {

0 commit comments

Comments
 (0)