public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "570070308 at qq dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/104805] [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
Date: Sun, 06 Mar 2022 13:22:13 +0000	[thread overview]
Message-ID: <bug-104805-4-E5n0CuYaDP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104805-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from 。 <570070308 at qq dot com> ---
(In reply to Jakub Jelinek from comment #4)
> rbp is hard frame pointer, so depending on whether the function needs a
> frame pointer (at -O0 I think all functions do), the register isn't
> available for use (and therefore for clobbering) in inline asm.
> Only in functions where it isn't needed, it is not fixed then and can be
> used for other purposes.

So you explained why "rbp" cann't be in the clobber list with -O0, and may be
can be in the clobber list with -O1,-O2 or -O3(when the function don't needs a
frame pointer), I understand this now.

But when the "rbp" is in the clobber list successfully, it should not be used
to represent any input/output operands according to the doc because user may
change the %rbp and make the input/output operands wrong.

for example:
```
void kkk()
{
    char a;
    __asm__ volatile (
            "writing %%rbp\n\t"
            // %0 may point to error memory because %rbp change
            // for example -9(%rbp) represent char a
            "reading %0\n\t"
            "writing %0"
            :"+m"(a)
            :
            : "rsp","rbp"
            );
}
```

I have done a lot of experiments, if a register is list in the clobber list, it
will never appear to represent in the input/output operands, and the doc say so
too. Only "rbp" is an exception.

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers
```
When the compiler selects which registers to use to represent input and output
operands, it does not use any of the clobbered registers. As a result,
clobbered registers are available for any use in the assembler code.
```

  parent reply	other threads:[~2022-03-06 13:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 11:43 [Bug c/104805] New: " 570070308 at qq dot com
2022-03-06 11:46 ` [Bug c/104805] " jakub at gcc dot gnu.org
2022-03-06 11:51 ` 570070308 at qq dot com
2022-03-06 12:09 ` 570070308 at qq dot com
2022-03-06 13:03 ` jakub at gcc dot gnu.org
2022-03-06 13:22 ` 570070308 at qq dot com [this message]
2022-03-06 19:47 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104805-4-E5n0CuYaDP@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).