| author | |
| committer | |
| log | 53500a57684665e08a2e18e7a736aacfa6548062 |
| tree | 4504dfb16ce7655307c72adce1f8a97704f8c331 |
| parent | 70d8baaec11ca370b73fce72d7f3dfce2277455b |
4 files changed, 45 insertions(+), 2 deletions(-)
src/Sema.zig+2-2| ... | @@ -4814,7 +4814,7 @@ fn validateStructInit( | ... | @@ -4814,7 +4814,7 @@ fn validateStructInit( |
| 4814 | 4814 | ||
| 4815 | // Possible performance enhancement: save the `block_index` between iterations | 4815 | // Possible performance enhancement: save the `block_index` between iterations |
| 4816 | // of the for loop. | 4816 | // of the for loop. |
| 4817 | var block_index = block.instructions.items.len - 1; | 4817 | var block_index = block.instructions.items.len -| 1; |
| 4818 | while (block_index > 0) : (block_index -= 1) { | 4818 | while (block_index > 0) : (block_index -= 1) { |
| 4819 | const store_inst = block.instructions.items[block_index]; | 4819 | const store_inst = block.instructions.items[block_index]; |
| 4820 | if (Air.indexToRef(store_inst) == field_ptr_ref) { | 4820 | if (Air.indexToRef(store_inst) == field_ptr_ref) { |
| ... | @@ -5070,7 +5070,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5070,7 +5070,7 @@ fn zirValidatePtrArrayInit( |
| 5070 | 5070 | ||
| 5071 | // Possible performance enhancement: save the `block_index` between iterations | 5071 | // Possible performance enhancement: save the `block_index` between iterations |
| 5072 | // of the for loop. | 5072 | // of the for loop. |
| 5073 | var block_index = block.instructions.items.len - 1; | 5073 | var block_index = block.instructions.items.len -| 1; |
| 5074 | while (block_index > 0) : (block_index -= 1) { | 5074 | while (block_index > 0) : (block_index -= 1) { |
| 5075 | const store_inst = block.instructions.items[block_index]; | 5075 | const store_inst = block.instructions.items[block_index]; |
| 5076 | if (Air.indexToRef(store_inst) == elem_ptr_ref) { | 5076 | if (Air.indexToRef(store_inst) == elem_ptr_ref) { |
test/standalone.zig+4| ... | @@ -234,6 +234,10 @@ pub const build_cases = [_]BuildCase{ | ... | @@ -234,6 +234,10 @@ pub const build_cases = [_]BuildCase{ |
| 234 | .build_root = "test/standalone/strip_empty_loop", | 234 | .build_root = "test/standalone/strip_empty_loop", |
| 235 | .import = @import("standalone/strip_empty_loop/build.zig"), | 235 | .import = @import("standalone/strip_empty_loop/build.zig"), |
| 236 | }, | 236 | }, |
| 237 | .{ | ||
| 238 | .build_root = "test/standalone/strip_struct_init", | ||
| 239 | .import = @import("standalone/strip_struct_init/build.zig"), | ||
| 240 | }, | ||
| 237 | .{ | 241 | .{ |
| 238 | .build_root = "test/standalone/cmakedefine", | 242 | .build_root = "test/standalone/cmakedefine", |
| 239 | .import = @import("standalone/cmakedefine/build.zig"), | 243 | .import = @import("standalone/cmakedefine/build.zig"), |
test/standalone/strip_struct_init/build.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub fn build(b: *std.Build) void { | ||
| 4 | const test_step = b.step("test", "Test it"); | ||
| 5 | b.default_step = test_step; | ||
| 6 | |||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | ||
| 8 | |||
| 9 | const main = b.addTest(.{ | ||
| 10 | .root_source_file = .{ .path = "main.zig" }, | ||
| 11 | .optimize = optimize, | ||
| 12 | }); | ||
| 13 | main.strip = true; | ||
| 14 | |||
| 15 | test_step.dependOn(&b.addRunArtifact(main).step); | ||
| 16 | } | ||
test/standalone/strip_struct_init/main.zig created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | fn Func(comptime Type: type) type { | ||
| 2 | return struct { value: Type }; | ||
| 3 | } | ||
| 4 | |||
| 5 | inline fn func(value: anytype) Func(@TypeOf(value)) { | ||
| 6 | return .{ .value = value }; | ||
| 7 | } | ||
| 8 | |||
| 9 | test { | ||
| 10 | _ = func(type); | ||
| 11 | } | ||
| 12 | |||
| 13 | test { | ||
| 14 | const S = struct { field: u32 }; | ||
| 15 | comptime var arr: [1]S = undefined; | ||
| 16 | arr[0] = .{ .field = 0 }; | ||
| 17 | } | ||
| 18 | |||
| 19 | test { | ||
| 20 | const S = struct { u32 }; | ||
| 21 | comptime var arr: [1]S = undefined; | ||
| 22 | arr[0] = .{0}; | ||
| 23 | } | ||