Incorrect codegen if a macro ends with unreachable and is assigned to something. #2210

This commit is contained in:
Christoffer Lerno
2025-06-15 22:35:44 +02:00
parent 07eee04e94
commit 3ce15bd7af
3 changed files with 41 additions and 1 deletions

View File

@@ -40,6 +40,7 @@
- Fix to `is_array_or_slice_of_char` #2214.
- Method on array slice caused segfault #2211.
- In some cases, the compiler would dereference a compile time null. #2215
- Incorrect codegen if a macro ends with unreachable and is assigned to something. #2210
### Stdlib changes
- Deprecate `String.is_zstr` and `String.quick_zstr` #2188.

View File

@@ -122,6 +122,7 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValue
BEValue result;
// Emit the fault type.
llvm_emit_expr(c, &result, expr->inner_expr);
llvm_value_rvalue(c, &result);
LLVMValueRef err_val = result.value;
@@ -201,7 +202,7 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValue
{
llvm_emit_expr(c, &value, expr);
}
if (!c->current_block) goto AFTER_STORE;
if (value.type != type_void) llvm_store(c, ref, &value);
}
@@ -209,6 +210,7 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *expr, LLVMValue
{
llvm_store_to_ptr_raw(c, optional, llvm_get_zero(c, type_fault), type_fault);
}
AFTER_STORE:;
POP_CATCH();
if (assign_block)

View File

@@ -0,0 +1,37 @@
// #target: windows-x64
module test;
macro int create_int2() {
$$unreachable();
}
fn void test()
{
int x = create_int2();
}
macro int? create_int()
{
$$unreachable();
}
fn int main()
{
int? x = create_int();
}
/* #expect: test.ll
define void @test.test() #0 {
entry:
%x = alloca i32, align 4
%blockret = alloca i32, align 4
unreachable
}
define i32 @main() #0 {
entry:
%x = alloca i32, align 4
%x.f = alloca i64, align 8
%blockret = alloca i32, align 4
unreachable
}