A GCC bug related to inline?

Kumar, Venkataramanan Venkataramanan.Kumar@amd.com
Sun Nov 11 11:10:00 GMT 2018


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.


More information about the Gcc mailing list