Trying to build @memset with a slice pointer causes segfault
Zig Version
0.11.0-dev.3395+1e7dcaa3a
Steps to Reproduce and Observed Behavior
- Write to
demo.zig:
pub fn main() void {
var slice: []u8 = undefined;
@memset(slice.ptr, 0);
}
- Run
zig build-exe demo.zigOutput:Segmentation fault (core dumped)
Expected Behavior
Expected some error message
~~this is not a bug. the crash happens because. the slice is undefined. this is an issue tracker, not a place to ask questions. these types of questions should be directed to the community: https://github.com/ziglang/zig/wiki/Community~~
thread 875350 panic: reached unreachable code
/home/meghan/src/zig/src/codegen/llvm.zig:8327:56: 0x15f108f in airMemset (zig)
const len = self.sliceOrArrayLenInBytes(dest_slice, ptr_ty);
^
/home/meghan/src/zig/src/codegen/llvm.zig:4466:54: 0x1107b1a in genBody (zig)
.memset_safe => try self.airMemset(inst, true),
^
/home/meghan/src/zig/src/codegen/llvm.zig:1215:19: 0x1101e2b in updateFunc (zig)
fg.genBody(air.getMainBody()) catch |err| switch (err) {
^
/home/meghan/src/zig/src/link/Elf.zig:2582:74: 0x110a7bb in updateFunc (zig)
if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness);
^
/home/meghan/src/zig/src/link.zig:572:77: 0xec5833 in updateFunc (zig)
.elf => return @fieldParentPtr(Elf, "base", base).updateFunc(module, func_index, air, liveness),
^
/home/meghan/src/zig/src/Module.zig:4215:37: 0xd0485a in ensureFuncBodyAnalyzed (zig)
comp.bin_file.updateFunc(mod, func_index, air, liveness) catch |err| switch (err) {
^
/home/meghan/src/zig/src/Compilation.zig:3143:42: 0xd01e39 in processOneJob (zig)
module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
^
/home/meghan/src/zig/src/Compilation.zig:3080:30: 0xba0f9e in performAllTheWork (zig)
try processOneJob(comp, work_item, main_progress_node);
^
/home/meghan/src/zig/src/Compilation.zig:2029:31: 0xb9d648 in update (zig)
try comp.performAllTheWork(main_progress_node);
^
/home/meghan/src/zig/src/main.zig:3840:24: 0xbcad3a in updateModule (zig)
try comp.update(main_progress_node);
^
/home/meghan/src/zig/src/main.zig:3275:17: 0xa54aff in buildOutputType (zig)
updateModule(comp) catch |err| switch (err) {
^
/home/meghan/src/zig/src/main.zig:277:31: 0xa07a65 in mainArgs (zig)
return buildOutputType(gpa, arena, args, .run);
^
/home/meghan/src/zig/src/main.zig:213:20: 0xa04c05 in main (zig)
return mainArgs(gpa, arena, args);
^
/home/meghan/src/zig/lib/std/start.zig:609:37: 0xa04688 in main (zig)
const result = root.main() catch |err| {
^
???:?:?: 0x7f9fb52bc24d in ??? (???)
???:?:?: 0x7ffcf8e47cc4 in ??? (???)
Aborted (core dumped)
this is not a bug. the crash happens because. the slice is undefined. this is an issue tracker, not a place to ask questions. these types of questions should be directed to the community: https://github.com/ziglang/zig/wiki/Community
I think I responded too quickly. This does seem like a bug. I agree that it shouldn't crash the compiler. I originally thought this was a runtime crash due to dereffing slice.ptr.
#16698 was a duplicate of this.