================ @@ -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 + StructType *OtherStruct = + StructType::get(Context, Struct->elements(), /*isPacked=*/false); + + Type *TargetExtensionType = + TargetExtType::get(Context, "structTET", {Struct}, {0, 1}); + Type *OtherTargetExtensionType = + TargetExtType::get(Context, "structTET", {OtherStruct}, {0, 1}); + + SmallVector<char, 50> TETV; + SmallVector<char, 50> OtherTETV; + + llvm::raw_svector_ostream TETStream(TETV); + TargetExtensionType->print(TETStream); + + llvm::raw_svector_ostream OtherTETStream(OtherTETV); + OtherTargetExtensionType->print(OtherTETStream); + + EXPECT_STREQ(TETStream.str().str().data(), + "target(\"structTET\", %MyStruct, 0, 1)"); + EXPECT_STREQ(OtherTETStream.str().str().data(), + "target(\"structTET\", { i32, float }, 0, 1)"); ---------------- bogner wrote:
It'd be better to do all of the work to test the identified struct, and then do the work for the literal struct as a second step. This way you can avoid the duplicate `StructType *`, `TargetExtensionType *`, `SmallVector`, and `raw_svector_ostream` variables, and it will be clearer that these are two related but entirely independent tests. https://github.com/llvm/llvm-project/pull/115971 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits