authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-19 14:46:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-19 14:46:12-04:00
log44fb5275c1babed97a38b4b3c97e59740a2a5cc5
tree421673b24e4605ce0fc8290c1248ebffc4364728
parent3f7f52003690ccee8a2a33e91258428e22761492
signaturelock-open Commit is signed but in an unrecognized format.

fix array multiplication not setting parent value info

closes #3095

2 files changed, 25 insertions(+), 4 deletions(-)

src/ir.cpp+5-2
......@@ -13963,8 +13963,11 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1396313963 uint64_t i = 0;
1396413964 for (uint64_t x = 0; x < mult_amt; x += 1) {
1396513965 for (uint64_t y = 0; y < old_array_len; y += 1) {
13966 copy_const_val(&out_val->data.x_array.data.s_none.elements[i],
13967 &array_val->data.x_array.data.s_none.elements[y], false);
13966 ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
13967 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
13968 elem_dest_val->parent.id = ConstParentIdArray;
13969 elem_dest_val->parent.data.p_array.array_val = out_val;
13970 elem_dest_val->parent.data.p_array.elem_index = i;
1396813971 i += 1;
1396913972 }
1397013973 }
test/stage1/behavior/array.zig+20-2
......@@ -1,5 +1,6 @@
1const expect = @import("std").testing.expect;
2const mem = @import("std").mem;
1const std = @import("std");
2const expect = std.testing.expect;
3const mem = std.mem;
34
45test "arrays" {
56 var array: [5]u32 = undefined;
......@@ -274,3 +275,20 @@ test "double nested array to const slice cast in array literal" {
274275 S.entry(2);
275276 comptime S.entry(2);
276277}
278
279test "read/write through global variable array of struct fields initialized via array mult" {
280 const S = struct {
281 fn doTheTest() void {
282 expect(storage[0].term == 1);
283 storage[0] = MyStruct{ .term = 123 };
284 expect(storage[0].term == 123);
285 }
286
287 pub const MyStruct = struct {
288 term: usize,
289 };
290
291 var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
292 };
293 S.doTheTest();
294}