public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Laurent Alfonsi <laurent.alfonsi@st.com>
To: Jeff Law <law@redhat.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix PR49718 : allow no_instrument_function attribute in class member definition/declaration
Date: Wed, 15 Jan 2014 08:51:00 -0000	[thread overview]
Message-ID: <52D64C0B.4060005@st.com> (raw)
In-Reply-To: <52CEAF7B.7010101@st.com>

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

Ping ? Ok for trunk ?

On 01/09/14 15:17, Laurent Alfonsi wrote:
> On 01/09/14 06:02, Jeff Law wrote:
>> On 01/08/14 02:05, Laurent Alfonsi wrote:
>>>       All,
>>>
>>> I was looking at PR49718. I have enclosed a simple fix for this bug 
>>> report.
>>>
>>> 2014-01-07  Laurent Alfonsi <laurent.alfonsi@st.com>
>>>
>>>       * c-family/c-common.c 
>>> (handle_no_instrument_function_attribute): Allow
>>>         no_instrument_function attribute in class member
>>> definition/declaration.
>>>
>>>
>>> Looking at the implementation of the function attributes, I see no
>>> reason anymore to keep this error message.
>>> Let me know if I missed something.
>>> I have also added a testcase in the enclosed patch.
>>>
>>> 2014-01-07  Laurent Alfonsi <laurent.alfonsi@st.com>
>>>
>>>       PR c++/49718
>>>       * g++.dg/pr49718.C: New
>> Isn't the idea here that if we've already generated the function body
>> (presumably with instrumentation) that a no-instrument attribute
>> appearing on a later declaration won't do anything useful?
>>
>> jeff
>>
>>
> Jeff,
>
> You are right. That's probably the reason.
> From what i can see, the code instrumentation is performed in the 
> gimplification pass (gimplify_function_tree), and the function 
> attribute is handled and attached earlier in the parsing phase.
>
> I ve checked with an example like :
> ---8<------8<------8<------8<------8<---
> int foo () {
>   return 2;
> }
>
> int bar () {
>   return 1;
> }
>
> int foo () __attribute__((no_instrument_function));
> ---8<------8<------8<------8<------8<---
> The attribute is well honored on foo function.
> I might need to add this test case too.
>
> Let me know if fix is ok.
>
> Thanks
> Laurent


[-- Attachment #2: Fix-PR49718-allow-no_instrument_function-attribute-i.patch --]
[-- Type: text/plain, Size: 2524 bytes --]

From 141d2bcfeab5e0635c7f4e362387fd5b1b9494e6 Mon Sep 17 00:00:00 2001
From: Laurent ALFONSI <laurent.alfonsi@st.com>
Date: Tue, 7 Jan 2014 16:26:04 +0100
Subject: [PATCH] Fix PR49718 : allow no_instrument_function attribute in class
 member definition/declaration

---
 gcc/c-family/c-common.c        |  6 ------
 gcc/testsuite/g++.dg/pr49718.C | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr49718.C

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 8ecb70c..17fcb0d 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -7929,12 +7929,6 @@ handle_no_instrument_function_attribute (tree *node, tree name,
 		"%qE attribute applies only to functions", name);
       *no_add_attrs = true;
     }
-  else if (DECL_INITIAL (decl))
-    {
-      error_at (DECL_SOURCE_LOCATION (decl),
-		"can%'t set %qE attribute after definition", name);
-      *no_add_attrs = true;
-    }
   else
     DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
 
diff --git a/gcc/testsuite/g++.dg/pr49718.C b/gcc/testsuite/g++.dg/pr49718.C
new file mode 100644
index 0000000..07cac8c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr49718.C
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -finstrument-functions" } */
+/* { dg-final { scan-assembler-times "__cyg_profile_func_enter" 1} } */
+
+#define NOINSTR __attribute__((no_instrument_function))
+
+struct t
+{
+   public:
+       /* Function code should be instrumented */
+       __attribute__((noinline)) t() {}
+       
+       /* Function t::a() should not be instrumented */
+       NOINSTR void a(){
+       }
+       /* Function t::b() should not be instrumented */
+       void NOINSTR b(){
+       }
+       /* Function t::c() should not be instrumented */
+       void c() NOINSTR {
+       }
+       /* Function t::d() should not be instrumented */
+       void d() NOINSTR;
+};
+
+void t::d()
+{
+}
+
+/* Function call_all_functions() should not be instrumented */
+struct t call_all_functions() __attribute__((no_instrument_function));
+struct t call_all_functions() 
+{
+       struct t a;     /* Constructor not inlined */
+       a.a();	       /* Inlined t::a() should not be instrumented */
+       a.b();	       /* Inlined t::b() should not be instrumented */
+       a.c();	       /* Inlined t::c() should not be instrumented */
+       a.d();	       /* Inlined t::d() should not be instrumented */
+       return a;
+}
+
-- 
1.8.4.1


  reply	other threads:[~2014-01-15  8:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08  9:05 Laurent Alfonsi
2014-01-09  5:02 ` Jeff Law
2014-01-09 14:18   ` Laurent Alfonsi
2014-01-15  8:51     ` Laurent Alfonsi [this message]
2014-01-15 19:25     ` Jeff Law
2014-01-16  8:41       ` Laurent Alfonsi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52D64C0B.4060005@st.com \
    --to=laurent.alfonsi@st.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).