Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Linear increase in LLVM codegen size+time and segfaults with anon struct size and transmute

Open stianhj opened this issue 4 months ago • 0 comments

Ran into this while helping someone on Discord who was expanding on the microui example in the examples repo.

import "core:fmt"

N :: #config(N, 65)

x: f64 = 0.5

foo := struct {
	items: [N*1024]u8,
	num: u64,
}{
	num = transmute(u64)x,
}

main :: proc() {
	fmt.println(foo.num)
}

odin build . -debug segfaults on my machine:

Odin:    dev-2025-07:090cac62f
OS:      Arch Linux, Linux 6.15.9-zen1-1-zen
CPU:     AMD Ryzen 9 5900X 12-Core Processor
RAM:     31968 MiB
Backend: LLVM 20.1.7

If N is below 65 it doesn't segfault, but build time and size always increase with N. All the time difference is in LLVM API Code Gen.

Also starting with N=64 every mutiple of 2 does not segfault, but the program prints 0 instead of the correct transmuted value. I have tested a little bit on Windows as well, and see the same thing happening there. All builds are with the -debug flag.

N Build time Binary size Segfault Correct result
1 225 ms 578 KiB no yes
16 401 ms 986 KiB no yes
32 709 ms 1.4 MiB no yes
64 1.2 s 1.4 MiB no no (prints 0)
65 - - yes -
127 - - yes -
128 2.5 s 2.2 MiB no no (prints 0)
129 - - yes -
256 5.1 s 3.8 MiB no no (prints 0)
512 10.4 s 7.1 MiB no no (prints 0)
1023 - - yes -
1024 21 s 14 MiB no no (prints 0)

Notably, if you move the transmute to main everything works as expected. Build time and size are the same for every N I tested.

 foo := struct {
        items: [N*1024]u8,
        num: u64,
 }{
-       num = transmute(u64)x,
 }

 main :: proc() {
+       foo.num = transmute(u64)x
        fmt.println(foo.num)
 }

Also, the user I was helping on Discord was using a Mac, and the compiler didn't segfault, but build time and size increase was happening.

stianhj avatar Aug 12 '25 19:08 stianhj