public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: Stefan Franke <stefan@franke.ms>, gcc-help@gcc.gnu.org
Subject: Re: AW: C and C++ parser performing optimizations
Date: Tue, 4 Aug 2020 10:33:10 -0500	[thread overview]
Message-ID: <20200804153310.GH6753@gate.crashing.org> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2008041009540.2454@monopod.intra.ispras.ru>

Hi!

On Tue, Aug 04, 2020 at 10:13:12AM +0300, Alexander Monakov via Gcc-help wrote:
> On Tue, 4 Aug 2020, Stefan Franke wrote:
> > Here is an example where gcc creates wrong code:
> > 
> > test.c:
> > int foo() {
> >   const char * const txt = "hello";
> >   register const char * const p asm("ecx") = txt;
> >   register int dx asm("edx");
> >   asm(" call _faa" :"=r" (dx) :"rf" (p));

  return dx; // and then it is valid code, even

> > }
> > 
> > gcc -O1 -S test.c -fdump-tree-original
> > 
> > The variable p gets replaced and the asm input parameters are wrong:
> > 
> > __asm__(" call _faa":"=r" dx:"rf" (const char * const) "hello");
> 
> I think it's a separate issue: even if the frontend wouldn't do such
> propagation, I'm pretty sure later passes would.

I don't think so?  That would be separate extra bugs.

> const and volatile
> qualifiers just do not work as expected with register variables, and
> since recently the documentation mentions that:
> 
> 6.47.5.2 Specifying Registers for Local Variables
> 
> Do not use type qualifiers such as const and volatile, as the outcome may be
> contrary to expectations. In particular, when the const qualifier is used, the
> compiler may substitute the variable with its initializer in asm statements,
> which may cause the corresponding operand to appear in a different register. 

Either we should warn for this, or we should fix this to behave as
expected for "const".  "volatile" otoh, well, what would that even mean
here, maytbe we should just error for that.

(Global register vars are different still...  together with -ffixed-*
that should be pretty easy, but *without* -ffixed-*, global register
vars aren't very well defined anyway).


Segher

  reply	other threads:[~2020-08-04 15:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-02 18:15 Stefan Franke
2020-08-02 18:40 ` Alexander Monakov
2020-08-04  6:44   ` AW: " Stefan Franke
2020-08-04  7:13     ` Alexander Monakov
2020-08-04 15:33       ` Segher Boessenkool [this message]
2020-08-24 19:06     ` Gunther Nikl
2020-08-24 19:54       ` AW: " Stefan Franke

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=20200804153310.GH6753@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=amonakov@ispras.ru \
    --cc=gcc-help@gcc.gnu.org \
    --cc=stefan@franke.ms \
    /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).