aboutsummaryrefslogtreecommitdiff
path: root/test/cases
diff options
context:
space:
mode:
authorKrzysztof Wolicki <der.teufel.mail@gmail.com>2023-11-16 08:19:54 +0000
committerGitHub <noreply@github.com>2023-11-16 10:19:54 +0200
commitacf9de376d176d35dcfd245d14939766aeba4638 (patch)
treed2aed2f72db0586b2ff1500c58f432b79af7e7a1 /test/cases
parent359842f8d5a0ee2641c07c1e659d06553d6269fc (diff)
downloadzig-acf9de376d176d35dcfd245d14939766aeba4638.tar.gz
zig-acf9de376d176d35dcfd245d14939766aeba4638.zip
Sema: Add error for non-power of 2 field alignment when reifying Unions, Structs, Pointers
Diffstat (limited to 'test/cases')
-rw-r--r--test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig b/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig
new file mode 100644
index 0000000000..dc57ded029
--- /dev/null
+++ b/test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig
@@ -0,0 +1,50 @@
+comptime {
+ _ = @Type(.{
+ .Union = .{
+ .layout = .Auto,
+ .tag_type = null,
+ .fields = &.{
+ .{ .name = "foo", .type = usize, .alignment = 3 },
+ },
+ .decls = &.{},
+ },
+ });
+}
+comptime {
+ _ = @Type(.{
+ .Struct = .{
+ .layout = .Auto,
+ .fields = &.{.{
+ .name = "0",
+ .type = u32,
+ .default_value = null,
+ .is_comptime = true,
+ .alignment = 5,
+ }},
+ .decls = &.{},
+ .is_tuple = false,
+ },
+ });
+}
+comptime {
+ _ = @Type(.{
+ .Pointer = .{
+ .size = .Many,
+ .is_const = true,
+ .is_volatile = false,
+ .alignment = 7,
+ .address_space = .generic,
+ .child = u8,
+ .is_allowzero = false,
+ .sentinel = null,
+ },
+ });
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:9: error: alignment value '3' is not a power of two or zero
+// :14:9: error: alignment value '5' is not a power of two or zero
+// :30:9: error: alignment value '7' is not a power of two or zero