Bug 55965 - gcc -std=c99 emits code for inline even without extern with function which has builtin
Summary: gcc -std=c99 emits code for inline even without extern with function which ha...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-01-14 04:44 UTC by Jeremy Huddleston Sequoia
Modified: 2022-01-03 21:14 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 12.0, 4.1.2
Last reconfirmed: 2014-10-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Huddleston Sequoia 2013-01-14 04:44:06 UTC
$ cat /tmp/testa.c 
inline int isalnum(int _c) { return 1; }
inline int _isalnum(int _c) { return 1; }

$ /opt/local/bin/gcc-mp-4.8 -c /tmp/testa.c -o /tmp/test.o -std=c99

$ nm /tmp/test.o 
0000000000000010 s EH_frame1
0000000000000000 T _isalnum

---

isalnum is being emitted with external linkage even though it is inline and never declared as 'extern inline'  It looks like gcc may have implicit extern declarations for some functions which is forcing this 'inline' definition to be treated asn an 'extern inline' definition.
Comment 1 Marek Polacek 2014-10-23 14:36:07 UTC
Yes, I think this is a bug.  But I suppose that nm output mentioned isalnum, not _isalnum.
Comment 2 Manuel López-Ibáñez 2014-10-23 16:36:21 UTC
Yes, I get:

manuel@gcc10:~$ nm test.o
0000000000000000 T isalnum

and with:

~/test1/216257/build/gcc/xgcc -B ~/test1/216257/build/gcc/ -std=c99 test.c -c  -o test.o -fno-builtin-isalnum

I get nothing. Thus the analysis seems right but not sure how to fix it.
Comment 3 Jeremy Huddleston Sequoia 2014-10-24 02:32:49 UTC
On OSX, the _isalnum symbol corresponds to the isalnum() function and the __isalnum symbol would correspond to the _isalnum() function.  It is emitting the _isalnum symbol (for isalnum()) but not the __isalnum symbol (because _isalnum() is being inlined).

I suspect you seeing an isalnum symbol is because you're on a different platform that does not _-prefix.
Comment 4 Jakub Jelinek 2014-10-24 07:14:06 UTC
The implicit builtin FUNCTION_DECL should have UNKNOWN_LOCATION or BUILTIN_LOCATION, so should be easy to differentiate from explicit user extern decl.  Just it is important that when an inline without extern is merged with
the implicit decl that the result doesn't look like user extern inline
or user extern decl followed by inline decl.