Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: demonstrate wrong constant folding in strict boo...



details:   https://anonhg.NetBSD.org/src/rev/7a3ca413748e
branches:  trunk
changeset: 1023080:7a3ca413748e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 22 20:56:51 2021 +0000

description:
tests/lint: demonstrate wrong constant folding in strict bool mode

Found while investigating wrong constant folding in default mode.

diffstat:

 distrib/sets/lists/tests/mi                         |   4 +-
 tests/usr.bin/xlint/lint1/Makefile                  |   4 +-
 tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c   |  35 +++++++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp |   4 ++
 4 files changed, 45 insertions(+), 2 deletions(-)

diffs (83 lines):

diff -r f3f9fc5436d2 -r 7a3ca413748e distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 22 20:18:39 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 22 20:56:51 2021 +0000
@@ -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
diff -r f3f9fc5436d2 -r 7a3ca413748e tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Aug 22 20:18:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Aug 22 20:56:51 2021 +0000
@@ -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.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
diff -r f3f9fc5436d2 -r 7a3ca413748e tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c Sun Aug 22 20:56:51 2021 +0000
@@ -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;
+};
diff -r f3f9fc5436d2 -r 7a3ca413748e tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.exp       Sun Aug 22 20:56:51 2021 +0000
@@ -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]



Home | Main Index | Thread Index | Old Index