Skip to content

Commit 10bf696

Browse files
xdBronchVexu
authored andcommitted
translate-c: fix callconv attribute in macro
1 parent bbc2139 commit 10bf696

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/translate_c.zig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#define SYSV_ABI __attribute__((sysv_abi))
2+
void 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;

0 commit comments

Comments
 (0)