xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_141.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: msg_141.c,v 1.5 2021/08/23 06:50:01 rillig Exp $	*/
2 # 3 "msg_141.c"
3 
4 // Test for message: integer overflow detected, op '%s' [141]
5 
6 /* lint1-extra-flags: -h */
7 
8 /*
9  * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
10  * overflow in '-'.
11  */
12 int signed_int_max = (1u << 31) - 1;
13 
14 /*
15  * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
16  * overflow in '-'.
17  */
18 unsigned int unsigned_int_max = (1u << 31) - 1;
19 
20 /* expect+1: warning: integer overflow detected, op '+' [141] */
21 int int_overflow = (1 << 30) + (1 << 30);
22 
23 /* expect+2: warning: integer overflow detected, op '+' [141] */
24 /* expect+1: warning: initialization of unsigned with negative constant [221] */
25 unsigned int intermediate_overflow = (1 << 30) + (1 << 30);
26 
27 unsigned int no_overflow = (1U << 30) + (1 << 30);
28 
29 /* expect+1: warning: integer overflow detected, op '-' [141] */
30 unsigned int unsigned_int_min = 0u - (1u << 31);
31 
32 /* expect+1: warning: integer overflow detected, op '-' [141] */
33 unsigned int unsigned_int_min_unary = -(1u << 31);
34