[PATCH C++] Fix c++/41536, always_inline does not work always with constructors

Andrew Pinski pinskia@gmail.com
Fri Oct 2 19:24:00 GMT 2009


Hi,
  The problem here is that for the cloned constructor DECLs, they
don't have the attribute always_inline on them.  This is because we
created the cloned decls after the struct was finished and then while
doing duplicate_decls, the clones are not updated with the new
attributes.  maybe_clone_body updates some of the cloned decl bits but
it misses out on DECL_ATTRIBUTES and DECL_DISREGARD_INLINE_LIMITS.

This patch adds the copying of DECL_ATTRIBUTES and
DECL_DISREGARD_INLINE_LIMITS to maybe_clone_body.

OK? Bootstrapped and tested on i386-darwin8.11 with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
* optimize.c (maybe_clone_body): Copy DECL_ATTRIBUTES and
DECL_DISREGARD_INLINE_LIMITS also.

* g++.dg/ext/always_inline-5.C: New test.
-------------- next part --------------
Index: testsuite/g++.dg/ext/always_inline-5.C
===================================================================
--- testsuite/g++.dg/ext/always_inline-5.C	(revision 0)
+++ testsuite/g++.dg/ext/always_inline-5.C	(revision 0)
@@ -0,0 +1,28 @@
+// { dg-do compile }
+struct f
+{
+  inline f(void);
+  inline void f1(void);
+  int a;
+};
+
+inline __attribute__((always_inline))  f::f(void)
+{
+  a++;
+}
+
+inline __attribute__((always_inline)) void  f::f1(void)
+{
+  a++;
+}
+
+void g(void)
+{
+  f a, b, c, d;
+  a.f1();
+}
+
+// f::f() should be inlined even at -O0
+// { dg-final { scan-assembler-not "_ZN1fC1Ev" } }
+// Likewise for f::f1()
+// { dg-final { scan-assembler-not "_ZN1f2f1Ev" } }
Index: cp/optimize.c
===================================================================
--- cp/optimize.c	(revision 152380)
+++ cp/optimize.c	(working copy)
@@ -199,6 +199,8 @@ maybe_clone_body (tree fn)
       DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
       DECL_VISIBILITY_SPECIFIED (clone) = DECL_VISIBILITY_SPECIFIED (fn);
       DECL_DLLIMPORT_P (clone) = DECL_DLLIMPORT_P (fn);
+      DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (fn);
+      DECL_DISREGARD_INLINE_LIMITS (clone) = DECL_DISREGARD_INLINE_LIMITS (fn);
 
       /* Adjust the parameter names and locations.  */
       parm = DECL_ARGUMENTS (fn);


More information about the Gcc-patches mailing list