public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect
@ 2011-08-12 19:39 Siddhesh Poyarekar
  2011-08-23 15:39 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Siddhesh Poyarekar @ 2011-08-12 19:39 UTC (permalink / raw)
  To: gcc-patches

Hi,

When the location for throw() exception specification is not the same
as the function it is written against, it leads gcov to give incorrect
results. See bug 50055 for details of the the same. The following
patch makes sure that the exception specification block (nothrow or
otherwise) is always associated with the function definition line
number.

I have a test case included with the patch. I ran the c++ test suite
and found no regressions due to this patch.

--
Siddhesh

cp/ChangeLog:

    PR c++/50055
    * except.c (begin_eh_spec_block): Build EH_SPEC block on the
    same line as the function.

testsuite/ChangeLog:

    PR c++/50055
    * g++.dg/gcov/gcov-7.C: New test.

Index: gcc/testsuite/g++.dg/gcov/gcov-7.C
===================================================================
--- gcc/testsuite/g++.dg/gcov/gcov-7.C	(revision 0)
+++ gcc/testsuite/g++.dg/gcov/gcov-7.C	(revision 0)
@@ -0,0 +1,28 @@
+/* Check that Exception handler specification is not
+   mapped to the curly braces below the function
+   declaration.  */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+struct foo
+{
+  foo () throw (int)
+    {			/* count (-) */
+      throw (1);
+    }
+};
+
+int main ()
+{
+  try
+    {
+      foo f;
+    }
+  catch ( ...)
+    {
+      return 0;
+    }
+}
+
+/* { dg-final { run-gcov gcov-7.C } } */
Index: gcc/cp/except.c
===================================================================
--- gcc/cp/except.c	(revision 177613)
+++ gcc/cp/except.c	(working copy)
@@ -527,15 +527,17 @@
 begin_eh_spec_block (void)
 {
   tree r;
+  location_t spec_location = DECL_SOURCE_LOCATION (current_function_decl);
+
   /* A noexcept specification (or throw() with -fnothrow-opt) is a
      MUST_NOT_THROW_EXPR.  */
   if (TYPE_NOEXCEPT_P (TREE_TYPE (current_function_decl)))
     {
-      r = build_stmt (input_location, MUST_NOT_THROW_EXPR, NULL_TREE);
+      r = build_stmt (spec_location, MUST_NOT_THROW_EXPR, NULL_TREE);
       TREE_SIDE_EFFECTS (r) = 1;
     }
   else
-    r = build_stmt (input_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE);
+    r = build_stmt (spec_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE);
   add_stmt (r);
   TREE_OPERAND (r, 0) = push_stmt_list ();
   return r;

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

* Re: [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect
  2011-08-12 19:39 [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect Siddhesh Poyarekar
@ 2011-08-23 15:39 ` Jason Merrill
  2011-08-23 15:43   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2011-08-23 15:39 UTC (permalink / raw)
  To: Siddhesh Poyarekar; +Cc: gcc-patches

On 08/12/2011 03:18 PM, Siddhesh Poyarekar wrote:
> When the location for throw() exception specification is not the same
> as the function it is written against, it leads gcov to give incorrect
> results. See bug 50055 for details of the the same. The following
> patch makes sure that the exception specification block (nothrow or
> otherwise) is always associated with the function definition line
> number.

I'm applying this patch, thanks.

This patch is small enough not to need it, but for future contributions 
please file a copyright assignment with the FSF.  Send email to 
assign@gnu.org for more information.

Jason

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

* Re: [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect
  2011-08-23 15:39 ` Jason Merrill
@ 2011-08-23 15:43   ` Jakub Jelinek
  2011-08-23 15:45     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2011-08-23 15:43 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Siddhesh Poyarekar, gcc-patches

On Tue, Aug 23, 2011 at 10:56:26AM -0400, Jason Merrill wrote:
> This patch is small enough not to need it, but for future
> contributions please file a copyright assignment with the FSF.  Send
> email to assign@gnu.org for more information.

I think Siddhesh should be covered by the Red Hat assignment (it would help
if the patch has been mailed from a redhat.com address to notice that).

	Jakub

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

* Re: [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect
  2011-08-23 15:43   ` Jakub Jelinek
@ 2011-08-23 15:45     ` Siddhesh Poyarekar
  0 siblings, 0 replies; 4+ messages in thread
From: Siddhesh Poyarekar @ 2011-08-23 15:45 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

On Tue, Aug 23, 2011 at 8:33 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Tue, Aug 23, 2011 at 10:56:26AM -0400, Jason Merrill wrote:
>> This patch is small enough not to need it, but for future
>> contributions please file a copyright assignment with the FSF.  Send
>> email to assign@gnu.org for more information.
>
> I think Siddhesh should be covered by the Red Hat assignment (it would help
> if the patch has been mailed from a redhat.com address to notice that).
>

Thanks! I will keep that in mind for future submissions.


-- 
Siddhesh Poyarekar
http://siddhesh.in

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

end of thread, other threads:[~2011-08-23 15:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 19:39 [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect Siddhesh Poyarekar
2011-08-23 15:39 ` Jason Merrill
2011-08-23 15:43   ` Jakub Jelinek
2011-08-23 15:45     ` Siddhesh Poyarekar

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