Zig Version
0.15.2
Steps to Reproduce and Observed Behavior
Trying to format a string (both in a comptime block and on runtime) fails for my AVR target.
I tried to reduce the code to the bare minimum.
const std = @import("std");
export fn _start() noreturn {
main();
}
fn main() noreturn {
comptime {
const my_str = std.fmt.comptimePrint("my num: {d}", .{123});
@export(my_str, .{ .name = "my_exported_str"});
}
while(true) {}
}
Building the file with:
zig build-exe -OReleaseSmall -target avr-freestanding-none -mcpu avrxmega2 -fno-compiler-rt -fno-ubsan-rt main.zig
gives the following output:
zig-x86_64-linux-0.15.2/lib/std/os/windows.zig:4765:21: error: reached unreachable code
else => unreachable,
^~~~~~~~~~~
referenced by:
PEB: zig-x86_64-linux-0.15.2/lib/std/os/windows.zig:4665:24
os.windows.TEB: zig-x86_64-linux-0.15.2/lib/std/os/windows.zig:4611:31
19 reference(s) hidden; use '-freference-trace=21' to see all references
compiling the code for other targets appears to 'work' (it compiles)
zig build-exe -OReleaseSmall -target x86-freestanding-none -fno-compiler-rt -fno-ubsan-rt main.zig
zig build-exe -OReleaseSmall -target riscv32-freestanding-none -fno-compiler-rt -fno-ubsan-rt main.zig
zig build-exe -OReleaseSmall -target thumb-freestanding-none -fno-compiler-rt -fno-ubsan-rt main.zig
Note that something like this in the main function (after providing a memset/memcpy impl), will fail with the same error.
var buffer: [256]u8 = undefined;
var fba: std.heap.FixedBufferAllocator = .init(&buffer);
const allocator = fba.allocator();
const res = std.fmt.allocPrint(allocator, "my num: {d}", .{123});
if (res) |str| {
_ = str;
} else |_| {
}
Expected Behavior
The program compiles