From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19852 invoked by alias); 12 Jan 2012 13:44:29 -0000 Received: (qmail 19833 invoked by uid 22791); 12 Jan 2012 13:44:28 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 12 Jan 2012 13:44:15 +0000 From: "rguenth at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.4.7 X-Bugzilla-Changed-Fields: Keywords CC Component Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg01378.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33763 Richard Guenther changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code CC| |jsm28 at gcc dot gnu.org Component|tree-optimization |c --- Comment #23 from Richard Guenther 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);