authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-26 13:01:58+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-12-26 13:02:17+02:00
log50e8c3882a3f753fe504a82ebc0d853a1fa1e0ed
treed5ae1724c040279e040891d2b0ea0bb3101274a0
parent641bf4c46eb2d5c1f3e95898ed74848a56e0d999
signaturelock-open Commit is signed but in an unrecognized format.

translate-c: demote variadic functions to declarations


2 files changed, 16 insertions(+), 1 deletions(-)

src/translate_c.zig+7-1
......@@ -550,7 +550,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
550550 const fn_decl_loc = fn_decl.getLocation();
551551 const has_body = fn_decl.hasBody();
552552 const storage_class = fn_decl.getStorageClass();
553 const decl_ctx = FnDeclContext{
553 var decl_ctx = FnDeclContext{
554554 .fn_name = fn_name,
555555 .has_body = has_body,
556556 .storage_class = storage_class,
......@@ -584,6 +584,12 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
584584 const proto_node = switch (fn_type.getTypeClass()) {
585585 .FunctionProto => blk: {
586586 const fn_proto_type = @ptrCast(*const clang.FunctionProtoType, fn_type);
587 if (has_body and fn_proto_type.isVariadic()) {
588 decl_ctx.has_body = false;
589 decl_ctx.storage_class = .Extern;
590 decl_ctx.is_export = false;
591 try emitWarning(c, fn_decl_loc, "TODO unable to translate variadic function, demoted to declaration", .{});
592 }
587593 break :blk transFnProto(rp, fn_decl, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) {
588594 error.UnsupportedType => {
589595 return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{});
test/translate_c.zig+9
......@@ -3,6 +3,15 @@ const std = @import("std");
33const CrossTarget = std.zig.CrossTarget;
44
55pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("variadic function demoted to prototype",
7 \\int foo(int bar, ...) {
8 \\ return 1;
9 \\}
10 , &[_][]const u8{
11 \\warning: TODO unable to translate variadic function, demoted to declaration
12 \\pub extern fn foo(bar: c_int, ...) c_int;
13 });
14
615 cases.add("pointer to opaque demoted struct",
716 \\typedef struct {
817 \\ _Atomic int foo;