odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.55k stars 570 forks source link

Stack overflow with #raw_union #343

Closed JoshuaManton closed 5 years ago

JoshuaManton commented 5 years ago

Context

Current Behavior

Odin compiler stack overflows with a struct #raw_union containing another struct, it seems

Failure Information

The stack bounces between:

// ir.cpp:4308
e = ir_emit_conv(proc, e, alloc_type_pointer(type));

and

// ir.cpp:4807
irValue *res = ir_emit_deep_field_gep(proc, value, sel);

Steps to Reproduce

Run odin build . on:

package bug_test

import "core:fmt"

main :: proc() {
    Foo :: struct #raw_union {
        bar: Bar,
        baz: union {
            bool,
        },
    }

    Bar :: struct {
        asd: string,
    }

    foo: Foo;
    foo.bar = Bar{"asd"};
    fmt.println(foo);
}
gingerBill commented 5 years ago

Could you try again with the latest commit?

JoshuaManton commented 5 years ago

Tried, still crashing

dotbmp commented 5 years ago

Latest commit as of this comment, it doesn't crash but prints this:

Foo{}

Which is clearly wrong.

Interestingly fmt.println(foo.bar) works as expected:

Bar{asd = asd};

EDIT: Do raw union members not have a supported fmt representation? If that's the case then the bug is resolved as far as I can tell

JoshuaManton commented 5 years ago

https://github.com/odin-lang/Odin/blob/master/core/fmt/fmt.odin#L926

I think we have a winner folks 🎉

dotbmp commented 5 years ago

👍 case closed then