Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std.builtin.CallingConvention with a tagged union, eliminating @setAlignStack #21697

Merged
merged 28 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
51706af
compiler: introduce new `CallingConvention`
mlugg Sep 28, 2024
36405b9
stage1: update zig1.wasm
mlugg Oct 14, 2024
bc797a9
std: update for new `CallingConvention`
mlugg Oct 8, 2024
ec19086
compiler: remove @setAlignStack
mlugg Oct 14, 2024
4be0cf3
test: update for `CallingConvention` changes
mlugg Oct 13, 2024
cbfe00b
std.zig.render: fix `callconv(.Inline)` -> `inline fn` promotion
mlugg Oct 15, 2024
2d9a167
std.Target: rename `defaultCCallingConvention` and `Cpu.Arch.fromCall…
mlugg Oct 15, 2024
6657982
std.builtin.CallingConvention: don't provide bogus `winapi` value
mlugg Oct 15, 2024
a2c519b
link: add clarifying comment
mlugg Oct 15, 2024
67580ed
std.builtin.CallingConvention: RISC-V `PrivilegeLevel` -> `PrivilegeM…
mlugg Oct 15, 2024
cb48376
cbe,translate-c: support more callconvs
mlugg Oct 15, 2024
d466c08
Sema: minor cleanup
mlugg Oct 15, 2024
2319d62
std.builtin.CallingConvention: include exact architecture tags in com…
mlugg Oct 15, 2024
0b78605
compiler: avoid unreasonable eval branch quotas
mlugg Oct 15, 2024
ed862b0
std.builtin.CallingConvention: remove deprecated RISC-V privilege mode
mlugg Oct 15, 2024
1f11eed
llvm: fix lowering of avr_interrupt and m68k_interrupt callconvs
mlugg Oct 15, 2024
bde68fd
std.Target: correct C callconv on hardfloat ARM
mlugg Oct 15, 2024
1d1e8e1
link.Dwarf: handle `avr_signal` and `avr_builtin` callconvs
mlugg Oct 15, 2024
3ef8bb6
llvn: fix incorrect mips64 callconv handling
mlugg Oct 15, 2024
8302301
std: update uses of `.Inline` callconv
mlugg Oct 16, 2024
04ffc1c
langref: update `enum_export_error.zig` for callconv changes
mlugg Oct 16, 2024
28cb887
Zcu: correct `callconvSupported` for self-hosted aarch64
mlugg Oct 16, 2024
289b2f8
llvm: fix lowering `arm_aapcs_vfp` functions
mlugg Oct 16, 2024
cf39652
compiler_rt: remove bogus tests
mlugg Oct 16, 2024
387965a
x86_64,riscv64: fix incorrect `incoming_stack_alignment` handling
mlugg Oct 16, 2024
73f4c68
x86_64: handle incoming stack alignment
mlugg Oct 17, 2024
8d5ac6b
Sema: add and improve some callconv compile errors
mlugg Oct 17, 2024
f7d679c
riscv: disable failing test
mlugg Oct 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/langref/enum_export_error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export fn entry(foo: Foo) void {
_ = foo;
}

// obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'C'
// obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'x86_64_sysv'
// target=x86_64-linux
68 changes: 60 additions & 8 deletions lib/compiler/aro_translate_c/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,26 @@ pub const Payload = struct {
is_var_args: bool,
name: ?[]const u8,
linksection_string: ?[]const u8,
explicit_callconv: ?std.builtin.CallingConvention,
explicit_callconv: ?CallingConvention,
params: []Param,
return_type: Node,
body: ?Node,
alignment: ?c_uint,
},

pub const CallingConvention = enum {
c,
x86_64_sysv,
x86_64_win,
x86_stdcall,
x86_fastcall,
x86_thiscall,
x86_vectorcall,
aarch64_vfabi,
arm_aapcs,
arm_aapcs_vfp,
m68k_rtd,
};
};

pub const Param = struct {
Expand Down Expand Up @@ -2812,14 +2826,52 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
const callconv_expr = if (payload.explicit_callconv) |some| blk: {
_ = try c.addToken(.keyword_callconv, "callconv");
_ = try c.addToken(.l_paren, "(");
_ = try c.addToken(.period, ".");
const res = try c.addNode(.{
.tag = .enum_literal,
.main_token = try c.addTokenFmt(.identifier, "{s}", .{@tagName(some)}),
.data = undefined,
});
const cc_node = switch (some) {
.c => cc_node: {
_ = try c.addToken(.period, ".");
break :cc_node try c.addNode(.{
.tag = .enum_literal,
.main_token = try c.addToken(.identifier, "c"),
.data = undefined,
});
},
.x86_64_sysv,
.x86_64_win,
.x86_stdcall,
.x86_fastcall,
.x86_thiscall,
.x86_vectorcall,
.aarch64_vfabi,
.arm_aapcs,
.arm_aapcs_vfp,
.m68k_rtd,
=> cc_node: {
// .{ .foo = .{} }
_ = try c.addToken(.period, ".");
const outer_lbrace = try c.addToken(.l_brace, "{");
_ = try c.addToken(.period, ".");
_ = try c.addToken(.identifier, @tagName(some));
_ = try c.addToken(.equal, "=");
_ = try c.addToken(.period, ".");
const inner_lbrace = try c.addToken(.l_brace, "{");
_ = try c.addToken(.r_brace, "}");
_ = try c.addToken(.r_brace, "}");
break :cc_node try c.addNode(.{
.tag = .struct_init_dot_two,
.main_token = outer_lbrace,
.data = .{
.lhs = try c.addNode(.{
.tag = .struct_init_dot_two,
.main_token = inner_lbrace,
.data = .{ .lhs = 0, .rhs = 0 },
}),
.rhs = 0,
},
});
},
};
_ = try c.addToken(.r_paren, ")");
break :blk res;
break :blk cc_node;
} else 0;

const return_type_expr = try renderNode(c, payload.return_type);
Expand Down
39 changes: 0 additions & 39 deletions lib/compiler_rt/int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const is_test = builtin.is_test;
const common = @import("common.zig");
const udivmod = @import("udivmod.zig").udivmod;
const __divti3 = @import("divti3.zig").__divti3;
const arm = @import("arm.zig");

pub const panic = common.panic;

Expand Down Expand Up @@ -102,25 +101,6 @@ test "test_divmoddi4" {
}
}

fn test_one_aeabi_ldivmod(a: i64, b: i64, expected_q: i64, expected_r: i64) !void {
const LdivmodRes = extern struct {
q: i64, // r1:r0
r: i64, // r3:r2
};
const actualIdivmod = @as(*const fn (a: i64, b: i64) callconv(.AAPCS) LdivmodRes, @ptrCast(&arm.__aeabi_ldivmod));
const arm_res = actualIdivmod(a, b);
try testing.expectEqual(expected_q, arm_res.q);
try testing.expectEqual(expected_r, arm_res.r);
}

test "arm.__aeabi_ldivmod" {
if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;

for (cases__divmodsi4) |case| {
try test_one_aeabi_ldivmod(case[0], case[1], case[2], case[3]);
}
}

pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
return udivmod(u64, a, b, maybe_rem);
}
Expand Down Expand Up @@ -261,25 +241,6 @@ test "test_divmodsi4" {
}
}

fn test_one_aeabi_idivmod(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
const IdivmodRes = extern struct {
q: i32, // r0
r: i32, // r1
};
const actualIdivmod = @as(*const fn (a: i32, b: i32) callconv(.AAPCS) IdivmodRes, @ptrCast(&arm.__aeabi_idivmod));
const arm_res = actualIdivmod(a, b);
try testing.expectEqual(expected_q, arm_res.q);
try testing.expectEqual(expected_r, arm_res.r);
}

test "arm.__aeabi_idivmod" {
if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;

for (cases__divmodsi4) |case| {
try test_one_aeabi_idivmod(case[0], case[1], case[2], case[3]);
}
}

pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
const d = __udivsi3(a, b);
rem.* = @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b))));
Expand Down
21 changes: 0 additions & 21 deletions lib/compiler_rt/udivmoddi4_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const testing = @import("std").testing;
const builtin = @import("builtin");
const __udivmoddi4 = @import("int.zig").__udivmoddi4;
const __aeabi_uldivmod = @import("arm.zig").__aeabi_uldivmod;

fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
var r: u64 = undefined;
Expand All @@ -18,26 +17,6 @@ test "udivmoddi4" {
}
}

const ARMRes = extern struct {
q: u64, // r1:r0
r: u64, // r3:r2
};

fn test__aeabi_uldivmod(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
const actualUldivmod = @as(*const fn (a: u64, b: u64) callconv(.AAPCS) ARMRes, @ptrCast(&__aeabi_uldivmod));
const arm_res = actualUldivmod(a, b);
try testing.expectEqual(expected_q, arm_res.q);
try testing.expectEqual(expected_r, arm_res.r);
}

test "arm.__aeabi_uldivmod" {
if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;

for (cases) |case| {
try test__aeabi_uldivmod(case[0], case[1], case[2], case[3]);
}
}

const cases = [_][4]u64{
[_]u64{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
[_]u64{0x0000000000000000, 0x0000000000000002, 0x0000000000000000, 0x0000000000000000},
Expand Down
25 changes: 8 additions & 17 deletions lib/compiler_rt/udivmodsi4_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@
// zig fmt: off
const testing = @import("std").testing;
const builtin = @import("builtin");
const __aeabi_uidivmod = @import("arm.zig").__aeabi_uidivmod;
const __udivmodsi4 = @import("int.zig").__udivmodsi4;

const ARMRes = extern struct {
q: u32, // r0
r: u32, // r1
};

fn test__aeabi_uidivmod(a: u32, b: u32, expected_q: u32, expected_r: u32) !void {
const actualUidivmod = @as(*const fn (a: u32, b: u32) callconv(.AAPCS) ARMRes, @ptrCast(&__aeabi_uidivmod));
const arm_res = actualUidivmod(a, b);
try testing.expectEqual(expected_q, arm_res.q);
try testing.expectEqual(expected_r, arm_res.r);
fn test__udivmodsi4(a: u32, b: u32, expected_q: u32, expected_r: u32) !void {
var r: u32 = undefined;
const q = __udivmodsi4(a, b, &r);
try testing.expectEqual(expected_q, q);
try testing.expectEqual(expected_r, r);
}

test "arm.__aeabi_uidivmod" {
if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;

var i: i32 = 0;
test "udivmodsi4" {
for (cases) |case| {
try test__aeabi_uidivmod(case[0], case[1], case[2], case[3]);
i+=1;
try test__udivmodsi4(case[0], case[1], case[2], case[3]);
}
}

Expand Down
Loading
Loading