authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2025-05-06 19:08:15-04:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-09 16:43:35+02:00
log55acb29d68e7cb9a7585929f60c2dfb4c39a3b04
treea42d48170b5cbcd06d83e2aebe2923be7f550caf
parentb21fa8e2cd98d487d50755416c7ab90ebd6e620e
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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...@@ -403,22 +403,26 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
403403
404 switch (fn_type.getTypeClass()) {404 switch (fn_type.getTypeClass()) {
405 .Attributed => {405 .Attributed => {
406 const attr_type = @as(*const clang.AttributedType, @ptrCast(fn_type));406 const attr_type: *const clang.AttributedType = @ptrCast(fn_type);
407 fn_qt = attr_type.getEquivalentType();407 fn_qt = attr_type.getEquivalentType();
408 },408 },
409 .Paren => {409 .Paren => {
410 const paren_type = @as(*const clang.ParenType, @ptrCast(fn_type));410 const paren_type: *const clang.ParenType = @ptrCast(fn_type);
411 fn_qt = paren_type.getInnerType();411 fn_qt = paren_type.getInnerType();
412 },412 },
413 .MacroQualified => {
414 const macroqualified_ty: *const clang.MacroQualifiedType = @ptrCast(fn_type);
415 fn_qt = macroqualified_ty.getModifiedType();
416 },
413 else => break fn_type,417 else => break fn_type,
414 }418 }
415 };419 };
416 const fn_ty = @as(*const clang.FunctionType, @ptrCast(fn_type));420 const fn_ty: *const clang.FunctionType = @ptrCast(fn_type);
417 const return_qt = fn_ty.getReturnType();421 const return_qt = fn_ty.getReturnType();
418422
419 const proto_node = switch (fn_type.getTypeClass()) {423 const proto_node = switch (fn_type.getTypeClass()) {
420 .FunctionProto => blk: {424 .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);
422 if (has_body and fn_proto_type.isVariadic()) {426 if (has_body and fn_proto_type.isVariadic()) {
423 decl_ctx.has_body = false;427 decl_ctx.has_body = false;
424 decl_ctx.storage_class = .Extern;428 decl_ctx.storage_class = .Extern;
...@@ -434,7 +438,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E...@@ -434,7 +438,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
434 };438 };
435 },439 },
436 .FunctionNoProto => blk: {440 .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);
438 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {442 break :blk transFnNoProto(c, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
439 error.UnsupportedType => {443 error.UnsupportedType => {
440 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});444 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...@@ -490,7 +494,7 @@ fn transFnDecl(c: *Context, scope: *Scope, fn_decl: *const clang.FunctionDecl) E
490 param_id += 1;494 param_id += 1;
491 }495 }
492496
493 const casted_body = @as(*const clang.CompoundStmt, @ptrCast(body_stmt));497 const casted_body: *const clang.CompoundStmt = @ptrCast(body_stmt);
494 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {498 transCompoundStmtInline(c, casted_body, &block_scope) catch |err| switch (err) {
495 error.OutOfMemory => |e| return e,499 error.OutOfMemory => |e| return e,
496 error.UnsupportedTranslation,500 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;