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 lint: improve introduction of test...



details:   https://anonhg.NetBSD.org/src/rev/02b4932194de
branches:  trunk
changeset: 958880:02b4932194de
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 24 09:18:42 2021 +0000

description:
lint: improve introduction of test d_c99_bool_strict_syshdr

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c   |  51 ++++++++++-------
 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp |  12 ++--
 2 files changed, 37 insertions(+), 26 deletions(-)

diffs (132 lines):

diff -r 5a57adf49865 -r 02b4932194de tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sun Jan 24 07:58:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c      Sun Jan 24 09:18:42 2021 +0000
@@ -1,11 +1,22 @@
-/*     $NetBSD: d_c99_bool_strict_syshdr.c,v 1.7 2021/01/24 07:58:48 rillig Exp $      */
+/*     $NetBSD: d_c99_bool_strict_syshdr.c,v 1.8 2021/01/24 09:18:42 rillig Exp $      */
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
- * Macros from system headers may use int expressions where bool expressions
- * are expected.  These headers are not allowed to include <stdbool.h>
- * themselves, and even if they could, lint must accept other scalar types
- * as well, since system headers are not changed lightheartedly.
+ * In strict bool mode, lint treats bool as incompatible with any other scalar
+ * types.  This mode helps in migrating code from pre-C99 to C99.
+ *
+ * System headers, on the other hand, cannot be migrated if they need to stay
+ * compatible with pre-C99 code.  Therefore, the checks for system headers are
+ * loosened.  In contexts where a scalar expression is compared to 0, macros
+ * and functions from system headers may use int expressions as well.
+ *
+ * These headers are not allowed to include <stdbool.h>[references needed].
+ * Doing so would inject lint's own <stdbool.h>, which defines the macros
+ * false and true to other identifiers instead of the plain 0 and 1, thereby
+ * allowing to see whether the code really uses true and false as identifiers.
+ *
+ * Since the system headers cannot include <stdbool.h>, they need to use the
+ * traditional bool constants 0 and 1.
  */
 
 /* lint1-extra-flags: -T */
@@ -31,12 +42,12 @@
                println("nothing");
        } while (/*CONSTCOND*/0);       /* expect: 333 */
 
-# 35 "d_c99_bool_strict_syshdr.c" 3 4
+# 46 "d_c99_bool_strict_syshdr.c" 3 4
        do {
                println("nothing");
        } while (/*CONSTCOND*/0);       /* ok */
 
-# 40 "d_c99_bool_strict_syshdr.c"
+# 51 "d_c99_bool_strict_syshdr.c"
        do {
                println("nothing");
        } while (/*CONSTCOND*/0);       /* expect: 333 */
@@ -70,28 +81,28 @@
         * All other combinations of type are safe from truncation.
         */
        _Bool system_int_assigned_to_bool =
-# 74 "d_c99_bool_strict_syshdr.c" 3 4
+# 85 "d_c99_bool_strict_syshdr.c" 3 4
            (int)((ctype_table + 1)[c] & 0x0040)        /* INT */
-# 76 "d_c99_bool_strict_syshdr.c"
+# 87 "d_c99_bool_strict_syshdr.c"
        ;                       /* expect: 107 */
 
        int system_bool_assigned_to_int =
-# 80 "d_c99_bool_strict_syshdr.c" 3 4
+# 91 "d_c99_bool_strict_syshdr.c" 3 4
            (int)((ctype_table + 1)[c] & 0x0040) != 0   /* BOOL */
-# 82 "d_c99_bool_strict_syshdr.c"
+# 93 "d_c99_bool_strict_syshdr.c"
        ;
 
        if (
-# 86 "d_c99_bool_strict_syshdr.c" 3 4
+# 97 "d_c99_bool_strict_syshdr.c" 3 4
            (int)((ctype_table + 1)[c] & 0x0040)        /* INT */
-# 88 "d_c99_bool_strict_syshdr.c"
+# 99 "d_c99_bool_strict_syshdr.c"
        )
                println("system macro returning INT");
 
        if (
-# 93 "d_c99_bool_strict_syshdr.c" 3 4
+# 104 "d_c99_bool_strict_syshdr.c" 3 4
            ((ctype_table + 1)[c] & 0x0040) != 0        /* BOOL */
-# 95 "d_c99_bool_strict_syshdr.c"
+# 106 "d_c99_bool_strict_syshdr.c"
        )
                println("system macro returning BOOL");
 }
@@ -100,9 +111,9 @@
 ch_isspace_sys_int(char c)
 {
        return
-# 104 "d_c99_bool_strict_syshdr.c" 3 4
+# 115 "d_c99_bool_strict_syshdr.c" 3 4
            ((ctype_table + 1)[c] & 0x0040)
-# 106 "d_c99_bool_strict_syshdr.c"
+# 117 "d_c99_bool_strict_syshdr.c"
            != 0;
 }
 
@@ -115,9 +126,9 @@
 ch_isspace_sys_bool(char c)
 {
        return
-# 119 "d_c99_bool_strict_syshdr.c" 3 4
+# 130 "d_c99_bool_strict_syshdr.c" 3 4
            ((ctype_table + 1)[(unsigned char)c] & 0x0040) != 0
-# 121 "d_c99_bool_strict_syshdr.c"
+# 132 "d_c99_bool_strict_syshdr.c"
            != 0;
 }
 
@@ -142,7 +153,7 @@
 extern int finite(double);
 # 1 "string.h" 3 4
 extern int strcmp(const char *, const char *);
-# 146 "d_c99_bool_strict_syshdr.c"
+# 157 "d_c99_bool_strict_syshdr.c"
 
 /*ARGSUSED*/
 _Bool
diff -r 5a57adf49865 -r 02b4932194de tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sun Jan 24 07:58:48 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp    Sun Jan 24 09:18:42 2021 +0000
@@ -1,6 +1,6 @@
-d_c99_bool_strict_syshdr.c(32): controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict_syshdr.c(42): controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict_syshdr.c(76): operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict_syshdr.c(151): return value type mismatch (_Bool) and (int) [211]
-d_c99_bool_strict_syshdr.c(164): operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict_syshdr.c(164): warning: function str_equal_bad expects to return value [214]
+d_c99_bool_strict_syshdr.c(43): controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict_syshdr.c(53): controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict_syshdr.c(87): operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict_syshdr.c(162): return value type mismatch (_Bool) and (int) [211]
+d_c99_bool_strict_syshdr.c(175): operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict_syshdr.c(175): warning: function str_equal_bad expects to return value [214]



Home | Main Index | Thread Index | Old Index