Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Debug builds of have corrupted stack frame when procedure is passed an array argument

Open graphitemaster opened this issue 3 years ago • 1 comments

Context

Debug builds have corrupted stack frame when procedure is passed an array argument proceeding values passed to another procedure in the same stack frame.

Odin: dev-2022-01:8f91e930
OS:   Arch Linux, Linux 5.15.12-arch1-1
CPU:  AMD Ryzen Threadripper 1950X 16-Core Processor 
RAM:  32009 MiB

Expected Behavior

Procedure locals should not be corrupted.

Current Behavior

The locals preceding are corrupted due to mismanagement of callee-saved arguments when copying an array to the stack.

Steps to Reproduce

The following simple test case demonstrates the problem

package test
import "core:fmt"
import "core:runtime"
a :: proc(x, y: i32) {
  fmt.printf("%d %d\n", x, y);
}
b :: proc(x, y: i32, z: [3]i32) {
  a(x, y);
  fmt.printf("%v\n", z);
}
@export // called from c
c :: proc "c" (x, y, z: i32) {
  context = runtime.default_context();
  b(420, 69, [3]i32{x, y, z});
}

When built as a shared library, e.g -build-mode:dll, or as an executable, and c called as c(0, 1, 2) this prints, successfully:

420 69
{0, 1, 2}

When built as a DEBUG shared library, e.g -build-mode:dll -debug, or as an executable, and c called as c(0, 1, 2) this prints, unsuccessfully:

0, 0
{0, 1, 2}

The values x and y which should be 420 and 69 respectively, become 0 (or garbage values), if these were passed after the array the problem goes away. The implicit context argument is corrupted as well in some cases.

EDIT: This also applies for executables

graphitemaster avatar Jan 11 '22 23:01 graphitemaster

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan on resolving the issue.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..

github-actions[bot] avatar Jul 24 '22 22:07 github-actions[bot]