cbe: fix crash rendering argument names in lazy functions

Closes #19905
This commit is contained in:
Jacob Young 2025-02-09 10:12:15 -05:00 committed by Andrew Kelley
parent eb7963e4c7
commit 74fbcd22e6
2 changed files with 23 additions and 19 deletions

View File

@ -2855,7 +2855,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
try w.writeByte('('); try w.writeByte('(');
for (0..fn_info.param_ctypes.len) |arg| { for (0..fn_info.param_ctypes.len) |arg| {
if (arg > 0) try w.writeAll(", "); if (arg > 0) try w.writeAll(", ");
try o.dg.writeCValue(w, .{ .arg = arg }); try w.print("a{d}", .{arg});
} }
try w.writeAll(");\n}\n"); try w.writeAll(");\n}\n");
}, },

View File

@ -21,37 +21,41 @@ test "super basic invocations" {
test "basic invocations" { test "basic invocations" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support tail call modifiers
const foo = struct { const foo = struct {
fn foo() i32 { fn foo(_: i32) i32 {
return 1234; return 1234;
} }
}.foo; }.foo;
try expect(@call(.auto, foo, .{}) == 1234); try expect(@call(.auto, foo, .{1}) == 1234);
comptime { comptime {
// modifiers that allow comptime calls // comptime calls with supported modifiers
try expect(@call(.auto, foo, .{}) == 1234); try expect(@call(.auto, foo, .{2}) == 1234);
try expect(@call(.no_async, foo, .{}) == 1234); try expect(@call(.no_async, foo, .{3}) == 1234);
try expect(@call(.always_tail, foo, .{}) == 1234); try expect(@call(.always_tail, foo, .{4}) == 1234);
try expect(@call(.always_inline, foo, .{}) == 1234); try expect(@call(.always_inline, foo, .{5}) == 1234);
} }
{ // comptime call without comptime keyword
// comptime call without comptime keyword const result = @call(.compile_time, foo, .{6}) == 1234;
const result = @call(.compile_time, foo, .{}) == 1234; comptime assert(result);
comptime assert(result); // runtime calls of comptime-known function
} try expect(@call(.no_async, foo, .{7}) == 1234);
{ try expect(@call(.never_tail, foo, .{8}) == 1234);
// call of non comptime-known function try expect(@call(.never_inline, foo, .{9}) == 1234);
// CBE does not support attributes on runtime functions
if (builtin.zig_backend != .stage2_c) {
// runtime calls of non comptime-known function
var alias_foo = &foo; var alias_foo = &foo;
_ = &alias_foo; _ = &alias_foo;
try expect(@call(.no_async, alias_foo, .{}) == 1234); try expect(@call(.no_async, alias_foo, .{10}) == 1234);
try expect(@call(.never_tail, alias_foo, .{}) == 1234); try expect(@call(.never_tail, alias_foo, .{11}) == 1234);
try expect(@call(.never_inline, alias_foo, .{}) == 1234); try expect(@call(.never_inline, alias_foo, .{12}) == 1234);
} }
} }