zig
zig copied to clipboard
Translate-c generates invalid Zig (pointless discard of local constant)
Zig Version
0.10.0-dev.4437+1e963053d
Steps to Reproduce
Try to compile stb_image v2.27 library:
const c = @cImport({
@cDefine("STB_IMAGE_IMPLEMENTATION", {});
@cDefine("STBI_ONLY_PNG", {});
@cDefine("STBI_NO_STDIO", {});
@cInclude("stb_image.h");
});
pub fn main() void {
const png = [_]u8 {};
const png_len = @intCast(c_int, png.len);
var c_width: c_int = undefined;
var c_height: c_int = undefined;
_ = c.stbi_info_from_memory(png.ptr, png_len, &c_width, &c_height, null);
}
Expected Behavior
Compile successfully.
Actual Behavior
Compilation fails with
[snip]\cimport.zig:3691:66: error: pointless discard of local constant
break :blk_4 tmp;
^~~
[snip]\cimport.zig:3690:60: note: used here
}).* = tmp;
^~~
[6 more errors]
[snip]\src\main.zig:1:11: error: C import failed: AnalysisFail
pub usingnamespace @cImport({
^~~~~~~~
what was the rest of your test code?
I've updated the usage example.
Reduction:
test {
var b: u32 = 1;
_ = blk: {
const a = 1;
b = a;
break :blk a;
};
}
ohhhh same error happened but it works on stage1