Skip to content

C backend generated code triggers warnings #19467

@andrewrk

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",

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