ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.67k stars 2.47k forks source link

C backend generated code triggers warnings #19467

Open andrewrk opened 5 months ago

andrewrk commented 5 months ago

Zig Version

0.12.0-dev.3493+3661133f9

Steps to Reproduce and Observed Behavior

Run the C behavior tests outside of zig build test-behavior:

$ stage4/bin/zig test ../test/behavior.zig -ofmt=c -lc
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:65265:5: error: incompatible pointer types assigning to 'void (*)(void)' from 'uint8_t (*)[4]' (aka 'unsigned char (*)[4]')
 t0 = &behavior_cast_global_array__1596;
    ^~~~
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:133807:11: error: incompatible pointer types passing 'struct A__11025 *' to parameter of type 'struct A__11021 *'
 issue529(((struct A__11025 *)(uintptr_t)0x0ul));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:20713:43: note: passing argument to parameter here
zig_extern void issue529(struct A__11021 *);
                                          ^
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:133809:11: error: incompatible pointer types passing 'struct A__11026 *' to parameter of type 'struct A__11021 *'
 issue529(((struct A__11026 *)(uintptr_t)0x0ul));
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:20713:43: note: passing argument to parameter here
zig_extern void issue529(struct A__11021 *);
                                          ^
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:154728:64: error: taking address of packed member 'data' of class or structure 'test_under_2daligned_20struct_20field_S__11770' may result in an unaligned pointer value
 t6 = (union test_under_2daligned_20struct_20field_U__11769 *)&t4.data;
                                                               ^~~~
/home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c:197605:47: error: incompatible function pointer types initializing 'void (*)(int, const struct siginfo_t__struct_7163__7163 *, void *)' with an expression of type 'void (*)(int32_t, const struct siginfo_t__struct_7163__7163 *, const void *)' (aka 'void (*)(int, const struct siginfo_t__struct_7163__7163 *, const void *)')
 t0 = (struct Sigaction__7159){{ .sigaction = &debug_handleSegfaultPosix__236 },{UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0),UINT32_C(0)},2415919108u,((void (*)(void))(uintptr_t)0x0ul)};
                                              ^~
error: the following test command failed with exit code 1:
/home/andy/dev2/zig/build-release/stage4/bin/zig run -I /home/andy/dev2/zig/lib -lc /home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c

It works if I manually silence these errors:

stage4/bin/zig cc -o test  -I /home/andy/dev2/zig/lib -lc /home/andy/dev2/zig/zig-cache/o/6bfbca337d5fc3c5fed111b5c0ce840e/test.c -Wno-incompatible-function-pointer-types

Expected Behavior

No warning suppression lines should be required:

https://github.com/ziglang/zig/blob/3661133f989fefa64c58447dd0073b8c0e8050fc/test/tests.zig#L1166-L1181

jacobly0 commented 5 months ago

Some of these warnings are fixed by #19470, and some of these warnings come from pretty questionable zig code that I can't even begin to imagine a way to work around. Note that the only actual error here is also fixed by #19470, so once that is merged, the zig test command will no longer fail.