public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10035] coverage: handle function beginning
@ 2021-08-13 13:59 Martin Liska
  0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2021-08-13 13:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ff3978f5ea2672b208830a97d276cc1c856f6231

commit r10-10035-gff3978f5ea2672b208830a97d276cc1c856f6231
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Jun 1 15:13:18 2021 +0200

    coverage: handle function beginning
    
            PR gcov-profile/100788
    
    gcc/ChangeLog:
    
            * coverage.c (coverage_begin_function): Update function
              beginning when #line macro is used.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/pr100788.c: New test.

Diff:
---
 gcc/coverage.c                  | 28 +++++++++++++++++-----------
 gcc/testsuite/gcc.dg/pr100788.c | 13 +++++++++++++
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 38820bc170f..2747f8f1b4c 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -616,18 +616,16 @@ coverage_compute_cfg_checksum (struct function *fn)
 int
 coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
 {
-  expanded_location xloc;
-  unsigned long offset;
-
   /* We don't need to output .gcno file unless we're under -ftest-coverage
      (e.g. -fprofile-arcs/generate/use don't need .gcno to work). */
   if (no_coverage || !bbg_file_name)
     return 0;
 
-  xloc = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
+  expanded_location startloc
+    = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
 
   /* Announce function */
-  offset = gcov_write_tag (GCOV_TAG_FUNCTION);
+  unsigned long offset = gcov_write_tag (GCOV_TAG_FUNCTION);
   if (param_profile_func_internal_id)
     gcov_write_unsigned (current_function_funcdef_no + 1);
   else
@@ -644,16 +642,24 @@ coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
   gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl)
 		       && !DECL_FUNCTION_VERSIONED (current_function_decl)
 		       && !DECL_LAMBDA_FUNCTION_P (current_function_decl));
-  gcov_write_filename (xloc.file);
-  gcov_write_unsigned (xloc.line);
-  gcov_write_unsigned (xloc.column);
+  gcov_write_filename (startloc.file);
+  gcov_write_unsigned (startloc.line);
+  gcov_write_unsigned (startloc.column);
 
   expanded_location endloc = expand_location (cfun->function_end_locus);
 
   /* Function can start in a single file and end in another one.  */
-  int end_line = endloc.file == xloc.file ? endloc.line : xloc.line;
-  int end_column = endloc.file == xloc.file ? endloc.column: xloc.column;
-  gcc_assert (xloc.line <= end_line);
+  int end_line
+    = endloc.file == startloc.file ? endloc.line : startloc.line;
+  int end_column
+    = endloc.file == startloc.file ? endloc.column: startloc.column;
+
+  if (startloc.line > end_line)
+    {
+      end_line = startloc.line;
+      end_column = startloc.column;
+    }
+
   gcov_write_unsigned (end_line);
   gcov_write_unsigned (end_column);
   gcov_write_length (offset);
diff --git a/gcc/testsuite/gcc.dg/pr100788.c b/gcc/testsuite/gcc.dg/pr100788.c
new file mode 100644
index 00000000000..5d54329f752
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr100788.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "--coverage" } */
+
+void
+foo()
+{
+#line 1
+}
+
+int main()
+{
+  foo ();
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-13 13:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 13:59 [gcc r10-10035] coverage: handle function beginning Martin Liska

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