[clang] [llvm] [HLSL] Disallow named struct types as parameters in target extension types (PR #115971)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 25 10:14:15 PST 2024


================
@@ -40,10 +40,43 @@ TEST(TypesTest, TargetExtType) {
   Type *A = TargetExtType::get(Context, "typea");
   Type *Aparam = TargetExtType::get(Context, "typea", {}, {0, 1});
   Type *Aparam2 = TargetExtType::get(Context, "typea", {}, {0, 1});
+
   // Opaque types with same parameters are identical...
   EXPECT_EQ(Aparam, Aparam2);
   // ... but just having the same name is not enough.
   EXPECT_NE(A, Aparam);
+
+  // ensure struct types in targest extension types
+  // only show the struct name, not the struct body
+  Type *Int32Type = Type::getInt32Ty(Context);
+  Type *FloatType = Type::getFloatTy(Context);
+  std::vector<Type *> OriginalElements = {Int32Type, FloatType};
+  StructType *Struct = llvm::StructType::create(Context, "MyStruct");
+  Struct->setBody(OriginalElements);
+
+  // the other struct is different only in that it's an anonymous struct,
+  // without a name
----------------
bogner wrote:

The StructType docs call an unnamed struct a "literal struct" rather than anonymous: https://llvm.org/doxygen/classllvm_1_1StructType.html#details.

I would probably just say something to the effect of "ensure that literal structs in the target extension type print the struct body" to mirror the comment earlier.

https://github.com/llvm/llvm-project/pull/115971


More information about the cfe-commits mailing list