Segfault using ternary with no assignment #1468.

This commit is contained in:
Christoffer Lerno
2024-09-21 00:57:36 +02:00
parent 2a9078a3b4
commit d727696830
3 changed files with 37 additions and 0 deletions

View File

@@ -46,6 +46,7 @@
- Folding a constant array of structs at compile time would cause an assert. - Folding a constant array of structs at compile time would cause an assert.
- Enum attributes would be overwritten by enum value attributes. - Enum attributes would be overwritten by enum value attributes.
- LLVM issue with try when bool is combined #1467 - LLVM issue with try when bool is combined #1467
- Segfault using ternary with no assignment #1468
### Stdlib changes ### Stdlib changes
- Additional init functions for hashmap. - Additional init functions for hashmap.

View File

@@ -4969,6 +4969,11 @@ void gencontext_emit_ternary_expr(GenContext *c, BEValue *value, Expr *expr)
return; return;
} }
if (expr->type == type_void)
{
llvm_value_set(value, NULL, expr->type);
return;
}
llvm_new_phi(c, value, "val", expr->type, lhs_value, lhs_exit, rhs_value, rhs_exit); llvm_new_phi(c, value, "val", expr->type, lhs_value, lhs_exit, rhs_value, rhs_exit);
} }
static LLVMValueRef llvm_emit_real(LLVMTypeRef type, Float f) static LLVMValueRef llvm_emit_real(LLVMTypeRef type, Float f)

View File

@@ -0,0 +1,31 @@
// #target: macos-x64
module test;
fn void foo() { }
fn void bar() {}
fn void main()
{
bool b = true;
true ? foo() : bar(); // ok
b ? foo() : bar(); // segfault
}
/* #expect: test.ll
entry:
%b = alloca i8, align 1
store i8 1, ptr %b, align 1
call void @test.foo()
%0 = load i8, ptr %b, align 1
%1 = trunc i8 %0 to i1
br i1 %1, label %cond.lhs, label %cond.rhs
cond.lhs: ; preds = %entry
call void @test.foo()
br label %cond.phi
cond.rhs: ; preds = %entry
call void @test.bar()
br label %cond.phi
cond.phi: ; preds = %cond.rhs, %cond.lhs
ret void
}