Skip to content

Commit 4303400

Browse files
Parzival-3141Vexu
andauthored
Sema+llvm: properly implement Interrupt callconv
Co-authored-by: Veikka Tuominen <[email protected]>
1 parent 8a36a1f commit 4303400

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Sema.zig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9700,6 +9700,18 @@ fn funcCommon(
97009700
{
97019701
return sema.fail(block, param_src, "non-pointer parameter declared noalias", .{});
97029702
}
9703+
9704+
if (cc_resolved == .Interrupt) switch (target.cpu.arch) {
9705+
.x86, .x86_64 => {
9706+
const err_code_size = target.ptrBitWidth();
9707+
switch (i) {
9708+
0 => if (param_ty.zigTypeTag(mod) != .Pointer) return sema.fail(block, param_src, "parameter must be a pointer type", .{}),
9709+
1 => if (param_ty.bitSize(mod) != err_code_size) return sema.fail(block, param_src, "parameter must be a {d}-bit integer", .{err_code_size}),
9710+
else => return sema.fail(block, param_src, "Interrupt calling convention supports up to 2 parameters, found {d}", .{i + 1}),
9711+
}
9712+
},
9713+
else => return sema.fail(block, param_src, "parameters are not allowed with Interrupt calling convention", .{}),
9714+
};
97039715
}
97049716

97059717
var ret_ty_requires_comptime = false;
@@ -10048,6 +10060,15 @@ fn finishFunc(
1004810060
});
1004910061
}
1005010062

10063+
if (cc_resolved == .Interrupt and return_type.zigTypeTag(mod) != .Void) {
10064+
return sema.fail(
10065+
block,
10066+
cc_src,
10067+
"non-void return type '{}' not allowed in function with calling convention 'Interrupt'",
10068+
.{return_type.fmt(mod)},
10069+
);
10070+
}
10071+
1005110072
if (cc_resolved == .Inline and is_noinline) {
1005210073
return sema.fail(block, cc_src, "'noinline' function cannot have callconv 'Inline'", .{});
1005310074
}

src/codegen/llvm.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,6 +4529,10 @@ pub const Object = struct {
45294529
if (!param_ty.isPtrLikeOptional(mod) and !ptr_info.flags.is_allowzero) {
45304530
try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
45314531
}
4532+
if (fn_info.cc == .Interrupt) {
4533+
const child_type = try lowerType(o, Type.fromInterned(ptr_info.child));
4534+
try attributes.addParamAttr(llvm_arg_i, .{ .byval = child_type }, &o.builder);
4535+
}
45324536
if (ptr_info.flags.is_const) {
45334537
try attributes.addParamAttr(llvm_arg_i, .readonly, &o.builder);
45344538
}

0 commit comments

Comments
 (0)