Skip to content

C code generates depends on itself false positive #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Jul 31, 2018 · 1 comment
Closed

C code generates depends on itself false positive #1310

andrewrk opened this issue Jul 31, 2018 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@andrewrk
Copy link
Member

typedef const struct InvocationTable_ *VM;

struct VM_ {
    const struct InvocationTable_ *functions;
};

struct InvocationTable_ {
    int (*GetVM)(VM *vm);
}; 

int agent_callback(VM *vm, char *options);

translated to zig:

pub const VM = ?[*]const struct_InvocationTable_;
pub const struct_InvocationTable_ = extern struct {
    GetVM: ?extern fn(?[*]VM) c_int,
};

pub const struct_VM_ = extern struct {
    functions: ?[*]const struct_InvocationTable_,
};

//excised output from stdlib.h etc

pub const InvocationTable_ = struct_InvocationTable_;
pub const VM_ = struct_VM_;

usage:

const vm = @cImport({ @cInclude("vm.h"); });

export fn agent_callback(_vm: [*]vm.VM, options: [*]u8) i32 {
    return 0;
}

output:

zig -isystem . build-lib vm.zig

vm.zig:1:12: error: compiler bug: @cImport generated invalid zig code
const vm = @cImport({ @cInclude("vm.h"); });
           ^
?.c:1:1: note: 'VM' depends on itself
TODO: remember C source location to display here
^

Possibly related: #624 and #679

Reported by @moysesb

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jul 31, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Jul 31, 2018
@andrewrk andrewrk changed the title C code generatesdepends on itself false positive C code generates depends on itself false positive Jul 31, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Sep 11, 2018
@andrewrk
Copy link
Member Author

andrewrk commented Mar 1, 2019

I'm pretty sure this is a duplicate of #624 but it is not a dependency of #679. I will leave it open until this test case is added as a regression test.

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Apr 3, 2019
@andrewrk andrewrk added the translate-c C to Zig source translation feature (@cImport) label Jun 16, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.5.0 Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

1 participant