diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2026-02-02 11:33:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-02 11:33:21 +0000 |
| commit | b9e4007cb190c1a5d96e7786e726dcbcac1d08c9 (patch) | |
| tree | 37abe1e7e329c02fa541f5d0534a1ac1ea0713f6 /src | |
| parent | c85af4a454dac14a8b557fa80fe68f5bf1905673 (diff) | |
| parent | 63c4faca75635c0203ff576d7392fe7a0f9bca6c (diff) | |
Merge pull request #6216 from odin-lang/bill/debug-info-fixes
Debug Info Fixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend.hpp | 1 | ||||
| -rw-r--r-- | src/llvm_backend_const.cpp | 3 | ||||
| -rw-r--r-- | src/llvm_backend_debug.cpp | 21 | ||||
| -rw-r--r-- | src/llvm_backend_expr.cpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_proc.cpp | 2 | ||||
| -rw-r--r-- | src/llvm_backend_stmt.cpp | 26 |
6 files changed, 43 insertions, 12 deletions
diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 3491c0d39..a8076d75e 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -290,6 +290,7 @@ struct lbDefer { isize scope_index; isize context_stack_count; lbBlock * block; + TokenPos pos; union { Ast *stmt; struct { diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 8ce2137ab..57c07f5c9 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -736,13 +736,14 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb } LLVMValueRef tag = LLVMConstInt(LLVMStructGetTypeAtIndex(llvm_type, 1), tag_value, false); LLVMValueRef padding = nullptr; - LLVMValueRef values[3] = {cv.value, tag, padding}; isize value_count = 2; if (LLVMCountStructElementTypes(llvm_type) > 2) { value_count = 3; padding = LLVMConstNull(LLVMStructGetTypeAtIndex(llvm_type, 2)); } + + LLVMValueRef values[3] = {cv.value, tag, padding}; res.value = llvm_const_named_struct_internal(m, llvm_type, values, value_count); res.type = original_type; return res; diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 187aebf7c..e9b0f72cb 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -729,22 +729,22 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { case Basic_i128be: return lb_debug_type_basic_type(m, str_lit("i128be"), 128, LLVMDWARFTypeEncoding_Signed, LLVMDIFlagBigEndian); case Basic_u128be: return lb_debug_type_basic_type(m, str_lit("u128be"), 128, LLVMDWARFTypeEncoding_Unsigned, LLVMDIFlagBigEndian); - case Basic_f16be: return lb_debug_type_basic_type(m, str_lit("f16be"), 16, LLVMDWARFTypeEncoding_Float, LLVMDIFlagLittleEndian); - case Basic_f32be: return lb_debug_type_basic_type(m, str_lit("f32be"), 32, LLVMDWARFTypeEncoding_Float, LLVMDIFlagLittleEndian); - case Basic_f64be: return lb_debug_type_basic_type(m, str_lit("f64be"), 64, LLVMDWARFTypeEncoding_Float, LLVMDIFlagLittleEndian); + case Basic_f16be: return lb_debug_type_basic_type(m, str_lit("f16be"), 16, LLVMDWARFTypeEncoding_Float, LLVMDIFlagBigEndian); + case Basic_f32be: return lb_debug_type_basic_type(m, str_lit("f32be"), 32, LLVMDWARFTypeEncoding_Float, LLVMDIFlagBigEndian); + case Basic_f64be: return lb_debug_type_basic_type(m, str_lit("f64be"), 64, LLVMDWARFTypeEncoding_Float, LLVMDIFlagBigEndian); case Basic_complex32: { LLVMMetadataRef elements[2] = {}; elements[0] = lb_debug_struct_field(m, str_lit("real"), t_f16, 0*16); elements[1] = lb_debug_struct_field(m, str_lit("imag"), t_f16, 1*16); - return lb_debug_basic_struct(m, str_lit("complex32"), 64, 32, elements, gb_count_of(elements)); + return lb_debug_basic_struct(m, str_lit("complex32"), 32, 16, elements, gb_count_of(elements)); } case Basic_complex64: { LLVMMetadataRef elements[2] = {}; elements[0] = lb_debug_struct_field(m, str_lit("real"), t_f32, 0*32); - elements[1] = lb_debug_struct_field(m, str_lit("imag"), t_f32, 2*32); + elements[1] = lb_debug_struct_field(m, str_lit("imag"), t_f32, 1*32); return lb_debug_basic_struct(m, str_lit("complex64"), 64, 32, elements, gb_count_of(elements)); } case Basic_complex128: @@ -762,7 +762,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { elements[1] = lb_debug_struct_field(m, str_lit("jmag"), t_f16, 1*16); elements[2] = lb_debug_struct_field(m, str_lit("kmag"), t_f16, 2*16); elements[3] = lb_debug_struct_field(m, str_lit("real"), t_f16, 3*16); - return lb_debug_basic_struct(m, str_lit("quaternion64"), 128, 32, elements, gb_count_of(elements)); + return lb_debug_basic_struct(m, str_lit("quaternion64"), 64, 16, elements, gb_count_of(elements)); } case Basic_quaternion128: { @@ -780,7 +780,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { elements[1] = lb_debug_struct_field(m, str_lit("jmag"), t_f64, 1*64); elements[2] = lb_debug_struct_field(m, str_lit("kmag"), t_f64, 2*64); elements[3] = lb_debug_struct_field(m, str_lit("real"), t_f64, 3*64); - return lb_debug_basic_struct(m, str_lit("quaternion256"), 256, 32, elements, gb_count_of(elements)); + return lb_debug_basic_struct(m, str_lit("quaternion256"), 256, 64, elements, gb_count_of(elements)); } @@ -792,6 +792,8 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { } case Basic_string: { + // NOTE(bill): size_of(^u8) <= size_of(int) + LLVMMetadataRef elements[2] = {}; elements[0] = lb_debug_struct_field(m, str_lit("data"), t_u8_ptr, 0); elements[1] = lb_debug_struct_field(m, str_lit("len"), t_int, int_bits); @@ -805,6 +807,8 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { case Basic_string16: { + // NOTE(bill): size_of(^u16) <= size_of(int) + LLVMMetadataRef elements[2] = {}; elements[0] = lb_debug_struct_field(m, str_lit("data"), t_u16_ptr, 0); elements[1] = lb_debug_struct_field(m, str_lit("len"), t_int, int_bits); @@ -820,7 +824,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { { LLVMMetadataRef elements[2] = {}; elements[0] = lb_debug_struct_field(m, str_lit("data"), t_rawptr, 0); - elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, 64); + elements[1] = lb_debug_struct_field(m, str_lit("id"), t_typeid, 64); // typeid is always 64 bits in size and 64 bits in alignment return lb_debug_basic_struct(m, str_lit("any"), 128, 64, elements, gb_count_of(elements)); } @@ -843,6 +847,7 @@ gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { GB_PANIC("Type_Named should be handled in lb_debug_type separately"); case Type_SoaPointer: + // TODO(bill): This is technically incorrect and needs fixing return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->SoaPointer.elem), int_bits, int_bits, 0, nullptr, 0); case Type_Pointer: return LLVMDIBuilderCreatePointerType(m->debug_builder, lb_debug_type(m, type->Pointer.elem), ptr_bits, ptr_bits, 0, nullptr, 0); diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index aba196af8..d4acfa196 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -1377,6 +1377,8 @@ gb_internal LLVMValueRef lb_integer_modulo(lbProcedure *p, LLVMValueRef lhs, LLV if (LLVMIsConstant(rhs)) { if (LLVMIsNull(rhs)) { switch (behaviour) { + case IntegerDivisionByZero_Trap: + break; case IntegerDivisionByZero_Self: return zero; case IntegerDivisionByZero_Zero: diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index c80241e09..07b1870f0 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1290,7 +1290,7 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c } } - lb_add_defer_proc(p, p->scope_index, deferred, result_as_args); + lb_add_defer_proc(p, p->scope_index, deferred, result_as_args, e->token.pos); } } diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 81755af2d..05ec10cda 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -847,6 +847,10 @@ gb_internal void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node, lb_close_scope(p, lbDeferExit_Default, nullptr, node->left); lb_pop_target_list(p); + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, rs->body)); + } + if (check != nullptr) { lb_emit_jump(p, check); lb_start_block(p, check); @@ -979,6 +983,9 @@ gb_internal void lb_build_range_tuple(lbProcedure *p, AstRangeStmt *rs, Scope *s lb_close_scope(p, lbDeferExit_Default, nullptr, rs->body); lb_pop_target_list(p); + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, rs->body)); + } lb_emit_jump(p, loop); lb_start_block(p, done); } @@ -1108,6 +1115,9 @@ gb_internal void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs lb_close_scope(p, lbDeferExit_Default, nullptr, rs->body); lb_pop_target_list(p); + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, rs->body)); + } lb_emit_jump(p, loop); lb_start_block(p, done); @@ -1330,6 +1340,9 @@ gb_internal void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *sc lb_close_scope(p, lbDeferExit_Default, nullptr, rs->body); lb_pop_target_list(p); + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, rs->body)); + } lb_emit_jump(p, loop); lb_start_block(p, done); } @@ -1807,6 +1820,10 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * } lbBlock *next_cond = nullptr; + if (p->debug_info != nullptr) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_end_location_from_ast(p, clause)); + } + for (Ast *expr : cc->list) { expr = unparen_expr(expr); @@ -3164,6 +3181,9 @@ gb_internal void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) { if (d.kind == lbDefer_Node) { lb_build_stmt(p, d.stmt); } else if (d.kind == lbDefer_Proc) { + if (p->debug_info != nullptr && d.pos.line > 0) { + LLVMSetCurrentDebugLocation2(p->builder, lb_debug_location_from_token_pos(p, d.pos)); + } lb_emit_call(p, d.proc.deferred, d.proc.result_as_args); } } @@ -3240,10 +3260,11 @@ gb_internal void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) d->scope_index = scope_index; d->context_stack_count = p->context_stack.count; d->block = p->curr_block; - d->stmt = stmt; + d->pos = ast_token(stmt).pos; + d->stmt = stmt; } -gb_internal void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array<lbValue> const &result_as_args) { +gb_internal void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array<lbValue> const &result_as_args, TokenPos pos) { Type *pt = base_type(p->type); GB_ASSERT(pt->kind == Type_Proc); if (pt->Proc.calling_convention == ProcCC_Odin) { @@ -3254,6 +3275,7 @@ gb_internal void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue de d->kind = lbDefer_Proc; d->scope_index = p->scope_index; d->block = p->curr_block; + d->pos = pos; d->context_stack_count = p->context_stack.count; d->proc.deferred = deferred; d->proc.result_as_args = result_as_args; |