Module Name:    src
Committed By:   rillig
Date:           Tue Oct  5 22:15:32 UTC 2021

Modified Files:
        src/external/bsd/byacc/dist: reader.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/external/bsd/byacc/dist/reader.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/byacc/dist/reader.c
diff -u src/external/bsd/byacc/dist/reader.c:1.19 src/external/bsd/byacc/dist/reader.c:1.20
--- src/external/bsd/byacc/dist/reader.c:1.19	Sat Feb 20 22:57:56 2021
+++ src/external/bsd/byacc/dist/reader.c	Tue Oct  5 22:15:32 2021
@@ -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 @@ copy_action(void)
 		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 @@ copy_action(void)
     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 @@ copy_action(void)
 	    }
 	}
 #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);

Reply via email to