Module Name: src
Committed By: rillig
Date: Sun Aug 22 20:56:51 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
src/tests/usr.bin/xlint/lint1: expr_fold_strict_bool.c
expr_fold_strict_bool.exp
Log Message:
tests/lint: demonstrate wrong constant folding in strict bool mode
Found while investigating wrong constant folding in default mode.
To generate a diff of this commit:
cvs rdiff -u -r1.1113 -r1.1114 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.105 -r1.106 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c \
src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1113 src/distrib/sets/lists/tests/mi:1.1114
--- src/distrib/sets/lists/tests/mi:1.1113 Thu Aug 19 20:32:33 2021
+++ src/distrib/sets/lists/tests/mi Sun Aug 22 20:56:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1113 2021/08/19 20:32:33 rillig Exp $
+# $NetBSD: mi,v 1.1114 2021/08/22 20:56:51 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6249,6 +6249,8 @@
./usr/tests/usr.bin/xlint/lint1/expr_cast.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_fold.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_fold.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_precedence.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_precedence.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/expr_promote.c tests-usr.bin-tests compattestfile,atf
Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.105 src/tests/usr.bin/xlint/lint1/Makefile:1.106
--- src/tests/usr.bin/xlint/lint1/Makefile:1.105 Thu Aug 19 20:32:33 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile Sun Aug 22 20:56:51 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.105 2021/08/19 20:32:33 rillig Exp $
+# $NetBSD: Makefile,v 1.106 2021/08/22 20:56:51 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 346 # see lint1/err.c
@@ -141,6 +141,8 @@ FILES+= expr_cast.c
FILES+= expr_cast.exp
FILES+= expr_fold.c
FILES+= expr_fold.exp
+FILES+= expr_fold_strict_bool.c
+FILES+= expr_fold_strict_bool.exp
FILES+= expr_precedence.c
FILES+= expr_precedence.exp
FILES+= expr_promote.c
Added files:
Index: src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c:1.1
--- /dev/null Sun Aug 22 20:56:51 2021
+++ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c Sun Aug 22 20:56:51 2021
@@ -0,0 +1,35 @@
+/* $NetBSD: expr_fold_strict_bool.c,v 1.1 2021/08/22 20:56:51 rillig Exp $ */
+# 3 "expr_fold_strict_bool.c"
+
+/*
+ * Test constant folding in strict bool mode.
+ *
+ * In this mode, _Bool is not an unsigned integer type. In fact, it is not
+ * an arithmetic type at all.
+ */
+
+/* lint1-extra-flags: -T */
+/* lint1-only-if: lp64 */
+
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+
+struct fold_64_bit {
+
+ _Bool lt_signed_small_ok: -3LL < 1LL ? 1 : -1;
+ /* expect+1: error: illegal bit-field size: 255 [36] */
+ _Bool lt_signed_small_bad: 1LL < -3LL ? 1 : -1;
+
+ _Bool lt_signed_big_ok: (int64_t)(1ULL << 63) < 1LL ? 1 : -1;
+ /* expect+1: error: illegal bit-field size: 255 [36] */
+ _Bool lt_signed_big_bad: 1LL < (int64_t)(1ULL << 63) ? 1 : -1;
+
+ _Bool lt_unsigned_small_ok: 1ULL < 3ULL ? 1 : -1;
+ /* expect+1: error: illegal bit-field size: 255 [36] */
+ _Bool lt_unsigned_small_bad: 3ULL < 1ULL ? 1 : -1;
+
+ /* FIXME: 1 is much smaller than 1ULL << 63. */
+ /* expect+1: error: illegal bit-field size: 255 [36] */
+ _Bool lt_unsigned_big_ok: 1ULL < 1ULL << 63 ? 1 : -1;
+ _Bool lt_unsigned_big_bad: 1ULL << 63 < 1ULL ? 1 : -1;
+};
Index: src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp:1.1
--- /dev/null Sun Aug 22 20:56:51 2021
+++ src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp Sun Aug 22 20:56:51 2021
@@ -0,0 +1,4 @@
+expr_fold_strict_bool.c(21): error: illegal bit-field size: 255 [36]
+expr_fold_strict_bool.c(25): error: illegal bit-field size: 255 [36]
+expr_fold_strict_bool.c(29): error: illegal bit-field size: 255 [36]
+expr_fold_strict_bool.c(33): error: illegal bit-field size: 255 [36]