https://gcc.gnu.org/g:2b3fbac8e37384857cd594c0800fccd99e4d39a1

commit r15-1962-g2b3fbac8e37384857cd594c0800fccd99e4d39a1
Author: Jørgen Kvalsvik <j...@lambda.is>
Date:   Wed Jul 10 18:47:27 2024 +0200

    Ensure function.end_line in source_info.lines
    
    Ensure that the function.end_line in the lines vector for the source
    file, even if it is not explicitly touched by a basic block. This
    ensures consistency with what you would expect. For example, this file
    has sources[sum.cc].lines.size () == 23 and main.end_line == 2 without
    adjusting sources.lines, which in this case is a no-op.
    
        #####:   17:int main ()
            -:   18:{
        #####:   19:  sum (1, 2);
        #####:   20:  sum (1.1, 2);
        #####:   21:  sum (2.2, 2.3);
        #####:   22:}
    
    This is a useful property when combined with selective reporting.
    
    gcc/ChangeLog:
    
            * gcov.cc (process_all_functions): Ensure fn.end_line is
            included source[fn].lines.

Diff:
---
 gcc/gcov.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index 2e4bd9d3c5da..7b4a075c5db6 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -1544,6 +1544,12 @@ process_all_functions (void)
                }
            }
 
+         /* Make sure to include the last line for this function even when it
+            is not directly covered by a basic block, for example when } is on
+            its own line.  */
+         if (sources[fn->src].lines.size () <= fn->end_line)
+           sources[fn->src].lines.resize (fn->end_line + 1);
+
          /* Allocate lines for group function, following start_line
             and end_line information of the function.  */
          if (fn->is_group)

Reply via email to