Odin
Odin copied to clipboard
Segfault when calling proc(vec: [$N]$T)
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})
}
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
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])
}
}
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
the crash (currently) only happens in debug mode