https://github.com/danix800 created https://github.com/llvm/llvm-project/pull/100545
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. >From 2365cb103365994df0669e003a6afdeffb4d34e5 Mon Sep 17 00:00:00 2001 From: dingfei <fd...@feysh.com> Date: Thu, 25 Jul 2024 17:37:56 +0800 Subject: [PATCH] [clang][ASTImporter][NFC] add unittests for unnamed EnumDecl These tests are for 0a6233a68c7b575d05bca0f0c708b7e97cc710d1 multiple anonymous EnumDecls structural eq test & importing. --- clang/unittests/AST/ASTImporterTest.cpp | 37 +++++++++++++++++++ .../AST/StructuralEquivalenceTest.cpp | 14 +++++++ 2 files changed, 51 insertions(+) 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits