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.