Skip to content

Commit

Permalink
Correct debug info on parameters without storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed May 17, 2024
1 parent 97c9bd7 commit ff8b78f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Union is not properly zero-initialized with designated initializer #1194.
- Compile time fmod evaluates to 0 #1195.
- Assertion failed when casting (unsigned) argument to enum #1196
- Correct debug info on parameters without storage.

### Stdlib changes
- Add 'zstr' variants for `string::new_format` / `string::tformat`.
Expand Down
13 changes: 11 additions & 2 deletions src/compiler/llvm_codegen_debug_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,18 @@ void llvm_emit_debug_parameter(GenContext *c, Decl *parameter, unsigned index)
LLVMDIFlagZero);
LLVMMetadataRef inline_at = NULL;

if (parameter->is_value) return;
if (parameter->is_value)
{
LLVMDIBuilderInsertDbgValueAtEnd(c->debug.builder, parameter->backend_value, parameter->var.backend_debug_ref,
LLVMDIBuilderCreateExpression(c->debug.builder, NULL, 0),
LLVMDIBuilderCreateDebugLocation(c->context, row, col, c->debug.function,
inline_at),
LLVMGetInsertBlock(c->builder));
return;
}

LLVMDIBuilderInsertDeclareAtEnd(c->debug.builder,
parameter->is_value ? NULL : parameter->backend_ref,
parameter->backend_ref,
parameter->var.backend_debug_ref,
LLVMDIBuilderCreateExpression(c->debug.builder, NULL, 0),
LLVMDIBuilderCreateDebugLocation(c->context, row, col, c->debug.function,
Expand Down
19 changes: 11 additions & 8 deletions test/test_suite/concurrency/atomic_load_store_debug.c3t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fn void main()
/* #expect: test.ll
%.introspect = type { i8, i64, ptr, i64, i64, i64, [0 x i64] }
%"any*" = type { ptr, i64 }

@"$ct.test.Ghh" = linkonce global %.introspect { i8 10, i64 0, ptr null, i64 12, i64 0, i64 3, [0 x i64] zeroinitializer }, align 8
@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@"$ct.int" = linkonce global %.introspect { i8 2, i64 0, ptr null, i64 4, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8
Expand Down Expand Up @@ -59,8 +58,10 @@ entry:
; Function Attrs:
define i32 @main(i32 %0, ptr %1) #0 !dbg !33 {
entry:
call void @test.main(), !dbg !39
ret i32 0, !dbg !42
call void @llvm.dbg.value(metadata i32 %0, metadata !39, metadata !DIExpression()), !dbg !40
call void @llvm.dbg.value(metadata ptr %1, metadata !41, metadata !DIExpression()), !dbg !40
call void @test.main(), !dbg !42
ret i32 0, !dbg !45
}

declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
Expand All @@ -72,7 +73,6 @@ declare i1 @llvm.expect.i1(i1, i1) #2

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.dbg.cu = !{!4}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 2, !"Debug Info Version", i32 3}
!2 = !{i32 2, !"frame-pointer", i32 2}
Expand Down Expand Up @@ -112,7 +112,10 @@ declare i1 @llvm.expect.i1(i1, i1) #2
!36 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "char**", baseType: !37, size: 64, align: 64, dwarfAddressSpace: 0)
!37 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "char*", baseType: !38, size: 64, align: 64, dwarfAddressSpace: 0)
!38 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char)
!39 = !DILocation(line: 18, column: 2, scope: !40)
!40 = distinct !DILexicalBlock(scope: !33, file: !41, line: 18, column: 2)
!41 = !DIFile(filename: "main_stub.c3"
!42 = !DILocation(line: 19, column: 9, scope: !40)
!39 = !DILocalVariable(name: ".anon", arg: 1, scope: !33
!40 = !DILocation(line: 10, column: 9, scope: !33)
!41 = !DILocalVariable(name: ".anon", arg: 2, scope: !33
!42 = !DILocation(line: 18, column: 2, scope: !43)
!43 = distinct !DILexicalBlock(scope: !33, file: !44, line: 18, column: 2)
!44 = !DIFile(filename: "main_stub.c3"
!45 = !DILocation(line: 19, column: 9, scope: !43)

0 comments on commit ff8b78f

Please sign in to comment.