Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Segfault when calling proc(vec: [$N]$T)

Open Beefster09 opened this issue 2 years ago • 4 comments

Context

When calling a parapoly which has an array of a parameterized type, the program crashes.

making $T a constant type avoids the crash ([$N]int still works, for instance)

  • Operating System & Odin Version:
        Odin: dev-2022-12-nightly:521ed286
        OS:   Windows 10 Home Basic (version: 21H2), build 19044.2364
        CPU:  Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
        RAM:  65343 MiB

Expected Behavior

there should not be a crash

Current Behavior

there is a crash

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

this_crashes :: proc(vec: [$N]$T) {
    // proc body can be anything. it crashes no matter what is inside
}

main :: proc() {
    this_crashes([4]int{1,2,3,4})
}

Beefster09 avatar Dec 16 '22 06:12 Beefster09

I am wondering that the provided code snippet can compile. On Linux it results in correct parsing error:

Too few arguments for 'this_crashes', expected 1 arguments, got 0

tstibor avatar Dec 16 '22 08:12 tstibor

I fixed the snippet, but I'm having issues reproducing the bug now. Seems to only turn up in very specific situations.

These are my problem procs. Might be a weird interaction with using and pointers to structs.

_load_fixvec :: proc(vec: [$N]$T/fixed.Fixed) -> [N]f64 {
    result: [N]f64
    for i in 0..<N {
        result[i] = fixed_to_f64(vec[i])
    }
    return result
}

_store_fixvec :: proc(dest: ^[$N]$T/fixed.Fixed, src: [N]f64) {
    for i in 0..<N {
        set_fixed_from_f64(&dest^[i], src[i])
    }
}

Beefster09 avatar Dec 16 '22 10:12 Beefster09

I ran the first snippet (crash) and cannot reproduce the problem:

$ N=0; MAX=10000; for i in {1..$MAX}; do ./crash && ((N++)) done; echo $N==$MAX
10000==10000

tstibor avatar Dec 16 '22 10:12 tstibor

the crash (currently) only happens in debug mode

Beefster09 avatar Dec 16 '22 21:12 Beefster09