From d067a037cce906d600851e9b88df251451f9a93e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 19 Aug 2019 15:58:31 -0400 Subject: [PATCH] fix void array as a local variable initializer Related: #1767 --- src/ir.cpp | 12 ++++++++++-- test/stage1/behavior/void.zig | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 3b855b374f4c16f5d3900f61242c38bf75219925..ccdd34f893868b9f70beffcbc225e4dc30c85f2c 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -13940,8 +13940,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * uint64_t old_array_len = array_type->data.array.len; uint64_t new_array_len; - if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) - { + if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) { ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow")); return ira->codegen->invalid_instruction; } @@ -13956,6 +13955,15 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * return result; } + switch (type_has_one_possible_value(ira->codegen, result->value.type)) { + case OnePossibleValueInvalid: + return ira->codegen->invalid_instruction; + case OnePossibleValueYes: + return result; + case OnePossibleValueNo: + break; + } + // TODO optimize the buf case expand_undef_array(ira->codegen, array_val); out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len); diff --git a/test/stage1/behavior/void.zig b/test/stage1/behavior/void.zig index 972279194689fa120c70f4cb4fa41cf6e4dc97c3..19e879d1570d328fd146a15a7ff3a619e90808dc 100644 --- a/test/stage1/behavior/void.zig +++ b/test/stage1/behavior/void.zig @@ -33,3 +33,8 @@ test "void optional" { var x: ?void = {}; expect(x != null); } + +test "void array as a local variable initializer" { + var x = [_]void{{}} ** 1004; + var y = x[0]; +} -- 2.54.0