Bug 736451

Summary: gcc drops inline function incorrectly with "-std=c99"
Product: Red Hat Enterprise Linux 6 Reporter: Kirby Zhou <kirbyzhou>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.1   
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-09-07 18:04:33 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kirby Zhou 2011-09-07 17:37:52 UTC
Description of problem:

A simple C program can not be compiled by gcc with "-std=c99"

Version-Release number of selected component (if applicable):

gcc-4.4.5-6.el6.x86_64
gcc-4.6.0-10.fc15.x86_64

How reproducible:

100%


Steps to Reproduce:

[root@djt-17-109-v06 tmp]# cat c99bug.c 
#include <stdio.h>

struct dummy;

inline int 
__foo(struct dummy *disk)
{
        printf("dummy\n");
        return -1;
}

static struct dummy *
foo_wrapper(const char *device)
{
        struct dummy* disk = (struct dummy*)device;
        __foo(disk);
        return NULL;
}

int
main(int argc, char *argv[])
{
        foo_wrapper("");
        return 0;
}

[root@djt-17-109-v06 tmp]# gcc -std=c99 c99bug.c 
/tmp/ccGNGqb6.o: In function `foo_wrapper':
c99bug.c:(.text+0x1c): undefined reference to `__foo'
collect2: ld returned 1 exit status

 
Actual results:


Expected results:

compile the simple demo code successfully.

Additional info:

The following gcc do not have this bug.

gcc-4.1.2-51.el5
gcc44-4.4.4-13.el5

Comment 2 Jakub Jelinek 2011-09-07 18:04:33 UTC
That is not a bug, it is what ISO C99 requires.  It is incompatible with the GNU inline extension behavior, and starting with GCC 4.3 -std=c99 or -std=gnu99 enables the ISO C99 mandated semantics.  You can use -fgnu89-inline command line option to force the GNU inline semantics, or you can use __attribute__((gnu_inline)) on functions that should have the GNU inline semantics.