Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Issue with argument values when using "core:c" int

Open foxik0169 opened this issue 3 years ago • 2 comments

Context

I was working with Vulkan library and come across this weird behaviour that might be a bug. It's scoped to usage of "core:c" module for types.

  • I am wokring on a workstation in Linux (Fedora 36), Odin tag dev-2022-07.

  • odin report:

    Odin: dev-2022-07:1676c643 OS: Fedora Linux 36 (Thirty Six), Linux 5.18.11-200.fc36.x86_64 CPU: AMD Phenom(tm) II X4 955 Processor RAM: 9945 MiB

Expected Behavior

I expect to be able to read procedure arguments with their correct values independent of the location in the argument list.

Current Behavior

Value of first argument changes based on the second argument.

Failure Information (for bugs)

When 1st argument of a procedure is vk.Format and second argument is vk.Extent3D, the 1st argument value is changed to 0.

Steps to Reproduce

The problem can be reproduced by creating function with 1st argument of type c.int and second argument of Odin struct with 3 fields:

import "core:c"
import "core:fmt"

TestStruct :: struct {
    width:  u32,
    height: u32,
    depth:  u32,
}

test :: proc (t: c.int, t2: TestStruct) {
    fmt.printf("testing : %v %v\n", t, t2) 
}

test(123, {1, 2, 3})
// expect "testing : 123 TestStruct{width = 1, height = 2, depth = 3}"
// prints "testing : 32643 TestStruct{width = 1, height = 2, depth = 3}" - the value of t is not consistent between executions

Same behaviour happens when using vk.Format and vk.Extent3D in the same order. When the order is reversed, the values are correct.

foxik0169 avatar Jul 23 '22 09:07 foxik0169

This issue seems to be the same as #1879 On my machine i get the output testing : 32764 TestStruct{width = 1, height = 2, depth = 3} the first argument seems to be garbage data and not just 0. Also this bug still occurs for me without core:c and replacing the c.int with i32, heres that output: testing : 32767 TestStruct{width = 1, height = 2, depth = 3} nearly the same but still garbage. and adding other lines of code also causes the value to change I'm also on Linux too in case that matters:

Odin: dev-2022-07:6c7e5748
OS:   Manjaro Linux, Linux 5.10.129-1-MANJARO
CPU:  Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
RAM:  7773 MiB

BruhNye avatar Jul 24 '22 23:07 BruhNye

Also possibly related to #1825

hasenj avatar Jul 25 '22 00:07 hasenj