xref: /illumos-gate/usr/src/tools/smatch/src/validation/expand/bad-shift.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 #define MAX	(sizeof(int) * __CHAR_BIT__)
2 
3 static int lmax(int a)
4 {
5 	return 1 << MAX;
6 }
7 
8 static int lneg(int a)
9 {
10 	return 1 << -1;
11 }
12 
13 static int rmax(int a)
14 {
15 	return 1 >> MAX;
16 }
17 
18 static int rneg(int a)
19 {
20 	return 1 >> -1;
21 }
22 
23 /*
24  * check-name: bad-shift
25  * check-command: test-linearize -Wno-decl $file
26  *
27  * check-output-start
28 lmax:
29 .L0:
30 	<entry-point>
31 	shl.32      %r1 <- $1, $32
32 	ret.32      %r1
33 
34 
35 lneg:
36 .L2:
37 	<entry-point>
38 	shl.32      %r3 <- $1, $0xffffffff
39 	ret.32      %r3
40 
41 
42 rmax:
43 .L4:
44 	<entry-point>
45 	asr.32      %r5 <- $1, $32
46 	ret.32      %r5
47 
48 
49 rneg:
50 .L6:
51 	<entry-point>
52 	asr.32      %r7 <- $1, $0xffffffff
53 	ret.32      %r7
54 
55 
56  * check-output-end
57  *
58  * check-error-start
59 expand/bad-shift.c:5:18: warning: shift too big (32) for type int
60 expand/bad-shift.c:10:18: warning: shift count is negative (-1)
61 expand/bad-shift.c:15:18: warning: shift too big (32) for type int
62 expand/bad-shift.c:20:18: warning: shift count is negative (-1)
63  * check-error-end
64  */
65