- Compiler assert when passing returning CT failure immediately rethrown #2689.

This commit is contained in:
Christoffer Lerno
2025-12-26 22:00:31 +01:00
parent e76278cfd7
commit a2c886a2d9
3 changed files with 55 additions and 0 deletions

View File

@@ -33,6 +33,7 @@
- Incorrectly using LLVMStructType when emitting dynamic functions on MachO #2666 - Incorrectly using LLVMStructType when emitting dynamic functions on MachO #2666
- FixedThreadPool join did not work correctly. - FixedThreadPool join did not work correctly.
- Fix bug when creating bool vectors in certain cases. - Fix bug when creating bool vectors in certain cases.
- Compiler assert when passing returning CT failure immediately rethrown #2689.
### Stdlib changes ### Stdlib changes
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.

View File

@@ -2369,6 +2369,12 @@ static inline void llvm_emit_deref(GenContext *c, BEValue *value, Expr *inner, T
break; break;
} }
llvm_emit_expr(c, value, inner); llvm_emit_expr(c, value, inner);
if (!c->current_block)
{
value->type = type_void;
*value = (BEValue) { .type = type_void, .kind = BE_VALUE, .value = NULL };
return;
}
llvm_value_rvalue(c, value); llvm_value_rvalue(c, value);
AlignSize alignment = type_abi_alignment(type); AlignSize alignment = type_abi_alignment(type);
bool is_const = expr_is_const(inner); bool is_const = expr_is_const(inner);

View File

@@ -0,0 +1,48 @@
// #target: macos-x64
module test;
import std::io;
faultdef OH_NO;
const int C = 1;
fn void main()
{
(void)do_thing();
}
fn void? do_thing()
{
int* a_value;
// Change 'C' below to any integer value and the assert goes away.
*a_value = may_fault(C)!;
io::printfn("Value: %d", *a_value);
}
macro may_fault($incoming)
{
$switch $incoming:
$case 1: return OH_NO?;
$default: return 0;
$endswitch
}
/* #expect: test.ll
%"char[]" = type { ptr, i64 }
@test.C = local_unnamed_addr constant i32 1, align 4
@test.OH_NO = linkonce constant %"char[]" { ptr @test.OH_NO.nameof, i64 11 }, align 8
@test.OH_NO.nameof = internal constant [12 x i8] c"test::OH_NO\00", align 1
define i64 @test.do_thing() #0 {
entry:
%a_value = alloca ptr, align 8
%error_var = alloca i64, align 8
store ptr null, ptr %a_value, align 8
store i64 ptrtoint (ptr @test.OH_NO to i64), ptr %error_var, align 8
br label %guard_block
guard_block: ; preds = %entry
%0 = load i64, ptr %error_var, align 8
ret i64 %0
}