Module Name:    src
Committed By:   rillig
Date:           Wed Dec 22 15:36:38 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool_strict_syshdr.c
            d_c99_bool_strict_syshdr.exp
        src/usr.bin/xlint/lint1: ckbool.c

Log Message:
lint: fix wrong error in strict bool mode in condition with comma

For the result of the comma operator, it doesn't matter whether the
comma itself comes from a system header or not.  Instead, it's the main
operator of the right operand.

Since 2021-11-16.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.13 -r1.14 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ckbool.c

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_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.12
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.11	Wed Dec 22 15:20:08 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c	Wed Dec 22 15:36:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.11 2021/12/22 15:20:08 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.12 2021/12/22 15:36:37 rillig Exp $	*/
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
@@ -181,6 +181,12 @@ str_equal_good(const char *s1, const cha
 
 int read_char(void);
 
+/*
+ * Between tree.c 1.395 from 2021-11-16 and ckbool.c 1.10 from 2021-12-22,
+ * lint wrongly complained that the controlling expression would have to be
+ * _Bool instead of int.  Since the right-hand side of the ',' operator comes
+ * from a system header, this is OK though.
+ */
 void
 controlling_expression_with_comma_operator(void)
 {
@@ -195,17 +201,5 @@ controlling_expression_with_comma_operat
 	    )] & 0x0040 /* Space     */))
 # 197 "c_c99_bool_strict_syshdr.c"
 	    )
-	/* expect-1: error: controlling expression must be bool, not 'int' [333] */
 		continue;
-	/*
-	 * TODO: investigate why lint doesn't accept this call to isspace().
-	 *  It comes from a system header, therefore type 'int' should be OK.
-	 *  It is probably because the ',' of the controlling expression
-	 *  comes from the main source file, and lint assumes that the main
-	 *  operator of the controlling expression decides its outcome.  This
-	 *  assumption does not hold for the ',' operator since its result
-	 *  only depends on its right-hand operand.
-	 *
-	 *  Since tree.c 1.395 from 2021-11-16.
-	 */
 }

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.13 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.14
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.13	Wed Dec 22 15:20:08 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp	Wed Dec 22 15:36:37 2021
@@ -4,4 +4,3 @@ d_c99_bool_strict_syshdr.c(80): error: o
 d_c99_bool_strict_syshdr.c(157): error: return value type mismatch (_Bool) and (int) [211]
 d_c99_bool_strict_syshdr.c(172): error: operand of '!' must be bool, not 'int' [330]
 d_c99_bool_strict_syshdr.c(172): warning: function 'str_equal_bad' expects to return value [214]
-c_c99_bool_strict_syshdr.c(197): error: controlling expression must be bool, not 'int' [333]

Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.9 src/usr.bin/xlint/lint1/ckbool.c:1.10
--- src/usr.bin/xlint/lint1/ckbool.c:1.9	Tue Nov 16 21:01:05 2021
+++ src/usr.bin/xlint/lint1/ckbool.c	Wed Dec 22 15:36:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.9 2021/11/16 21:01:05 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.10 2021/12/22 15:36:37 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.9 2021/11/16 21:01:05 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.10 2021/12/22 15:36:37 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -49,6 +49,7 @@ __RCSID("$NetBSD: ckbool.c,v 1.9 2021/11
  * See d_c99_bool_strict.c for the exact rules and for examples.
  */
 
+
 static const char *
 op_name(op_t op)
 {
@@ -215,6 +216,8 @@ is_typeok_bool_operand(const tnode_t *tn
 
 	lint_assert(Tflag);
 
+	while (tn->tn_op == COMMA)
+		tn = tn->tn_right;
 	tn = before_conversion(tn);
 	t = tn->tn_type->t_tspec;
 

Reply via email to