Skip to content

Commit e063c96

Browse files
committed
Fix and test SubProgram handling.
1 parent 1ca9dc6 commit e063c96

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/debuginfo.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ DEBUG_METADATA_VERSION() = API.LLVMDebugMetadataVersion()
55
strip_debuginfo!(mod::Module) = API.LLVMStripModuleDebugInfo(mod)
66

77
if version() >= v"8.0"
8+
function get_subprogram(func::Function)
9+
ref = API.LLVMGetSubprogram(func)
10+
ref==C_NULL ? nothing : Metadata(ref)
11+
end
812
set_subprogram!(func::Function, sp::Metadata) = API.LLVMSetSubprogram(func, sp)
9-
get_subprogram(func::Function) = Metadata(API.LLVMGetSubprogram(func))
1013
end

test/debuginfo.jl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ DEBUG_METADATA_VERSION()
55
Context() do ctx
66
if LLVM.version() < v"8.0"
77
mod = parse(LLVM.Module, """
8-
define void @fun() !dbg !5 {
8+
define void @foo() !dbg !5 {
99
top:
1010
ret void, !dbg !7
1111
}
1212
13+
define void @bar() {
14+
top:
15+
ret void
16+
}
17+
1318
!llvm.module.flags = !{!0, !1}
1419
!llvm.dbg.cu = !{!2}
1520
@@ -18,16 +23,21 @@ Context() do ctx
1823
!2 = distinct !DICompileUnit(language: DW_LANG_C89, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
1924
!3 = !DIFile(filename: "REPL[1]", directory: ".")
2025
!4 = !{}
21-
!5 = distinct !DISubprogram(name: "foo", linkageName: "fun", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !4)
26+
!5 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !4)
2227
!6 = !DISubroutineType(types: !4)
2328
!7 = !DILocation(line: 1, scope: !5)""", ctx)
2429
else
2530
mod = parse(LLVM.Module, """
26-
define void @fun() !dbg !5 {
31+
define void @foo() !dbg !5 {
2732
top:
2833
ret void, !dbg !7
2934
}
3035
36+
define void @bar() {
37+
top:
38+
ret void
39+
}
40+
3141
!llvm.module.flags = !{!0, !1}
3242
!llvm.dbg.cu = !{!2}
3343
@@ -36,13 +46,24 @@ Context() do ctx
3646
!2 = distinct !DICompileUnit(language: DW_LANG_C89, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
3747
!3 = !DIFile(filename: "REPL[1]", directory: ".")
3848
!4 = !{}
39-
!5 = distinct !DISubprogram(name: "foo", linkageName: "fun", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2)
49+
!5 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2)
4050
!6 = !DISubroutineType(types: !4)
4151
!7 = !DILocation(line: 1, scope: !5)""", ctx)
4252
end
4353

44-
fun = functions(mod)["fun"]
45-
bb = entry(fun)
54+
foo = functions(mod)["foo"]
55+
56+
if LLVM.version() >= v"8.0"
57+
sp = LLVM.get_subprogram(foo)
58+
@test sp !== nothing
59+
60+
bar = functions(mod)["bar"]
61+
@test LLVM.get_subprogram(bar) === nothing
62+
LLVM.set_subprogram!(bar, sp)
63+
@test LLVM.get_subprogram(bar) == sp
64+
end
65+
66+
bb = entry(foo)
4667
inst = first(instructions(bb))
4768

4869
@test !isempty(metadata(inst))

0 commit comments

Comments
 (0)