Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/byacc/dist byacc: fix line number information f...



details:   https://anonhg.NetBSD.org/src/rev/6884681d43e7
branches:  trunk
changeset: 1023980:6884681d43e7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 05 22:15:32 2021 +0000

description:
byacc: fix line number information for code coverage

Previously, running gcov on a parser generated by byacc resulted in
obviously wrong counts. There were empty lines that had counts, and the
same counts spilled over to some nearby lines.

Only generate preprocessor line directives for the actual action code,
switch back to an empty filename for the glue code.

This only fixes the parsers in default mode. Parsers that use the
backtracking option may still report wrong counts.

Reported upstream via private mail.

diffstat:

 external/bsd/byacc/dist/reader.c |  19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diffs (53 lines):

diff -r 2d05ce1f1706 -r 6884681d43e7 external/bsd/byacc/dist/reader.c
--- a/external/bsd/byacc/dist/reader.c  Tue Oct 05 22:09:05 2021 +0000
+++ b/external/bsd/byacc/dist/reader.c  Tue Oct 05 22:15:32 2021 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: reader.c,v 1.19 2021/02/20 22:57:56 christos Exp $     */
+/*     $NetBSD: reader.c,v 1.20 2021/10/05 22:15:32 rillig Exp $       */
 
 /* Id: reader.c,v 1.84 2020/09/10 20:26:13 tom Exp  */
 
 #include "defs.h"
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: reader.c,v 1.19 2021/02/20 22:57:56 christos Exp $");
+__RCSID("$NetBSD: reader.c,v 1.20 2021/10/05 22:15:32 rillig Exp $");
 
 /*  The line size must be a positive integer.  One hundred was chosen  */
 /*  because few lines in Yacc input grammars exceed 100 characters.    */
@@ -2949,7 +2949,10 @@
                trialaction = 0;
                goto loop;
            }
-           fprintf(f, "\nbreak;\n");
+           fprintf(f, "\n");
+           if (!lflag)
+               fprintf(f, line_format, 1, "");
+           fprintf(f, "break;\n");
            FREE(a.a_line);
            if (maxoffset > 0)
                FREE(offsets);
@@ -2969,7 +2972,10 @@
     case ';':
        if (depth > 0)
            goto loop;
-       fprintf(f, "\nbreak;\n");
+       fprintf(f, "\n");
+       if (!lflag)
+           fprintf(f, line_format, 1, "");
+       fprintf(f, "break;\n");
        free(a.a_line);
        if (maxoffset > 0)
            FREE(offsets);
@@ -3012,7 +3018,10 @@
            }
        }
 #endif
-       fprintf(f, "\nbreak;\n");
+       fprintf(f, "\n");
+       if (!lflag)
+           fprintf(f, line_format, 1, "");
+       fprintf(f, "break;\n");
        free(a.a_line);
        if (maxoffset > 0)
            FREE(offsets);



Home | Main Index | Thread Index | Old Index