-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
MultiArrayList can have unexpected results when combining zero sized fields and optional pointers #12781
Copy link
Copy link
Open
Labels
backend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone
Description
Zig Version
0.10.0-dev.3885+a7661f115d
Steps to Reproduce
test.zig
const std = @import("std");
const testing = std.testing;
test {
const S = struct { key: u32, value: void };
const allocator = std.testing.allocator;
var list = std.MultiArrayList(S){};
defer list.deinit(allocator);
try list.append(allocator, .{ .key = 0, .value = {} });
const a: ?*const void = &list.items(.value)[0];
try testing.expect(a != null);
}$ zig test test.zig
Expected Behavior
All tests pass. We take a pointer to an existing value in the values slices of the list. We store then store this non null pointer in an optional pointer.
Actual Behavior
Test [1/1] test_0... FAIL (TestUnexpectedResult)
/usr/lib/zig/std/testing.zig:351:14: 0x21168f in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
./test.zig:14:5: 0x2117a0 in test_0 (test)
try testing.expect(a != null);
^
0 passed; 0 skipped; 1 failed.
error: the following test command failed with exit code 1:
zig-cache/o/85be9248e4b75e6a5942ec409fcfeca7/test /usr/bin/zig
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
backend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.