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

Payload-less tagged union initialisation cause segfault #1478

Closed
hcff opened this Issue Sep 5, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@hcff
Contributor

hcff commented Sep 5, 2018

pub const Union = union(enum) {
    A,
    B,
};

pub fn main() void {
    const a = Union{ .A={} };
}
 $ gdb zig-linux-x86_64-0.2.0.master/zig
GNU gdb (GDB) Fedora 8.1.1-3.fc28
...
(gdb) run build-exe uniontest/uniontest2.zig 
Starting program: zig-linux-x86_64-0.2.0.master/zig build-exe uniontest/uniontest2.zig

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff63a6b20 in llvm::Value::getContext() const ()
(gdb) bt
#0  0x00007ffff63a6380 in llvm::Value::getContext() const ()
#1  0x00007ffff6341b86 in llvm::StoreInst::StoreInst(llvm::Value*, llvm::Value*, bool, unsigned int, llvm::AtomicOrdering, unsigned char, llvm::Instruction*)
    ()
#2  0x00007ffff6341c33 in llvm::StoreInst::StoreInst(llvm::Value*, llvm::Value*, bool, unsigned int, llvm::Instruction*) ()
#3  0x00007ffff62e0282 in LLVMBuildStore ()
#4  0x00007ffff3815b8c in gen_store_untyped(CodeGen*, LLVMOpaqueValue*, LLVMOpaqueValue*, unsigned int, bool) ()
#5  0x00007ffff3821ae6 in gen_assign_raw(CodeGen*, LLVMOpaqueValue*, TypeTableEntry*, LLVMOpaqueValue*) ()
#6  0x00007ffff3821eb1 in ir_render_decl_var(CodeGen*, IrExecutable*, IrInstructionDeclVar*) [clone .isra.147] ()
#7  0x00007ffff3826f8b in ir_render_instruction(CodeGen*, IrExecutable*, IrInstruction*) [clone .isra.181] ()
#8  0x00007ffff382bcb7 in codegen_build(CodeGen*) ()
#9  0x00007ffff376bb9b in main ()

Using Union(undefined) instead of Union{ .A={} } or turning the union(enum) into a enum also fix the segfault.

@andrewrk andrewrk added this to the 0.3.0 milestone Sep 5, 2018

@andrewrk andrewrk added the bug label Sep 5, 2018

@andrewrk andrewrk closed this in ffb3b15 Sep 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment