public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] don't declare header-defined functions both static and inline
Date: Tue, 31 Jan 2023 09:42:54 +0100	[thread overview]
Message-ID: <Y9jUjr70zPTlYNmA@tucnak> (raw)
In-Reply-To: <CAFiYyc35A3J8hV7k+YYcxefWuLm1PmDJ1NmXSxVrt3n=TTHGfw@mail.gmail.com>

On Tue, Jan 31, 2023 at 08:05:15AM +0100, Richard Biener via Gcc-patches wrote:
> On Tue, Jan 31, 2023 at 4:39 AM Patrick Palka via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Many functions defined in our headers are declared 'static inline' which
> > is a vestige from when GCC's implementation language was C.  But in C++
> > the inline keyword is more than just a compiler hint, and is sufficient
> > to give the function the intended semantics.  In fact declaring a
> > (namespace-scope) function both static and inline is a pessimization
> > since static effectively disables the intended definition merging
> > behavior that inline provides, and is also a source of (harmless) ODR
> > violations when a static inline function gets called from a non-static
> > inline one (such as tree_operand_length being called from
> > tree_operand_check).
> >
> > This patch mechanically fixes the vast majority of occurrences of this
> > anti-pattern throughout the compiler's headers via the command line
> >
> >   echo gcc/*.h gcc/*/*.h | xargs sed -i 's/^static inline/inline/g'
> >
> > Besides fixing the ODR violations, this speeds up stage1 cc1plus by
> > about 2% and reduces the size of its text segment by 1.5MB.
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, would this be OK to
> > push now or wait for stage1?
> 
> Speeding up and reducing the size of cc1plus improves on continued
> regression in this area.  So I'd vote +1 to do this now, let's see what others
> think.

I lean towards +1 too, but
1) we should make sure we don't do that for installed headers with the
   exception of headers meant for GCC plugins; in quick skimming I don't
   see ginclude/ headers among the changed ones, but perhaps doing all
   languages make install, then applying the patch, make and make install
   again into another tree and compare all the headers in those tree
   with the exception of paths with /plugin/include/ in it?
2) we should make sure we don't introduce ODR violations through this, if
   say 2 headers would define different static inline functions with the
   same name (or even one static inline and another without that).
   Don't know what would be best to catch that, get from the patch
   list of changed functions and then search for it in readelf -wi output
   using some script, or would LTO bootstrap detect that, or libabigail?
   What I'm worried about is 2 different headers defining the same
   function perhaps with different arguments/return values or content and
   that we happen to never include the two headers in the same TU
3) we have also gcc/ada/gcc-interface/*.h with
ada.h:#define INLINE static inline
gigi.h:static inline unsigned HOST_WIDE_INT
gigi.h:static inline bool
gigi.h:static inline bool
gigi.h:static inline bool
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
gigi.h:static inline tree
   I think we can defer that to Ada maintaners but we should tell them
   about it
4) there are some static inline also in
   gcc/config/*/*.h (and some in gcc/common/*/*.h - though in that case
   it is solely in installed header that shouldn't be changed)
avr/avr-protos.h:static inline unsigned
pru/pru-protos.h:static inline bool
rs6000/rs6000-internal.h:static inline bool
rs6000/rs6000-protos.h:static inline bool
s390/s390-builtins.h:static inline unsigned int
s390/s390-builtins.h:static inline unsigned int
s390/vecintrin.h:static inline int
   The last one is an installed header, so I think we shouldn't touch
   it, the rest should be considered.

	Jakub


  reply	other threads:[~2023-01-31  8:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31  3:37 Patrick Palka
2023-01-31  7:05 ` Richard Biener
2023-01-31  8:42   ` Jakub Jelinek [this message]
2023-01-31  9:09     ` Richard Biener
2023-01-31 10:21     ` Eric Botcazou
2023-02-16 13:37     ` Patrick Palka
2023-02-16 13:50       ` Jakub Jelinek
2023-02-16 13:44     ` [PATCH] don't declare header-defined functions both static and inline, pt 2 Patrick Palka
2023-02-27 15:13       ` Patrick Palka

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=Y9jUjr70zPTlYNmA@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    --cc=richard.guenther@gmail.com \
    /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).