Fix of issue with "a ?? false"

This commit is contained in:
Christoffer Lerno
2022-03-21 13:22:59 +01:00
parent d1fadf6428
commit 8b8a8d81db
4 changed files with 51 additions and 4 deletions

View File

@@ -296,6 +296,7 @@ extern fn CFile tmpnam(char* str);
extern fn int fprintf(CFile stream, char* format, ...);
extern fn int printf(char* format, ...);
extern fn int sprintf(char* str, char* format, ...);
extern fn int snprintf(char* str, usize size, char* format, ...);
extern fn int fscanf(CFile stream, char* format, ...);
extern fn int scanf(char* format, ...);
extern fn int sscanf(char* str, char* format, ...);

View File

@@ -3523,13 +3523,27 @@ static void gencontext_emit_or_error(GenContext *c, BEValue *be_value, Expr *exp
return;
}
LLVMValueRef phi = LLVMBuildPhi(c->builder, llvm_get_type(c, expr->type), "val");
if (expr->type->type_kind == TYPE_BOOL)
{
}
LLVMValueRef logic_values[2] = { normal_value.value, else_value.value };
LLVMBasicBlockRef blocks[2] = { success_end_block, else_block_exit };
LLVMAddIncoming(phi, logic_values, blocks, 2);
llvm_value_set(be_value, phi, expr->type);
if (expr->type->type_kind == TYPE_BOOL)
{
LLVMValueRef phi = LLVMBuildPhi(c->builder, c->bool_type, "val");
LLVMAddIncoming(phi, logic_values, blocks, 2);
llvm_value_set_bool(be_value, phi);
return;
}
else
{
LLVMValueRef phi = LLVMBuildPhi(c->builder, llvm_get_type(c, expr->type), "val");
LLVMAddIncoming(phi, logic_values, blocks, 2);
llvm_value_set(be_value, phi, expr->type);
}
}

View File

@@ -1 +1 @@
#define COMPILER_VERSION "PRE.27"
#define COMPILER_VERSION "PRE.28"

View File

@@ -0,0 +1,32 @@
module test;
fn void tester()
{
bool! x = false;
x ?? true;
}
/* #expect: test.ll
define void @test.tester() #0 {
entry:
%x = alloca i8, align 1
%x.f = alloca i64, align 8
store i8 0, i8* %x, align 1
store i64 0, i64* %x.f, align 8
%0 = load i64, i64* %x.f, align 8
%not_err = icmp eq i64 %0, 0
br i1 %not_err, label %after_check, label %else_block
after_check: ; preds = %entry
%1 = load i8, i8* %x, align 1
%2 = trunc i8 %1 to i1
br label %phi_block
else_block: ; preds = %entry
br label %phi_block
phi_block: ; preds = %else_block, %after_check
%val = phi i1 [ %2, %after_check ], [ true, %else_block ]
ret void
}