Module Name: src Committed By: rillig Date: Mon Aug 23 17:47:34 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: lex_string.c lex_string.exp lex_wide_string.c lex_wide_string.exp msg_162.c msg_162.exp msg_230.c msg_230.exp Log Message: tests/lint: add tests for integer comparisons To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/lex_string.c \ src/tests/usr.bin/xlint/lint1/lex_string.exp \ src/tests/usr.bin/xlint/lint1/msg_162.c \ src/tests/usr.bin/xlint/lint1/msg_162.exp cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/lex_wide_string.c \ src/tests/usr.bin/xlint/lint1/lex_wide_string.exp cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_230.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_230.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/lex_string.c diff -u src/tests/usr.bin/xlint/lint1/lex_string.c:1.2 src/tests/usr.bin/xlint/lint1/lex_string.c:1.3 --- src/tests/usr.bin/xlint/lint1/lex_string.c:1.2 Sat Jun 19 08:37:18 2021 +++ src/tests/usr.bin/xlint/lint1/lex_string.c Mon Aug 23 17:47:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lex_string.c,v 1.2 2021/06/19 08:37:18 rillig Exp $ */ +/* $NetBSD: lex_string.c,v 1.3 2021/08/23 17:47:34 rillig Exp $ */ # 3 "lex_string.c" /* @@ -25,4 +25,9 @@ test(void) /* expect+1: dubious escape \y [79] */ sink("\y"); /* unknown escape sequence */ + + sink("first" "second"); + + /* expect+1: error: cannot concatenate wide and regular string literals [292] */ + sink("plain" L"wide"); } Index: src/tests/usr.bin/xlint/lint1/lex_string.exp diff -u src/tests/usr.bin/xlint/lint1/lex_string.exp:1.2 src/tests/usr.bin/xlint/lint1/lex_string.exp:1.3 --- src/tests/usr.bin/xlint/lint1/lex_string.exp:1.2 Sat Jun 19 08:37:18 2021 +++ src/tests/usr.bin/xlint/lint1/lex_string.exp Mon Aug 23 17:47:34 2021 @@ -1,2 +1,3 @@ lex_string.c(24): error: no hex digits follow \x [74] lex_string.c(27): warning: dubious escape \y [79] +lex_string.c(32): error: cannot concatenate wide and regular string literals [292] Index: src/tests/usr.bin/xlint/lint1/msg_162.c diff -u src/tests/usr.bin/xlint/lint1/msg_162.c:1.2 src/tests/usr.bin/xlint/lint1/msg_162.c:1.3 --- src/tests/usr.bin/xlint/lint1/msg_162.c:1.2 Sun Feb 21 09:07:58 2021 +++ src/tests/usr.bin/xlint/lint1/msg_162.c Mon Aug 23 17:47:34 2021 @@ -1,7 +1,53 @@ -/* $NetBSD: msg_162.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */ +/* $NetBSD: msg_162.c,v 1.3 2021/08/23 17:47:34 rillig Exp $ */ # 3 "msg_162.c" // Test for message: comparison of %s with %s, op %s [162] -TODO: "Add example code that triggers the above message." /* expect: 249 */ -TODO: "Add example code that almost triggers the above message." +/* lint1-extra-flags: -hp */ + +void +left_unsigned(unsigned int ui) +{ + if (ui < -5.0) { + } + + /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */ + if (ui < -5) { + } + + /* expect+1: warning: comparison of unsigned int with 0, op < [162] */ + if (ui < 0) { + } + + /* expect+1: warning: comparison of unsigned int with 0, op >= [162] */ + if (ui >= 0) { + } + + /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */ + if (ui <= 0) { + } +} + +void +right_unsigned(unsigned int ui) +{ + + if (-5.0 > ui) { + } + + /* expect+1: warning: comparison of negative constant with unsigned int, op > [162] */ + if (-5 > ui) { + } + + /* expect+1: warning: comparison of 0 with unsigned int, op > [162] */ + if (0 > ui) { + } + + /* expect+1: warning: comparison of 0 with unsigned int, op <= [162] */ + if (0 <= ui) { + } + + /* expect+1: warning: comparison of 0 with unsigned int, op >= [162] */ + if (0 >= ui) { + } +} Index: src/tests/usr.bin/xlint/lint1/msg_162.exp diff -u src/tests/usr.bin/xlint/lint1/msg_162.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_162.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_162.exp:1.2 Sun Mar 21 20:45:00 2021 +++ src/tests/usr.bin/xlint/lint1/msg_162.exp Mon Aug 23 17:47:34 2021 @@ -1 +1,8 @@ -msg_162.c(6): error: syntax error ':' [249] +msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162] +msg_162.c(19): warning: comparison of unsigned int with 0, op < [162] +msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162] +msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162] +msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162] +msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162] +msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162] +msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162] Index: src/tests/usr.bin/xlint/lint1/lex_wide_string.c diff -u src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.1 src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.2 --- src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.1 Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_string.c Mon Aug 23 17:47:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lex_wide_string.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +/* $NetBSD: lex_wide_string.c,v 1.2 2021/08/23 17:47:34 rillig Exp $ */ # 3 "lex_wide_string.c" /* @@ -25,4 +25,9 @@ test(void) /* expect+1: dubious escape \y [79] */ sink(L"\y"); + + sink(L"first" L"second"); + + /* expect+1: error: cannot concatenate wide and regular string literals [292] */ + sink(L"wide" "plain"); } Index: src/tests/usr.bin/xlint/lint1/lex_wide_string.exp diff -u src/tests/usr.bin/xlint/lint1/lex_wide_string.exp:1.1 src/tests/usr.bin/xlint/lint1/lex_wide_string.exp:1.2 --- src/tests/usr.bin/xlint/lint1/lex_wide_string.exp:1.1 Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_string.exp Mon Aug 23 17:47:34 2021 @@ -1,2 +1,3 @@ lex_wide_string.c(24): error: no hex digits follow \x [74] lex_wide_string.c(27): warning: dubious escape \y [79] +lex_wide_string.c(32): error: cannot concatenate wide and regular string literals [292] Index: src/tests/usr.bin/xlint/lint1/msg_230.c diff -u src/tests/usr.bin/xlint/lint1/msg_230.c:1.5 src/tests/usr.bin/xlint/lint1/msg_230.c:1.6 --- src/tests/usr.bin/xlint/lint1/msg_230.c:1.5 Sat Aug 21 11:50:57 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.c Mon Aug 23 17:47:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_230.c,v 1.5 2021/08/21 11:50:57 rillig Exp $ */ +/* $NetBSD: msg_230.c,v 1.6 2021/08/23 17:47:34 rillig Exp $ */ # 3 "msg_230.c" // Test for message: nonportable character comparison, op %s [230] @@ -31,4 +31,11 @@ void example(char c, unsigned char uc, s return; if (sc <= -1) return; + + /* expect+1: warning: nonportable character comparison, op <= [230] */ + if (-1 <= c) + return; + /* expect+1: warning: nonportable character comparison, op <= [230] */ + if (256 <= c) + return; } Index: src/tests/usr.bin/xlint/lint1/msg_230.exp diff -u src/tests/usr.bin/xlint/lint1/msg_230.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_230.exp:1.5 --- src/tests/usr.bin/xlint/lint1/msg_230.exp:1.4 Sat Jul 3 19:31:22 2021 +++ src/tests/usr.bin/xlint/lint1/msg_230.exp Mon Aug 23 17:47:34 2021 @@ -1,3 +1,5 @@ msg_230.c(14): warning: comparison of unsigned char with 0, op < [162] msg_230.c(27): warning: nonportable character comparison, op <= [230] msg_230.c(30): warning: comparison of unsigned char with negative constant, op <= [162] +msg_230.c(36): warning: nonportable character comparison, op <= [230] +msg_230.c(39): warning: nonportable character comparison, op <= [230]