Skip to content

Commit

Permalink
Fix crash with --spirv-preserve-auxdata and removed function (#2052)
Browse files Browse the repository at this point in the history
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 <nick.sarnie@intel.com>
  • Loading branch information
sarnex authored Jun 19, 2023
1 parent b1782bf commit 9823690
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3378,15 +3378,16 @@ bool SPIRVToLLVM::translate() {
if (!postProcessBuiltinsReturningStruct(M, IsCpp))
return false;
}
eraseUselessFunctions(M);

DbgTran->addDbgInfoVersion();
DbgTran->finalize();

for (SPIRVExtInst *EI : BM->getAuxDataInstVec()) {
transAuxDataInst(EI);
}

eraseUselessFunctions(M);

DbgTran->addDbgInfoVersion();
DbgTran->finalize();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llvm-as -opaque-pointers=1 %s -o %t.bc
; 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
; RUN: llvm-spirv --spirv-preserve-auxdata --spirv-target-env=SPV-IR --spirv-text -r %t.txt -o %t.bc
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
; RUN: FileCheck < %t.ll %s --check-prefix=CHECK-LLVM

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"
target triple = "spir-unknown-unknown"

; CHECK-LLVM: define spir_kernel void @test_array
define spir_kernel void @test_array(ptr addrspace(1) %in, ptr addrspace(1) %out) {
call void @llvm.memmove.p1.p1.i32(ptr addrspace(1) %out, ptr addrspace(1) %in, i32 72, i1 false)
ret void
}

; Function Attrs: nounwind
declare void @llvm.memmove.p1.p1.i32(ptr addrspace(1) nocapture, ptr addrspace(1) nocapture readonly, i32, i1) #0
; CHECK-SPIRV: Name [[#ID:]] "llvm.memmove.p1.p1.i32"
; CHECK-LLVM-NOT: llvm.memmove

; CHECK-LLVM: attributes #0 = { nounwind }
attributes #0 = { nounwind }

0 comments on commit 9823690

Please sign in to comment.