Bug 34000 - GCC pedwarns about use of static inline functions from system headers in extern inline functions
Summary: GCC pedwarns about use of static inline functions from system headers in exte...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-05 23:00 UTC by Jonathan Lennox
Modified: 2008-03-14 14:41 UTC (History)
3 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test program illustrating the warning about static inline functions, using emmintrin.h (98 bytes, text/plain)
2008-01-30 18:28 UTC, Jonathan Lennox
Details
test program using pointers to functions from emmintrin.h (178 bytes, text/plain)
2008-02-13 04:35 UTC, Jonathan Lennox
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Lennox 2007-11-05 23:00:24 UTC
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.
Comment 1 Jonathan Lennox 2008-01-30 18:26:30 UTC
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'
Comment 2 Jonathan Lennox 2008-01-30 18:28:51 UTC
Created attachment 15058 [details]
test program illustrating the warning about static inline functions, using emmintrin.h
Comment 3 Jonathan Lennox 2008-02-11 19:51:44 UTC
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.
Comment 4 Mike Stump 2008-02-12 01:28:54 UTC
We fixed the mmintrin.h issues by using inline when __GNUC_STDC_INLINE__, and static inline otherwise in our tree.
Comment 5 Andrew Pinski 2008-02-12 01:37:27 UTC
(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.
Comment 6 Jonathan Lennox 2008-02-12 15:49:12 UTC
(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.
Comment 7 Mike Stump 2008-02-12 18:01:23 UTC
Testcase for comment #6?  I believe we tested every case and it works fine.
Comment 8 Jonathan Lennox 2008-02-12 21:37:08 UTC
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
Comment 9 Mike Stump 2008-02-12 22:04:27 UTC
Ah, I see now, you're right, that doesn't work.  :-(
Comment 10 Jonathan Lennox 2008-02-12 22:46:21 UTC
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.
Comment 11 Mike Stump 2008-02-13 02:59:07 UTC
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)?
Comment 12 Jonathan Lennox 2008-02-13 04:35:53 UTC
Created attachment 15134 [details]
test program using pointers to functions from emmintrin.h
Comment 13 Jonathan Lennox 2008-02-13 04:38:23 UTC
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.
Comment 14 Mike Stump 2008-02-13 20:49:15 UTC
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.
Comment 15 Jonathan Lennox 2008-02-13 22:27:38 UTC
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.
Comment 16 Jonathan Lennox 2008-02-19 21:01:02 UTC
Is there any possibility of getting a fix for this into 4.3.0?
Comment 17 Manuel López-Ibáñez 2008-02-20 01:10:39 UTC
(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).
Comment 18 Jonathan Lennox 2008-02-20 05:03:33 UTC
This is a regression from 4.2, despite the lack of marking.
Comment 19 uros 2008-03-13 13:34:46 UTC
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

Comment 20 uros 2008-03-14 14:35:02 UTC
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

Comment 21 Uroš Bizjak 2008-03-14 14:41:25 UTC
Fixed.