Skip to content

Commit f35a963

Browse files
Vexuandrewrk
authored andcommitted
translate-c properly handle unused var-args
1 parent 576320e commit f35a963

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src-self-hosted/translate_c.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,14 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
477477
var it = proto_node.params.iterator(0);
478478
while (it.next()) |p| {
479479
const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);
480-
const param_name = tokenSlice(c, param.name_token orelse
481-
return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name}));
480+
const param_name = if (param.name_token) |name_tok|
481+
tokenSlice(c, name_tok)
482+
else if (param.var_args_token != null) {
483+
assert(it.next() == null);
484+
_ = proto_node.params.pop();
485+
break;
486+
} else
487+
return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name});
482488

483489
const mangled_param_name = try block_scope.makeMangledName(c, param_name);
484490

test/translate_c.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,9 +2307,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23072307
\\inline void a(void) {}
23082308
\\static void b(void) {}
23092309
\\void c(void) {}
2310+
\\static void foo() {}
23102311
, &[_][]const u8{
23112312
\\pub fn a() void {}
23122313
\\pub fn b() void {}
23132314
\\pub export fn c() void {}
2315+
\\pub fn foo() void {}
23142316
});
23152317
}

0 commit comments

Comments
 (0)