aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-30 21:18:10 -0400
committerGitHub <noreply@github.com>2022-05-30 21:18:10 -0400
commitc3ef4ac15f4aa0a4bbf546fb46745d445b97d717 (patch)
tree98158ea6835297c116bbaf2735d32e556e8741c2 /test/behavior
parentc84f5a5f91d31b20b2e187d84fc8a80a190a1212 (diff)
parentbd89a73d5289536948b052eb7f052d6de193441b (diff)
downloadzig-c3ef4ac15f4aa0a4bbf546fb46745d445b97d717.tar.gz
zig-c3ef4ac15f4aa0a4bbf546fb46745d445b97d717.zip
Merge pull request #11752 from ziglang/zir-fancy-fns
stage2: add missing data to ZIR encoding of functions
Diffstat (limited to 'test/behavior')
-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" {