[Attributor][FIX] checkForAllInstructions, correctly handle declarations
authorKuter Dinel <kuterdinel@gmail.com>
Thu, 22 Jul 2021 03:19:07 +0000 (06:19 +0300)
committerKuter Dinel <kuterdinel@gmail.com>
Fri, 23 Jul 2021 23:21:29 +0000 (02:21 +0300)
checkForAllInstructions was not handling declarations correctly.
It should have been returning false when it gets called on a declaration

The patch also fixes a test case for AAFunctionReachability for it to be able
to pass after the changes to the checkForAllinstructions.

Differential Revision: https://reviews.llvm.org/D106625

llvm/lib/Transforms/IPO/Attributor.cpp
llvm/unittests/Transforms/IPO/AttributorTest.cpp

index fcee3af..1e4d990 100644 (file)
@@ -1146,6 +1146,9 @@ bool Attributor::checkForAllInstructions(function_ref<bool(Instruction &)> Pred,
   if (!AssociatedFunction)
     return false;
 
+  if (AssociatedFunction->isDeclaration())
+    return false;
+
   // TODO: use the function scope once we have call site AAReturnedValues.
   const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction);
   const auto *LivenessAA =
index 8bbea56..51de06c 100644 (file)
@@ -75,8 +75,16 @@ TEST_F(AttributorTestBase, TestCast) {
 
 TEST_F(AttributorTestBase, AAReachabilityTest) {
   const char *ModuleString = R"(
-    declare void @func4()
-    declare void @func3()
+    @x = global i32 0
+    define void @func4() {
+      store i32 0, i32* @x
+      ret void
+    }
+
+    define void @func3() {
+      store i32 0, i32* @x
+      ret void
+    }
 
     define void @func2() {
     entry: