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: demonstrate wrong warn...



details:   https://anonhg.NetBSD.org/src/rev/0f2017a1c2e7
branches:  trunk
changeset: 1023086:0f2017a1c2e7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 23 05:52:04 2021 +0000

description:
tests/lint: demonstrate wrong warnings for integer overflow

diffstat:

 tests/usr.bin/xlint/lint1/msg_141.c   |  22 +++++++++++++++++++---
 tests/usr.bin/xlint/lint1/msg_141.exp |   6 +++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r db9fa0c55ebc -r 0f2017a1c2e7 tests/usr.bin/xlint/lint1/msg_141.c
--- a/tests/usr.bin/xlint/lint1/msg_141.c       Sun Aug 22 22:24:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_141.c       Mon Aug 23 05:52:04 2021 +0000
@@ -1,7 +1,23 @@
-/*     $NetBSD: msg_141.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_141.c,v 1.3 2021/08/23 05:52:04 rillig Exp $       */
 # 3 "msg_141.c"
 
 // Test for message: integer overflow detected, op %s [141]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -h */
+
+/* FIXME */
+/* expect+1: warning: integer overflow detected, op - [141] */
+int signed_int_max = (1u << 31) - 1;
+
+/* FIXME */
+/* expect+1: warning: integer overflow detected, op - [141] */
+unsigned int unsigned_int_max = (1u << 31) - 1;
+
+/* expect+1: warning: integer overflow detected, op + [141] */
+int int_overflow = (1 << 30) + (1 << 30);
+
+/* expect+2: warning: integer overflow detected, op + [141] */
+/* expect+1: warning: initialization of unsigned with negative constant [221] */
+unsigned int intermediate_overflow = (1 << 30) + (1 << 30);
+
+unsigned int no_overflow = (1U << 30) + (1 << 30);
diff -r db9fa0c55ebc -r 0f2017a1c2e7 tests/usr.bin/xlint/lint1/msg_141.exp
--- a/tests/usr.bin/xlint/lint1/msg_141.exp     Sun Aug 22 22:24:11 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_141.exp     Mon Aug 23 05:52:04 2021 +0000
@@ -1,1 +1,5 @@
-msg_141.c(6): error: syntax error ':' [249]
+msg_141.c(10): warning: integer overflow detected, op - [141]
+msg_141.c(14): warning: integer overflow detected, op - [141]
+msg_141.c(17): warning: integer overflow detected, op + [141]
+msg_141.c(21): warning: integer overflow detected, op + [141]
+msg_141.c(21): warning: initialization of unsigned with negative constant [221]



Home | Main Index | Thread Index | Old Index