Skip to content

C code generates depends on itself false positive #1310

Closed
@andrewrk

Description

@andrewrk
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviortranslate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions