This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c99 'static inline' bug fix


My previous patch would set DECL_EXTERNAL in c99 mode whenever
'extern' was not specified with 'inline'.  However, 'static inline'
functions don't have 'extern' but are not DECL_EXTERNAL.  This caused
GCC to not emit out-of-line copies of static inline functions.

Bootstrapped & tested on powerpc-darwin8.

On hold for GCC 4.3, along with the other c99 inlining patches.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-c99inline-static.patch================
Index: ChangeLog
2006-05-16  Geoffrey Keating  <geoffk@apple.com>

	* c-decl.c (grokdeclarator): Don't set DECL_EXTERNAL on
	inline static functions in c99 mode.

Index: testsuite/ChangeLog
2006-05-16  Geoffrey Keating  <geoffk@apple.com>

	* gcc.dg/inline-16.c: New.

Index: testsuite/gcc.dg/inline-16.c
===================================================================
--- testsuite/gcc.dg/inline-16.c	(revision 0)
+++ testsuite/gcc.dg/inline-16.c	(revision 0)
@@ -0,0 +1,21 @@
+/* { dg-do link } */
+/* { dg-options "-std=c99" } */
+
+static inline int
+func1(const volatile void * base, int byteOffset)
+{
+  volatile int *addr = (volatile int *)((int)base + byteOffset);
+  return *addr;
+}
+
+static inline int
+func2(int data)
+{
+    return func1(&data, 0);
+}
+
+int main(int argc, char *argv[]) {
+  int b = func2(argc);
+
+  return 0;
+}
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 114130)
+++ c-decl.c	(working copy)
@@ -4672,7 +4672,7 @@
 	   means that the later definition of the function must be output
 	   in this file, C99 6.7.4p6.  In GNU C89, a function declared
 	   'extern inline' is an external reference.  */
-	else if (declspecs->inline_p)
+	else if (declspecs->inline_p && storage_class != csc_static)
 	  DECL_EXTERNAL (decl) = (storage_class == csc_extern) == !flag_isoc99;
 	else
 	  DECL_EXTERNAL (decl) = !initialized;
============================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]