Module Name:    src
Committed By:   rillig
Date:           Tue Nov 16 18:27:04 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
            d_c99_bool_strict.exp
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: fix wrong error message in strict bool mode

This fix only affects the last token before a macro, as well as the last
token in the expanded macro.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.30 -r1.31 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
cvs rdiff -u -r1.368 -r1.369 src/usr.bin/xlint/lint1/cgram.y

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.32 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.33
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.32	Tue Nov 16 06:55:03 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Tue Nov 16 18:27:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.32 2021/11/16 06:55:03 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.33 2021/11/16 18:27:04 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -838,14 +838,14 @@ controlling_expression(FILE *f, const ch
 		return;
 
 	/*
-	 * FIXME: At the end of parsing the name 'stdio_stdout', the parser
-	 * has already looked ahead to the next token, to see whether it is
-	 * a '(' of a function call.  At that point, the parser is no longer
-	 * in a system header, therefore 'stdio_stdout' is not tn_relaxed,
-	 * and this information is pushed down to the whole function call
-	 * expression.
+	 * Before cgram.y 1.369 from 2021-11-16, at the end of parsing the
+	 * name 'stdio_stdout', the parser already looked ahead to the next
+	 * token, to see whether it was the '(' of a function call.  At that
+	 * point, the parser was no longer in a system header, therefore
+	 * 'stdio_stdout' was not tn_relaxed, and this information was pushed
+	 * down to the whole function call expression (which was another bug
+	 * at that time).
 	 */
-	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
 # 851 "d_c99_bool_strict.c" 3 4
 	    stdio_stdout
@@ -867,12 +867,12 @@ controlling_expression(FILE *f, const ch
 		return;
 
 	/*
-	 * A comment following 'stdio_stdout' does not prevent the search for
-	 * '('.  At the point where build_name calls expr_zalloc_tnode, the
-	 * parser is already in the main file again, thus treating
-	 * stdio_stdout as not coming from a system header.
+	 * Before cgram.y 1.369 from 2021-11-16, the comment following
+	 * 'stdio_stdout' did not prevent the search for '('.  At the point
+	 * where build_name calls expr_zalloc_tnode, the parser was already
+	 * in the main file again, thus treating 'stdio_stdout' as not coming
+	 * from a system header.
 	 */
-	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
 # 878 "d_c99_bool_strict.c" 3 4
 	    stdio_stdout /* comment */

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.30 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.31
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.30	Tue Nov 16 06:55:03 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp	Tue Nov 16 18:27:04 2021
@@ -171,5 +171,3 @@ d_c99_bool_strict.c(805): error: control
 d_c99_bool_strict.c(808): error: controlling expression must be bool, not 'int' [333]
 d_c99_bool_strict.c(811): error: operand of '!' must be bool, not 'int' [330]
 d_c99_bool_strict.c(814): error: operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict.c(853): error: controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict.c(880): error: controlling expression must be bool, not 'int' [333]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.368 src/usr.bin/xlint/lint1/cgram.y:1.369
--- src/usr.bin/xlint/lint1/cgram.y:1.368	Tue Nov 16 17:41:23 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Nov 16 18:27:04 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.368 2021/11/16 17:41:23 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.369 2021/11/16 18:27:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.368 2021/11/16 17:41:23 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.369 2021/11/16 18:27:04 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -420,10 +420,14 @@ string2:
 /* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
 primary_expression:
 	  T_NAME {
-		/* XXX really necessary? */
+	  	bool sys_name, sys_next;
+		sys_name = in_system_header;
 		if (yychar < 0)
 			yychar = yylex();
+		sys_next = in_system_header;
+		in_system_header = sys_name;
 		$$ = build_name(getsym($1), yychar);
+		in_system_header = sys_next;
 	  }
 	| T_CON {
 		$$ = build_constant(gettyp($1->v_tspec), $1);

Reply via email to