public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Stefan Franke" <s.franke@bebbosoft.de>
To: <gcc-help@gcc.gnu.org>
Subject: AW: C and C++ parser performing optimizations
Date: Mon, 24 Aug 2020 21:54:53 +0200	[thread overview]
Message-ID: <04c301d67a50$6f855630$4e900290$@bebbosoft.de> (raw)
In-Reply-To: <20200824210620.00005690@justmail.de>



> -----Ursprüngliche Nachricht-----
> Von: Gunther Nikl <gnikl@justmail.de>
> Gesendet: Montag, 24. August 2020 21:06
> An: Stefan Franke <stefan@franke.ms>; gcc-help@gcc.gnu.org
> Betreff: Re: C and C++ parser performing optimizations
> 
> stefan@franke.ms (Stefan Franke) wrote:
> 
> > > Von: Alexander Monakov <amonakov@ispras.ru>
> > > Betreff: Re: C and C++ parser performing optimizations
> > >
> > > On Sun, 2 Aug 2020, Stefan Franke wrote:
> > >
> > > > So the parser performs unwanted and uncontrollable optimizations,
> > > > which I consider bogus.
> > >
> > > On occasion they are also incorrect.
> > >
> > > My (possibly wrong or incomplete) understanding is that GCC does not
> > > have internal separation of mandatory simplifications that need to
> > > be done in
> > the
> > > frontend (like constant folding in the context of integer constant
> > > expressions) vs. optional simplifications (optimizing
> > > substitutions). So it just does both at the same time.
> > >
> > > Alexander
> >
> > 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)); }
> 
> Let me guess: this is about the m68k-amigaos LP macros? Can you show an
> example for that target?
> 
> Gunther

Your guess is correct, the m68k-amigaos LP macros are affected. And you may
choose any bogus defined lib function. E.g.

#define InitStruct(___initTable, ___memory, ___size) \
      LP3NR(0x4e, InitStruct , const APTR, ___initTable, a1, APTR,
___memory, a2, ULONG, ___size, d0,\
      , EXEC_BASE_NAME)

What's wrong here? It yields
	register const APTR  __initTable asm("a1");
which is
	register void * const __initTable asm("a1");
(some might expect
	register const void * __initTable asm("a1");
but that's not the case).

So __initTable is const which triggers the bogus optimization in the parsers
(c and c++ don't share the code - they reimplemented that bug).

I patched the parsers to omit that optimization. There are many other passes
which handle const propagation without dropping the register information.

One could fix the headers to circumvent that bug, all 'const <typedef>'
locations need a fix, but that's another story...

Stefan



      reply	other threads:[~2020-08-24 19:55 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
2020-08-24 19:06     ` Gunther Nikl
2020-08-24 19:54       ` Stefan Franke [this message]

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='04c301d67a50$6f855630$4e900290$@bebbosoft.de' \
    --to=s.franke@bebbosoft.de \
    --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).