ebf8ff0ee026 — Leonard Ritter 11 days ago
* LLVM: fix wrong file being displayed in debugger by switching lexical block
1 files changed, 7 insertions(+), 1 deletions(-)

M src/gen_llvm.cpp
M src/gen_llvm.cpp +7 -1
@@ 2390,9 2390,15 @@ struct LLVMIRGenerator {
         LLVMValueRef func = LLVMGetBasicBlockParent(old_bb);
         LLVMMetadataRef disp = LLVMGetSubprogram(func);
 
+        LLVMMetadataRef scope = disp;
+        if (active_function.anchor()->path != anchor->path) {
+            LLVMMetadataRef difile = source_file_to_scope(anchor->path);
+            scope = LLVMDIBuilderCreateLexicalBlock(di_builder, disp, difile, 1, 1);
+        }
+
         LLVMMetadataRef result = LLVMDIBuilderCreateDebugLocation(
             LLVMGetGlobalContext(),
-            anchor->lineno, anchor->column, disp, nullptr);
+            anchor->lineno, anchor->column, scope, nullptr);
 
         return result;
     }