-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Compile crash #21147
Labels
bug
Observed behavior contradicts documented or intended behavior
Comments
crat1985
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Aug 20, 2024
When using this code : const std = @import("std");
pub const StackAllocator = struct {
data: [40]u8 = undefined,
offset: usize = 0,
const Self = @This();
fn alloc(ctx: *anyopaque, n: usize, ptr_align: u8, return_address: usize) ?[*]u8 {
const self: *Self = @ptrCast(@alignCast(ctx));
_ = n;
_ = self;
_ = ptr_align;
_ = return_address;
// const data = self.data[self.offset .. self.offset + n];
// return data.ptr + n;
return null;
}
pub fn allocator(comptime self: *Self) std.mem.Allocator {
return std.mem.Allocator{ .ptr = self, .vtable = &.{ .alloc = alloc, .free = undefined, .resize = undefined } };
}
};
pub const HandlerFn =
*const fn () void;
pub fn main() !void {
comptime {
var stack_allocator = StackAllocator{};
const allocator = stack_allocator.allocator();
const value =
try allocator.create(HandlerFn);
const handle_fn = struct {
fn handle() void {}
}.handle;
value.* = handle_fn;
}
} The diff is : fn alloc(ctx: *anyopaque, n: usize, ptr_align: u8, return_address: usize) ?[*]u8 {
const self: *Self = @ptrCast(@alignCast(ctx));
- // _ = n;
- // _ = self;
+ _ = n;
+ _ = self;
_ = ptr_align;
_ = return_address;
- const data = self.data[self.offset .. self.offset + n];
+ // const data = self.data[self.offset .. self.offset + n];
- return data.ptr + n;
- // return null;
+ // return data.ptr + n;
+ return null;
}
pub fn allocator(comptime self: *Self) std.mem.Allocator { There is a compiler error :
|
Duplicate of #20765 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zig Version
0.14.0-dev.1200+104553714
Steps to Reproduce and Observed Behavior
Create a new Zig project directory, and replace the main file content with the following :
Run
zig build
Expected Behavior
The code to compile or at least to throw a real error (I think the issue comes from setting the std.mem.Allocator VTable's functions to undefined).
When compiling, I get the following error :
The text was updated successfully, but these errors were encountered: