public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH C++] Fix c++/41536, always_inline does not work always with   constructors
@ 2009-10-02 19:24 Andrew Pinski
  2009-10-16 19:05 ` Andrew Pinski
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Pinski @ 2009-10-02 19:24 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 751 bytes --]

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.

[-- Attachment #2: fixpr41536.diff.txt --]
[-- Type: text/plain, Size: 1320 bytes --]

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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH C++] Fix c++/41536, always_inline does not work always   with constructors
  2009-10-02 19:24 [PATCH C++] Fix c++/41536, always_inline does not work always with constructors Andrew Pinski
@ 2009-10-16 19:05 ` Andrew Pinski
  2009-10-16 19:25   ` Jan Hubicka
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Pinski @ 2009-10-16 19:05 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

PING?

On Fri, Oct 2, 2009 at 12:24 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> 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.
>

[-- Attachment #2: fixpr41536.diff.txt --]
[-- Type: text/plain, Size: 1320 bytes --]

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);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH C++] Fix c++/41536, always_inline does not work always   with constructors
  2009-10-16 19:05 ` Andrew Pinski
@ 2009-10-16 19:25   ` Jan Hubicka
  2009-11-02 13:52     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Jan Hubicka @ 2009-10-16 19:25 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: GCC Patches

> +      DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (fn);

I don't think it is safe to share (parts of) attributes list.  It would
be probably better to unshare it first?

Honza
> +      DECL_DISREGARD_INLINE_LIMITS (clone) = DECL_DISREGARD_INLINE_LIMITS (fn);
>  
>        /* Adjust the parameter names and locations.  */
>        parm = DECL_ARGUMENTS (fn);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH C++] Fix c++/41536, always_inline does not work always    with constructors
  2009-10-16 19:25   ` Jan Hubicka
@ 2009-11-02 13:52     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2009-11-02 13:52 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: Andrew Pinski, GCC Patches

On 10/16/2009 03:05 PM, Jan Hubicka wrote:
>> +      DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (fn);
>
> I don't think it is safe to share (parts of) attributes list.  It would
> be probably better to unshare it first?

I'm not sure, but we might as well be conservative, and using copy_list 
would be a simple way to do that.  OK with that change.  Please CC me on 
C++ patches, or at least on pings, as I tend to get behind on 
gcc-patches mail.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-02 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-02 19:24 [PATCH C++] Fix c++/41536, always_inline does not work always with constructors Andrew Pinski
2009-10-16 19:05 ` Andrew Pinski
2009-10-16 19:25   ` Jan Hubicka
2009-11-02 13:52     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).