Browse Source

Fix Ternary Operator IR bug

Ginger Bill 8 years ago
parent
commit
3e18f5f057
2 changed files with 7 additions and 7 deletions
  1. 3 3
      core/os.odin
  2. 4 4
      src/ir.c

+ 3 - 3
core/os.odin

@@ -8,13 +8,13 @@ write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
 
 
 read_entire_file :: proc(name: string) -> ([]byte, bool) {
 read_entire_file :: proc(name: string) -> ([]byte, bool) {
 	fd, err := open(name, O_RDONLY, 0);
 	fd, err := open(name, O_RDONLY, 0);
-	if err != ERROR_NONE {
+	if err != 0 {
 		return nil, false;
 		return nil, false;
 	}
 	}
 	defer close(fd);
 	defer close(fd);
 
 
 	length: i64;
 	length: i64;
-	if length, err = file_size(fd); err != ERROR_NONE {
+	if length, err = file_size(fd); err != 0 {
 		return nil, false;
 		return nil, false;
 	}
 	}
 
 
@@ -28,7 +28,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
 	}
 	}
 
 
 	bytes_read, read_err := read(fd, data);
 	bytes_read, read_err := read(fd, data);
-	if read_err != ERROR_NONE {
+	if read_err != 0 {
 		free(data);
 		free(data);
 		return nil, false;
 		return nil, false;
 	}
 	}

+ 4 - 4
src/ir.c

@@ -3658,22 +3658,22 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
 		irValue *cond = ir_build_cond(proc, te->cond, then, else_);
 		irValue *cond = ir_build_cond(proc, te->cond, then, else_);
 		ir_start_block(proc, then);
 		ir_start_block(proc, then);
 
 
+		Type *type = type_of_expr(proc->module->info, expr);
+
 		ir_open_scope(proc);
 		ir_open_scope(proc);
-		array_add(&edges, ir_build_expr(proc, te->x));
+		array_add(&edges, ir_emit_conv(proc, ir_build_expr(proc, te->x), type));
 		ir_close_scope(proc, irDeferExit_Default, NULL);
 		ir_close_scope(proc, irDeferExit_Default, NULL);
 
 
 		ir_emit_jump(proc, done);
 		ir_emit_jump(proc, done);
 		ir_start_block(proc, else_);
 		ir_start_block(proc, else_);
 
 
 		ir_open_scope(proc);
 		ir_open_scope(proc);
-		array_add(&edges, ir_build_expr(proc, te->y));
+		array_add(&edges, ir_emit_conv(proc, ir_build_expr(proc, te->y), type));
 		ir_close_scope(proc, irDeferExit_Default, NULL);
 		ir_close_scope(proc, irDeferExit_Default, NULL);
 
 
 		ir_emit_jump(proc, done);
 		ir_emit_jump(proc, done);
 		ir_start_block(proc, done);
 		ir_start_block(proc, done);
 
 
-		Type *type = type_of_expr(proc->module->info, expr);
-
 		return ir_emit(proc, ir_instr_phi(proc, edges, type));
 		return ir_emit(proc, ir_instr_phi(proc, edges, type));
 	case_end;
 	case_end;