Fix -debug when every initial file is excluded

The debug compile unit was made from the first file of the initial
package. When build tags exclude all of its files, as for the
Windows-only tests/issues/test_issue_7547.odin on other targets, there
is none, and `odin test -debug` crashed on an out-of-bounds index.
Without `-debug` such a test builds and reports that there are no
tests to run, which `tests/issues/run.sh` relies on.

Fall back to the package's path for the compile unit's file.
This commit is contained in:
bbodi committed 2026-10-08 15:51:24 +02:00
1 parent d65a9ba9bc
commit 8dbbbd2d64
2 files changed
+13 -2

No files matched your search

+12 -2
View File
@@ -3706,7 +3706,10 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
gbString split_name = gb_string_make(temporary_allocator(), "");
LLVMBool is_optimized = build_context.optimization_level > 0;
AstFile *init_file = m->info->init_package->files[0];
AstFile *init_file = nullptr;
if (m->info->init_package->files.count > 0) {
init_file = m->info->init_package->files[0];
}
if (Entity *entry_point = m->info->entry_point) {
if (Ast *ident = entry_point->identifier.load()) {
@@ -3716,11 +3719,18 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
}
}
LLVMMetadataRef init_file_metadata = lb_get_file_metadata(m, init_file);
if (init_file_metadata == nullptr) {
// every file of the initial package was excluded by its build tags, as can be done for `odin test`
String path = m->info->init_package->fullpath;
init_file_metadata = LLVMDIBuilderCreateFile(m->debug_builder, cast(char const *)path.text, path.len, "", 0);
}
LLVMBool split_debug_inlining = build_context.build_mode == BuildMode_Assembly;
LLVMBool debug_info_for_profiling = false;
m->debug_compile_unit = LLVMDIBuilderCreateCompileUnit(m->debug_builder, LLVMDWARFSourceLanguageC99,
lb_get_file_metadata(m, init_file),
init_file_metadata,
producer, gb_string_length(producer),
is_optimized, "", 0,
1, split_name, gb_string_length(split_name),
+1
View File
@@ -268,6 +268,7 @@ fi
$ODIN test ../test_lifetime_markers.odin $COMMON -o:size -lifetime-markers
$ODIN test ../test_lifetime_markers.odin $COMMON -o:speed -lifetime-markers
$ODIN test ../test_issue_7547.odin $COMMON
$ODIN test ../test_issue_7547.odin $COMMON -debug
$ODIN test ../test_issue_7490.odin $COMMON
$ODIN test ../test_issue_7779.odin $COMMON
$ODIN run ../test_issue_7798.odin $COMMON