aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkcbanner <kcbanner@gmail.com>2023-11-11 16:48:11 -0500
committerAndrew Kelley <andrew@ziglang.org>2023-11-12 18:22:57 -0500
commit53500a57684665e08a2e18e7a736aacfa6548062 (patch)
tree4504dfb16ce7655307c72adce1f8a97704f8c331 /test
parent70d8baaec11ca370b73fce72d7f3dfce2277455b (diff)
downloadzig-53500a57684665e08a2e18e7a736aacfa6548062.tar.gz
zig-53500a57684665e08a2e18e7a736aacfa6548062.zip
sema: fixup underflows during struct / ptr array init when using -fstrip
Diffstat (limited to 'test')
-rw-r--r--test/standalone.zig4
-rw-r--r--test/standalone/strip_struct_init/build.zig16
-rw-r--r--test/standalone/strip_struct_init/main.zig23
3 files changed, 43 insertions, 0 deletions
diff --git a/test/standalone.zig b/test/standalone.zig
index 368da008d8..fc455a2aa7 100644
--- a/test/standalone.zig
+++ b/test/standalone.zig
@@ -235,6 +235,10 @@ pub const build_cases = [_]BuildCase{
.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",
.import = @import("standalone/cmakedefine/build.zig"),
},
diff --git a/test/standalone/strip_struct_init/build.zig b/test/standalone/strip_struct_init/build.zig
new file mode 100644
index 0000000000..b67da46819
--- /dev/null
+++ b/test/standalone/strip_struct_init/build.zig
@@ -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);
+}
diff --git a/test/standalone/strip_struct_init/main.zig b/test/standalone/strip_struct_init/main.zig
new file mode 100644
index 0000000000..4f3d63c960
--- /dev/null
+++ b/test/standalone/strip_struct_init/main.zig
@@ -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};
+}