Hi!

As Richard reported on IRC, we are marking C99 inline (without extern)
functions as effectively always_inline, even when the intent has been to do
this only for the GNU extern inline functions (i.e. -fgnu89-inline extern
inline or extern inline __attribute__((gnu_inline))).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?  The alias-11.c change is needed because the inliner decides not to
inline new_cfi, and as it uses since -std=c11 default C99 inline semantics
without extern, the body isn't emitted.

2016-07-22  Jakub Jelinek  <ja...@redhat.com>

        PR c/71969
        * c-decl.c (finish_function): Only set DECL_DISREGARD_INLINE_LIMITS
        on GNU extern inline functions.

        * gcc.dg/alias-11.c (add_cfi, new_cfi): Change __inline__ to
        static __inline__.
        * gcc.dg/pr71969-1.c: New test.
        * gcc.dg/pr71969-2.c: New test.
        * gcc.dg/pr71969-3.c: New test.

--- gcc/c/c-decl.c.jj   2016-07-21 08:59:53.000000000 +0200
+++ gcc/c/c-decl.c      2016-07-22 13:46:40.766019603 +0200
@@ -9262,7 +9262,9 @@ finish_function (void)
 
   /* For GNU C extern inline functions disregard inline limits.  */
   if (DECL_EXTERNAL (fndecl)
-      && DECL_DECLARED_INLINE_P (fndecl))
+      && DECL_DECLARED_INLINE_P (fndecl)
+      && (flag_gnu89_inline
+         || lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (fndecl))))
     DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1;
 
   /* Genericize before inlining.  Delay genericizing nested functions
--- gcc/testsuite/gcc.dg/alias-11.c.jj  2008-09-05 12:54:36.000000000 +0200
+++ gcc/testsuite/gcc.dg/alias-11.c     2016-07-22 17:01:49.930290850 +0200
@@ -24,7 +24,7 @@ dw_cfi_node *cie_cfi_head;
 unsigned fde_table_in_use;
 dw_fde_node *fde_table;
 
-__inline__ void
+static __inline__ void
 add_cfi (dw_cfi_node **list_head, dw_cfi_node *cfi)
 {
   dw_cfi_node **p;
@@ -35,7 +35,7 @@ add_cfi (dw_cfi_node **list_head, dw_cfi
   *p = cfi;
 }
 
-__inline__ struct dw_cfi_struct *
+static __inline__ struct dw_cfi_struct *
 new_cfi (void)
 {
   dw_cfi_node *cfi = (dw_cfi_node *) malloc (sizeof (dw_cfi_node));
--- gcc/testsuite/gcc.dg/pr71969-1.c.jj 2016-07-22 14:18:44.336452571 +0200
+++ gcc/testsuite/gcc.dg/pr71969-1.c    2016-07-22 14:25:23.877557343 +0200
@@ -0,0 +1,37 @@
+/* PR c/71969 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fno-gnu89-inline -O2 -fdump-tree-einline-details" 
} */
+
+volatile int v;
+#define S v++;
+#define S10 S S S S S S S S S S
+#define S100 S10 S10 S10 S10 S10 S10 S10 S10 S10 S10
+
+extern inline void
+foo (void) { S100 }
+
+inline void
+bar (void) { S100 }
+
+static inline void
+baz (void) { S100 }
+
+int
+main ()
+{
+  foo ();
+  foo ();
+  foo ();
+  foo ();
+  bar ();
+  bar ();
+  bar ();
+  bar ();
+  baz ();
+  baz ();
+  baz ();
+  baz ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "will not early inline" 12 "einline" } } 
*/
--- gcc/testsuite/gcc.dg/pr71969-2.c.jj 2016-07-22 14:27:35.781941234 +0200
+++ gcc/testsuite/gcc.dg/pr71969-2.c    2016-07-22 14:29:18.873678141 +0200
@@ -0,0 +1,23 @@
+/* PR c/71969 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fno-gnu89-inline -O2 -fdump-tree-einline-details" 
} */
+
+volatile int v;
+#define S v++;
+#define S10 S S S S S S S S S S
+#define S100 S10 S10 S10 S10 S10 S10 S10 S10 S10 S10
+
+extern inline __attribute__((gnu_inline)) void
+foo (void) { S100 }
+
+int
+main ()
+{
+  foo ();
+  foo ();
+  foo ();
+  foo ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "Inlining foo into main" 4 "einline" } } 
*/
--- gcc/testsuite/gcc.dg/pr71969-3.c.jj 2016-07-22 14:29:33.300501382 +0200
+++ gcc/testsuite/gcc.dg/pr71969-3.c    2016-07-22 14:30:18.360949296 +0200
@@ -0,0 +1,38 @@
+/* PR c/71969 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -fgnu89-inline -O2 -fdump-tree-einline-details" } 
*/
+
+volatile int v;
+#define S v++;
+#define S10 S S S S S S S S S S
+#define S100 S10 S10 S10 S10 S10 S10 S10 S10 S10 S10
+
+extern inline void
+foo (void) { S100 }
+
+inline void
+bar (void) { S100 }
+
+static inline void
+baz (void) { S100 }
+
+int
+main ()
+{
+  foo ();
+  foo ();
+  foo ();
+  foo ();
+  bar ();
+  bar ();
+  bar ();
+  bar ();
+  baz ();
+  baz ();
+  baz ();
+  baz ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "will not early inline" 8 "einline" } } */
+/* { dg-final { scan-tree-dump-times "Inlining foo into main" 4 "einline" } } 
*/

        Jakub

Reply via email to