https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115326

            Bug ID: 115326
           Summary: __builtin_sub_overflow reports incorrect overflow
                    value
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cody at tapscott dot me
  Target Milestone: ---

Created attachment 58334
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58334&action=edit
reduced test case

The `__builtin_sub_overflow` intrinsic appears to report an incorrect overflow
value, in a specific case when it is used with pointers to the field of a
union.

I would expect the two evaluations in the attached test program to be
identical, but instead on my machine the abort() is triggered:
$ gcc test2.c -O0 -fno-strict-aliasing
$ ./a.out
[1]    1099972 IOT instruction  ./a.out

$ gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/gcc-latest/libexec/gcc/x86_64-pc-linux-gnu/13.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-latest --enable-languages=c,c++
--enable-libstdcxx-debug --enable-libstdcxx-backtrace --disable-bootstrap
--disable-multilib --disable-libvtv --with-system-zlib --without-isl
--enable-multiarch
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.1 20230416 (experimental) (GCC)

Reply via email to