mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
sema: fixup underflows during struct / ptr array init when using -fstrip
This commit is contained in:
parent
70d8baaec1
commit
53500a5768
4 changed files with 45 additions and 2 deletions
|
|
@ -4814,7 +4814,7 @@ fn validateStructInit(
|
||||||
|
|
||||||
// Possible performance enhancement: save the `block_index` between iterations
|
// Possible performance enhancement: save the `block_index` between iterations
|
||||||
// of the for loop.
|
// of the for loop.
|
||||||
var block_index = block.instructions.items.len - 1;
|
var block_index = block.instructions.items.len -| 1;
|
||||||
while (block_index > 0) : (block_index -= 1) {
|
while (block_index > 0) : (block_index -= 1) {
|
||||||
const store_inst = block.instructions.items[block_index];
|
const store_inst = block.instructions.items[block_index];
|
||||||
if (Air.indexToRef(store_inst) == field_ptr_ref) {
|
if (Air.indexToRef(store_inst) == field_ptr_ref) {
|
||||||
|
|
@ -5070,7 +5070,7 @@ fn zirValidatePtrArrayInit(
|
||||||
|
|
||||||
// Possible performance enhancement: save the `block_index` between iterations
|
// Possible performance enhancement: save the `block_index` between iterations
|
||||||
// of the for loop.
|
// of the for loop.
|
||||||
var block_index = block.instructions.items.len - 1;
|
var block_index = block.instructions.items.len -| 1;
|
||||||
while (block_index > 0) : (block_index -= 1) {
|
while (block_index > 0) : (block_index -= 1) {
|
||||||
const store_inst = block.instructions.items[block_index];
|
const store_inst = block.instructions.items[block_index];
|
||||||
if (Air.indexToRef(store_inst) == elem_ptr_ref) {
|
if (Air.indexToRef(store_inst) == elem_ptr_ref) {
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,10 @@ pub const build_cases = [_]BuildCase{
|
||||||
.build_root = "test/standalone/strip_empty_loop",
|
.build_root = "test/standalone/strip_empty_loop",
|
||||||
.import = @import("standalone/strip_empty_loop/build.zig"),
|
.import = @import("standalone/strip_empty_loop/build.zig"),
|
||||||
},
|
},
|
||||||
|
.{
|
||||||
|
.build_root = "test/standalone/strip_struct_init",
|
||||||
|
.import = @import("standalone/strip_struct_init/build.zig"),
|
||||||
|
},
|
||||||
.{
|
.{
|
||||||
.build_root = "test/standalone/cmakedefine",
|
.build_root = "test/standalone/cmakedefine",
|
||||||
.import = @import("standalone/cmakedefine/build.zig"),
|
.import = @import("standalone/cmakedefine/build.zig"),
|
||||||
|
|
|
||||||
16
test/standalone/strip_struct_init/build.zig
Normal file
16
test/standalone/strip_struct_init/build.zig
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const test_step = b.step("test", "Test it");
|
||||||
|
b.default_step = test_step;
|
||||||
|
|
||||||
|
const optimize: std.builtin.OptimizeMode = .Debug;
|
||||||
|
|
||||||
|
const main = b.addTest(.{
|
||||||
|
.root_source_file = .{ .path = "main.zig" },
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
main.strip = true;
|
||||||
|
|
||||||
|
test_step.dependOn(&b.addRunArtifact(main).step);
|
||||||
|
}
|
||||||
23
test/standalone/strip_struct_init/main.zig
Normal file
23
test/standalone/strip_struct_init/main.zig
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
fn Func(comptime Type: type) type {
|
||||||
|
return struct { value: Type };
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn func(value: anytype) Func(@TypeOf(value)) {
|
||||||
|
return .{ .value = value };
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
_ = func(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
const S = struct { field: u32 };
|
||||||
|
comptime var arr: [1]S = undefined;
|
||||||
|
arr[0] = .{ .field = 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
const S = struct { u32 };
|
||||||
|
comptime var arr: [1]S = undefined;
|
||||||
|
arr[0] = .{0};
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue