Module Name: src Committed By: rillig Date: Sun Aug 1 16:29:28 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_binary_trad.c expr_binary_trad.exp Log Message: tests/lint: test the usual arithmetic conversions in traditional C To generate a diff of this commit: cvs rdiff -u -r1.1099 -r1.1100 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.98 -r1.99 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/expr_binary_trad.c \ src/tests/usr.bin/xlint/lint1/expr_binary_trad.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.1099 src/distrib/sets/lists/tests/mi:1.1100 --- src/distrib/sets/lists/tests/mi:1.1099 Sun Aug 1 13:31:48 2021 +++ src/distrib/sets/lists/tests/mi Sun Aug 1 16:29:28 2021 @@ -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 Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.98 src/tests/usr.bin/xlint/lint1/Makefile:1.99 --- src/tests/usr.bin/xlint/lint1/Makefile:1.98 Sun Aug 1 13:31:49 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Sun Aug 1 16:29:28 2021 @@ -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 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 Added files: Index: src/tests/usr.bin/xlint/lint1/expr_binary_trad.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_binary_trad.c:1.1 --- /dev/null Sun Aug 1 16:29:28 2021 +++ src/tests/usr.bin/xlint/lint1/expr_binary_trad.c Sun Aug 1 16:29:28 2021 @@ -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; +} Index: src/tests/usr.bin/xlint/lint1/expr_binary_trad.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/expr_binary_trad.exp:1.1 --- /dev/null Sun Aug 1 16:29:28 2021 +++ src/tests/usr.bin/xlint/lint1/expr_binary_trad.exp Sun Aug 1 16:29:28 2021 @@ -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]