Module Name:    src
Committed By:   rillig
Date:           Sat Jun 11 14:17:33 UTC 2022

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

Log Message:
tests/lint: demonstrate wrong syshdr check in strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.16 -r1.17 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp

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.15 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.16
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.15	Fri May 20 21:03:04 2022
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c	Sat Jun 11 14:17:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.15 2022/05/20 21:03:04 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.16 2022/06/11 14:17:33 rillig Exp $	*/
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
@@ -136,11 +136,11 @@ ch_isspace_sys_bool(char c)
  *	* strcmp: 0 means equal, < 0 means less than, > 0 means greater than
  *
  * Without a detailed list of individual functions, it's not possible to
- * guess what the return value means.  Therefore in strict bool mode, the
+ * guess what the return value means.  Therefore, in strict bool mode, the
  * return value of these functions cannot be implicitly converted to bool,
- * not even in a context where the result is compared to 0.  Allowing that
- * would allow expressions like !strcmp(s1, s2), which is not correct since
- * strcmp returns an "ordered comparison result", not a bool.
+ * not even in a controlling expression.  Allowing that would allow
+ * expressions like !strcmp(s1, s2), which is not correct since strcmp
+ * returns an "ordered comparison result", not a bool.
  */
 
 # 1 "math.h" 3 4
@@ -247,3 +247,42 @@ pass_bool_to_function(void)
 # 248 "d_c99_bool_strict_syshdr.c"
 	);
 }
+
+
+extern int *errno_location(void);
+
+/*
+ * As of 2022-06-11, the rule for loosening the strict boolean check for
+ * expressions from system headers is flawed.  That rule allows statements
+ * like 'if (NULL)' or 'if (errno)', even though these have pointer type or
+ * integer type.
+ */
+void
+if_pointer_or_int(void)
+{
+	/* if (NULL) */
+	if (
+# 266 "d_c99_bool_strict_syshdr.c" 3 4
+	    ((void *)0)
+# 268 "d_c99_bool_strict_syshdr.c"
+		       )
+		return;
+	/* expect-1: warning: statement not reached [193] */
+
+	/* if (EXIT_SUCCESS) */
+	if (
+# 275 "d_c99_bool_strict_syshdr.c" 3 4
+	    0
+# 277 "d_c99_bool_strict_syshdr.c"
+		       )
+		return;
+	/* expect-1: warning: statement not reached [193] */
+
+	/* if (errno) */
+	if (
+# 284 "d_c99_bool_strict_syshdr.c" 3 4
+	    (*errno_location())
+# 286 "d_c99_bool_strict_syshdr.c"
+		       )
+		return;
+}

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.16 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.17
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.16	Thu May 19 17:24:14 2022
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp	Sat Jun 11 14:17:33 2022
@@ -6,3 +6,5 @@ d_c99_bool_strict_syshdr.c(172): error: 
 d_c99_bool_strict_syshdr.c(172): warning: function 'str_equal_bad' expects to return value [214]
 d_c99_bool_strict_syshdr.c(229): error: argument #1 expects '_Bool', gets passed 'int' [334]
 d_c99_bool_strict_syshdr.c(242): error: argument #1 expects '_Bool', gets passed 'int' [334]
+d_c99_bool_strict_syshdr.c(269): warning: statement not reached [193]
+d_c99_bool_strict_syshdr.c(278): warning: statement not reached [193]

Reply via email to