Module Name:    src
Committed By:   rillig
Date:           Mon Aug 23 05:52:04 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_141.c msg_141.exp

Log Message:
tests/lint: demonstrate wrong warnings for integer overflow


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_141.c \
    src/tests/usr.bin/xlint/lint1/msg_141.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_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.2 src/tests/usr.bin/xlint/lint1/msg_141.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Mon Aug 23 05:52:04 2021
@@ -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);
Index: src/tests/usr.bin/xlint/lint1/msg_141.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_141.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_141.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_141.exp:1.2	Sun Mar 21 20:44:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_141.exp	Mon Aug 23 05:52:04 2021
@@ -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]

Reply via email to