authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2025-05-06 19:08:15-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2025-05-07 16:15:51+03:00
log10bf6964edc6d1a002b0ea313e256701295ba11c
treee80674a2f7ba0f5c0231a6b88bc7a35257a29561
parentbbc21393b407bea0f8346083bfda9425ab3ff40e

translate-c: fix callconv attribute in macro


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

src/translate_c.zig+10-6
......@@ -403,22 +403,26 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
403403
404404 switch (fn_type.getTypeClass()) {
405405 .Attributed => {
406 const attr_type = @as(*const clang.AttributedType, @ptrCast(fn_type));
406 const attr_type: *const clang.AttributedType = @ptrCast(fn_type);
407407 fn_qt = attr_type.getEquivalentType();
408408 },
409409 .Paren => {
410 const paren_type = @as(*const clang.ParenType, @ptrCast(fn_type));
410 const paren_type: *const clang.ParenType = @ptrCast(fn_type);
411411 fn_qt = paren_type.getInnerType();
412412 },
413 .MacroQualified => {
414 const macroqualified_ty: *const clang.MacroQualifiedType = @ptrCast(fn_type);
415 fn_qt = macroqualified_ty.getModifiedType();
416 },
413417 else => break fn_type,
414418 }
415419 };
416 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_type));
420 const fn_ty: *const clang.FunctionType = @ptrCast(fn_type);
417421 const return_qt = fn_ty.getReturnType();
418422
419423 const proto_node = switch (fn_type.getTypeClass()) {
420424 .FunctionProto => blk: {
421 const fn_proto_type = @as(*const clang.FunctionProtoType, @ptrCast(fn_type));
425 const fn_proto_type: *const clang.FunctionProtoType = @ptrCast(fn_type);
422426 if (has_body and fn_proto_type.isVariadic()) {
423427 decl_ctx.has_body = false;
424428 decl_ctx.storage_class = .Extern;
......@@ -434,7 +438,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
434438 };
435439 },
436440 .FunctionNoProto => blk: {
437 const fn_no_proto_type = @as(*const clang.FunctionType, @ptrCast(fn_type));
441 const fn_no_proto_type: *const clang.FunctionType = @ptrCast(fn_type);
438442 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
439443 error.UnsupportedType => {
440444 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
490494 param_id += 1;
491495 }
492496
493 const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt));
497 const casted_body: *const clang.CompoundStmt = @ptrCast(body_stmt);
494498 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {
495499 error.OutOfMemory => |e| return e,
496500 error.UnsupportedTranslation,
test/cases/translate_c/macro_calling_convention.c created+9
......@@ -0,0 +1,9 @@
1#define SYSV_ABI __attribute__((sysv_abi))
2void SYSV_ABI foo(void);
3
4
5// translate-c
6// c_frontend=clang
7// target=x86_64-windows
8//
9// pub extern fn foo() callconv(.{ .x86_64_sysv = .{} }) void;