llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Ding Fei (danix800) <details> <summary>Changes</summary> These tests are for multiple anonymous EnumDecls structural eq test & importing. We found the anonymous enums importing issue a few days ago and tried to fix it but 0a6233a68c7b575d05bca0f0c708b7e97cc710d1 already did this. I think these tests are still useful for regressions. --- Full diff: https://github.com/llvm/llvm-project/pull/100545.diff 2 Files Affected: - (modified) clang/unittests/AST/ASTImporterTest.cpp (+37) - (modified) clang/unittests/AST/StructuralEquivalenceTest.cpp (+14) ``````````diff diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 6d987cc7e9ec6..9b12caa37cf79 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9783,6 +9783,43 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportExistingEmptyAnonymousEnums) { EXPECT_EQ(ImportedE2, ToE1); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportMultipleAnonymousEnumDecls) { + Decl *ToTU = getToTuDecl("", Lang_CXX03); + Decl *FromTU = getTuDecl( + R"( + struct foo { + enum { A }; + enum { B }; + }; + )", + Lang_CXX03); + + auto EnumConstA = enumConstantDecl(hasName("A")); + auto EnumConstB = enumConstantDecl(hasName("B")); + + auto *FromA = FirstDeclMatcher<EnumConstantDecl>().match(FromTU, EnumConstA); + auto *FromB = FirstDeclMatcher<EnumConstantDecl>().match(FromTU, EnumConstB); + + auto *ToA = Import(FromA, Lang_CXX03); + auto *ToB = Import(FromB, Lang_CXX03); + + ASSERT_TRUE(ToA); + ASSERT_TRUE(ToB); + + auto *ToFooA = FirstDeclMatcher<CXXRecordDecl>().match( + ToTU, tagDecl(has(enumDecl(has(EnumConstA))))); + auto *ToFooB = FirstDeclMatcher<CXXRecordDecl>().match( + ToTU, tagDecl(has(enumDecl(has(EnumConstB))))); + ASSERT_EQ(ToFooA, ToFooB); + + // different EnumDecl + auto *ToEnumDeclA = + FirstDeclMatcher<EnumDecl>().match(ToTU, enumDecl(has(EnumConstA))); + auto *ToEnumDeclB = + FirstDeclMatcher<EnumDecl>().match(ToTU, enumDecl(has(EnumConstB))); + ASSERT_NE(ToEnumDeclA, ToEnumDeclB); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 952c83be0cb64..e994086c99d04 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -1109,6 +1109,20 @@ TEST_F(StructuralEquivalenceEnumTest, EnumsWithDifferentBody) { EXPECT_FALSE(testStructuralMatch(t)); } +TEST_F(StructuralEquivalenceEnumTest, AnonymousEnumsWithSameConsts) { + // field x is required to trigger comparison of the anonymous enum + auto t = makeNamedDecls("struct foo { enum { A } x; };", + "struct foo { enum { A } x;};", Lang_CXX11); + EXPECT_TRUE(testStructuralMatch(t)); +} + +TEST_F(StructuralEquivalenceEnumTest, AnonymousEnumsWithDiffConsts) { + // field x is required to trigger comparison of the anonymous enum + auto t = makeNamedDecls("struct foo { enum { A } x; };", + "struct foo { enum { B } x;};", Lang_CXX11); + EXPECT_FALSE(testStructuralMatch(t)); +} + struct StructuralEquivalenceEnumConstantTest : StructuralEquivalenceTest {}; TEST_F(StructuralEquivalenceEnumConstantTest, EnumConstantsWithSameValues) { `````````` </details> https://github.com/llvm/llvm-project/pull/100545 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits