Skip to content

Commit 840fffd

Browse files
authored
[ESIMD] Fix removal of "llvm.used" global in sycl-post-link (#5853)
The code removing llvm.used global in sycl-post-link wrongly assumed that all elements of the global array are either functions or function declarations. In fact llvm.used also may contain specialization constants as well. The fix adds additional check of IR before removal. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 46fb286 commit 840fffd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,11 @@ static bool removeSYCLKernelsConstRefArray(GlobalVariable *GV) {
859859
for (auto It = IOperands.begin(); It != IOperands.end(); It++) {
860860
assert(llvm::isSafeToDestroyConstant(*It) &&
861861
"Cannot remove an element of initializer of llvm.used global");
862-
auto F = cast<Function>((*It)->getOperand(0));
862+
auto Op = (*It)->getOperand(0);
863863
(*It)->destroyConstant();
864864
// Remove unused kernel declarations to avoid LLVM IR check fails.
865-
if (F->isDeclaration())
865+
auto *F = dyn_cast<Function>(Op);
866+
if (F && F->isDeclaration())
866867
F->eraseFromParent();
867868
}
868869
return true;

0 commit comments

Comments
 (0)