authorgravatar for cfillion@users.noreply.github.comcfillion <cfillion@users.noreply.github.com> 2023-12-08 13:59:15-05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-12-28 14:44:26+02:00
logb0dba4680012e47ffc99f87bab4b53a976cb8b8e
treed558f189ae44138be9608882caf943dc1275d195
parentff17b11692f6a87b55470b7fc03babd382460886

Sema: fix merging stores instructions from a comptime struct value with `-fstrip`

The first instruction in the block was never checked resulting in `struct_is_comptime` being incorrectly cleared if there are no instructions before the first field of the comptime struct. Fixes #17119

1 files changed, 8 insertions(+), 8 deletions(-)

src/Sema.zig+8-8
...@@ -4783,11 +4783,9 @@ fn validateStructInit(...@@ -4783,11 +4783,9 @@ fn validateStructInit(
47834783
4784 const field_ptr_ref = sema.inst_map.get(field_ptr).?;4784 const field_ptr_ref = sema.inst_map.get(field_ptr).?;
47854785
4786 //std.debug.print("validateStructInit (field_ptr_air_inst=%{d}):\n", .{4786 //std.debug.print("validateStructInit (field_ptr_ref=%{d}):\n", .{field_ptr_ref});
4787 // field_ptr_air_inst,
4788 //});
4789 //for (block.instructions.items) |item| {4787 //for (block.instructions.items) |item| {
4790 // std.debug.print(" %{d} = {s}\n", .{item, @tagName(air_tags[item])});4788 // std.debug.print(" %{d} = {s}\n", .{item, @tagName(air_tags[@intFromEnum(item)])});
4791 //}4789 //}
47924790
4793 // We expect to see something like this in the current block AIR:4791 // We expect to see something like this in the current block AIR:
...@@ -4804,8 +4802,9 @@ fn validateStructInit(...@@ -4804,8 +4802,9 @@ fn validateStructInit(
48044802
4805 // Possible performance enhancement: save the `block_index` between iterations4803 // Possible performance enhancement: save the `block_index` between iterations
4806 // of the for loop.4804 // of the for loop.
4807 var block_index = block.instructions.items.len -| 1;4805 var block_index = block.instructions.items.len;
4808 while (block_index > 0) : (block_index -= 1) {4806 while (block_index > 0) {
4807 block_index -= 1;
4809 const store_inst = block.instructions.items[block_index];4808 const store_inst = block.instructions.items[block_index];
4810 if (store_inst.toRef() == field_ptr_ref) {4809 if (store_inst.toRef() == field_ptr_ref) {
4811 struct_is_comptime = false;4810 struct_is_comptime = false;
...@@ -5060,8 +5059,9 @@ fn zirValidatePtrArrayInit(...@@ -5060,8 +5059,9 @@ fn zirValidatePtrArrayInit(
50605059
5061 // Possible performance enhancement: save the `block_index` between iterations5060 // Possible performance enhancement: save the `block_index` between iterations
5062 // of the for loop.5061 // of the for loop.
5063 var block_index = block.instructions.items.len -| 1;5062 var block_index = block.instructions.items.len;
5064 while (block_index > 0) : (block_index -= 1) {5063 while (block_index > 0) {
5064 block_index -= 1;
5065 const store_inst = block.instructions.items[block_index];5065 const store_inst = block.instructions.items[block_index];
5066 if (store_inst.toRef() == elem_ptr_ref) {5066 if (store_inst.toRef() == elem_ptr_ref) {
5067 array_is_comptime = false;5067 array_is_comptime = false;