summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-06-24 08:11:12 +0000
committerrillig <rillig@NetBSD.org>2023-06-24 08:11:12 +0000
commited1ea27f95d04ad338a74593086cecd68fbea545 (patch)
tree12d15dac320187338c5bab5a0ac1982ab8730cda /tests
parent40ed500245dca4f087783fd470f156cad915c5bb (diff)
lint: add query for comparing 'char' with plain integers
Diffstat (limited to 'tests')
-rw-r--r--tests/usr.bin/xlint/lint1/queries.c24
-rw-r--r--tests/usr.bin/xlint/lint1/t_usage.sh8
2 files changed, 26 insertions, 6 deletions
diff --git a/tests/usr.bin/xlint/lint1/queries.c b/tests/usr.bin/xlint/lint1/queries.c
index 4c3873def98..4f3a609b082 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.16 2023/06/24 06:55:34 rillig Exp $ */
+/* $NetBSD: queries.c,v 1.17 2023/06/24 08:11:12 rillig Exp $ */
# 3 "queries.c"
/*
@@ -15,7 +15,7 @@
* such as casts between arithmetic types.
*/
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14 -X 351 */
typedef unsigned char u8_t;
typedef unsigned short u16_t;
@@ -403,6 +403,26 @@ void extern_Q13(void);
/* expect+1: redundant 'extern' in function declaration of 'extern_Q13' [Q13] */
extern void extern_Q13(void), *extern_ptr;
+int
+Q14(char c, 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;
+ if (sc == 'c' || sc == L'w' || sc == 92 || sc == 0)
+ return 2;
+ /* expect+4: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
+ /* expect+3: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
+ /* expect+2: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
+ /* expect+1: implicit conversion changes sign from 'unsigned char' to 'int' [Q3] */
+ if (uc == 'c' || uc == L'w' || uc == 92 || uc == 0)
+ return 3;
+ if (wc == 'c' || wc == L'w' || wc == 92 || wc == 0)
+ return 4;
+ 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
diff --git a/tests/usr.bin/xlint/lint1/t_usage.sh b/tests/usr.bin/xlint/lint1/t_usage.sh
index ade5f88093d..f7c73bec854 100644
--- a/tests/usr.bin/xlint/lint1/t_usage.sh
+++ b/tests/usr.bin/xlint/lint1/t_usage.sh
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.6 2023/06/24 06:55:34 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.7 2023/06/24 08:11:12 rillig Exp $
#
# Copyright (c) 2023 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -97,13 +97,13 @@ enable_queries_body()
# The largest known query.
atf_check \
- "$lint1" -q 13 code.c /dev/null
+ "$lint1" -q 14 code.c /dev/null
# Larger than the largest known query.
atf_check \
-s 'exit:1' \
- -e "inline:lint1: invalid query ID '14'\n" \
- "$lint1" -q 14 code.c /dev/null
+ -e "inline:lint1: invalid query ID '15'\n" \
+ "$lint1" -q 15 code.c /dev/null
# Whitespace is not allowed before a query ID.
atf_check \