authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 18:26:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-27 18:26:39-05:00
logb38b96784406c1d9e5f4246442f9414dba6812d2
treed9b9632ea260fc6089538e1ca58976902f0ce105
parentb96872ef2f619de476fb79c0bb142ebdace62382
signature Commit is signed but in an unrecognized format.

fix triple level result location with bitcast sandwich

...passed as tuple element

2 files changed, 24 insertions(+), 2 deletions(-)

src/ir.cpp+14-2
...@@ -18505,6 +18505,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18505,6 +18505,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18505 return bitcasted_value;18505 return bitcasted_value;
18506 }18506 }
1850718507
18508 bool parent_was_written = result_bit_cast->parent->written;
18508 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,18509 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
18509 dest_type, bitcasted_value, force_runtime, true);18510 dest_type, bitcasted_value, force_runtime, true);
18510 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18511 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
...@@ -18521,13 +18522,24 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18521,13 +18522,24 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18521 return parent_result_loc;18522 return parent_result_loc;
18522 }18523 }
1852318524
18524 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {18525 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) {
18525 return ira->codegen->invalid_inst_gen;18526 return ira->codegen->invalid_inst_gen;
18526 }18527 }
1852718528
18528 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18529 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusSizeKnown))) {
18529 return ira->codegen->invalid_inst_gen;18530 return ira->codegen->invalid_inst_gen;
18530 }18531 }
18532
18533 if (child_type != ira->codegen->builtin_types.entry_var) {
18534 if (type_size(ira->codegen, child_type) != type_size(ira->codegen, value_type)) {
18535 // pointer cast won't work; we need a temporary location.
18536 result_bit_cast->parent->written = parent_was_written;
18537 result_loc->written = true;
18538 result_loc->resolved_loc = ir_resolve_result(ira, suspend_source_instr, no_result_loc(),
18539 value_type, bitcasted_value, force_runtime, true);
18540 return result_loc->resolved_loc;
18541 }
18542 }
18531 uint64_t parent_ptr_align = 0;18543 uint64_t parent_ptr_align = 0;
18532 if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18544 if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
18533 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,18545 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
test/stage1/behavior/bitcast.zig+10
...@@ -177,3 +177,13 @@ test "bitcast passed as tuple element" {...@@ -177,3 +177,13 @@ test "bitcast passed as tuple element" {
177 };177 };
178 S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});178 S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
179}179}
180
181test "triple level result location with bitcast sandwich passed as tuple element" {
182 const S = struct {
183 fn foo(args: var) void {
184 comptime expect(@TypeOf(args[0]) == f64);
185 expect(args[0] > 12.33 and args[0] < 12.35);
186 }
187 };
188 S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
189}