Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: demonstrate wrong sysh...



details:   https://anonhg.NetBSD.org/src/rev/77fde0f6294f
branches:  trunk
changeset: 366732:77fde0f6294f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 11 14:17:33 2022 +0000

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

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c   |  49 ++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp |   2 +
 2 files changed, 46 insertions(+), 5 deletions(-)

diffs (77 lines):

diff -r 9870ef6d1a64 -r 77fde0f6294f tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sat Jun 11 13:19:28 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sat Jun 11 14:17:33 2022 +0000
@@ -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 @@
  *     * 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 @@
 # 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;
+}
diff -r 9870ef6d1a64 -r 77fde0f6294f tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sat Jun 11 13:19:28 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sat Jun 11 14:17:33 2022 +0000
@@ -6,3 +6,5 @@
 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]



Home | Main Index | Thread Index | Old Index