[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);
----------------
bogner wrote:

There's an overload of `create` that sets the elements directly:
```suggestion
  StructType *Struct = llvm::StructType::create(Context, Elements, "MyStruct",
                                                /*isPacked=*/false);
```

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


More information about the cfe-commits mailing list