Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions llvm/test/tools/sycl-post-link/erase_used_decl.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; This test checks that the post-link tool doesn't incorrectly remove function
; declarations which are still in use while erasing the "llvm.used" global.
;
; RUN: sycl-post-link -split=auto -symbols -S %s -o %t.files.table
; RUN: FileCheck %s -input-file=%t.files_0.ll
;
target triple = "spir64-unknown-unknown"

; CHECK-NOT: llvm.used
@llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @notused to i8*), i8* bitcast (void ()* @stillused to i8*)], section "llvm.metadata"

; CHECK: declare spir_func void @stillused
declare spir_func void @stillused() #0
declare spir_func void @notused() #0

define spir_kernel void @entry() #0 {
call spir_func void @stillused()
ret void
}

define spir_kernel void @bar() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="erase_used_decl.cpp" }
2 changes: 1 addition & 1 deletion llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static bool removeSYCLKernelsConstRefArray(Module &M) {
}

// Remove unused kernel declarations to avoid LLVM IR check fails.
if (F && F->isDeclaration())
if (F && F->isDeclaration() && F->use_empty())
F->eraseFromParent();
}
return true;
Expand Down