public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67925] New: docs lie about being unable to inline function call before definition
@ 2015-10-11 19:59 arkadiusz at drabczyk dot org
  2015-10-11 20:08 ` [Bug c/67925] " arkadiusz at drabczyk dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-11 19:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

            Bug ID: 67925
           Summary: docs lie about being unable to inline function call
                    before definition
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arkadiusz at drabczyk dot org
  Target Milestone: ---

Here https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Inline.html it says:

"Some calls cannot be integrated for various reasons (in particular, calls that
precede the function's definition cannot be integrated (...)).". However, since
several releases of GCC this in no longer true as shown in the example:

$ ./gcc --version
gcc (GCC) 6.0.0 20151004 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat bug.c
#include <stdio.h>
#include <stdlib.h>

inline static void def(void);

int main(void)
{
        def();
        exit(0);
}

static void def(void)
{
        puts("blah blah");
}
$ ./gcc bug.c -O2 -S
$ cat bug.s
        .file   "bug.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "blah blah"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB21:
        .cfi_startproc
        movl    $.LC0, %edi
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        call    puts
        xorl    %edi, %edi
        call    exit
        .cfi_endproc
.LFE21:
        .size   main, .-main
        .ident  "GCC: (GNU) 6.0.0 20151004 (experimental)"
        .section        .note.GNU-stack,"",@progbits

The same happens with -O1 and on older versions of GCC such as 4.9.2. I think
that this outdated piece of documentation should be removed.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
@ 2015-10-11 20:08 ` arkadiusz at drabczyk dot org
  2015-10-11 20:30 ` miyuki at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-11 20:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #1 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
BTW, the same incorrect wording is repeated in doc/extend.texi in GCC source
tarball.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
  2015-10-11 20:08 ` [Bug c/67925] " arkadiusz at drabczyk dot org
@ 2015-10-11 20:30 ` miyuki at gcc dot gnu.org
  2015-10-12  8:08 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-10-11 20:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |documentation
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-10-11
                 CC|                            |miyuki at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
OMG. IIUC, this limitation was fixed in GCC 3.x (early 2000s):
http://hubicka.blogspot.ru/2014/04/linktime-optimization-in-gcc-1-brief.html


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
  2015-10-11 20:08 ` [Bug c/67925] " arkadiusz at drabczyk dot org
  2015-10-11 20:30 ` miyuki at gcc dot gnu.org
@ 2015-10-12  8:08 ` rguenth at gcc dot gnu.org
  2015-10-12 19:20 ` arkadiusz at drabczyk dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-10-12  8:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Patches welcome ;)  I think refering to -Winline here might make most sense.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (2 preceding siblings ...)
  2015-10-12  8:08 ` rguenth at gcc dot gnu.org
@ 2015-10-12 19:20 ` arkadiusz at drabczyk dot org
  2015-10-12 19:20 ` arkadiusz at drabczyk dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-12 19:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #4 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
Created attachment 36488
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36488&action=edit
suggested patch


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (3 preceding siblings ...)
  2015-10-12 19:20 ` arkadiusz at drabczyk dot org
@ 2015-10-12 19:20 ` arkadiusz at drabczyk dot org
  2015-10-12 19:32 ` arkadiusz at drabczyk dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-12 19:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #5 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
-Winline is mentioned in the next paragraph. The whole sentence I posted in the
first comment is:

"Some calls cannot be integrated for various reasons (in particular, calls that
precede the function's definition cannot be integrated, and neither can
recursive calls within the definition)."

I think it's completely wrong - recursive functions can also be inlined:

$ ./gcc --version
gcc (GCC) 6.0.0 20151004 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat bug1.c
#include <stdio.h>
#include <stdlib.h>

inline static int factorial(unsigned int i)
{
   if(i <= 1)
   {
      return 1;
   }
   return i * factorial(i - 1);
}

int main(void)
{
        factorial(12);
        exit(0);
}
$ ./gcc bug1.c -O2 -S
$ cat bug1.s
        .file   "bug1.c"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB22:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        xorl    %edi, %edi
        call    exit
        .cfi_endproc
.LFE22:
        .size   main, .-main
        .ident  "GCC: (GNU) 6.0.0 20151004 (experimental)"
        .section        .note.GNU-stack,"",@progbits

I attach a suggested patch.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (4 preceding siblings ...)
  2015-10-12 19:20 ` arkadiusz at drabczyk dot org
@ 2015-10-12 19:32 ` arkadiusz at drabczyk dot org
  2015-10-13 15:11 ` arkadiusz at drabczyk dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-12 19:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #6 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
Sorry, this code is wrong of course, value returned by factorial() must be used
to generate an actual code:

$ cat bug1.c
#include <stdio.h>
#include <stdlib.h>

inline static int factorial(unsigned int i)
{
   if(i <= 1)
   {
      return 1;
   }
   return i * factorial(i - 1);
}

int main(void)
{
        printf("%d\n", factorial(12));
        exit(0);
}
$ cat bug1.s
        .file   "bug1.c"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "%d\n"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB22:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        movl    $1, %esi
        movl    $12, %eax
        .p2align 4,,10
        .p2align 3
.L2:
        imull   %eax, %esi
        subl    $1, %eax
        cmpl    $1, %eax
        jne     .L2
        movl    $.LC0, %edi
        xorl    %eax, %eax
        call    printf
        xorl    %edi, %edi
        call    exit
        .cfi_endproc
.LFE22:
        .size   main, .-main
        .ident  "GCC: (GNU) 6.0.0 20151004 (experimental)"
        .section        .note.GNU-stack,"",@progbits


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (5 preceding siblings ...)
  2015-10-12 19:32 ` arkadiusz at drabczyk dot org
@ 2015-10-13 15:11 ` arkadiusz at drabczyk dot org
  2015-10-13 15:12 ` arkadiusz at drabczyk dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-13 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #36488|0                           |1
        is obsolete|                            |

--- Comment #7 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
Created attachment 36502
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36502&action=edit
better suggested patch


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (6 preceding siblings ...)
  2015-10-13 15:11 ` arkadiusz at drabczyk dot org
@ 2015-10-13 15:12 ` arkadiusz at drabczyk dot org
  2015-10-13 18:18 ` segher at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-13 15:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #8 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
I attach a new patch with an extra whitespace after dot to keep up with an
existing convention.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (7 preceding siblings ...)
  2015-10-13 15:12 ` arkadiusz at drabczyk dot org
@ 2015-10-13 18:18 ` segher at gcc dot gnu.org
  2015-10-13 22:52 ` arkadiusz at drabczyk dot org
  2015-10-20  5:53 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: segher at gcc dot gnu.org @ 2015-10-13 18:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

Segher Boessenkool <segher at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |segher at gcc dot gnu.org

--- Comment #9 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Please send the patch to gcc-patches@gcc.gnu.org as described at
<http://gcc.gnu.org/contribute.html>.  Thanks!


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (8 preceding siblings ...)
  2015-10-13 18:18 ` segher at gcc dot gnu.org
@ 2015-10-13 22:52 ` arkadiusz at drabczyk dot org
  2015-10-20  5:53 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: arkadiusz at drabczyk dot org @ 2015-10-13 22:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

--- Comment #10 from Arkadiusz Drabczyk <arkadiusz at drabczyk dot org> ---
Patch sent for review here:
https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01303.html


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c/67925] docs lie about being unable to inline function call before definition
  2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
                   ` (9 preceding siblings ...)
  2015-10-13 22:52 ` arkadiusz at drabczyk dot org
@ 2015-10-20  5:53 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: law at redhat dot com @ 2015-10-20  5:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67925

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |law at redhat dot com
         Resolution|---                         |FIXED

--- Comment #11 from Jeffrey A. Law <law at redhat dot com> ---
Fixed on trunk.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-10-20  5:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-11 19:59 [Bug c/67925] New: docs lie about being unable to inline function call before definition arkadiusz at drabczyk dot org
2015-10-11 20:08 ` [Bug c/67925] " arkadiusz at drabczyk dot org
2015-10-11 20:30 ` miyuki at gcc dot gnu.org
2015-10-12  8:08 ` rguenth at gcc dot gnu.org
2015-10-12 19:20 ` arkadiusz at drabczyk dot org
2015-10-12 19:20 ` arkadiusz at drabczyk dot org
2015-10-12 19:32 ` arkadiusz at drabczyk dot org
2015-10-13 15:11 ` arkadiusz at drabczyk dot org
2015-10-13 15:12 ` arkadiusz at drabczyk dot org
2015-10-13 18:18 ` segher at gcc dot gnu.org
2015-10-13 22:52 ` arkadiusz at drabczyk dot org
2015-10-20  5:53 ` law at redhat dot com

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).