translate-c: regression when translating mutually recursive C typedef'ed structs
bug
### Zig Version
0.16.0-dev.1485+0f1a6ae94
### Steps to Reproduce and Observed Behavior
I use the C library `LibBF` in a project, whose header translates fine on 0.15.2
On master, compilation fails with
`.zig-cache/o/<hash>/cimport.zig:193:5: error: dependency loop detected`
I narrowed it down to the follow repro (the LibBF library has more types involved in the dependency loop, but this is enough to reproduce):
```c
// NOTE: this is an anonymous struct, and that seems to cause problems
typedef struct {
struct bf_context_t *ctx;
} bf_t;
// NOTE: this struct, on the other hand, is tagged
typedef struct bf_context_t {
bf_t val;
} bf_context_t;
```
`zig-master translate-c repro.zig` generates problematic code:
```zig
// error: dependency loop detected
pub const bf_t = bf_t;
pub const struct_bf_context_t = extern struct {
val: bf_t = @import("std").mem.zeroes(bf_t),
};
pub const bf_context_t = struct_bf_context_t;
```
`zig-0.15.2 translate-c repro.zig` generates code that compiles:
```zig
pub const struct_bf_context_t = extern struct {
val: bf_t = @import("std").mem.zeroes(bf_t),
};
pub const bf_t = extern struct {
ctx: [*c]struct_bf_context_t = @import("std").mem.zeroes([*c]struct_bf_context_t),
};
pub const bf_context_t = struct_bf_context_t;
```
### Expected Behavior
Generation of correct Zig source code when translating mutually recursive C structs.
0 条评论