mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Incorrect codegen if a macro ends with unreachable and is assigned to something. #2210
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
37
test/test_suite/assert/unreachable_in_assign.c3t
Normal file
37
test/test_suite/assert/unreachable_in_assign.c3t
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user