translate-c: fix callconv attribute in macro

This commit is contained in:
xdBronch 2025-05-06 19:08:15 -04:00 committed by Veikka Tuominen
parent bbc21393b4
commit 10bf6964ed
2 changed files with 19 additions and 6 deletions

View File

@ -403,22 +403,26 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
switch (fn_type.getTypeClass()) { switch (fn_type.getTypeClass()) {
.Attributed => { .Attributed => {
const attr_type = @as(*const clang.AttributedType, @ptrCast(fn_type)); const attr_type: *const clang.AttributedType = @ptrCast(fn_type);
fn_qt = attr_type.getEquivalentType(); fn_qt = attr_type.getEquivalentType();
}, },
.Paren => { .Paren => {
const paren_type = @as(*const clang.ParenType, @ptrCast(fn_type)); const paren_type: *const clang.ParenType = @ptrCast(fn_type);
fn_qt = paren_type.getInnerType(); fn_qt = paren_type.getInnerType();
}, },
.MacroQualified => {
const macroqualified_ty: *const clang.MacroQualifiedType = @ptrCast(fn_type);
fn_qt = macroqualified_ty.getModifiedType();
},
else => break fn_type, else => break fn_type,
} }
}; };
const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_type)); const fn_ty: *const clang.FunctionType = @ptrCast(fn_type);
const return_qt = fn_ty.getReturnType(); const return_qt = fn_ty.getReturnType();
const proto_node = switch (fn_type.getTypeClass()) { const proto_node = switch (fn_type.getTypeClass()) {
.FunctionProto => blk: { .FunctionProto => blk: {
const fn_proto_type = @as(*const clang.FunctionProtoType, @ptrCast(fn_type)); const fn_proto_type: *const clang.FunctionProtoType = @ptrCast(fn_type);
if (has_body and fn_proto_type.isVariadic()) { if (has_body and fn_proto_type.isVariadic()) {
decl_ctx.has_body = false; decl_ctx.has_body = false;
decl_ctx.storage_class = .Extern; decl_ctx.storage_class = .Extern;
@ -434,7 +438,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
}; };
}, },
.FunctionNoProto => blk: { .FunctionNoProto => blk: {
const fn_no_proto_type = @as(*const clang.FunctionType, @ptrCast(fn_type)); const fn_no_proto_type: *const clang.FunctionType = @ptrCast(fn_type);
break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
error.UnsupportedType => { error.UnsupportedType => {
return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
@ -490,7 +494,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
param_id += 1; param_id += 1;
} }
const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt)); const casted_body: *const clang.CompoundStmt = @ptrCast(body_stmt);
transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) { transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {
error.OutOfMemory => |e| return e, error.OutOfMemory => |e| return e,
error.UnsupportedTranslation, error.UnsupportedTranslation,

View File

@ -0,0 +1,9 @@
#define SYSV_ABI __attribute__((sysv_abi))
void SYSV_ABI foo(void);
// translate-c
// c_frontend=clang
// target=x86_64-windows
//
// pub extern fn foo() callconv(.{ .x86_64_sysv = .{} }) void;