-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
WASI assert(@alignOf(i16) == 2) fails when compiling for AVR #19919
Copy link
Copy link
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.12.0
Steps to Reproduce and Observed Behavior
Compile a small file using std.log for AVR:
// foo.zig
const std = @import("std");
extern fn logBackend(ptr: [*:0]const u8, len: usize) void;
pub fn logFn(
comptime level: std.log.Level,
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
const level_prefix = comptime level.asText();
const prefix = comptime level_prefix ++ switch (scope) {
.default => ": ",
else => " (" ++ @tagName(scope) ++ "): ",
};
var buf: [1024:0]u8 = undefined;
const string = std.fmt.bufPrintZ(&buf, prefix ++ format, args) catch &buf;
logBackend(string.ptr, string.len);
}
pub const std_options = std.Options{
.logFn = logFn,
};
export fn meow() u16 {
std.log.info("meow called", .{});
return 5;
}$ zig build-obj foo.zig -O ReleaseFast -target avr-freestanding -mcpu=atmega4809 -freference-trace
/usr/lib/zig/std/debug.zig:403:14: error: reached unreachable code
if (!ok) unreachable; // assertion failure
^~~~~~~~~~~
/usr/lib/zig/std/os/wasi.zig:12:11: note: called from here
assert(@alignOf(i16) == 2);
~~~~~~^~~~~~~~~~~~~~~~~~~~
This assertion fails since apparently i16 is 1 byte aligned on AVR.
If I remove only the std.log.info line, it compiles fine.
Expected Behavior
I expect this file to compile without issues, since I provided a backend for std.log which doesn't need any OS support. It seems std.os.wasi is getting referenced by the definition of std.Options, as that uses os.wasi.fd_t:
wasiCwd: fn () os.wasi.fd_t = fs.defaultWasiCwd,It seems like I can fix this by changing that definition to have the type void on non-WASM targets, but I'm not 100% confident that doesn't break anything else. I can PR that change if desired.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior