GCC 4.3 prints an unsuppressable warning about any use of a static inline function or static const data in a non-static inline function. While this is useful for non-const static data, and possibly for non-inlined static functions, it is extremely annoying for static inline functions or static const objects. On MacOS X Leopard (Darwin 9), the following program prints warnings. (Note that htons() has a static inline declaration in the system header files. This problem makes extern inline functions essentially useless, since they cannot use system inline functions without warnings.) #include <arpa/inet.h> #include <stdbool.h> extern inline short ntohs_wrapper(short x) { return ntohs(x); } extern inline bool less_than_threshhold(int val) { static const int threshhold = 100; return val < threshhold; } [jonathan@Buzz ~]$ ~/FSF-GCC/bin/gcc -c inline-test.c inline-test.c: In function 'ntohs_wrapper': inline-test.c:6: warning: '_OSSwapInt16' is static but used in inline function 'ntohs_wrapper' which is not static inline-test.c: In function 'less_than_threshhold': inline-test.c:12: warning: 'threshhold' is static but declared in inline function 'less_than_threshhold' which is not static inline-test.c:13: warning: 'threshhold' is static but used in inline function 'less_than_threshhold' which is not static [jonathan@Buzz ~]$ ~/FSF-GCC/bin/gcc -c -v inline-test.c Using built-in specs. Target: i386-apple-darwin9.0.0 Configured with: ../gcc/configure --prefix=/Users/jonathan/FSF-GCC/ --with-gmp=/Users/jonathan/FSF-GCC/ --with-mpfr=/Users/jonathan/FSF-GCC/ --enable-lanaguages=c,c++,fortran,objc,obj-c++ --enable-checking=release --with-tune=generic Thread model: posix gcc version 4.3.0 20071105 (experimental) (GCC) COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.5.0' '-c' '-v' '-mtune=generic' /Users/jonathan/FSF-GCC/bin/../libexec/gcc/i386-apple-darwin9.0.0/4.3.0/cc1 -quiet -v -iprefix /Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/ -D__DYNAMIC__ inline-test.c -fPIC -quiet -dumpbase inline-test.c -mmacosx-version-min=10.5.0 -mtune=generic -auxbase inline-test -version -o /var/tmp//ccJzAq19.s ignoring nonexistent directory "/Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/../../../../i386-apple-darwin9.0.0/include" ignoring nonexistent directory "/usr/local/include" ignoring duplicate directory "/Users/jonathan/FSF-GCC/bin/../lib/gcc/../../lib/gcc/i386-apple-darwin9.0.0/4.3.0/include" ignoring duplicate directory "/Users/jonathan/FSF-GCC/bin/../lib/gcc/../../lib/gcc/i386-apple-darwin9.0.0/4.3.0/include-fixed" ignoring nonexistent directory "/Users/jonathan/FSF-GCC/bin/../lib/gcc/../../lib/gcc/i386-apple-darwin9.0.0/4.3.0/../../../../i386-apple-darwin9.0.0/include" #include "..." search starts here: #include <...> search starts here: /Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/include /Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/include-fixed /Users/jonathan/FSF-GCC/bin/../lib/gcc/../../include /usr/include /System/Library/Frameworks /Library/Frameworks End of search list. GNU C (GCC) version 4.3.0 20071105 (experimental) (i386-apple-darwin9.0.0) compiled by GNU C version 4.3.0 20071105 (experimental), GMP version 4.2.2, MPFR version 2.3.0. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 4eaa8600939e59258d37cac385804206 inline-test.c: In function 'ntohs_wrapper': inline-test.c:6: warning: '_OSSwapInt16' is static but used in inline function 'ntohs_wrapper' which is not static inline-test.c: In function 'less_than_threshhold': inline-test.c:12: warning: 'threshhold' is static but declared in inline function 'less_than_threshhold' which is not static inline-test.c:13: warning: 'threshhold' is static but used in inline function 'less_than_threshhold' which is not static COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.5.0' '-c' '-v' '-mtune=generic' as -arch i386 -force_cpusubtype_ALL -o inline-test.o /var/tmp//ccJzAq19.s COMPILER_PATH=/Users/jonathan/FSF-GCC/bin/../libexec/gcc/i386-apple-darwin9.0.0/4.3.0/:/Users/jonathan/FSF-GCC/bin/../libexec/gcc/ LIBRARY_PATH=/Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/:/Users/jonathan/FSF-GCC/bin/../lib/gcc/:/Users/jonathan/FSF-GCC/bin/../lib/gcc/i386-apple-darwin9.0.0/4.3.0/../../../:/usr/lib/ COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.5.0' '-c' '-v' '-mtune=generic' COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.5.0' '-c' '-v' '-mtune=generic' This problem appears to have been introduced by Geoffrey Keating in Subversion Revision 118356, a fix for PR 11377. GCC 4.2 does not have this problem.
The static const data problem is also PR 35017, now fixed; I'm editing the summary accordingly. The problem with static inline functions is not restricted to Darwin. The following example shows the problem on any X86 platform with SSE enabled, because the MMX/SSE intrinsic functions in GCC's <*mmintrin.h> headers are defined as static inline functions. This is a regression from GCC 4.2. $ ~/GCC/bin/gcc -msse2 -c inline-test-sse.c inline-test-sse.c: In function ‘vect_add’: inline-test-sse.c:5: warning: ‘_mm_add_epi8’ is static but used in inline function ‘vect_add’ which is not static $ ~/GCC/bin/gcc -v -msse2 -c inline-test-sse.c Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.3-20080125/configure --prefix=/home/jonathan/GCC Thread model: posix gcc version 4.3.0 20080125 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-msse2' '-c' '-mtune=generic' /home/jonathan/GCC/libexec/gcc/i686-pc-linux-gnu/4.3.0/cc1 -quiet -v inline-test-sse.c -quiet -dumpbase inline-test-sse.c -msse2 -mtune=generic -auxbase inline-test-sse -version -o /tmp/ccuQGUgc.s ignoring nonexistent directory "/home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /home/jonathan/GCC/include /home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/include /home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/include-fixed /usr/include End of search list. GNU C (GCC) version 4.3.0 20080125 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 4.3.0 20080125 (experimental), GMP version 4.2.1, MPFR version 2.2.1. GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 531c82c665c608438f0d85483de1c151 inline-test-sse.c: In function ‘vect_add’: inline-test-sse.c:5: warning: ‘_mm_add_epi8’ is static but used in inline function ‘vect_add’ which is not static COLLECT_GCC_OPTIONS='-v' '-msse2' '-c' '-mtune=generic' as -V -Qy -o inline-test-sse.o /tmp/ccuQGUgc.s GNU assembler version 2.17.50 (i586-suse-linux) using BFD version (GNU Binutils) 2.17.50.20070726-14 (SUSE Linux) COMPILER_PATH=/home/jonathan/GCC/libexec/gcc/i686-pc-linux-gnu/4.3.0/:/home/jonathan/GCC/libexec/gcc/i686-pc-linux-gnu/4.3.0/:/home/jonathan/GCC/libexec/gcc/i686-pc-linux-gnu/:/home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/:/home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/ LIBRARY_PATH=/home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/:/home/jonathan/GCC/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-msse2' '-c' '-mtune=generic'
Created attachment 15058 [details] test program illustrating the warning about static inline functions, using emmintrin.h
A discussion on comp.std.c <http://groups.google.com/group/comp.std.c/browse_thread/thread/8118ae4c53a4de60> indicates that this is indeed a constraint violation; the poster thinks that system headers should be fixed. I don't think it would be possible to write a fixincludes fix to turn static inlines into GNU89 or C99 extern inlines, however, so I think suppressing the pedwarn for system headers is the best option.
We fixed the mmintrin.h issues by using inline when __GNUC_STDC_INLINE__, and static inline otherwise in our tree.
(In reply to comment #4) > We fixed the mmintrin.h issues by using inline when __GNUC_STDC_INLINE__, and > static inline otherwise in our tree. The other way is to use the gnu_inline attribute always which case I am turning this into a target issue.
(In reply to comment #4) The problem occurs equally with gnu89 "extern inline" functions as with c99 "inline" functions (as seen in the initial bug report), so using static inline when !__GNUC_STDC_INLINE__ still leaves the problem.
Testcase for comment #6? I believe we tested every case and it works fine.
The attachment (inline-test-sse.c) on this PR is the gnu89 version of the problem. On MacOS X 10.5.2 (Apple gcc 5465), which has the same code as mainline FSF GCC, it prints: inline-test-sse.c: In function 'vect_add': inline-test-sse.c:5: warning: '_mm_add_epi8' is static but used in inline function 'vect_add' which is not static
Ah, I see now, you're right, that doesn't work. :-(
The right answer is probably to declare the system header functions "inline" when __GNUC_STDC_INLINE__, otherwise "extern inline"; or equivalently to declare them "extern inline __attribute__((__gnu_inline__))". You then need to provide an out-of-line definition in the appropriate system library, e.g. libgcc for the mmintrin functions. Note that even if you declare the function with __attribute__((__always_inline__)), there are uses that require a non-inlined version of the function, e.g. pointer-to-function. This is the main reason why it's not practical for fixincludes to do this transformation on system headers.
Ok, how about: #ifdef __GNUC_STDC_INLINE__ #define __EXTERN_INLINE __inline __attribute__((always_inline)) #else #define __EXTERN_INLINE extern __inline __attribute__((always_inline)) #endif __EXTERN_INLINE void foo() ; __EXTERN_INLINE void foo() { __asm ("nop"); } void bar1() { foo(); } I think that will work... See any gotchas (other than linking when it can't be inlined)?
Created attachment 15134 [details] test program using pointers to functions from emmintrin.h
Linking when the functions can't be inlined would be the only gotcha, but that would mean that the new attachment (func-pointer-sse.c) would regress.
I think we should do this; further, I think we should add && pedantic to it as well. Only people that want to be hurt by the standard should be.
Arguably, the use of static data (possible excepting const static data) or a non-inline static function is worthy of a pedwarn. But I'd certainly be inclined to agree for static inline functions.
Is there any possibility of getting a fix for this into 4.3.0?
(In reply to comment #16) > Is there any possibility of getting a fix for this into 4.3.0? No. GCC 4.3 will be released soon and this isn't even marked as a regression (much less a P1 regression).
This is a regression from 4.2, despite the lack of marking.
Subject: Bug 34000 Author: uros Date: Thu Mar 13 13:33:47 2008 New Revision: 133169 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133169 Log: PR target/34000 PR target/35553 * config/i386/xmmintrin.h: Change all static inline functions to extern inline and add __gnu_inline__ attribute. * config/i386/bmintrin.h: Ditto. * config/i386/smmintrin.h: Ditto. * config/i386/tmmintrin.h: Ditto. * config/i386/mmintrin-common.h: Ditto. * config/i386/ammintrin.h: Ditto. * config/i386/emmintrin.h: Ditto. * config/i386/pmmintrin.h: Ditto. * config/i386/mmintrin.h: Ditto. * config/i386/mm3dnow.h: Ditto. testsuite/ChangeLog: PR target/34000 PR target/35553 * g++.dg/other/i386-3.C: New test. * gcc.target/i386/sse-13.c: Redefine extern instead of static. * gcc.target/i386/sse-14.c: Ditto. * gcc.target/i386/mmx-1.c: Ditto. * gcc.target/i386/mmx-2.c: Ditto. * gcc.target/i386/3dnow-1.c: Ditto. * gcc.target/i386/3dnow-2.c: Ditto. * gcc.target/i386/3dnowA-1.c: Ditto. * gcc.target/i386/3dnowA-2.c: Ditto. Added: trunk/gcc/testsuite/g++.dg/other/i386-3.C Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/ammintrin.h trunk/gcc/config/i386/bmmintrin.h trunk/gcc/config/i386/emmintrin.h trunk/gcc/config/i386/mm3dnow.h trunk/gcc/config/i386/mmintrin-common.h trunk/gcc/config/i386/mmintrin.h trunk/gcc/config/i386/pmmintrin.h trunk/gcc/config/i386/smmintrin.h trunk/gcc/config/i386/tmmintrin.h trunk/gcc/config/i386/xmmintrin.h trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.target/i386/3dnow-1.c trunk/gcc/testsuite/gcc.target/i386/3dnow-2.c trunk/gcc/testsuite/gcc.target/i386/3dnowA-1.c trunk/gcc/testsuite/gcc.target/i386/3dnowA-2.c trunk/gcc/testsuite/gcc.target/i386/mmx-1.c trunk/gcc/testsuite/gcc.target/i386/mmx-2.c trunk/gcc/testsuite/gcc.target/i386/sse-13.c trunk/gcc/testsuite/gcc.target/i386/sse-14.c
Subject: Bug 34000 Author: uros Date: Fri Mar 14 14:34:09 2008 New Revision: 133217 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133217 Log: PR target/34000 PR target/35553 * config/i386/xmmintrin.h: Change all static inline functions to extern inline and add __gnu_inline__ attribute. * config/i386/bmintrin.h: Ditto. * config/i386/smmintrin.h: Ditto. * config/i386/tmmintrin.h: Ditto. * config/i386/mmintrin-common.h: Ditto. * config/i386/ammintrin.h: Ditto. * config/i386/emmintrin.h: Ditto. * config/i386/pmmintrin.h: Ditto. * config/i386/mmintrin.h: Ditto. * config/i386/mm3dnow.h: Ditto. testsuite/ChangeLog: PR target/34000 PR target/35553 * g++.dg/other/i386-3.C: New test. * gcc.target/i386/sse-13.c: Redefine extern instead of static. * gcc.target/i386/sse-14.c: Ditto. * gcc.target/i386/mmx-1.c: Ditto. * gcc.target/i386/mmx-2.c: Ditto. * gcc.target/i386/3dnow-1.c: Ditto. * gcc.target/i386/3dnow-2.c: Ditto. * gcc.target/i386/3dnowA-1.c: Ditto. * gcc.target/i386/3dnowA-2.c: Ditto. Added: branches/gcc-4_3-branch/gcc/testsuite/g++.dg/other/i386-3.C - copied unchanged from r133169, trunk/gcc/testsuite/g++.dg/other/i386-3.C Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/config/i386/ammintrin.h branches/gcc-4_3-branch/gcc/config/i386/bmmintrin.h branches/gcc-4_3-branch/gcc/config/i386/emmintrin.h branches/gcc-4_3-branch/gcc/config/i386/mm3dnow.h branches/gcc-4_3-branch/gcc/config/i386/mmintrin-common.h branches/gcc-4_3-branch/gcc/config/i386/mmintrin.h branches/gcc-4_3-branch/gcc/config/i386/pmmintrin.h branches/gcc-4_3-branch/gcc/config/i386/smmintrin.h branches/gcc-4_3-branch/gcc/config/i386/tmmintrin.h branches/gcc-4_3-branch/gcc/config/i386/xmmintrin.h branches/gcc-4_3-branch/gcc/testsuite/ChangeLog branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/3dnow-1.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/3dnow-2.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/3dnowA-1.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/3dnowA-2.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/mmx-1.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/mmx-2.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/sse-13.c branches/gcc-4_3-branch/gcc/testsuite/gcc.target/i386/sse-14.c
Fixed.