Skip to content

Commit e4406ce

Browse files
committed
[RPOFuncAttrs] Fix norecurse detection
We wanted to check if all uses of the function are direct calls, but the code didn't account for passing the function as a parameter. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D128104
1 parent eb15c80 commit e4406ce

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,12 +2014,13 @@ static bool addNoRecurseAttrsTopDown(Function &F) {
20142014
// this function could be recursively (indirectly) called. Note that this
20152015
// also detects if F is directly recursive as F is not yet marked as
20162016
// a norecurse function.
2017-
for (auto *U : F.users()) {
2018-
auto *I = dyn_cast<Instruction>(U);
2017+
for (auto &U : F.uses()) {
2018+
auto *I = dyn_cast<Instruction>(U.getUser());
20192019
if (!I)
20202020
return false;
20212021
CallBase *CB = dyn_cast<CallBase>(I);
2022-
if (!CB || !CB->getParent()->getParent()->doesNotRecurse())
2022+
if (!CB || !CB->isCallee(&U) ||
2023+
!CB->getParent()->getParent()->doesNotRecurse())
20232024
return false;
20242025
}
20252026
F.setDoesNotRecurse();

llvm/test/Transforms/FunctionAttrs/norecurse.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ define void @p() norecurse {
9999
}
100100

101101
; CHECK: Function Attrs
102-
; CHECK-SAME: norecurse nosync readnone
102+
; CHECK-NOT: norecurse
103+
; CHECK-SAME: nosync readnone
104+
; CHECK-NOT: norecurse
103105
; CHECK-NEXT: define internal i32 @escapes_as_parameter
104106
define internal i32 @escapes_as_parameter(ptr %p) {
105107
%a = call i32 @k()

0 commit comments

Comments
 (0)