Skip to content

C backend generated code triggers warnings #19467

Open

Description

@andrewrk

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:

zig/test/tests.zig

Lines 1166 to 1181 in 3661133

.flags = &.{
// TODO output -std=c89 compatible C code
"-std=c99",
"-pedantic",
"-Werror",
// TODO stop violating these pedantic errors. spotted everywhere
"-Wno-builtin-requires-header",
// TODO stop violating these pedantic errors. spotted on linux
"-Wno-address-of-packed-member",
"-Wno-gnu-folding-constant",
"-Wno-incompatible-function-pointer-types",
"-Wno-incompatible-pointer-types",
"-Wno-overlength-strings",
// TODO stop violating these pedantic errors. spotted on darwin
"-Wno-dollar-in-identifier-extension",
"-Wno-absolute-value",

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    backend-cThe C backend (CBE) outputs C source code.
    on Mar 28, 2024
  2. added this to the 0.15.0 milestone on Mar 28, 2024
  3. jacobly0 commented on Mar 31, 2024

    @jacobly0
    Member

    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.

  4. mlugg commented on Dec 6, 2024

    @mlugg
    Member

    Here's another warning which the C backend can trigger, and which seems not to be excluded by the compiler test suite's cflags right now. I think this is -Wtautological-compare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-cThe C backend (CBE) outputs C source code.bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions