https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103979
Bug ID: 103979 Summary: asm goto is not considered volatile Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gareth.webb+gccbugzilla at outlook dot com Target Milestone: --- Created attachment 52165 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52165&action=edit Minimal reproduction of bug I have discovered a bug with GCC's 'asm goto'. It is documented that "note that an asm goto statement is always implicitly considered volatile." but it is not. It is using the same heuristic as non-goto asm (no outputs => volatile. outputs => not-volatile, unless explicitly specified). This can result in the optimizer removing the asm block completely. Confirmed the bug is present on Ubuntu 20.10's gcc package, as well as my own build from source (tag: releases/gcc-11.2.0). A minimal pre-processed reproduction is attached. Compile with gcc -O2 -c asmgoto.c -o asmgoto.o, observe the disassembled output contains nothing but endb64/ret, no jmp. I also received an ICE at one point when trying to create a minimal reproduction, but could not reproduce. It's included below, but as I can't reproduce I don't know how useful it will be. Ubuntu package: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c, ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-share d --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enabl e-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --ena ble-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiar ch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload -targets=nvptx-none=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-ZPT0kp/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cu da-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enab le-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2) Myy own build: Using built-in specs. COLLECT_GCC=x86_64-elf-gcc COLLECT_LTO_WRAPPER=/home/gwebb/opt/cross/libexec/gcc/x86_64-elf/11.2.0/lto-wrapper Target: x86_64-elf Configured with: ../gcc/configure --target=x86_64-elf --prefix=/home/gwebb/opt/cross --disable-nls --enable-languages=c --without-headers Thread model: single Supported LTO compression algorithms: zlib gcc version 11.2.0 (GCC) Possibly related ICE? during RTL pass: fwprop1 gdt.c: In function 'flush_gdt': gdt.c:66:1: internal compiler error: in purge_dead_edges, at cfgrtl.c:3346 66 | } | ^ 0x5d253d purge_dead_edges(basic_block_def*) ../../gcc/gcc/cfgrtl.c:3346 0x143dc1f delete_trivially_dead_insns(rtx_insn*, int) ../../gcc/gcc/cse.c:7178 0x145baa9 fwprop_done ../../gcc/gcc/fwprop.c:917 0x145baa9 fwprop ../../gcc/gcc/fwprop.c:1001 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.