Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: fully cover the usual ...
details: https://anonhg.NetBSD.org/src/rev/74d5f82f457d
branches: trunk
changeset: 984944:74d5f82f457d
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Aug 01 14:42:21 2021 +0000
description:
tests/lint: fully cover the usual arithmetic conversions
diffstat:
tests/usr.bin/xlint/lint1/expr_binary.c | 119 +++++++++++++++++++++++------
tests/usr.bin/xlint/lint1/expr_binary.exp | 48 +++++++++--
2 files changed, 130 insertions(+), 37 deletions(-)
diffs (202 lines):
diff -r 78e1d0d9ad05 -r 74d5f82f457d tests/usr.bin/xlint/lint1/expr_binary.c
--- a/tests/usr.bin/xlint/lint1/expr_binary.c Sun Aug 01 13:49:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_binary.c Sun Aug 01 14:42:21 2021 +0000
@@ -1,13 +1,10 @@
-/* $NetBSD: expr_binary.c,v 1.3 2021/08/01 13:49:17 rillig Exp $ */
+/* $NetBSD: expr_binary.c,v 1.4 2021/08/01 14:42:21 rillig Exp $ */
# 3 "expr_binary.c"
/*
- * Test binary operators, in particular the usual arithmetic conversions.
- *
- * C99 6.3.1.8 "Usual arithmetic conversions"
+ * Test binary operators.
*/
-/* lint1-extra-flags: -Ac11 */
/* lint1-only-if: lp64 */
struct incompatible { /* just to generate the error message */
@@ -15,39 +12,109 @@
};
void sink(struct incompatible);
+/*
+ * Test the usual arithmetic conversions.
+ *
+ * C99 6.3.1.8 "Usual arithmetic conversions"
+ */
void
cover_balance(void)
{
- /* expect+1: 'int' */
- sink(1 + '\0');
+ /* expect+1: 'pointer to void' */
+ sink((void *)0 + 0);
+
+ /* expect+1: 'pointer to void' */
+ sink(0 + (void *)0);
/* expect+1: 'int' */
- sink((char)'\0' + (char)'\0');
+ sink(1 + 1);
+
+ /* expect+1: 'const int' */
+ sink((const int)1 + (volatile int)1);
+
+ /* expect+1: 'volatile int' */
+ sink((volatile int)1 + (const int)1);
+
+ long double _Complex cldbl = 0.0;
+ double _Complex cdbl = 0.0;
+ float _Complex cflt = 0.0f;
+ /* expect+1: error: invalid type for _Complex [308] */
+ _Complex invalid = 0.0;
+
+ /* expect+1: 'long double _Complex' */
+ sink(cldbl + 0);
+ /* expect+1: 'long double _Complex' */
+ sink(0 + cldbl);
+ /* expect+1: 'long double _Complex' */
+ sink(cldbl + cdbl);
+ /* expect+1: 'long double _Complex' */
+ sink(cdbl + cldbl);
- /* expect+1: 'float' */
- sink(1 + 1.0f);
+ /* expect+1: 'double _Complex' */
+ sink(cdbl + 0);
+ /* expect+1: 'double _Complex' */
+ sink(0 + cdbl);
+ /* expect+1: 'double _Complex' */
+ sink(cdbl + cflt);
+ /* expect+1: 'double _Complex' */
+ sink(cflt + cdbl);
+
+ /* expect+1: 'float _Complex' */
+ sink(cflt + 0);
+ /* expect+1: 'float _Complex' */
+ sink(0 + cflt);
+ /* expect+1: 'float _Complex' */
+ sink(cflt + (__uint128_t)0);
+ /* expect+1: 'float _Complex' */
+ sink((__uint128_t)0 + cflt);
+
+ /*
+ * The type specifier '_Complex' is only used during parsing, it does
+ * not make it to the expression.
+ */
+ /* expect+1: 'double _Complex' */
+ sink(invalid + 0);
+
+ /* expect+1: 'long double' */
+ sink(0.0L + 0);
+ /* expect+1: 'long double' */
+ sink(0 + 0.0L);
+ /* expect+1: 'long double' */
+ sink(0.0L + 0.0);
+ /* expect+1: 'long double' */
+ sink(0.0 + 0.0L);
/* expect+1: 'double' */
- sink(1 + 1.0);
-
- /* expect+1: 'float' */
- sink((long long)1 + 1.0f);
+ sink(0.0 + 0);
+ /* expect+1: 'double' */
+ sink(0 + 0.0);
+ /* expect+1: 'double' */
+ sink(0.0 + 0.0f);
+ /* expect+1: 'double' */
+ sink(0.0f + 0.0);
/* expect+1: 'float' */
- sink((long long)1 + 1.0f);
-
+ sink(0.0f + 0);
+ /* expect+1: 'float' */
+ sink(0 + 0.0f);
/* expect+1: 'float' */
- sink((__uint128_t)1 + 1.0f);
-
- /* expect+1: '__uint128_t' */
- sink((__uint128_t)1 + 1);
+ sink(0.0f + (__uint128_t)0);
+ /* expect+1: 'float' */
+ sink((__uint128_t)0 + 0.0f);
- /* expect+1: '__int128_t' */
- sink((__int128_t)1 + 1);
+ /* expect+1: 'unsigned long long' */
+ sink(0ULL + 0);
+ /* expect+1: 'unsigned long long' */
+ sink(0 + 0ULL);
- /* expect+1: '__uint128_t' */
- sink((__uint128_t)1 + (__int128_t)1);
+ /* expect+1: 'unsigned long long' */
+ sink(0ULL + 0LL);
+ /* expect+1: 'unsigned long long' */
+ sink(0LL + 0ULL);
- /* expect+1: '__uint128_t' */
- sink((__int128_t)1 + (__uint128_t)1);
+ /* If the bit-width is the same, prefer the unsigned variant. */
+ /* expect+1: 'unsigned long long' */
+ sink(0UL + 0LL);
+ /* expect+1: 'unsigned long long' */
+ sink(0LL + 0UL);
}
diff -r 78e1d0d9ad05 -r 74d5f82f457d tests/usr.bin/xlint/lint1/expr_binary.exp
--- a/tests/usr.bin/xlint/lint1/expr_binary.exp Sun Aug 01 13:49:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/expr_binary.exp Sun Aug 01 14:42:21 2021 +0000
@@ -1,11 +1,37 @@
-expr_binary.c(22): warning: passing 'int' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(25): warning: passing 'int' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(28): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(31): warning: passing 'double' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(34): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(37): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(40): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(43): warning: passing '__uint128_t' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(46): warning: passing '__int128_t' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(49): warning: passing '__uint128_t' to incompatible 'struct incompatible', arg #1 [155]
-expr_binary.c(52): warning: passing '__uint128_t' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(24): warning: passing 'pointer to void' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(27): warning: passing 'pointer to void' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(30): warning: passing 'int' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(33): warning: passing 'const int' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(36): warning: passing 'volatile int' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(42): error: invalid type for _Complex [308]
+expr_binary.c(45): warning: passing 'long double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(47): warning: passing 'long double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(49): warning: passing 'long double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(51): warning: passing 'long double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(54): warning: passing 'double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(56): warning: passing 'double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(58): warning: passing 'double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(60): warning: passing 'double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(63): warning: passing 'float _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(65): warning: passing 'float _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(67): warning: passing 'float _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(69): warning: passing 'float _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(76): warning: passing 'double _Complex' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(79): warning: passing 'long double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(81): warning: passing 'long double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(83): warning: passing 'long double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(85): warning: passing 'long double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(88): warning: passing 'double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(90): warning: passing 'double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(92): warning: passing 'double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(94): warning: passing 'double' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(97): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(99): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(101): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(103): warning: passing 'float' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(106): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(108): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(111): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(113): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(117): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
+expr_binary.c(119): warning: passing 'unsigned long long' to incompatible 'struct incompatible', arg #1 [155]
Home |
Main Index |
Thread Index |
Old Index