mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Segfault using ternary with no assignment #1468.
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
31
test/test_suite/expressions/ternary_void.c3t
Normal file
31
test/test_suite/expressions/ternary_void.c3t
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user