Module Name:    src
Committed By:   rillig
Date:           Mon Jul  3 09:37:14 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_bool_strict.c

Log Message:
tests/lint: clean up tests for C99 bool


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool.c
cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.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.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.10 src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.11
--- src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.10	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool.c	Mon Jul  3 09:37:14 2023
@@ -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]. */
+/* expect+1: error: negative array dimension (-2) [20] */
+int int_0[(_Bool)0 ? -1 : -2];
 
-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];
+int int_1[(_Bool)1 ? -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_2[(_Bool)2 ? -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_256[(_Bool)256 ? -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 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;
-}
-
-_Bool
-double_to_bool(double d)
-{
-	return d;
-}
-
-enum color {
-	RED
-};
-
-_Bool
-enum_to_bool(enum color e)
-{
-	return e;
-}
-
-_Bool
-pointer_to_bool(const char *p)
-{
-	return p;
-}
-
-_Bool
-function_pointer_to_bool(void (*f)(void))
-{
-	return f;
-}
+int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : -2];
 
 _Bool
-complex_to_bool(double _Complex c)
+convert_to_bool(int selector)
 {
-	return c;
+	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 };
+
+	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;
+	}
 }

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.40 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.41
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.40	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Mon Jul  3 09:37:14 2023
@@ -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;

Reply via email to