From 0cd964ff254888d563659f4f8f39c934732aa487 Mon Sep 17 00:00:00 2001 From: Kuter Dinel Date: Thu, 22 Jul 2021 06:19:07 +0300 Subject: [PATCH] [Attributor][FIX] checkForAllInstructions, correctly handle declarations 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 | 3 +++ llvm/unittests/Transforms/IPO/AttributorTest.cpp | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index fcee3afe8d97..1e4d990e0df1 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1146,6 +1146,9 @@ bool Attributor::checkForAllInstructions(function_ref 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 = diff --git a/llvm/unittests/Transforms/IPO/AttributorTest.cpp b/llvm/unittests/Transforms/IPO/AttributorTest.cpp index 8bbea568b391..51de06c6d5e1 100644 --- a/llvm/unittests/Transforms/IPO/AttributorTest.cpp +++ b/llvm/unittests/Transforms/IPO/AttributorTest.cpp @@ -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: