Skip to content

[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

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

danix800
Copy link
Member

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.

These tests are for 0a6233a
multiple anonymous EnumDecls structural eq test & importing.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 25, 2024
@danix800 danix800 requested a review from balazske July 25, 2024 09:48
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-clang

Author: Ding Fei (danix800)

Changes

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.


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 --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) {

Copy link
Collaborator

@balazske balazske left a 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.

@danix800 danix800 merged commit 978c40b into llvm:main Jul 26, 2024
7 of 9 checks passed
@danix800 danix800 deleted the test/anony-enum-decl-testcases branch July 26, 2024 01:34
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 26, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux running on sanitizer-buildbot2 while building clang at step 2 "annotate".

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:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
[372/377] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[373/377] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[374/377] Generating Msan-x86_64-with-call-Test
[375/377] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[376/377] Generating Msan-x86_64-Test
[376/377] Running compiler_rt regression tests
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276: warning: input '/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig' contained no tests
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10075 tests, 88 workers --
Testing:  0.. 10
FAIL: AddressSanitizer-i386-linux :: TestCases/leaks.cpp (1296 of 10075)
******************** TEST 'AddressSanitizer-i386-linux :: TestCases/leaks.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 4: /b/sanitizer-x86_64-linux/build/build_default/./bin/clang  --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only  -m32  -O0 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp -o /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp
+ /b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m32 -O0 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp -o /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp:16:16: warning: unknown attribute 'noopt' ignored [-Wunknown-attributes]
   16 | __attribute__((noopt)) void leak(int n) {
      |                ^~~~~
1 warning generated.
RUN: at line 5: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 0 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 0
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 6: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 7: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000
RUN: at line 8: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000000
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 9: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 10000000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 10000000
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp:37:11: error: CHECK: expected string not found in input
// CHECK: LeakSanitizer: detected memory leaks
          ^
<stdin>:1:1: note: scanning from here
t: 0xe39d9800
^

Input file: <stdin>
Check file: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp

-dump-input=help explains the following input dump.

Step 9 (test compiler-rt symbolizer) failure: test compiler-rt symbolizer (failure)
...
[372/377] Generating MSAN_INST_GTEST.gtest-all.cc.x86_64.o
[373/377] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64-with-call.o
[374/377] Generating Msan-x86_64-with-call-Test
[375/377] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.x86_64.o
[376/377] Generating Msan-x86_64-Test
[376/377] Running compiler_rt regression tests
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:276: warning: input '/b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/rtsan/X86_64LinuxConfig' contained no tests
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 10075 tests, 88 workers --
Testing:  0.. 10
FAIL: AddressSanitizer-i386-linux :: TestCases/leaks.cpp (1296 of 10075)
******************** TEST 'AddressSanitizer-i386-linux :: TestCases/leaks.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 4: /b/sanitizer-x86_64-linux/build/build_default/./bin/clang  --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only  -m32  -O0 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp -o /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp
+ /b/sanitizer-x86_64-linux/build/build_default/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m32 -O0 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp -o /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp:16:16: warning: unknown attribute 'noopt' ignored [-Wunknown-attributes]
   16 | __attribute__((noopt)) void leak(int n) {
      |                ^~~~~
1 warning generated.
RUN: at line 5: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 0 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 0
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 6: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 7: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000
RUN: at line 8: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 1000000
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
RUN: at line 9: not  /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 10000000 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
+ not /b/sanitizer-x86_64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/asan/I386LinuxConfig/TestCases/Output/leaks.cpp.tmp 10000000
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp:37:11: error: CHECK: expected string not found in input
// CHECK: LeakSanitizer: detected memory leaks
          ^
<stdin>:1:1: note: scanning from here
t: 0xe39d9800
^

Input file: <stdin>
Check file: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/asan/TestCases/leaks.cpp

-dump-input=help explains the following input dump.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants