Skip to content

Unexpected aliasing of union parameters in "odin" convention #5153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hitchh1k3r opened this issue May 12, 2025 · 1 comment
Closed

Unexpected aliasing of union parameters in "odin" convention #5153

hitchh1k3r opened this issue May 12, 2025 · 1 comment

Comments

@hitchh1k3r
Copy link

Context

I am storing a level id union into a globally loaded level, but when reloading the level (loading the current level's id), I found this bug...

Odin: dev-2025-05:4d7876bdb
OS: Windows 10 Professional (version: 22H2), build 19045.5737
CPU: Intel(R) Core(TM) i7-4771 CPU @ 3.50GHz
RAM: 16311 MiB
Backend: LLVM 20.1.0

Expected Behavior

Non-pointer parameters should always act as if they are copied by value, not reference.

Failure Information

It seems like the "odin" calling convention is optimizing large (over 128 bit) union values to pointers, even when the value is modified in the procedure.

Here is a simple test case, that additionally shows that this issue is not present in "cdecl" procedures:

package main

import "base:runtime"

import "core:fmt"

global : UnionType

UnionType :: union {
  i128,
}

main :: proc() {
  global = 42
  set_global_cdecl(global, context)
  set_global_odin(global)
}

set_global_cdecl :: proc "cdecl" (new_value : UnionType, ctx : runtime.Context) {
  context = ctx

  fmt.println("C BEFORE:", new_value) // C BEFORE: 42
  global = {}
  fmt.println("C AFTER:", new_value)  // C AFTER: 42

  global = new_value
}

set_global_odin :: proc "odin" (new_value : UnionType) {
  fmt.println("O BEFORE:", new_value) // O BEFORE: 42
  global = {}
  fmt.println("O AFTER:", new_value)  // O AFTER: nil

  global = new_value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants