Skip to content

Commit

Permalink
Sema: fix merging stores instructions from a comptime struct value wi…
Browse files Browse the repository at this point in the history
…th `-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
  • Loading branch information
cfillion authored and Vexu committed Dec 28, 2023
1 parent ff17b11 commit b0dba46
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4783,11 +4783,9 @@ fn validateStructInit(

const field_ptr_ref = sema.inst_map.get(field_ptr).?;

//std.debug.print("validateStructInit (field_ptr_air_inst=%{d}):\n", .{
// field_ptr_air_inst,
//});
//std.debug.print("validateStructInit (field_ptr_ref=%{d}):\n", .{field_ptr_ref});
//for (block.instructions.items) |item| {
// std.debug.print(" %{d} = {s}\n", .{item, @tagName(air_tags[item])});
// std.debug.print(" %{d} = {s}\n", .{item, @tagName(air_tags[@intFromEnum(item)])});
//}

// We expect to see something like this in the current block AIR:
Expand All @@ -4804,8 +4802,9 @@ fn validateStructInit(

// Possible performance enhancement: save the `block_index` between iterations
// of the for loop.
var block_index = block.instructions.items.len -| 1;
while (block_index > 0) : (block_index -= 1) {
var block_index = block.instructions.items.len;
while (block_index > 0) {
block_index -= 1;
const store_inst = block.instructions.items[block_index];
if (store_inst.toRef() == field_ptr_ref) {
struct_is_comptime = false;
Expand Down Expand Up @@ -5060,8 +5059,9 @@ fn zirValidatePtrArrayInit(

// Possible performance enhancement: save the `block_index` between iterations
// of the for loop.
var block_index = block.instructions.items.len -| 1;
while (block_index > 0) : (block_index -= 1) {
var block_index = block.instructions.items.len;
while (block_index > 0) {
block_index -= 1;
const store_inst = block.instructions.items[block_index];
if (store_inst.toRef() == elem_ptr_ref) {
array_is_comptime = false;
Expand Down

0 comments on commit b0dba46

Please sign in to comment.