Skip to content

Build fails with strict-aliasing violations #390

Description

@eli-schwartz

I tried to build with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming Undefined Behavior (UB) cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.

I got this error:

x86_64-pc-linux-gnu-gcc -pipe -ggdb -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -W -Wall -pedantic -DCF_XFREE86_TEXTPROP_BUG_WORKAROUND -DHAVE_X11_BMF   -DHAS_SYSTEM_ASPRINTF=1 -DNOTION_RELEASE='"4.0.4"' -MMD -W -Wall -pedantic -DCF_XFREE86_TEXTPROP_BUG_WORKAROUND -DHAVE_X11_BMF  -I.. -I.. -I..  -DHAS_SYSTEM_ASPRINTF=1 -DNOTION_RELEASE='"4.0.4"' -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -std=c99 -DCF_HAS_VA_COPY -MMD   -c -o rootwin.o rootwin.c
In file included from common.h:18,
                 from rootwin.c:22:
rootwin.c: In function ‘rootwin_init’:
rootwin.c:316:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  316 |     LINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rootwin, p_next, p_prev);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:19:9: note: in definition of macro ‘LINK_ITEM’
   19 |     if((LIST)==NULL){                     \
      |         ^~~~
rootwin.c:316:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  316 |     LINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rootwin, p_next, p_prev);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:20:10: note: in definition of macro ‘LINK_ITEM’
   20 |         (LIST)=(ITEM);                    \
      |          ^~~~
rootwin.c:316:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  316 |     LINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rootwin, p_next, p_prev);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:23:23: note: in definition of macro ‘LINK_ITEM’
   23 |         (ITEM)->PREV=(LIST)->PREV;        \
      |                       ^~~~
rootwin.c:316:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  316 |     LINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rootwin, p_next, p_prev);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:25:10: note: in definition of macro ‘LINK_ITEM’
   25 |         (LIST)->PREV=(ITEM);              \
      |          ^~~~
rootwin.c: In function ‘rootwin_deinit’:
rootwin.c:341:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  341 |     UNLINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rw, p_next, p_prev);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:68:21: note: in definition of macro ‘UNLINK_ITEM’
   68 |         if((ITEM)==(LIST)){                  \
      |                     ^~~~
rootwin.c:341:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  341 |     UNLINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rw, p_next, p_prev);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:69:14: note: in definition of macro ‘UNLINK_ITEM’
   69 |             (LIST)=(ITEM)->NEXT;             \
      |              ^~~~
rootwin.c:341:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  341 |     UNLINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rw, p_next, p_prev);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:70:17: note: in definition of macro ‘UNLINK_ITEM’
   70 |             if((LIST)!=NULL)                 \
      |                 ^~~~
rootwin.c:341:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  341 |     UNLINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rw, p_next, p_prev);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:71:18: note: in definition of macro ‘UNLINK_ITEM’
   71 |                 (LIST)->PREV=(ITEM)->PREV;   \
      |                  ^~~~
rootwin.c:341:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  341 |     UNLINK_ITEM(*(WRegion**)&ioncore_g.rootwins, (WRegion*)rw, p_next, p_prev);
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libtu/dlist.h:74:14: note: in definition of macro ‘UNLINK_ITEM’
   74 |             (LIST)->PREV=(ITEM)->PREV;       \
      |              ^~~~

Originally reported downstream at: https://bugs.gentoo.org/965850
Full build log: build.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions