Skip to content

Commit 22d83e0

Browse files
sarnexChenyang-L
authored andcommitted
Fix crash with --spirv-preserve-auxdata and removed function (#2052)
In SPIRVReader, we erase unused functions pretty late, but we were applying the ExtInst for `--spirv-preserve-auxdata` after that, causing us to try to work on a deleted function which lead to a crash. This isn't a problem for the SPIRVWriter case because the unused function deletion happens way earlier. Signed-off-by: Sarnie, Nick <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@9823690
1 parent ac09fd2 commit 22d83e0

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,15 +3356,16 @@ bool SPIRVToLLVM::translate() {
33563356
if (!postProcessBuiltinsReturningStruct(M, IsCpp))
33573357
return false;
33583358
}
3359-
eraseUselessFunctions(M);
3360-
3361-
DbgTran->addDbgInfoVersion();
3362-
DbgTran->finalize();
33633359

33643360
for (SPIRVExtInst *EI : BM->getAuxDataInstVec()) {
33653361
transAuxDataInst(EI);
33663362
}
33673363

3364+
eraseUselessFunctions(M);
3365+
3366+
DbgTran->addDbgInfoVersion();
3367+
DbgTran->finalize();
3368+
33683369
return true;
33693370
}
33703371

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llvm-as -opaque-pointers=1 %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -opaque-pointers=1 --spirv-preserve-auxdata --spirv-text -spirv-allow-unknown-intrinsics=llvm.genx. --spirv-preserve-auxdata -o %t.txt
3+
; RUN: llvm-spirv --spirv-preserve-auxdata --spirv-target-env=SPV-IR --spirv-text -r %t.txt -o %t.bc
4+
; RUN: llvm-dis %t.bc -o %t.ll
5+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
6+
; RUN: FileCheck < %t.ll %s --check-prefix=CHECK-LLVM
7+
8+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
9+
target triple = "spir-unknown-unknown"
10+
11+
; CHECK-LLVM: define spir_kernel void @test_array
12+
define spir_kernel void @test_array(ptr addrspace(1) %in, ptr addrspace(1) %out) {
13+
call void @llvm.memmove.p1.p1.i32(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 72, i1 false)
14+
ret void
15+
}
16+
17+
; Function Attrs: nounwind
18+
declare void @llvm.memmove.p1.p1.i32(ptr addrspace(1) nocapture, ptr addrspace(1) nocapture readonly, i32, i1) #0
19+
; CHECK-SPIRV: Name [[#ID:]] "llvm.memmove.p1.p1.i32"
20+
; CHECK-LLVM-NOT: llvm.memmove
21+
22+
; CHECK-LLVM: attributes #0 = { nounwind }
23+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)