Skip to content

Commit 384f916

Browse files
committed
Reapply 34cdc91 (#74455), call-site-splitting for RemoveDIs
Original commit message below; asan complained about this commit because it transpires that the final comparison with CurrentI is in fact a comparison of a pointer that has been freed. This seems to work fine most of the time, but using the iterator for such an instruction causes the freed instruction memory to be accessed, causing a use-after-free. The fix is to perform the comparison as an instruction, not an iterator. [NFC][DebugInfo][RemoveDIs] Use iterators to insert in callsite-splitting (#74455) This patch gets call site splitting to use iterators for insertion rather than instruction pointers. When we switch on non-instr debug-info this becomes significant, as the iterators are going to signal whether or not a position is before or after debug-info. NFC as this isn't going to affect the output of any existing test.
1 parent 565ddde commit 384f916

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ static void splitCallSite(CallBase &CB,
372372
return;
373373
}
374374

375-
auto *OriginalBegin = &*TailBB->begin();
375+
BasicBlock::iterator OriginalBegin = TailBB->begin();
376376
// Replace users of the original call with a PHI mering call-sites split.
377377
if (CallPN) {
378-
CallPN->insertBefore(OriginalBegin);
378+
CallPN->insertBefore(*TailBB, OriginalBegin);
379379
CB.replaceAllUsesWith(CallPN);
380380
}
381381

@@ -387,6 +387,7 @@ static void splitCallSite(CallBase &CB,
387387
// do not introduce unnecessary PHI nodes for def-use chains from the call
388388
// instruction to the beginning of the block.
389389
auto I = CB.getReverseIterator();
390+
Instruction *OriginalBeginInst = &*OriginalBegin;
390391
while (I != TailBB->rend()) {
391392
Instruction *CurrentI = &*I++;
392393
if (!CurrentI->use_empty()) {
@@ -399,13 +400,13 @@ static void splitCallSite(CallBase &CB,
399400
for (auto &Mapping : ValueToValueMaps)
400401
NewPN->addIncoming(Mapping[CurrentI],
401402
cast<Instruction>(Mapping[CurrentI])->getParent());
402-
NewPN->insertBefore(&*TailBB->begin());
403+
NewPN->insertBefore(*TailBB, TailBB->begin());
403404
CurrentI->replaceAllUsesWith(NewPN);
404405
}
405406
CurrentI->dropDbgValues();
406407
CurrentI->eraseFromParent();
407408
// We are done once we handled the first original instruction in TailBB.
408-
if (CurrentI == OriginalBegin)
409+
if (CurrentI == OriginalBeginInst)
409410
break;
410411
}
411412
}

0 commit comments

Comments
 (0)