You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
undefined parameter not set to 0xaa bytes in the llvm backend #24100
backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.
call me crazy but the order of statements seems to matter?!
After a bit more finagling, it seems (somewhat arbitrarily) dependant on the size of the type of the const too (with 2, 6, 8, and 12 bytes seemingly working!?)
Note: this is literally my first piece of comptime zig so please take it with a grain of salt...
conststd=@import("std");
constprint=std.debug.print;
constwarn=std.log.warn;
constexpect=std.testing.expect;
pubfnmain() !void {}
fndefault_val_for_type(comptimetyp: type) comptime_int {
varv=0;
varbits=1;
while (bits<=@bitSizeOf(typ)) : (bits+=1) {
v= (v<<1) | (bits%2);
}
returnv;
}
comptime {
consttypes= .{ u8, u12, u16, u24, u32, u48, u64, u96, u128, u192, u256, u384, u512 };
// NOTE: putting `u8` to the back somehow makes it work for `u8` too?!// const types = .{ u12, u16, u24, u32, u48, u64, u96, u128, u192, u256, u384, u512, u8 };for (types) |typ| {
_=struct {
test {
constexpected=default_val_for_type(typ);
warn("############################### {s} -- 0x{x:}", .{ @typeName(typ), expected });
constc: typ=undefined;
tryexpect(c==expected);
// var v: typ = undefined; // Uncomment => different results?!?!// try expect(v == expected);// v = undefined;// try expect(v == expected);warn("Passed for {s}!\n", .{@typeName(typ)});
}
};
}
}
Output:
[default] (warn): ############################### u8 -- 0xaa
1/13 main.comptime__struct_149.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a4120b in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u12 -- 0xaaa
2/13 main.comptime__struct_150.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a419eb in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u16 -- 0xaaaa
[default] (warn): Passed for u16!
[default] (warn): ############################### u24 -- 0xaaaaaa
4/13 main.comptime__struct_154.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a428bb in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u32 -- 0xaaaaaaaa
5/13 main.comptime__struct_156.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a42fa7 in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u48 -- 0xaaaaaaaaaaaa
[default] (warn): Passed for u48!
[default] (warn): ############################### u64 -- 0xaaaaaaaaaaaaaaaa
[default] (warn): Passed for u64!
[default] (warn): ############################### u96 -- 0xaaaaaaaaaaaaaaaaaaaaaaaa
[default] (warn): Passed for u96!
[default] (warn): ############################### u128 -- 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
9/13 main.comptime__struct_164.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a4526f in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u192 -- 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
10/13 main.comptime__struct_166.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a45a53 in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u256 -- 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
11/13 main.comptime__struct_168.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a47c8b in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u384 -- 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
12/13 main.comptime__struct_170.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a4a4df in test_0 (test)
try expect(c == expected);
^
[default] (warn): ############################### u512 -- 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
13/13 main.comptime__struct_172.test_0...FAIL (TestUnexpectedResult)
/Users/nashwan/Documents/Coding/Zig/compilers/zig-aarch64-macos-0.16.0-dev.1301+cbfa87cbe/lib/std/testing.zig:604:14: 0x102a411b7 in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/Users/nashwan/Documents/Coding/Zig/compilers/playground/src/main.zig:30:17: 0x102a4dddf in test_0 (test)
try expect(c == expected);
^
4 passed; 0 skipped; 9 failed.
error: the following test command failed with exit code 1:
.zig-cache/o/cd0e2620c51d4e7991d70f37a5320d2e/test --seed=0xa9e143ba
PS: being able to dynamically name comptime tests like test @typeName(typ) would have been pretty slick.
backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.
Activity
kmr-srbh commentedon Aug 20, 2025
@andrewrk may I please take up this issue? It might take me some time since I am starting out with
zig, but I wish to contribute to the project.silversquirl commentedon Aug 20, 2025
@kmr-srbh you can just start working on it, you don't need to ask for permission! :)
aznashwan commentedon Nov 12, 2025
Can confirm this is still an issue as of
0.16.0-dev.1301+cbfa87cbe.Would like to add there's some extra weird behavior when declaring single-byte variables:
consts (notvar)Output:
aznashwan commentedon Nov 12, 2025
After a bit more finagling, it seems (somewhat arbitrarily) dependant on the size of the type of the
consttoo (with 2, 6, 8, and 12 bytes seemingly working!?)Note: this is literally my first piece of
comptimezig so please take it with a grain of salt...Output:
PS: being able to dynamically name comptime tests like
test @typeName(typ)would have been pretty slick.