[Attributor] Properly repair broken unittest
authorJohannes Doerfert <johannes@jdoerfert.de>
Thu, 12 Jan 2023 10:20:50 +0000 (02:20 -0800)
committerJohannes Doerfert <johannes@jdoerfert.de>
Thu, 12 Jan 2023 10:23:59 +0000 (02:23 -0800)
Reverts 2dc7c7095153822ecd1a8f43aa4c185f9e80cc00 and instead repairs the
unittest properly. The test was broken as that it used references to
dead functions, assumed dead functions could reach code, assumed code
would not be deleted, and did not pre-query all assertion queries.
Arguably, the querry AAs don't make it easy to use them outside the
attributor pipeline, maybe we just should not (or should fix them
pessimistically). For now, the unittest is fixed.

llvm/unittests/Transforms/IPO/AttributorTest.cpp

index 65173ec..14dffc2 100644 (file)
@@ -77,7 +77,7 @@ TEST_F(AttributorTestBase, TestCast) {
 TEST_F(AttributorTestBase, AAReachabilityTest) {
   const char *ModuleString = R"(
     @x = external global i32
-    define internal void @func4() {
+    define void @func4() {
       store i32 0, i32* @x
       ret void
     }
@@ -98,7 +98,7 @@ TEST_F(AttributorTestBase, AAReachabilityTest) {
       ret void
     }
 
-    define internal void @func1() {
+    define void @func1() {
     entry:
       call void @func2()
       ret void
@@ -112,13 +112,14 @@ TEST_F(AttributorTestBase, AAReachabilityTest) {
       ret void
     }
 
-    define internal void @func6() {
+    define void @func6() {
     entry:
+      store i32 0, i32* @x
       call void @func5(void ()* @func3)
       ret void
     }
 
-    define internal void @func7() {
+    define void @func7() {
     entry:
       call void @func2()
       call void @func4()
@@ -186,13 +187,12 @@ TEST_F(AttributorTestBase, AAReachabilityTest) {
   F6AA.canReach(A, F4);
   F7AA.instructionCanReach(A, F7FirstCB, F3);
   F7AA.instructionCanReach(A, F7FirstCB, F4);
+  F9AA.instructionCanReach(A, F9SecondInst, F3);
   F9AA.instructionCanReach(A, F9FirstInst, F3);
   F9AA.instructionCanReach(A, F9FirstInst, F4);
 
   A.run();
 
-  // Under investigation
-#if 0
   ASSERT_TRUE(F1AA.canReach(A, F3));
   ASSERT_FALSE(F1AA.canReach(A, F4));
 
@@ -211,7 +211,6 @@ TEST_F(AttributorTestBase, AAReachabilityTest) {
   // Because func10 calls the func4 after the call to func9 it is reachable but
   // as it requires backwards logic we would need AA::isPotentiallyReachable.
   ASSERT_FALSE(F9AA.instructionCanReach(A, F9FirstInst, F4));
-#endif
 }
 
 } // namespace llvm