xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_141.c (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: msg_141.c,v 1.7 2023/07/09 11:01:27 rillig Exp $	*/
2 # 3 "msg_141.c"
3 
4 // Test for message: operator '%s' produces integer overflow [141]
5 
6 /* lint1-extra-flags: -h -X 351 */
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: operator '+' produces integer overflow [141] */
21 int int_overflow = (1 << 30) + (1 << 30);
22 
23 /* expect+2: warning: operator '+' produces integer overflow [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: operator '-' produces integer overflow [141] */
30 unsigned int unsigned_int_min = 0u - (1u << 31);
31 
32 /* expect+1: warning: operator '-' produces integer overflow [141] */
33 unsigned int unsigned_int_min_unary = -(1u << 31);
34