public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Seongbae Park (박성배, 朴成培)" <seongbae.park@gmail.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	 	"Mark Mitchell" <mark@codesourcery.com>,
	 	"Nathan Sidwell" <nathan@codesourcery.com>
Subject: [PATCH] Wrong line number for the closing brace of template functions
Date: Mon, 06 Aug 2007 17:36:00 -0000	[thread overview]
Message-ID: <ab3a61990708061036gbcb1a62pcdb81954e5d5c5de@mail.gmail.com> (raw)

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

Hi,

The included testcase in the patch demonstrates the bug,
which is that the last source line of a template function was not
propagated correctly to template function instances,
leading to all template functions to report wrong coverage count
for the implicit "return".

Note that the patch is supposed to be applied on top of my previous patch:

http://gcc.gnu.org/ml/gcc-patches/2007-07/msg01953.html

(Please consider this email as another ping for that patch as well)

The bootstrap is done, and regtest is under way.
If all tests look clean, OK for mainline ?


gcc/testsuite/ChangeLog:

2007-08-06  Seongbae Park <seongbae.park@gmail.com>

        * g++.dg/gcov/gcov-5.C: New test.


gcc/cp/ChangeLog:

2007-08-06  Seongbae Park <seongbae.park@gmail.com>

        * pt.c (instantiate_decl): Set input_location
        for the function end.

-- 
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com"

[-- Attachment #2: template-end-of-func.patch --]
[-- Type: text/x-patch, Size: 1960 bytes --]

Index: gcc/testsuite/g++.dg/gcov/gcov-5.C
===================================================================
--- gcc/testsuite/g++.dg/gcov/gcov-5.C	(revision 0)
+++ gcc/testsuite/g++.dg/gcov/gcov-5.C	(revision 0)
@@ -0,0 +1,50 @@
+/* Check that execution counts for template functions
+   are reported correctly by gcov. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* { dg-options "-fprofile-arcs -ftest-coverage -fno-inline" } */
+/* { dg-do run { target native } } */
+
+class A {
+  int count;
+ public:
+  A(int c) { count = c; }
+  void func(void) { printf("func\n"); }
+  bool done(void) { 
+    return (count == 0) ? true : (count-- != 0);
+  }
+  void run(void) { abort(); }
+};
+
+//typedef A T;
+template<class T>
+void WithoutBrace(T *a) {
+  while (!a->done())   
+    a->run();           /* count(#####) */
+}                       /* count(1) */
+
+template<class T>
+void WithBrace(T *a)
+{
+  while (!a->done())   
+    { 
+      a->run();         /* count(#####) */
+    }
+}                       /* count(1) */
+
+A *func(A *a)
+{
+  WithoutBrace(a);
+  WithBrace(a);
+  return a;
+}
+
+int main() {
+  A a(0);
+  func(&a);
+  return 0;
+}
+
+/* { dg-final { run-gcov gcov-5.C } } */
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 127246)
+++ gcc/cp/pt.c	(working copy)
@@ -14438,6 +14438,12 @@ instantiate_decl (tree d, int defer_ok,
 		   tf_warning_or_error, tmpl,
 		   /*integral_constant_expression_p=*/false);
 
+      /* Make sure the current input_location
+         is set correctly to the end of the function
+	 - this makes finish_function to set
+	 function_end_locus of this specialization correctly. */
+      input_location = DECL_STRUCT_FUNCTION (code_pattern)->function_end_locus;
+
       /* We don't need the local specializations any more.  */
       htab_delete (local_specializations);
       local_specializations = saved_local_specializations;

             reply	other threads:[~2007-08-06 17:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-06 17:36 Seongbae Park (박성배, 朴成培) [this message]
2007-08-06 18:11 ` Mark Mitchell
2007-08-06 18:47   ` Dave Korn

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=ab3a61990708061036gbcb1a62pcdb81954e5d5c5de@mail.gmail.com \
    --to=seongbae.park@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    --cc=nathan@codesourcery.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).