more regressions fixed
parent
fa34dfcce7
commit
8954a1bae5
47
src/ir.cpp
47
src/ir.cpp
|
@ -15537,6 +15537,26 @@ static bool ir_result_has_type(ResultLoc *result_loc) {
|
||||||
zig_unreachable();
|
zig_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,
|
||||||
|
ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)
|
||||||
|
{
|
||||||
|
Error err;
|
||||||
|
|
||||||
|
IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
|
||||||
|
if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
|
||||||
|
return ira->codegen->invalid_instruction;
|
||||||
|
alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
|
||||||
|
PtrLenSingle, 0, 0, 0, false);
|
||||||
|
set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
|
||||||
|
ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
|
||||||
|
if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
|
||||||
|
fn_entry->alloca_gen_list.append(alloca_gen);
|
||||||
|
}
|
||||||
|
result_loc->written = true;
|
||||||
|
result_loc->resolved_loc = &alloca_gen->base;
|
||||||
|
return result_loc->resolved_loc;
|
||||||
|
}
|
||||||
|
|
||||||
// when calling this function, at the callsite must check for result type noreturn and propagate it up
|
// when calling this function, at the callsite must check for result type noreturn and propagate it up
|
||||||
static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
|
static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
|
||||||
ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
|
ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
|
||||||
|
@ -15559,19 +15579,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// need to return a result location and don't have one. use a stack allocation
|
// need to return a result location and don't have one. use a stack allocation
|
||||||
IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
|
return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
|
||||||
if ((err = type_resolve(ira->codegen, value_type, ResolveStatusZeroBitsKnown)))
|
force_runtime, non_null_comptime);
|
||||||
return ira->codegen->invalid_instruction;
|
|
||||||
alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
|
|
||||||
PtrLenSingle, 0, 0, 0, false);
|
|
||||||
set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
|
|
||||||
ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
|
|
||||||
if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
|
|
||||||
fn_entry->alloca_gen_list.append(alloca_gen);
|
|
||||||
}
|
|
||||||
result_loc->written = true;
|
|
||||||
result_loc->resolved_loc = &alloca_gen->base;
|
|
||||||
return result_loc->resolved_loc;
|
|
||||||
}
|
}
|
||||||
case ResultLocIdVar: {
|
case ResultLocIdVar: {
|
||||||
ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
|
ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
|
||||||
|
@ -15710,6 +15719,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
|
||||||
return result_loc->resolved_loc;
|
return result_loc->resolved_loc;
|
||||||
}
|
}
|
||||||
case ResultLocIdCast: {
|
case ResultLocIdCast: {
|
||||||
|
if (!non_null_comptime && value != nullptr && value->value.special != ConstValSpecialRuntime)
|
||||||
|
return nullptr;
|
||||||
ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
|
ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
|
||||||
ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
|
ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
|
||||||
if (type_is_invalid(dest_type))
|
if (type_is_invalid(dest_type))
|
||||||
|
@ -15720,9 +15731,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
|
||||||
if (const_cast_result.id == ConstCastResultIdInvalid)
|
if (const_cast_result.id == ConstCastResultIdInvalid)
|
||||||
return ira->codegen->invalid_instruction;
|
return ira->codegen->invalid_instruction;
|
||||||
if (const_cast_result.id != ConstCastResultIdOk) {
|
if (const_cast_result.id != ConstCastResultIdOk) {
|
||||||
// We will not be able to provide a result location for this value. Allow the
|
// We will not be able to provide a result location for this value. Create
|
||||||
// code to create a new result location and then type coerce to the old one.
|
// a new result location.
|
||||||
return nullptr;
|
return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
|
||||||
|
force_runtime, non_null_comptime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this case we can pointer cast the result location.
|
// In this case we can pointer cast the result location.
|
||||||
|
@ -15755,6 +15767,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
|
||||||
if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
|
if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
|
||||||
return ira->codegen->invalid_instruction;
|
return ira->codegen->invalid_instruction;
|
||||||
}
|
}
|
||||||
|
if (!type_has_bits(value_type)) {
|
||||||
|
parent_ptr_align = 0;
|
||||||
|
}
|
||||||
ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
|
ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
|
||||||
parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
|
parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
|
||||||
parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
|
parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
comptime {
|
comptime {
|
||||||
_ = @import("behavior/align.zig");
|
_ = @import("behavior/align.zig");
|
||||||
_ = @import("behavior/alignof.zig");
|
_ = @import("behavior/alignof.zig");
|
||||||
//_ = @import("behavior/array.zig");
|
_ = @import("behavior/array.zig");
|
||||||
_ = @import("behavior/asm.zig");
|
_ = @import("behavior/asm.zig");
|
||||||
_ = @import("behavior/async_fn.zig");
|
_ = @import("behavior/async_fn.zig");
|
||||||
_ = @import("behavior/atomics.zig");
|
_ = @import("behavior/atomics.zig");
|
||||||
|
@ -50,7 +50,7 @@ comptime {
|
||||||
_ = @import("behavior/bugs/920.zig");
|
_ = @import("behavior/bugs/920.zig");
|
||||||
_ = @import("behavior/byteswap.zig");
|
_ = @import("behavior/byteswap.zig");
|
||||||
_ = @import("behavior/byval_arg_var.zig");
|
_ = @import("behavior/byval_arg_var.zig");
|
||||||
//_ = @import("behavior/cast.zig");
|
_ = @import("behavior/cast.zig");
|
||||||
_ = @import("behavior/const_slice_child.zig");
|
_ = @import("behavior/const_slice_child.zig");
|
||||||
_ = @import("behavior/defer.zig");
|
_ = @import("behavior/defer.zig");
|
||||||
_ = @import("behavior/enum.zig");
|
_ = @import("behavior/enum.zig");
|
||||||
|
|
|
@ -75,8 +75,8 @@ test "peer resolve array and const slice" {
|
||||||
comptime testPeerResolveArrayConstSlice(true);
|
comptime testPeerResolveArrayConstSlice(true);
|
||||||
}
|
}
|
||||||
fn testPeerResolveArrayConstSlice(b: bool) void {
|
fn testPeerResolveArrayConstSlice(b: bool) void {
|
||||||
const value1 = if (b) "aoeu" else ([]const u8)("zz");
|
const value1 = if (b) "aoeu" else @as([]const u8, "zz");
|
||||||
const value2 = if (b) ([]const u8)("zz") else "aoeu";
|
const value2 = if (b) @as([]const u8, "zz") else "aoeu";
|
||||||
expect(mem.eql(u8, value1, "aoeu"));
|
expect(mem.eql(u8, value1, "aoeu"));
|
||||||
expect(mem.eql(u8, value2, "zz"));
|
expect(mem.eql(u8, value2, "zz"));
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ test "@floatToInt" {
|
||||||
fn testFloatToInts() void {
|
fn testFloatToInts() void {
|
||||||
const x = @as(i32, 1e4);
|
const x = @as(i32, 1e4);
|
||||||
expect(x == 10000);
|
expect(x == 10000);
|
||||||
const y = @floatToInt(i32, f32(1e4));
|
const y = @floatToInt(i32, @as(f32, 1e4));
|
||||||
expect(y == 10000);
|
expect(y == 10000);
|
||||||
expectFloatToInt(f16, 255.1, u8, 255);
|
expectFloatToInt(f16, 255.1, u8, 255);
|
||||||
expectFloatToInt(f16, 127.2, i8, 127);
|
expectFloatToInt(f16, 127.2, i8, 127);
|
||||||
|
@ -392,7 +392,7 @@ fn MakeType(comptime T: type) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getNonNull() ?T {
|
fn getNonNull() ?T {
|
||||||
return T(undefined);
|
return @as(T, undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -535,12 +535,12 @@ test "peer type resolution: unreachable, error set, unreachable" {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "implicit cast comptime_int to comptime_float" {
|
test "implicit cast comptime_int to comptime_float" {
|
||||||
comptime expect(comptime_float(10) == f32(10));
|
comptime expect(@as(comptime_float, 10) == @as(f32, 10));
|
||||||
expect(2 == 2.0);
|
expect(2 == 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "implicit cast *[0]T to E![]const u8" {
|
test "implicit cast *[0]T to E![]const u8" {
|
||||||
var x = (anyerror![]const u8)(&[0]u8{});
|
var x = @as(anyerror![]const u8, &[0]u8{});
|
||||||
expect((x catch unreachable).len == 0);
|
expect((x catch unreachable).len == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue