zig version: 0.11.0-dev.1844+75ff34db9
const std = @import("std");
const testing = std.testing;
test "write through pointer to optional slice arg" {
var foo: ?[]const u8 = null;
try bar(&foo);
try testing.expectEqualStrings(foo.?, "ok");
}
fn bar(foo: *?[]const u8) !void {
foo.* = try baz();
}
fn baz() ![]const u8 {
return "ok";
}
$ stage4/bin/zig test test.zig
LLVM Emit Object... zig: /home/andy/Downloads/llvm-project-15/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::ValueAsMetadata; From = const llvm::Metadata]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Aborted (core dumped)
In this example it triggers an LLVM assertion. In the actual usage that I have, it is a silent miscompilation that leaves foo incorrectly null.
zig version:
0.11.0-dev.1844+75ff34db9In this example it triggers an LLVM assertion. In the actual usage that I have, it is a silent miscompilation that leaves
fooincorrectlynull.