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

            Bug ID: 104805
           Summary: [12.0] x86_64 Extended asm may use rbp register to
                    input/output even thougth "rbp" is in the clobber list
                    when "rsp" and "rbp" are both in the in the clobber
                    list
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 570070308 at qq dot com
  Target Milestone: ---

test.c:
```
void kkk()
{
    char a;
    __asm__ volatile (
            "%0"
            :"+m"(a)
            :
            : "rsp","rbp"
            );
}
```

assembly code:
```
#APP
# 4 "test.c" 1
    -9(%rbp)
# 0 "" 2
#NO_APP
```

can see that it use `-9(%rbp)` to represent `a`. Accouding to
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers,
the rbp should not be use to represent any operands because it is in the
clobber list.

compile log:
```
ig@ig-virtual-machine:~/temp$ gcc-12 -S test.c -O1 -v
Using built-in specs.
COLLECT_GCC=gcc-12
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
12-20220302-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--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-12-VlTCdr/gcc-12-12-20220302/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-VlTCdr/gcc-12-12-20220302/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.1 20220302 (experimental) [master r12-7448-g58394373a70]
(Ubuntu 12-20220302-1ubuntu1) 
COLLECT_GCC_OPTIONS='-S' '-O1' '-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu
test.c -quiet -dumpbase test.c -dumpbase-ext .c -mtune=generic -march=x86-64
-O1 -version -o test.s -fasynchronous-unwind-tables -fstack-protector-strong
-Wformat -Wformat-security -fstack-clash-protection -fcf-protection
GNU C17 (Ubuntu 12-20220302-1ubuntu1) version 12.0.1 20220302 (experimental)
[master r12-7448-g58394373a70] (x86_64-linux-gnu)
        compiled by GNU C version 12.0.1 20220302 (experimental) [master
r12-7448-g58394373a70], GMP version 6.2.1, MPFR version 4.1.0, MPC version
1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/12/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C17 (Ubuntu 12-20220302-1ubuntu1) version 12.0.1 20220302 (experimental)
[master r12-7448-g58394373a70] (x86_64-linux-gnu)
        compiled by GNU C version 12.0.1 20220302 (experimental) [master
r12-7448-g58394373a70], GMP version 6.2.1, MPFR version 4.1.0, MPC version
1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3929bb57dd80f5cc2d4f3202c349e2dc
test.c: In function ‘kkk’:
test.c:4:5: warning: listing the stack pointer register ‘rsp’ in a clobber list
is deprecated [-Wdeprecated]
    4 |     __asm__ volatile (
      |     ^~~~~~~
test.c:4:5: note: the value of the stack pointer after an ‘asm’ statement must
be the same as it was before the statement
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-S' '-O1' '-v' '-mtune=generic' '-march=x86-64'
ig@ig-virtual-machine:~/temp$
```

if compile with -O0, then gcc will give an error.

if don't put "rsp" and "rbp" both in the clobber list, the result will be
right.

gcc is installed by apt on ubuntu 22.04

Reply via email to