authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-02-09 10:12:15-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-10 17:20:52-08:00
log74fbcd22e6ebd12c227e1ba293d71c692f0edb8b
tree817f37d1b1a250efda6dcf595d5ebec61c53f52f
parenteb7963e4c7a0731c1ade884b9c6ae0d818bccafe

cbe: fix crash rendering argument names in lazy functions

Closes #19905

2 files changed, 23 insertions(+), 19 deletions(-)

src/codegen/c.zig+1-1
...@@ -2855,7 +2855,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2855,7 +2855,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2855 try w.writeByte('(');2855 try w.writeByte('(');
2856 for (0..fn_info.param_ctypes.len) |arg| {2856 for (0..fn_info.param_ctypes.len) |arg| {
2857 if (arg > 0) try w.writeAll(", ");2857 if (arg > 0) try w.writeAll(", ");
2858 try o.dg.writeCValue(w, .{ .arg = arg });2858 try w.print("a{d}", .{arg});
2859 }2859 }
2860 try w.writeAll(");\n}\n");2860 try w.writeAll(");\n}\n");
2861 },2861 },
test/behavior/call.zig+22-18
...@@ -21,37 +21,41 @@ test "super basic invocations" {...@@ -21,37 +21,41 @@ test "super basic invocations" {
2121
22test "basic invocations" {22test "basic invocations" {
23 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO23 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
24 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
25 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO24 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
26 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO25 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
27 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO26 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
28 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;27 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
2928
29 if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support tail call modifiers
30
30 const foo = struct {31 const foo = struct {
31 fn foo() i32 {32 fn foo(_: i32) i32 {
32 return 1234;33 return 1234;
33 }34 }
34 }.foo;35 }.foo;
35 try expect(@call(.auto, foo, .{}) == 1234);36 try expect(@call(.auto, foo, .{1}) == 1234);
36 comptime {37 comptime {
37 // modifiers that allow comptime calls38 // comptime calls with supported modifiers
38 try expect(@call(.auto, foo, .{}) == 1234);39 try expect(@call(.auto, foo, .{2}) == 1234);
39 try expect(@call(.no_async, foo, .{}) == 1234);40 try expect(@call(.no_async, foo, .{3}) == 1234);
40 try expect(@call(.always_tail, foo, .{}) == 1234);41 try expect(@call(.always_tail, foo, .{4}) == 1234);
41 try expect(@call(.always_inline, foo, .{}) == 1234);42 try expect(@call(.always_inline, foo, .{5}) == 1234);
42 }43 }
43 {44 // comptime call without comptime keyword
44 // comptime call without comptime keyword45 const result = @call(.compile_time, foo, .{6}) == 1234;
45 const result = @call(.compile_time, foo, .{}) == 1234;46 comptime assert(result);
46 comptime assert(result);47 // runtime calls of comptime-known function
47 }48 try expect(@call(.no_async, foo, .{7}) == 1234);
48 {49 try expect(@call(.never_tail, foo, .{8}) == 1234);
49 // call of non comptime-known function50 try expect(@call(.never_inline, foo, .{9}) == 1234);
51 // CBE does not support attributes on runtime functions
52 if (builtin.zig_backend != .stage2_c) {
53 // runtime calls of non comptime-known function
50 var alias_foo = &foo;54 var alias_foo = &foo;
51 _ = &alias_foo;55 _ = &alias_foo;
52 try expect(@call(.no_async, alias_foo, .{}) == 1234);56 try expect(@call(.no_async, alias_foo, .{10}) == 1234);
53 try expect(@call(.never_tail, alias_foo, .{}) == 1234);57 try expect(@call(.never_tail, alias_foo, .{11}) == 1234);
54 try expect(@call(.never_inline, alias_foo, .{}) == 1234);58 try expect(@call(.never_inline, alias_foo, .{12}) == 1234);
55 }59 }
56}60}
5761