Skip to content

Commit ff7d062

Browse files
authored
Fix crash at translation of Entity of DebugImportedEntity (#951)
This is workaround to fix crash, which caused by using `dyn_cast` on a `nullptr`, as the result of translation of `Entity` operand of `DebugImportedEntity`, because this operand is `DebugInfoNone`.
1 parent 58d6120 commit ff7d062

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ DINode *SPIRVToLLVMDbgTran::transImportedEntry(const SPIRVExtInst *DebugInst) {
769769
DIFile *File = getFile(Ops[SourceIdx]);
770770
auto *Entity = transDebugInst<DINode>(BM->get<SPIRVExtInst>(Ops[EntityIdx]));
771771
if (Ops[TagIdx] == SPIRVDebug::ImportedModule) {
772+
if (!Entity)
773+
return Builder.createImportedModule(
774+
Scope, static_cast<DIImportedEntity *>(nullptr), File, Line);
772775
if (DIImportedEntity *IE = dyn_cast<DIImportedEntity>(Entity))
773776
return Builder.createImportedModule(Scope, IE, File, Line);
774777
if (DINamespace *NS = dyn_cast<DINamespace>(Entity))

test/DebugInfo/DebugInfoNoneEntity.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; Translation shouldn't crash:
3+
; RUN: llvm-spirv %t.bc -spirv-text
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
7+
source_filename = "llvm-link"
8+
target datalayout = "e-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 = "spir64"
10+
11+
!llvm.module.flags = !{!1, !2, !3, !4}
12+
!llvm.dbg.cu = !{!5}
13+
14+
!0 = !{}
15+
!1 = !{i32 1, !"wchar_size", i32 4}
16+
!2 = !{i32 7, !"PIC Level", i32 2}
17+
!3 = !{i32 2, !"Debug Info Version", i32 3}
18+
!4 = !{i32 2, !"Dwarf Version", i32 4}
19+
!5 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !6, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !0, globals: !0, imports: !7, splitDebugInlining: false, nameTableKind: None)
20+
!6 = !DIFile(filename: "declare_target_subroutine.F90", directory: "/test")
21+
!7 = !{!8}
22+
!8 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !9, entity: !12, file: !6, line: 24)
23+
!9 = distinct !DISubprogram(name: "declare_target_subroutine", linkageName: "MAIN__", scope: !6, file: !6, line: 23, type: !10, scopeLine: 23, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !5, retainedNodes: !0)
24+
!10 = !DISubroutineType(types: !11)
25+
!11 = !{null}
26+
!12 = !DIModule(scope: !9, name: "iso_fortran_env", isDecl: true)

0 commit comments

Comments
 (0)