This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: A GCC bug related to inline?
- From: "Kumar, Venkataramanan" <Venkataramanan dot Kumar at amd dot com>
- To: Bin.Cheng <amker dot cheng at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Sun, 11 Nov 2018 07:22:46 +0000
- Subject: RE: A GCC bug related to inline?
- References: <CAHFci29WE8uH6iskLpu_1QeD=Fwa-ZbEas6xEag7Y_Kb8ZmNjQ@mail.gmail.com>
Hi Bin,
> -----Original Message-----
> From: gcc-owner@gcc.gnu.org <gcc-owner@gcc.gnu.org> On Behalf Of
> Bin.Cheng
> Sent: Sunday, November 11, 2018 12:28 PM
> To: GCC Development <gcc@gcc.gnu.org>
> Subject: A GCC bug related to inline?
>
> Hi,
> Given below simple code:
>
> inline int foo (int a) {
> return a + 1;
> }
> int g = 5;
> int main(void) {
> return foo(g);
> }
>
> When compiled with -O0, GCC generates below assembly:
> .file "test.c"
> .text
> .globl g
> .data
> .align 4
> .type g, @object
> .size g, 4
> g:
> .long 5
> .text
> .globl main
> .type main, @function
> main:
> .LFB1:
> .cfi_startproc
> pushq %rbp
> .cfi_def_cfa_offset 16
> .cfi_offset 6, -16
> movq %rsp, %rbp
> .cfi_def_cfa_register 6
> movl g(%rip), %eax
> movl %eax, %edi
> call foo
> popq %rbp
> .cfi_def_cfa 7, 8
> ret
> .cfi_endproc
> .LFE1:
> .size main, .-main
> .ident "GCC: (GNU) 9.0.0 20181031 (experimental)"
> .section .note.GNU-stack,"",@progbits
>
> Note the body of function foo is removed while call to foo isn't inlined, this
> results in undefined reference to "foo" at linking.
>
> Guess this is a bug?
Not sure if this is a bug.
Looks like -std=c99 or -std=gnu99 inline won't generate function body. Older standard do emit, I used extra -fgnu89-inline.
>
> Thanks,
> bin
Regards,
Venkat.