Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test the usual arithmetic conversions in traditi...



details:   https://anonhg.NetBSD.org/src/rev/bec2fd0b2cc9
branches:  trunk
changeset: 1022686:bec2fd0b2cc9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 01 16:29:28 2021 +0000

description:
tests/lint: test the usual arithmetic conversions in traditional C

diffstat:

 distrib/sets/lists/tests/mi                    |   4 +-
 tests/usr.bin/xlint/lint1/Makefile             |   4 +-
 tests/usr.bin/xlint/lint1/expr_binary_trad.c   |  67 ++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/expr_binary_trad.exp |  14 +++++
 4 files changed, 87 insertions(+), 2 deletions(-)

diffs (125 lines):

diff -r a6a338404bd5 -r bec2fd0b2cc9 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 01 16:17:05 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 01 16:29:28 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1099 2021/08/01 13:31:48 rillig Exp $
+# $NetBSD: mi,v 1.1100 2021/08/01 16:29:28 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6238,6 +6238,8 @@
 ./usr/tests/usr.bin/xlint/lint1/emit.ln                                tests-obsolete          obsolete
 ./usr/tests/usr.bin/xlint/lint1/expr_binary.c                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/expr_binary.exp                        tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_binary_trad.c             tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/expr_binary_trad.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_range.c                   tests-usr.bin-tests     compattestfile,atf
diff -r a6a338404bd5 -r bec2fd0b2cc9 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Aug 01 16:17:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Aug 01 16:29:28 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.98 2021/08/01 13:31:49 rillig Exp $
+# $NetBSD: Makefile,v 1.99 2021/08/01 16:29:28 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -133,6 +133,8 @@
 FILES+=                emit.exp-ln
 FILES+=                expr_binary.c
 FILES+=                expr_binary.exp
+FILES+=                expr_binary_trad.c
+FILES+=                expr_binary_trad.exp
 FILES+=                expr_precedence.c
 FILES+=                expr_precedence.exp
 FILES+=                expr_range.c
diff -r a6a338404bd5 -r bec2fd0b2cc9 tests/usr.bin/xlint/lint1/expr_binary_trad.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_binary_trad.c      Sun Aug 01 16:29:28 2021 +0000
@@ -0,0 +1,67 @@
+/*     $NetBSD: expr_binary_trad.c,v 1.1 2021/08/01 16:29:28 rillig Exp $      */
+# 3 "expr_binary_trad.c"
+
+/*
+ * Test binary operators in traditional C.
+ */
+
+/* lint1-flags: -tw */
+
+struct incompatible {          /* just to generate the error message */
+       int member;
+};
+struct incompatible sink;
+
+/*
+ * Test the usual arithmetic conversions.
+ *
+ * C99 6.3.1.8 "Usual arithmetic conversions"
+ */
+void
+cover_balance()
+{
+
+       /* expect+1: 'pointer to char' */
+       sink = (char *)0 + 0;
+
+       /* expect+1: 'pointer to char' */
+       sink = 0 + (char *)0;
+
+       /* expect+1: 'int' */
+       sink = 1 + 1;
+
+       /* expect+1: 'double' */
+       sink = 0.0 + 0;
+       /* expect+1: 'double' */
+       sink = 0 + 0.0;
+       /* expect+1: 'double' */
+       sink = 0.0 + (float)0.0;
+       /* expect+1: 'double' */
+       sink = (float)0.0 + 0.0;
+
+       /*
+        * In traditional C, 'float' gets promoted to 'double' before
+        * applying the usual arithmetic conversions; see 'promote'.
+        */
+       /* expect+1: 'double' */
+       sink = (float)0.0 + 0;
+       /* expect+1: 'double' */
+       sink = 0 + (float)0.0;
+
+       /* expect+1: 'unsigned long' */
+       sink = (unsigned long)0 + 0;
+       /* expect+1: 'unsigned long' */
+       sink = 0 + (unsigned long)0;
+
+       /* expect+1: 'unsigned long' */
+       sink = (unsigned long)0 + (long)0;
+       /* expect+1: 'unsigned long' */
+       sink = (long)0 + (unsigned long)0;
+
+       /*
+        * In traditional C, if one of the operands is unsigned, the result
+        * is unsigned as well.
+        */
+       /* expect+1: 'unsigned long' */
+       sink = (unsigned)0 + (long)0;
+}
diff -r a6a338404bd5 -r bec2fd0b2cc9 tests/usr.bin/xlint/lint1/expr_binary_trad.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_binary_trad.exp    Sun Aug 01 16:29:28 2021 +0000
@@ -0,0 +1,14 @@
+expr_binary_trad.c(25): error: cannot assign to 'struct incompatible' from 'pointer to char' [171]
+expr_binary_trad.c(28): error: cannot assign to 'struct incompatible' from 'pointer to char' [171]
+expr_binary_trad.c(31): error: cannot assign to 'struct incompatible' from 'int' [171]
+expr_binary_trad.c(34): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(36): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(38): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(40): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(47): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(49): error: cannot assign to 'struct incompatible' from 'double' [171]
+expr_binary_trad.c(52): error: cannot assign to 'struct incompatible' from 'unsigned long' [171]
+expr_binary_trad.c(54): error: cannot assign to 'struct incompatible' from 'unsigned long' [171]
+expr_binary_trad.c(57): error: cannot assign to 'struct incompatible' from 'unsigned long' [171]
+expr_binary_trad.c(59): error: cannot assign to 'struct incompatible' from 'unsigned long' [171]
+expr_binary_trad.c(66): error: cannot assign to 'struct incompatible' from 'unsigned long' [171]



Home | Main Index | Thread Index | Old Index