Zig Version
0.16.0
Steps to Reproduce, Observed Behavior, and Expected Behavior
Two flies.
lib.zig - an identity function in its float argument, preceded by 7 integer args, using the C calling conventions:
exportfnrepro(_:usize,_:usize,_:usize,_:usize,_:usize,_:usize,_:usize,x:f32)callconv(.c)f32{returnx;}
main.c - a C caller that passes 3.14 for that float and checks it comes back unchanged:
#include <stdio.h>extern float repro(unsigned long, unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long, float);
int main(void) {
float r = repro(1, 2, 3, 4, 5, 6, 7, 3.14f);
printf("repro(1..7, 3.14) = %g (expected 3.14)\n", (double)r);
return r == 3.14f ? 0 : 1;
}
Build and run on an x86_64 host (where the self-hosted backend is the default). Unfortunately, I only have a Mac so I used rosetta to reproduce.
zig build-obj -target x86_64-macos -fno-llvm -ODebug lib.zig -femit-bin=lib.o
zig cc -target x86_64-macos main.c lib.o -o demo
arch -x86_64 ./demo
Program output:
repro(1..7, 3.14) = 2.276e+19 (expected 3.14)
In the above sample, repro returns a wrong value, the 3.14 passed by the C caller does not arrive at the Zig function.
### Zig Version
0.16.0
### Steps to Reproduce, Observed Behavior, and Expected Behavior
Two flies.
`lib.zig` - an identity function in its float argument, preceded by 7 integer args, using the C calling conventions:
```zig
export fn repro(_: usize, _: usize, _: usize, _: usize, _: usize, _: usize, _: usize, x: f32) callconv(.c) f32 {
return x;
}
```
`main.c` - a C caller that passes `3.14` for that float and checks it comes back unchanged:
```c
#include <stdio.h>
extern float repro(unsigned long, unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long, float);
int main(void) {
float r = repro(1, 2, 3, 4, 5, 6, 7, 3.14f);
printf("repro(1..7, 3.14) = %g (expected 3.14)\n", (double)r);
return r == 3.14f ? 0 : 1;
}
```
Build and run on an x86_64 host (where the self-hosted backend is the default). Unfortunately, I only have a Mac so I used rosetta to reproduce.
```bash
zig build-obj -target x86_64-macos -fno-llvm -ODebug lib.zig -femit-bin=lib.o
zig cc -target x86_64-macos main.c lib.o -o demo
arch -x86_64 ./demo
```
Program output:
```
repro(1..7, 3.14) = 2.276e+19 (expected 3.14)
```
---
In the above sample, `repro` returns a wrong value, the 3.14 passed by the C caller does not arrive at the Zig function.