-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
runtime segfault when returning a union with a pointer #3138
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
Comments
Just looking at the code, I'd say the issue is that Maybe it would be an easier first step to disallow these conversions to pointer types ( |
Oy, you're right, but in my actual project I didn't have the pub fn cons(allocator: *Allocator, left: Atom, right: Atom) !Atom {
var pair = try allocator.create(Pair);
pair.* = Pair{
.left = left,
.right = right,
// Segfault ^ happens here, according to the stack trace
};
// Atom.Pair is of type *Pair
return Atom{ .Pair = pair };
} But the original example I had was incorrect, and compiles correctly when you do |
I did some more testing, the issue only seems to happen if the union has a field that is void, and the struct has at least 2 fields: const std = @import("std");
const Allocator = std.mem.Allocator;
const Struct = struct {
field: Union,
f2: Union,
};
const Union = union(enum) {
Num: u128,
Struct: *Struct,
Void,
};
fn allocFn(allocator: *Allocator, value: Union) !Union {
var s = try allocator.create(Struct);
s.* = Struct{ .field = value, .f2 = v2 };
return Union{ .Struct = s };
}
test "alloc fn" {
var s = try allocFn(std.heap.direct_allocator, Union{ .Num = 10 }, Union{ .Num = 11 });
} This example works if the struct has only one field, or if the union doesn't have the |
Make sure the resulting type is in-sync with the one produced and used by LLVM. Fixes ziglang#3138
minimal example:
The text was updated successfully, but these errors were encountered: