diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-03 15:29:42 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-03 15:29:42 +0000 |
| commit | bbfea7f8a8f76ed528dfa1077b3d86cfe6942d6c (patch) | |
| tree | c991bc889cbe4eb2fbcbe7c6df8ad1b307dfbac3 /tests | |
| parent | 018aed9ed29a485e1e2e733d0b785b77f66f5f58 (diff) | |
tests/lint: move platform-specific query tests to separate files
This fixes the tests on 'unsigned char' platforms.
Thanks martin@ for the notification.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/usr.bin/xlint/lint1/queries.c | 22 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/queries_schar.c | 32 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/queries_uchar.c | 36 |
3 files changed, 82 insertions, 8 deletions
diff --git a/tests/usr.bin/xlint/lint1/queries.c b/tests/usr.bin/xlint/lint1/queries.c index 767a4afc27b..604aaac366e 100644 --- a/tests/usr.bin/xlint/lint1/queries.c +++ b/tests/usr.bin/xlint/lint1/queries.c @@ -1,4 +1,4 @@ -/* $NetBSD: queries.c,v 1.18 2023/06/30 08:45:22 rillig Exp $ */ +/* $NetBSD: queries.c,v 1.19 2023/07/03 15:29:42 rillig Exp $ */ # 3 "queries.c" /* @@ -82,6 +82,7 @@ Q2(double dbl) return (int)dbl; } +// The Q3 query triggers so often that it also occurs outside this function. void Q3(int i, unsigned u) { @@ -90,6 +91,13 @@ Q3(int i, unsigned u) /* expect+1: implicit conversion changes sign from 'unsigned int' to 'int' [Q3] */ i = u; + + /* expect+2: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */ + /* expect+1: implicit conversion changes sign from 'int' to 'unsigned short' [Q3] */ + u16 += u8; + /* expect+2: implicit conversion changes sign from 'unsigned short' to 'int' [Q3] */ + /* expect+1: implicit conversion changes sign from 'int' to 'unsigned int' [Q3] */ + u32 += u16; } unsigned long long @@ -343,9 +351,9 @@ Q9(int x) return (0.0); case 9: return -# 347 "queries.c" 3 4 +# 355 "queries.c" 3 4 ((void *)0) -# 349 "queries.c" +# 357 "queries.c" /* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */ ; case 10: @@ -404,12 +412,10 @@ void extern_Q13(void); extern void extern_Q13(void), *extern_ptr; int -Q14(char c, signed char sc, unsigned char uc, int wc) +Q14(signed char sc, unsigned char uc, int wc) { - /* expect+2: comparison '==' of 'char' with plain integer 92 [Q14] */ - /* expect+1: comparison '==' of 'char' with plain integer 0 [Q14] */ - if (c == 'c' || c == L'w' || c == 92 || c == 0) - return 1; + // Plain 'char' is platform-dependent, see queries-{schar,uchar}.c. + if (sc == 'c' || sc == L'w' || sc == 92 || sc == 0) return 2; /* expect+4: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */ diff --git a/tests/usr.bin/xlint/lint1/queries_schar.c b/tests/usr.bin/xlint/lint1/queries_schar.c new file mode 100644 index 00000000000..6e3781b3a53 --- /dev/null +++ b/tests/usr.bin/xlint/lint1/queries_schar.c @@ -0,0 +1,32 @@ +/* $NetBSD: queries_schar.c,v 1.1 2023/07/03 15:29:42 rillig Exp $ */ +# 3 "queries_schar.c" + +/* + * Tests for queries that are specific to platforms where 'char' has the same + * representation as 'signed char'. + * + * See also: + * queries.c platform-independent tests + * queries_uchar.c for platforms where 'char' is unsigned + */ + +/* lint1-only-if: schar */ +/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -X 351 */ + +int +Q14(char c) +{ + /* expect+2: comparison '==' of 'char' with plain integer 92 [Q14] */ + /* expect+1: comparison '==' of 'char' with plain integer 0 [Q14] */ + if (c == 'c' || c == L'w' || c == 92 || c == 0) + return 1; + return 5; +} + +/* + * Since queries do not affect the exit status, force a warning to make this + * test conform to the general expectation that a test that produces output + * exits non-successfully. + */ +/* expect+1: warning: static variable 'unused' unused [226] */ +static int unused; diff --git a/tests/usr.bin/xlint/lint1/queries_uchar.c b/tests/usr.bin/xlint/lint1/queries_uchar.c new file mode 100644 index 00000000000..602bb8ce5ef --- /dev/null +++ b/tests/usr.bin/xlint/lint1/queries_uchar.c @@ -0,0 +1,36 @@ +/* $NetBSD: queries_uchar.c,v 1.1 2023/07/03 15:29:42 rillig Exp $ */ +# 3 "queries_uchar.c" + +/* + * Tests for queries that are specific to platforms where 'char' has the same + * representation as 'unsigned char'. + * + * See also: + * queries.c platform-independent tests + * queries_schar.c for platforms where 'char' is signed + */ + +/* lint1-only-if: uchar */ +/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -X 351 */ + +int +Q14(char c) +{ + /* expect+6: implicit conversion changes sign from 'char' to 'int' [Q3] */ + /* expect+5: implicit conversion changes sign from 'char' to 'int' [Q3] */ + /* expect+4: implicit conversion changes sign from 'char' to 'int' [Q3] */ + /* expect+3: comparison '==' of 'char' with plain integer 92 [Q14] */ + /* expect+2: implicit conversion changes sign from 'char' to 'int' [Q3] */ + /* expect+1: comparison '==' of 'char' with plain integer 0 [Q14] */ + if (c == 'c' || c == L'w' || c == 92 || c == 0) + return 1; + return 5; +} + +/* + * Since queries do not affect the exit status, force a warning to make this + * test conform to the general expectation that a test that produces output + * exits non-successfully. + */ +/* expect+1: warning: static variable 'unused' unused [226] */ +static int unused; |
