xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_120.c (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1 /*	$NetBSD: msg_120.c,v 1.7 2023/07/07 19:45:22 rillig Exp $	*/
2 # 3 "msg_120.c"
3 
4 // Test for message: bitwise '%s' on signed value nonportable [120]
5 
6 /* lint1-extra-flags: -p -X 351 */
7 
8 int
9 shr(int a, int b)
10 {
11 	/* expect+1: warning: bitwise '>>' on signed value possibly nonportable [117] */
12 	return a >> b;
13 }
14 
15 int
16 shr_lhs_constant_positive(int a)
17 {
18 	return 0x1234 >> a;
19 }
20 
21 int
22 shr_lhs_constant_negative(int a)
23 {
24 	/* expect+1: warning: bitwise '>>' on signed value nonportable [120] */
25 	return -0x1234 >> a;
26 }
27 
28 int
29 shr_rhs_constant_positive(int a)
30 {
31 	/* expect+2: warning: bitwise '>>' on signed value possibly nonportable [117] */
32 	/* expect+1: warning: shift amount 4660 is greater than bit-size 32 of 'int' [122] */
33 	return a >> 0x1234;
34 }
35 
36 int
37 shr_rhs_constant_negative(int a)
38 {
39 	/* expect+2: warning: bitwise '>>' on signed value possibly nonportable [117] */
40 	/* expect+1: warning: negative shift [121] */
41 	return a >> -0x1234;
42 }
43