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: clean up tests for C99...



details:   https://anonhg.NetBSD.org/src/rev/95921818dd97
branches:  trunk
changeset: 377246:95921818dd97
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 03 09:37:14 2023 +0000

description:
tests/lint: clean up tests for C99 bool

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool.c        |  128 +++++++++----------------
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c |    7 +-
 2 files changed, 52 insertions(+), 83 deletions(-)

diffs (187 lines):

diff -r b04fd8683332 -r 95921818dd97 tests/usr.bin/xlint/lint1/d_c99_bool.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.c    Mon Jul 03 09:33:07 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.c    Mon Jul 03 09:37:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool.c,v 1.10 2023/03/28 14:44:34 rillig Exp $   */
+/*     $NetBSD: d_c99_bool.c,v 1.11 2023/07/03 09:37:14 rillig Exp $   */
 # 3 "d_c99_bool.c"
 
 /*
@@ -11,114 +11,78 @@
 
 /* lint1-extra-flags: -X 351 */
 
-/* Below, each false statement produces "negative array dimension" [20]. */
-
-int int_0_converts_to_false[(_Bool)0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int int_0_converts_to_true_[(_Bool)0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int int_0[(_Bool)0 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_1_converts_to_false[(_Bool)1 ? -1 : 1];
-int int_1_converts_to_true_[(_Bool)1 ? 1 : -1];
+int int_1[(_Bool)1 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_2_converts_to_false[(_Bool)2 ? -1 : 1];
-int int_2_converts_to_true_[(_Bool)2 ? 1 : -1];
+int int_2[(_Bool)2 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_256_converts_to_false[(_Bool)256 ? -1 : 1];
-int int_256_converts_to_true_[(_Bool)256 ? 1 : -1];
+int int_256[(_Bool)256 ? -1 : -2];
 
-int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int null_pointer[(_Bool)(void *)0 ? -1 : -2];
 
 /*
- * XXX: lint does not treat the address of a global variable as a constant
- * expression.  This goes against C99 6.6p7 but is probably not too relevant
- * in practice.
+ * XXX: In initializers for global variables, taking the address of a variable
+ * is allowed and may be modified by a constant offset.  This is not a constant
+ * expression though.
  *
- * In such a case, to_int_constant(tn, false) in cgram.y:array_size_opt
- * returns 1 for the array size.  This is why neither of the following array
- * declarations generates an error message.
+ * In such a case, the grammar rule array_size_opt calls to_int_constant, which
+ * returns 1 for the array size without reporting an error.  This is why
+ * neither of the following array declarations generates an error message.
  */
 char ch;
 int nonnull_pointer_converts_to_false[(_Bool)&ch ? -1 : 1];
 int nonnull_pointer_converts_to_true_[(_Bool)&ch ? 1 : -1];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1];
-int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1];
+int double_minus_1_0[(_Bool)-1.0 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1];
-int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1];
+int double_minus_0_5[(_Bool)-0.5 ? -1 : -2];
 
-int double_minus_0_0_converts_to_false[(_Bool)-0.0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_0_0_converts_to_true_[(_Bool)-0.0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int double_minus_0_0[(_Bool)-0.0 ? -1 : -2];
 
-int double_0_0_converts_to_false[(_Bool)0.0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int double_0_0_converts_to_true_[(_Bool)0.0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int double_0_0[(_Bool)0.0 ? -1 : -2];
 
 /* The C99 rationale explains in 6.3.1.2 why (_Bool)0.5 is true. */
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1];
-int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1];
+int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : 1];
-int double_1_0_converts_to_true_[(_Bool)1.0 ? 1 : -1];
-
-_Bool
-bool_to_bool(_Bool b)
-{
-       return b;
-}
-
-_Bool
-char_to_bool(char c)
-{
-       return c;
-}
-
-_Bool
-int_to_bool(int i)
-{
-       return i;
-}
+int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : -2];
 
 _Bool
-double_to_bool(double d)
+convert_to_bool(int selector)
 {
-       return d;
-}
-
-enum color {
-       RED
-};
-
-_Bool
-enum_to_bool(enum color e)
-{
-       return e;
-}
+       static struct variant {
+               _Bool b;
+               char c;
+               int i;
+               double d;
+               enum color {
+                       RED
+               } e;
+               const char *pcc;
+               void (*f)(void);
+               double _Complex dc;
+       } v = { .i = 0 };
 
-_Bool
-pointer_to_bool(const char *p)
-{
-       return p;
+       switch (selector) {
+       case 0: return v.b;
+       case 1: return v.c;
+       case 2: return v.i;
+       case 3: return v.d;
+       case 4: return v.e;
+       case 5: return v.pcc;
+       case 6: return v.f;
+       case 7: return v.dc;
+       default: return v.b;
+       }
 }
-
-_Bool
-function_pointer_to_bool(void (*f)(void))
-{
-       return f;
-}
-
-_Bool
-complex_to_bool(double _Complex c)
-{
-       return c;
-}
diff -r b04fd8683332 -r 95921818dd97 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Mon Jul 03 09:33:07 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Mon Jul 03 09:37:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.40 2023/03/28 14:44:34 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.41 2023/07/03 09:37:14 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -1065,3 +1065,8 @@ controlling_expression(FILE *f, const ch
            ))
                return;
 }
+
+// In strict bool mode, the identifiers '__lint_false' and '__lint_true' are
+// predefined, but not any others.
+/* expect+1: error: '__lint_unknown' undefined [99] */
+int unknown = sizeof __lint_unknown;



Home | Main Index | Thread Index | Old Index