| author | |
| committer | |
| log | d18b5f8b53d24d5a27ebde5711d0d142a953adc0 |
| tree | 28f752869bb64e68466c5453dc7345f8ab540c66 |
| parent | 8c8078513e60df7e017f91193524384e4e9640ca |
Fixes #35324 files changed, 32 insertions(+), 2 deletions(-)
src/ir.cpp+2-2| ... | ... | @@ -18263,7 +18263,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 18263 | 18263 | if (!ptr_val) |
| 18264 | 18264 | return ira->codegen->invalid_instruction; |
| 18265 | 18265 | |
| 18266 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | |
| 18266 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && | |
| 18267 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { | |
| 18267 | 18268 | ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 18268 | 18269 | if (union_val == nullptr) |
| 18269 | 18270 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -18295,7 +18296,6 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 18295 | 18296 | |
| 18296 | 18297 | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| 18297 | 18298 | |
| 18298 | ||
| 18299 | 18299 | IrInstruction *result; |
| 18300 | 18300 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 18301 | 18301 | result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
src/ir_print.cpp+15| ... | ... | @@ -2549,3 +2549,18 @@ void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, |
| 2549 | 2549 | |
| 2550 | 2550 | ir_print_instruction(irp, instruction, false); |
| 2551 | 2551 | } |
| 2552 | ||
| 2553 | void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass) { | |
| 2554 | IrPrint ir_print = {}; | |
| 2555 | IrPrint *irp = &ir_print; | |
| 2556 | irp->pass = pass; | |
| 2557 | irp->codegen = codegen; | |
| 2558 | irp->f = f; | |
| 2559 | irp->indent = indent_size; | |
| 2560 | irp->indent_size = indent_size; | |
| 2561 | irp->printed = {}; | |
| 2562 | irp->printed.init(4); | |
| 2563 | irp->pending = {}; | |
| 2564 | ||
| 2565 | ir_print_const_value(irp, value); | |
| 2566 | } |
src/ir_print.hpp+1| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 | |
| 15 | 15 | void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass); |
| 16 | 16 | void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass); |
| 17 | void ir_print_const_expr(CodeGen *codegen, FILE *f, ConstExprValue *value, int indent_size, IrPass pass); | |
| 17 | 18 | |
| 18 | 19 | const char* ir_instruction_type_str(IrInstructionId id); |
| 19 | 20 |
test/stage1/behavior/union.zig+14| ... | ... | @@ -535,3 +535,17 @@ test "global union with single field is correctly initialized" { |
| 535 | 535 | }; |
| 536 | 536 | expect(glbl.f.x == 123); |
| 537 | 537 | } |
| 538 | ||
| 539 | pub const FooUnion = union(enum) { | |
| 540 | U0: usize, | |
| 541 | U1: u8, | |
| 542 | }; | |
| 543 | ||
| 544 | var glbl_array: [2]FooUnion = undefined; | |
| 545 | ||
| 546 | test "initialize global array of union" { | |
| 547 | glbl_array[1] = FooUnion{ .U1 = 2 }; | |
| 548 | glbl_array[0] = FooUnion{ .U0 = 1 }; | |
| 549 | expect(glbl_array[0].U0 == 1); | |
| 550 | expect(glbl_array[1].U1 == 2); | |
| 551 | } |