[CoroSplit] Avoid self-replacement

With opaque pointers, the bitcast might be a no-op, and this can
end up trying to replace a value with itself, which is illegal.
This commit is contained in:
Nikita Popov 2022-03-14 13:52:59 +01:00
parent 6ca2f1938f
commit ce6ca00a92
2 changed files with 4 additions and 2 deletions

View File

@ -1015,7 +1015,8 @@ void CoroCloner::create() {
auto *NewVFrame = Builder.CreateBitCast(
NewFramePtr, Type::getInt8PtrTy(Builder.getContext()), "vFrame");
Value *OldVFrame = cast<Value>(VMap[Shape.CoroBegin]);
OldVFrame->replaceAllUsesWith(NewVFrame);
if (OldVFrame != NewVFrame)
OldVFrame->replaceAllUsesWith(NewVFrame);
switch (Shape.ABI) {
case coro::ABI::Switch:

View File

@ -1,4 +1,5 @@
; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -S < %s | FileCheck %s
; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=0 -S < %s | FileCheck %s
; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=1 -S < %s | FileCheck %s
declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)