-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stage1: miscompilation on writing with comptime-computed offsets into comptime constructed buffer #10920
Comments
Potentially related to #10684? |
This comment was marked as outdated.
This comment was marked as outdated.
There's actually a bug in your program here. test {
comptime var x: u32 = undefined;
const p = &x;
@compileLog(@TypeOf(p));
p.* = runtimeVal();
}
The assignment of const std = @import("std");
test {
comptime var x: u32 = undefined;
const p = &x;
runtimeSet(p);
std.log.info("{}", .{x});
}
fn runtimeSet(p: *u32) void {
p.* = 42;
} Disaster strikes! Because EDIT: even simpler trigger! We can make the pointer runtime-known simply by putting it in a runtime test {
comptime var x: u32 = 0;
var p = &x; // p is now runtime-known!
p.* = runtimeVal(); // segfault
}
fn runtimeVal() u32 {
return 42;
} |
The language footgun here was solved by #19414, and the underlying issue has decent test coverage. |
Zig Version
0.10.0-dev.787+5aa35f62c
Steps to Reproduce
Run
Inspect with an editor the binary
comptimeMiscompilation
File
comptimeMiscompilation.zig
:Expected Behavior
mem.copy
the program works.Actual Behavior
Output of the broken comptime execution is written into the resulting elf binary (on Linux) stripped by the nonvisual parts:
Output is
Most likely the failures are caused by one or multiple offset-by-1 error. Speculatively there is missing/errorneous handling of the result and llvm doing bad stuff, but debugging is needed.
(And unfortunately I dont have time for this in the next month.)
The text was updated successfully, but these errors were encountered: