Skip to content

Commit 97fcdab

Browse files
dobbelaj-snpsmemfrob
authored andcommitted
[NFC] Do not track calls to inlined intrinsics in IFI.
Just like intrinsics are not tracked for IFI.InlinedCalls, they should not be tracked for IFI.InlinedCallSites. In the current top-of-tree this change is a NFC, but the full restrict patches (D68484) potentially trigger an read-after-free if intrinsics are also added to the InlindeCallSites, due to a late optimization potentially removing some of the inlined intrinsics. Also see https://lists.llvm.org/pipermail/llvm-dev/2021-July/151722.html for a discussion about the problem. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D105805
1 parent 74b60a7 commit 97fcdab

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
10071007

10081008
for (CallBase *ICB : reverse(IFI.InlinedCallSites)) {
10091009
Function *NewCallee = ICB->getCalledFunction();
1010+
assert(!(NewCallee && NewCallee->isIntrinsic()) &&
1011+
"Intrinsic calls should not be tracked.");
10101012
if (!NewCallee) {
10111013
// Try to promote an indirect (virtual) call without waiting for
10121014
// the post-inline cleanup and the next DevirtSCCRepeatedPass

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,14 +2438,17 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
24382438
// before we splice the inlined code into the CFG and lose track of which
24392439
// blocks were actually inlined, collect the call sites. We only do this if
24402440
// call graph updates weren't requested, as those provide value handle based
2441-
// tracking of inlined call sites instead.
2441+
// tracking of inlined call sites instead. Calls to intrinsics are not
2442+
// collected because they are not inlineable.
24422443
if (InlinedFunctionInfo.ContainsCalls && !IFI.CG) {
24432444
// Otherwise just collect the raw call sites that were inlined.
24442445
for (BasicBlock &NewBB :
24452446
make_range(FirstNewBlock->getIterator(), Caller->end()))
24462447
for (Instruction &I : NewBB)
24472448
if (auto *CB = dyn_cast<CallBase>(&I))
2448-
IFI.InlinedCallSites.push_back(CB);
2449+
if (!(CB->getCalledFunction() &&
2450+
CB->getCalledFunction()->isIntrinsic()))
2451+
IFI.InlinedCallSites.push_back(CB);
24492452
}
24502453

24512454
// If we cloned in _exactly one_ basic block, and if that block ends in a

0 commit comments

Comments
 (0)