Module Name: src
Committed By: rillig
Date: Sun Jan 17 13:15:03 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
d_c99_bool_strict.exp
Log Message:
lint: explain failing test case in strict bool mode
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.11 -r1.12 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.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.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.13 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.14
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.13 Sun Jan 17 11:32:06 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sun Jan 17 13:15:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_bool_strict.c,v 1.13 2021/01/17 11:32:06 rillig Exp $ */
+/* $NetBSD: d_c99_bool_strict.c,v 1.14 2021/01/17 13:15:03 rillig Exp $ */
# 3 "d_c99_bool_strict.c"
/*
@@ -716,6 +716,27 @@ strict_bool_operator_eq_bool_int(void)
(void)(strict_bool_conversion_return_false() == 0); /* expect: 107 */
}
+/*
+ * When building the NE node, the following steps happen:
+ *
+ * ln is promoted from BOOL:1 to INT:1 since it is a bit field and C90 says
+ * that bit fields must always be promoted to int.
+ *
+ * rn is promoted from BOOL. promote() does not handle BOOL explicitly,
+ * therefore it is kept as-is. That may or may not have been an oversight
+ * in the initial implementation of supporting BOOL.
+ *
+ * After that, the two nodes are balanced. At this point, their types are
+ * INT:1 and BOOL. INT is considered the larger of the two types, even
+ * though it is a bit field in this case. Therefore BOOL is converted to
+ * INT now, and since it is a constant, the converted node loses all
+ * information about its previous type.
+ *
+ * During these conversions and promotions, the code asks whether BOOL
+ * is an arithmetic type. If that isn't the case, no conversion or
+ * promotion takes place. Since strict bool mode explicitly treats BOOL
+ * as non-arithmetic, changing is_arithmetic sounds like the way to go.
+ */
void
strict_bool_assign_bit_field_then_compare(void)
{
Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.12
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.11 Sun Jan 17 11:32:06 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sun Jan 17 13:15:03 2021
@@ -142,4 +142,4 @@ d_c99_bool_strict.c(670): operands of '=
d_c99_bool_strict.c(677): operands of '=' have incompatible types (_Bool != int) [107]
d_c99_bool_strict.c(652): warning: argument flags unused in function strict_bool_bitwise_and_enum [231]
d_c99_bool_strict.c(716): operands of '==' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict.c(729): operands of '!=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(750): operands of '!=' have incompatible types (_Bool != int) [107]