-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][ASTImporter][NFC] add unittests for unnamed EnumDecl #100545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
These tests are for 0a6233a multiple anonymous EnumDecls structural eq test & importing.
@llvm/pr-subscribers-clang Author: Ding Fei (danix800) ChangesThese 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 Full diff: https://github.com/llvm/llvm-project/pull/100545.diff 2 Files Affected:
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) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Buildbot failure looks not related.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/2152 Here is the relevant piece of the build log for the reference:
|
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 0a6233a already did this. I think these tests are still useful for regressions.