Module Name: src Committed By: rillig Date: Sun Sep 5 16:47:24 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_162.c msg_162.exp Log Message: tests/lint: test comparison of 'unsigned <= 0' To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_162.c \ src/tests/usr.bin/xlint/lint1/msg_162.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/msg_162.c diff -u src/tests/usr.bin/xlint/lint1/msg_162.c:1.4 src/tests/usr.bin/xlint/lint1/msg_162.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_162.c:1.4 Sat Aug 28 14:45:19 2021 +++ src/tests/usr.bin/xlint/lint1/msg_162.c Sun Sep 5 16:47:24 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_162.c,v 1.4 2021/08/28 14:45:19 rillig Exp $ */ +/* $NetBSD: msg_162.c,v 1.5 2021/09/05 16:47:24 rillig Exp $ */ # 3 "msg_162.c" // Test for message: comparison of %s with %s, op %s [162] @@ -82,3 +82,47 @@ compare_unsigned_char(unsigned char uc) if (uc == 256) return; } + +void take_bool(_Bool); + +void +compare_operators(unsigned int x) +{ + /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */ + take_bool(x < -1); + /* expect+1: warning: comparison of unsigned int with 0, op < [162] */ + take_bool(x < 0); + take_bool(x < 1); + + /* expect+1: warning: comparison of unsigned int with negative constant, op <= [162] */ + take_bool(x <= -1); + /* + * XXX: The expression 'x <= 0' is equivalent to 'x < 1', so lint + * should not warn about it, just as it doesn't warn about the + * inverted condition, which is 'x > 0'. + */ + /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */ + take_bool(x <= 0); + take_bool(x <= 1); + + /* expect+1: warning: comparison of unsigned int with negative constant, op > [162] */ + take_bool(x > -1); + take_bool(x > 0); + take_bool(x > 1); + + /* expect+1: warning: comparison of unsigned int with negative constant, op >= [162] */ + take_bool(x >= -1); + /* expect+1: warning: comparison of unsigned int with 0, op >= [162] */ + take_bool(x >= 0); + take_bool(x >= 1); + + /* expect+1: warning: comparison of unsigned int with negative constant, op == [162] */ + take_bool(x == -1); + take_bool(x == 0); + take_bool(x == 1); + + /* expect+1: warning: comparison of unsigned int with negative constant, op != [162] */ + take_bool(x != -1); + take_bool(x != 0); + take_bool(x != 1); +} Index: src/tests/usr.bin/xlint/lint1/msg_162.exp diff -u src/tests/usr.bin/xlint/lint1/msg_162.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_162.exp:1.5 --- src/tests/usr.bin/xlint/lint1/msg_162.exp:1.4 Sat Aug 28 14:45:19 2021 +++ src/tests/usr.bin/xlint/lint1/msg_162.exp Sun Sep 5 16:47:24 2021 @@ -7,3 +7,12 @@ msg_162.c(43): warning: comparison of 0 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] msg_162.c(76): warning: comparison of unsigned char with negative constant, op == [162] +msg_162.c(92): warning: comparison of unsigned int with negative constant, op < [162] +msg_162.c(94): warning: comparison of unsigned int with 0, op < [162] +msg_162.c(98): warning: comparison of unsigned int with negative constant, op <= [162] +msg_162.c(105): warning: comparison of unsigned int with 0, op <= [162] +msg_162.c(109): warning: comparison of unsigned int with negative constant, op > [162] +msg_162.c(114): warning: comparison of unsigned int with negative constant, op >= [162] +msg_162.c(116): warning: comparison of unsigned int with 0, op >= [162] +msg_162.c(120): warning: comparison of unsigned int with negative constant, op == [162] +msg_162.c(125): warning: comparison of unsigned int with negative constant, op != [162]