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

            Bug ID: 117546
           Summary: Different (and incorrect) behavior when compiling C
                    code with -O2
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: github at skef dot org
  Target Milestone: ---

Created attachment 59581
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59581&action=edit
The requested intermediate file corresponding to my ttread.c source file

I've been seeing a compilation problem with gcc on Arch Linux since around the
end of May 2024, which given how quickly Arch upgrades probably implicates gcc
14 generally. I figured it would be seen in flashier contexts so I decided to
be lazy and wait. But it's still happening with 14.2.1 so I made a minimal-ish
case. 

Note that this relates to https://github.com/adobe-type-tools/afdko/issues/1760

When I compile the attached, self-contained c file with

gcc -Wall -Wextra -g -lm -o foo ttread.c

the compiled program produces the expected output:

194.000000
52.000000
350.000000
311.500000
250.000000
73.000000
264.000000
355.000000

When I compile it with

gcc -Wall -Wextra -g -O2 -lm -o foo ttread.c 

its output is different:

194.000000
194.000000
194.000000
194.000000
194.000000
194.000000
73.000000
73.000000
355.000000

There are no compiler warnings and compiling with -fsanitize=undefined produces
no warnings. 


Output of gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240910 (GCC)

Reply via email to