mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Lowering of optional in && was incorrect #2843
This commit is contained in:
@@ -131,6 +131,7 @@
|
||||
- Bitstruct as substruct fails to properly work with designated initializers. #2827
|
||||
- Bug when initializing an inferred array with deep structure using designated init #2826
|
||||
- Packed .c3l files without compressions weren't unpacked correctly.
|
||||
- Lowering of optional in && was incorrect #2843
|
||||
|
||||
### Stdlib changes
|
||||
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.
|
||||
|
||||
@@ -189,6 +189,7 @@ BEValue llvm_emit_assign_expr(GenContext *c, BEValue *ref, Expr *ref_expr, Expr
|
||||
else
|
||||
{
|
||||
Type *type = ref_expr ? type_lowering(ref_expr->type) : ref->type;
|
||||
|
||||
BEValue val = llvm_emit_alloca_b(c, type, ".assign_list");
|
||||
llvm_emit_initialize_reference(c, &val, expr);
|
||||
if (ref_expr) llvm_emit_expr(c, ref, ref_expr);
|
||||
@@ -5855,6 +5856,7 @@ INLINE void llvm_emit_varargs_expr(GenContext *c, BEValue *value_ref, Expr **var
|
||||
FOREACH_IDX(foreach_index, Expr *, val, varargs)
|
||||
{
|
||||
llvm_emit_expr(c, &inner_temp, val);
|
||||
RETURN_ON_EMPTY_BLOCK(value_ref);
|
||||
llvm_value_fold_optional(c, &inner_temp);
|
||||
BEValue slot = llvm_emit_array_gep(c, &array_ref, foreach_index);
|
||||
llvm_store(c, &slot, &inner_temp);
|
||||
@@ -6751,6 +6753,7 @@ static inline void llvm_emit_builtin_access(GenContext *c, BEValue *be_value, Ex
|
||||
Expr *inner = exprptr(expr->builtin_access_expr.inner);
|
||||
llvm_emit_expr(c, be_value, inner);
|
||||
llvm_value_fold_optional(c, be_value);
|
||||
RETURN_ON_EMPTY_BLOCK(be_value);
|
||||
switch (expr->builtin_access_expr.kind)
|
||||
{
|
||||
case ACCESS_FAULTNAME:
|
||||
@@ -6930,6 +6933,7 @@ void llvm_emit_expr_global_value(GenContext *c, BEValue *value, Expr *expr)
|
||||
static void llvm_emit_int_to_bool(GenContext *c, BEValue *value, Expr *expr)
|
||||
{
|
||||
llvm_emit_expr(c, value, expr->int_to_bool_expr.inner);
|
||||
RETURN_ON_EMPTY_BLOCK(value);
|
||||
Type *inner_type = value->type;
|
||||
if (inner_type->type_kind == TYPE_ARRAY)
|
||||
{
|
||||
@@ -7100,6 +7104,7 @@ static inline void llvm_emit_vector_to_array(GenContext *c, BEValue *value, Expr
|
||||
void llvm_emit_slice_to_vec_array(GenContext *c, BEValue *value, Expr *expr)
|
||||
{
|
||||
llvm_emit_expr(c, value, expr->inner_expr);
|
||||
RETURN_ON_EMPTY_BLOCK(value);
|
||||
llvm_value_rvalue(c, value);
|
||||
BEValue pointer;
|
||||
Type *base = value->type->array.base;
|
||||
|
||||
@@ -332,6 +332,7 @@ bool llvm_value_is_const(BEValue *value);
|
||||
void llvm_value_rvalue(GenContext *c, BEValue *value);
|
||||
void llvm_value_deref(GenContext *c, BEValue *value);
|
||||
void llvm_value_set(BEValue *value, LLVMValueRef llvm_value, Type *type);
|
||||
void llvm_value_set_empty(BEValue *value);
|
||||
void llvm_value_set_int(GenContext *c, BEValue *value, Type *type, uint64_t i);
|
||||
void llvm_value_set_address(GenContext *c, BEValue *value, LLVMValueRef llvm_value, Type *type, AlignSize alignment);
|
||||
void llvm_value_set_alloca(GenContext *c, BEValue *value, Type *type, AlignSize align, const char *name);
|
||||
@@ -593,6 +594,7 @@ void llvm_emit_debug_local_var(GenContext *c, Decl *var);
|
||||
#define EMIT_SPAN(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x); } while (0)
|
||||
#define PUSH_DEFER_ERROR(val__) LLVMValueRef def_err__ = c->defer_error_var; c->defer_error_var = val__
|
||||
#define POP_DEFER_ERROR() c->defer_error_var = def_err__
|
||||
#define RETURN_ON_EMPTY_BLOCK(value__) do { if (!c->current_block) { llvm_value_set_empty(value__); return; }} while(0)
|
||||
|
||||
LLVMAtomicOrdering llvm_atomic_ordering(Atomicity atomicity);
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ static inline void llvm_emit_return(GenContext *c, Ast *ast)
|
||||
{
|
||||
BEValue be_value;
|
||||
llvm_emit_expr(c, &be_value, expr->inner_expr);
|
||||
RETURN_ON_EMPTY_BLOCK(&be_value);
|
||||
if (ast->return_stmt.cleanup_fail)
|
||||
{
|
||||
llvm_value_rvalue(c, &be_value);
|
||||
|
||||
@@ -12,6 +12,13 @@ void llvm_value_deref(GenContext *c, BEValue *value)
|
||||
value->alignment = type_abi_alignment(type);
|
||||
}
|
||||
|
||||
void llvm_value_set_empty(BEValue *value)
|
||||
{
|
||||
value->value = NULL;
|
||||
value->type = type_void;
|
||||
value->kind = BE_VALUE;
|
||||
}
|
||||
|
||||
void llvm_value_set(BEValue *value, LLVMValueRef llvm_value, Type *type)
|
||||
{
|
||||
type = type_lowering(type);
|
||||
@@ -84,6 +91,7 @@ void llvm_value_addr(GenContext *c, BEValue *value)
|
||||
}
|
||||
else
|
||||
{
|
||||
RETURN_ON_EMPTY_BLOCK(value);
|
||||
BEValue temp = llvm_emit_alloca_b(c, value->type, "taddr");
|
||||
llvm_store(c, &temp, value);
|
||||
*value = temp;
|
||||
|
||||
72
test/test_suite/expressions/optional_in_addr.c3t
Normal file
72
test/test_suite/expressions/optional_in_addr.c3t
Normal file
@@ -0,0 +1,72 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
faultdef ABC;
|
||||
macro int? tester()
|
||||
{
|
||||
return ABC~;
|
||||
}
|
||||
fn void? test2(int )
|
||||
{
|
||||
if (&&(tester()!));
|
||||
}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
fault d = @catch(test2(1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i64 @test.test2(i32 %0) #0 {
|
||||
entry:
|
||||
%error_var = alloca i64, align 8
|
||||
store i64 ptrtoint (ptr @test.ABC to i64), ptr %error_var, align 8
|
||||
br label %guard_block
|
||||
|
||||
guard_block: ; preds = %entry
|
||||
%1 = load i64, ptr %error_var, align 8
|
||||
ret i64 %1
|
||||
}
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%d = alloca i64, align 8
|
||||
%blockret = alloca i64, align 8
|
||||
%f = alloca i64, align 8
|
||||
br label %testblock
|
||||
|
||||
testblock: ; preds = %entry
|
||||
%0 = call i64 @test.test2(i32 1)
|
||||
%not_err = icmp eq i64 %0, 0
|
||||
%1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
|
||||
br i1 %1, label %after_check, label %assign_optional
|
||||
|
||||
assign_optional: ; preds = %testblock
|
||||
store i64 %0, ptr %f, align 8
|
||||
br label %end_block
|
||||
|
||||
after_check: ; preds = %testblock
|
||||
store i64 0, ptr %f, align 8
|
||||
br label %end_block
|
||||
|
||||
end_block: ; preds = %after_check, %assign_optional
|
||||
%2 = load i64, ptr %f, align 8
|
||||
%i2b = icmp ne i64 %2, 0
|
||||
br i1 %i2b, label %if.then, label %if.exit
|
||||
|
||||
if.then: ; preds = %end_block
|
||||
%3 = load i64, ptr %f, align 8
|
||||
store i64 %3, ptr %blockret, align 8
|
||||
br label %expr_block.exit
|
||||
|
||||
if.exit: ; preds = %end_block
|
||||
store i64 0, ptr %blockret, align 8
|
||||
br label %expr_block.exit
|
||||
|
||||
expr_block.exit: ; preds = %if.exit, %if.then
|
||||
%4 = load i64, ptr %blockret, align 8
|
||||
store i64 %4, ptr %d, align 8
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user