https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93302
Bug ID: 93302 Summary: -O2 -fno-inline produces wrong results Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lifeibiren at gmail dot com Target Milestone: --- Created attachment 47665 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47665&action=edit preprocessed file I am code to do tcp checksum and find that output binary doesn't work as expected with compilation option -O2 -fno-inline. Partial source code is uploaded as an attachment and it seems to work with any compilation options but -O2 -fno-inline. Test Env: gcc 9.2.0 (Arch Linux) gcc 5.3.0 (Ubuntu 16.04) Expected output: 12345678 87654321 40 12 5678 5678 1234 68ac 4321 abcd 8765 13332 600 13932 2800 16132 I disassemble the output binary and find that the instructions to store saddr and daddr to stack memory are optimized out so hdr's first two members stay uninitialized. If a memory barrier 'asm volatile("": : :"memory");' is put before access 'hdr', gcc could get it right. Env Info: GCC VERSION: $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc Thread model: posix gcc version 9.2.0 (GCC) BUG COMMAND: $ gcc test3.c -O2 -fno-inline COMPILER OUTPUT: NOTHING OS: $ cat /etc/issue Arch Linux \r (\l) PREP FILE: ATTACHMENT