Skip to content

Commit 4960e71

Browse files
authored
[SYCL] Fix SYCLLowerWGLocalMemoryPass crash (#3582)
When call of __sycl_allocateLocalMemory is lowered and erased from parent function block then iterator on this call instruction may be invalidated. Modify iterating through __sycl_allocateLocalMemory function users. Signed-off-by: Mikhail Lychkov <[email protected]>
1 parent c957c7b commit 4960e71

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

llvm/lib/SYCLLowerIR/LowerWGLocalMemory.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ static void lowerAllocaLocalMemCall(CallInst *CI, Module &M) {
8888
Value *GVPtr =
8989
Builder.CreatePointerCast(LocalMemArrayGV, Builder.getInt8PtrTy(LocalAS));
9090
CI->replaceAllUsesWith(GVPtr);
91-
92-
assert(CI->use_empty() && "removing live instruction");
93-
CI->eraseFromParent();
9491
}
9592

9693
static bool allocaWGLocalMemory(Module &M) {
@@ -100,9 +97,16 @@ static bool allocaWGLocalMemory(Module &M) {
10097

10198
assert(ALMFunc->isDeclaration() && "should have declaration only");
10299

100+
SmallVector<CallInst *, 4> DelCalls;
103101
for (User *U : ALMFunc->users()) {
104102
auto *CI = cast<CallInst>(U);
105103
lowerAllocaLocalMemCall(CI, M);
104+
DelCalls.push_back(CI);
105+
}
106+
107+
for (auto *CI : DelCalls) {
108+
assert(CI->use_empty() && "removing live instruction");
109+
CI->eraseFromParent();
106110
}
107111

108112
// Remove __sycl_allocateLocalMemory declaration.

0 commit comments

Comments
 (0)