odin-lang / Odin

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

Taking address of loop variable silently crashes compiler #3739

Closed karl-zylinski closed 3 weeks ago

karl-zylinski commented 3 weeks ago

Context

    Odin:    dev-2024-06:603581aa5
    OS:      Windows 10 Professional (version: 22H2), build 19045.4412
    CPU:     Intel(R) Core(TM) i7-6950X CPU @ 3.00GHz
    RAM:     32674 MiB
    Backend: LLVM 17.0.1

Expected Behavior

Taking address of loop variable shouldn't crash compiler.

Current Behavior

Taking address of i in for i in 0..<4 {} crashes compiler.

Failure Information (for bugs)

Crash in

gb_internal bool is_type_map(Type *t) {
    t = base_type(t);
    return t->kind == Type_Map;
}

t is null

Callstack: image

Steps to Reproduce

package main

import "core:fmt"

main :: proc() {
    for i in 0..<4 {
        fmt.println(&i)
    }

    fmt.println("got here")
}

Save in a file. Run with odin run .

Note that "got here" never prints. In fact, the compiler crashes.

If you do ii := i inside the loop and take address of that, then it compiles and runs fine.