public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/33763] [4.4/4.5/4.6/4.7 Regression] Bogus inlining failed in call to `xxx': redefined extern inline functions are not considered for inlining
Date: Thu, 12 Jan 2012 13:44:00 -0000	[thread overview]
Message-ID: <bug-33763-4-cgqdvoMOMg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-33763-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33763

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |jsm28 at gcc dot gnu.org
          Component|tree-optimization           |c

--- Comment #23 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-12 13:42:39 UTC ---
Shorter testcase

extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
void open ()
{
}
void open ()
{
  open ();
}

fails on trunk like

> ./cc1 -quiet t.c -O
t.c: In function 'open':
t.c:5:6: error: inlining failed in call to always_inline 'open': function not
inlinable
t.c:7:8: error: called from here

and creates wrong code at -O0 (and probably would, at -On):

open:
.LFB1:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movl    $0, %eax
        call    open
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret

as the always-inline body was not inlined.

Note that the initial callgraph is already wrong:

Initial callgraph:

open/0 @0x7ffff5a2b6c0 (asm: open) analyzed needed reachable body finalized
redefined_extern_inline
  called by: open/0 (1.00 per call)
  calls: open/0 (1.00 per call)
  References:
  Refering this function:
variable pool:

as said, the C frontend needs to create two decls for open for this to
properly work.

OTOH, it is time to deprecate this extension and warn about it (after
all we miscompile this since quite some time, GCC 3.3 and 4.1 already produce
the recursive open - how was this intended to work? ...)  I don't have
3.2 (and 2.95 does not have always_inline).

The "proper" way to write the testcase is

extern __inline __attribute__ ((__always_inline__,__gnu_inline__))
void open ()
{
}
void open_1 () asm("open");
void open_1 ()
{
  open ();
}

So, Joseph - would you be fine with changing behavior for this testcase
from ICEing at -On, miscompiling at -O0 to rejecting it?  Thus,

Index: c-decl.c
===================================================================
--- c-decl.c    (revision 183121)
+++ c-decl.c    (working copy)
@@ -1855,21 +1855,10 @@ diagnose_mismatched_decls (tree newdecl,
        {
          if (DECL_INITIAL (olddecl))
            {
-             /* If both decls are in the same TU and the new declaration
-                isn't overriding an extern inline reject the new decl.
+             /* If both decls are in the same TU reject the new decl.
                 In c99, no overriding is allowed in the same translation
                 unit.  */
-             if ((!DECL_EXTERN_INLINE (olddecl)
-                  || DECL_EXTERN_INLINE (newdecl)
-                  || (!flag_gnu89_inline
-                      && (!DECL_DECLARED_INLINE_P (olddecl)
-                          || !lookup_attribute ("gnu_inline",
-                                                DECL_ATTRIBUTES (olddecl)))
-                      && (!DECL_DECLARED_INLINE_P (newdecl)
-                          || !lookup_attribute ("gnu_inline",
-                                                DECL_ATTRIBUTES (newdecl))))
-                 )
-                 && same_translation_unit_p (newdecl, olddecl))
+             if (same_translation_unit_p (newdecl, olddecl))
                {
                  error ("redefinition of %q+D", newdecl);
                  locate_old_decl (olddecl);


  parent reply	other threads:[~2012-01-12 13:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-33763-4@http.gcc.gnu.org/bugzilla/>
2011-03-04 12:37 ` [Bug tree-optimization/33763] [4.3/4.4/4.5/4.6 " rguenth at gcc dot gnu.org
2011-03-05 12:45 ` hubicka at ucw dot cz
2011-03-11 22:16 ` pthaugen at gcc dot gnu.org
2011-06-27 14:51 ` [Bug tree-optimization/33763] [4.3/4.4/4.5/4.6/4.7 " rguenth at gcc dot gnu.org
2012-01-12 13:44 ` rguenth at gcc dot gnu.org [this message]
2012-01-12 14:24 ` [Bug c/33763] [4.4/4.5/4.6/4.7 " hubicka at ucw dot cz
2012-01-12 14:28 ` rguenther at suse dot de
2012-01-12 14:33 ` rguenth at gcc dot gnu.org
2012-01-12 14:33 ` rguenth at gcc dot gnu.org
2012-01-12 14:38 ` joseph at codesourcery dot com
2012-01-12 14:51 ` rguenth at gcc dot gnu.org
2012-01-12 14:54 ` rguenth at gcc dot gnu.org
2012-01-13  9:31 ` rguenth at gcc dot gnu.org
2012-03-13 15:27 ` [Bug c/33763] [4.5/4.6/4.7/4.8 " jakub at gcc dot gnu.org
2012-07-02 11:52 ` rguenth at gcc dot gnu.org
2012-07-09 15:04 ` [Bug c/33763] [4.6/4.7/4.8 " dschepler at gmail dot com
2012-07-09 15:41 ` rguenth at gcc dot gnu.org
2012-10-05 11:44 ` jakub at gcc dot gnu.org
2012-10-05 11:59 ` jakub at gcc dot gnu.org
2012-10-05 12:02 ` jakub at gcc dot gnu.org
2012-11-11 21:27 ` steven at gcc dot gnu.org
2012-11-11 21:29 ` jakub at gcc dot gnu.org
2013-09-20 22:15 ` kaltsi+gnu at gmail dot com
2013-09-20 22:21 ` jakub at gcc dot gnu.org
2013-09-20 22:25 ` kaltsi+gnu at gmail dot com

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-33763-4-cgqdvoMOMg@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).