Crash when using --no-obj without compile-only. #1653

This commit is contained in:
Christoffer Lerno
2024-12-03 19:48:24 +01:00
parent 5463c398cb
commit 8569239bc1
2 changed files with 16 additions and 4 deletions

View File

@@ -29,6 +29,7 @@
- Fix bug preventing optionals from being used in ranges or as indices.
- Crash compiling for arm64 when returning 16 byte and smaller structs by value not a power of 2 #1649.
- Enforce single module compilation for static libraries to make constructors run properly.
- Crash when using --no-obj without compile-only. #1653
### Stdlib changes
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.

View File

@@ -424,6 +424,7 @@ void compiler_compile(void)
void **gen_contexts;
void (*task)(void *);
if (compiler.build.asm_file_dir || compiler.build.ir_file_dir || compiler.build.emit_object_files)
{
if (compiler.build.build_dir && !file_exists(compiler.build.build_dir) && !dir_make(compiler.build.build_dir))
@@ -589,14 +590,16 @@ void compiler_compile(void)
{
puts("# output-files-begin");
}
for (unsigned i = 0; i < output_file_count; i++)
int index = 0;
for (unsigned i = output_file_count; i > 0; i--)
{
obj_files[i] = compile_data[i].object_name;
const char *name = compile_data[i - 1].object_name;
if (!name) output_file_count--;
obj_files[index++] = name;
if (compiler.build.print_output)
{
puts(obj_files[i]);
puts(name);
}
ASSERT0(obj_files[i] || !output_exe);
}
if (compiler.build.print_output)
{
@@ -607,6 +610,14 @@ void compiler_compile(void)
free(compile_data);
compiler_codegen_time = bench_mark();
if ((output_static || output_dynamic || output_exe) && !output_file_count)
{
if (!compiler.build.object_files)
{
error_exit("Compilation could not complete due to --no-obj, please try removing it.");
}
error_exit("Compilation produced no object files, maybe there was no code?");
}
if (output_exe)
{
if (compiler.build.output_dir)