-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.miscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Milestone
Description
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.
jayschwa
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.miscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.