-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
arch-x86_6464-bit x8664-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Milestone
Description
Zig Version
0.16.0-dev.235+377a8b2a3
Steps to Reproduce and Observed Behavior
pub fn main() void {
var cond = false;
_ = &cond;
const num: f32 = if (cond) 100 else 200;
var a = f();
_ = &a;
std.debug.print("{}\n", .{num});
}
pub fn f() callconv(.c) A {
return .{};
}
pub const A = extern struct {
x: f32 = 0,
y: f32 = 0,
z: f32 = 0,
};On Fedora linux x86_64, running this snippet with zig run src/main.zig outputs 0
Running with zig run src/main.zig -fllvm outputs 200
Notes:
Inserting a print before f is called gives a correct output of 200 twice.
Replacing
const num: f32 = if (cond) 100 else 200;with
var num: f32 = 200;
if (cond) num = 100;also gives the correct output of 200.
Expected Behavior
Expected an output of 200 with the original snippet
Metadata
Metadata
Assignees
Labels
arch-x86_6464-bit x8664-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.