zig
zig copied to clipboard
"comptime bitcast with fields following f80" behavior test causing undefined behavior in the compiler
Zig Version
0.12.0-dev.3405+31791ae15
Steps to Reproduce and Observed Behavior
test "comptime bitcast with fields following f80" {
const FloatT = extern struct { f: f80, x: u128 align(16) };
const x: FloatT = .{ .f = 0.5, .x = 123 };
var x_as_uint: u256 = comptime @as(u256, @bitCast(x));
_ = &x_as_uint;
try expect(x.f == @as(FloatT, @bitCast(x_as_uint)).f);
try expect(x.x == @as(FloatT, @bitCast(x_as_uint)).x);
}
$ valgrind debug/bin/zig test example.zig -fno-emit-bin
==1652853== Thread 1:
==1652853== Conditional jump or move depends on uninitialised value(s)
==1652853== at 0x61245D6: array_hash_map.ArrayHashMapUnmanaged(void,void,array_hash_map.AutoContext(void),true).getOrPutInternal__anon_78747 (array_hash_map.zig:1664)
==1652853== by 0x5E546B5: array_hash_map.ArrayHashMapUnmanaged(void,void,array_hash_map.AutoContext(void),true).getOrPutAssumeCapacityAdapted__anon_63790 (array_hash_map.zig:816)
==1652853== by 0x5E5383D: array_hash_map.ArrayHashMapUnmanaged(void,void,array_hash_map.AutoContext(void),true).getOrPutContextAdapted__anon_63786 (array_hash_map.zig:753)
==1652853== by 0x5E54795: array_hash_map.ArrayHashMapUnmanaged(void,void,array_hash_map.AutoContext(void),true).getOrPutAdapted__anon_63785 (array_hash_map.zig:738)
==1652853== by 0x5C62D55: InternPool.get (InternPool.zig:4992)
==1652853== by 0x5CF9F19: Module.intern (Module.zig:5713)
==1652853== by 0x5FA8451: Module.intValue_big (Module.zig:5915)
==1652853== by 0x6A5A28C: Value.readFromMemory (Value.zig:957)
==1652853== by 0x6AF42ED: Sema.bitCastVal (Sema.zig:31512)
==1652853== by 0x65AE0A5: Sema.bitCast (Sema.zig:31479)
==1652853== by 0x698A395: Sema.zirBitcast (Sema.zig:10494)
==1652853== by 0x64A224F: Sema.analyzeBodyInner (Sema.zig:1013)
Expected Behavior
No errors found by Valgrind.