diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index 238568407..95d840833 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -208,17 +208,22 @@ void llvm_emit_debug_parameter(GenContext *c, Decl *parameter, unsigned index) } +LLVMMetadataRef llvm_create_debug_location(GenContext *c, SourceSpan location) +{ + LLVMMetadataRef scope = llvm_debug_current_scope(c); + unsigned row = location.row; + unsigned col = location.col; + return llvm_create_debug_location_with_inline(c, row ? row : 1, col ? col : 1, scope); +} + void llvm_emit_debug_location(GenContext *c, SourceSpan location) { if (llvm_is_global_eval(c)) return; // Avoid re-emitting the same location. LLVMMetadataRef oldloc = LLVMGetCurrentDebugLocation2(c->builder); if (oldloc && c->last_emitted_loc.a == location.a) return; - LLVMMetadataRef scope = llvm_debug_current_scope(c); - unsigned row = location.row; - unsigned col = location.col; + LLVMMetadataRef loc = llvm_create_debug_location(c, location); c->last_emitted_loc.a = location.a; - LLVMMetadataRef loc = llvm_create_debug_location_with_inline(c, row ? row : 1, col ? col : 1, scope); LLVMSetCurrentDebugLocation2(c->builder, loc); } diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index dd7c40250..c83bfa41e 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -6180,9 +6180,7 @@ static inline void llvm_emit_expr_block(GenContext *c, BEValue *be_value, Expr * SourceSpan span = expr->span; Decl *macro = declptr(expr->expr_block.macro_id); LLVMMetadataRef macro_def = llvm_debug_create_macro(c, macro); - LLVMMetadataRef loc = LLVMDIBuilderCreateDebugLocation(c->context, span.row, span.col, - llvm_debug_current_scope(c), - old_inline_location ? old_inline_location->inline_loc : NULL); + LLVMMetadataRef loc = llvm_create_debug_location(c, span); updated = (DebugScope) { .lexical_block = macro_def, .inline_loc = loc, .outline_loc = old_inline_location }; c->debug.block_stack = &updated; @@ -6314,8 +6312,19 @@ static void llvm_emit_macro_body_expansion(GenContext *c, BEValue *value, Expr * Decl **declarations = body_expr->body_expansion_expr.declarations; Expr **values = body_expr->body_expansion_expr.values; - DebugScope *old_inline_loc = c->debug.block_stack; - c->debug.block_stack = old_inline_loc ? old_inline_loc->outline_loc : NULL; + + + DebugScope *old_inline_loc = c->debug.block_stack; + LLVMMetadataRef debug_location; + if (llvm_use_debug(c)) + { + debug_location = llvm_create_debug_location(c, body_expr->span); + assert(old_inline_loc && old_inline_loc->outline_loc); + DebugScope patched = *old_inline_loc->outline_loc; + patched.inline_loc = debug_location; + c->debug.block_stack = &patched; + } + // Create backend refs on demand. VECEACH(declarations, i) { diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 0caef16d6..ffb3951c6 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -555,6 +555,7 @@ DebugScope llvm_debug_create_lexical_scope(GenContext *context, SourceSpan locat LLVMMetadataRef llvm_debug_current_scope(GenContext *context); void llvm_emit_debug_function(GenContext *c, Decl *decl); void llvm_emit_debug_location(GenContext *c, SourceSpan location); +LLVMMetadataRef llvm_create_debug_location(GenContext *c, SourceSpan location); void llvm_emit_debug_parameter(GenContext *c, Decl *parameter, unsigned index); void llvm_emit_debug_local_var(GenContext *c, Decl *var); void llvm_emit_debug_global_var(GenContext *c, Decl *global);