aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/align.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-30 14:16:28 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-30 14:16:28 -0700
commitbd89a73d5289536948b052eb7f052d6de193441b (patch)
tree39930f14ff7576884e67ed54a3d3f06ec8ab2785 /test/behavior/align.zig
parent7e98b047ddc51062a32cbf2fb852d38e5023886c (diff)
downloadzig-bd89a73d5289536948b052eb7f052d6de193441b.tar.gz
zig-bd89a73d5289536948b052eb7f052d6de193441b.zip
Sema: implement functions generic across callconv() or align()
Diffstat (limited to 'test/behavior/align.zig')
-rw-r--r--test/behavior/align.zig43
1 files changed, 31 insertions, 12 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig
index 2c0893074e..d77a2153cc 100644
--- a/test/behavior/align.zig
+++ b/test/behavior/align.zig
@@ -334,25 +334,44 @@ fn simple4() align(4) i32 {
return 0x19;
}
-test "generic function with align param" {
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+test "function align expression depends on generic parameter" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
// function alignment is a compile error on wasm32/wasm64
if (native_arch == .wasm32 or native_arch == .wasm64) return error.SkipZigTest;
if (native_arch == .thumb) return error.SkipZigTest;
- try expect(whyWouldYouEverDoThis(1) == 0x1);
- try expect(whyWouldYouEverDoThis(4) == 0x1);
- try expect(whyWouldYouEverDoThis(8) == 0x1);
+ const S = struct {
+ fn doTheTest() !void {
+ try expect(foobar(1) == 2);
+ try expect(foobar(4) == 5);
+ try expect(foobar(8) == 9);
+ }
+
+ fn foobar(comptime align_bytes: u8) align(align_bytes) u8 {
+ return align_bytes + 1;
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
-fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
- _ = align_bytes;
- return 0x1;
+test "function callconv expression depends on generic parameter" {
+ if (builtin.zig_backend == .stage1) return error.SkipZigTest;
+
+ const S = struct {
+ fn doTheTest() !void {
+ try expect(foobar(.C, 1) == 2);
+ try expect(foobar(.Unspecified, 2) == 3);
+ }
+
+ fn foobar(comptime cc: std.builtin.CallingConvention, arg: u8) callconv(cc) u8 {
+ return arg + 1;
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
}
test "runtime known array index has best alignment possible" {