• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

simple(int s,unsigned int u,int p)1 int simple(int s, unsigned int u, int p)
2 {
3 	s = s >> 100;
4 	u = u >> 101;
5 	u = u << 102;
6 	s = s >>  -1;
7 	u = u >>  -2;
8 	u = u <<  -3;
9 	if (0) return s >> 103;
10 	if (0) return u >> 104;
11 	if (0) return u << 105;
12 	if (0) return s >>  -4;
13 	if (0) return u >>  -5;
14 	if (0) return u <<  -6;
15 	if (p && 0) return s >> 106;
16 	if (p && 0) return u >> 107;
17 	if (p && 0) return u << 108;
18 	if (p && 0) return s >>  -7;
19 	if (p && 0) return u >>  -8;
20 	if (p && 0) return u <<  -9;
21 	s = s >> ((p & 0) + 109); u ^= p; // reloaded because now == 0
22 	u = u >> ((p & 0) + 110); u ^= p; // reloaded because now == 0
23 	u = u << ((p & 0) + 111); u ^= p; // reloaded because now == 0
24 	s = s >> ((p & 0) + -10);
25 	u = u >> ((p & 0) + -11); u ^= p; // reloaded because now == 0
26 	u = u << ((p & 0) + -12); u ^= p; // reloaded because now == 0
27 	return s + u;
28 }
29 
compound(int s,unsigned int u,int p)30 int compound(int s, unsigned int u, int p)
31 {
32 	s >>= 100;
33 	u >>= 101;
34 	u <<= 102;
35 	s >>=  -1;
36 	u >>=  -2;
37 	u <<=  -3;
38 	if (0) return s >>= 103;
39 	if (0) return u >>= 104;
40 	if (0) return u <<= 105;
41 	if (0) return s >>=  -4;
42 	if (0) return u >>=  -5;
43 	if (0) return u <<=  -6;
44 	if (p && 0) return s >>= 106;
45 	if (p && 0) return u >>= 107;
46 	if (p && 0) return u <<= 108;
47 	if (p && 0) return s >>=  -7;
48 	if (p && 0) return u >>=  -8;
49 	if (p && 0) return u <<=  -9;
50 	s >>= ((p & 0) + 109); u ^= p; // reloaded because now == 0
51 	u >>= ((p & 0) + 110); u ^= p; // reloaded because now == 0
52 	u <<= ((p & 0) + 111); u ^= p; // reloaded because now == 0
53 	s >>= ((p & 0) + -10);
54 	u >>= ((p & 0) + -11); u ^= p; // reloaded because now == 0
55 	u <<= ((p & 0) + -12); u ^= p; // reloaded because now == 0
56 	return s + u;
57 }
58 
ok(int s,unsigned int u,int p)59 int ok(int s, unsigned int u, int p)
60 {
61 	// GCC doesn't warn on these
62 	if (0 && (s >> 100)) return 0;
63 	if (0 && (u >> 101)) return 0;
64 	if (0 && (u << 102)) return 0;
65 	if (0 && (s >>  -1)) return 0;
66 	if (0 && (u >>  -2)) return 0;
67 	if (0 && (u <<  -3)) return 0;
68 	if (0 && (s >>= 103)) return 0;
69 	if (0 && (u >>= 104)) return 0;
70 	if (0 && (u <<= 105)) return 0;
71 	if (0 && (s >>=  -4)) return 0;
72 	if (0 && (u >>=  -5)) return 0;
73 	if (0 && (u <<=  -6)) return 0;
74 	return 1;
75 }
76 
77 struct bf {
78 	unsigned int u:8;
79 	         int s:8;
80 };
81 
bf(struct bf * p)82 int bf(struct bf *p)
83 {
84 	unsigned int r = 0;
85 	r += p->s << 8;
86 	r += p->s >> 8;
87 	r += p->u >> 8;
88 	return r;
89 }
90 
91 /*
92  * The following is used in the kernel at several places
93  * It shouldn't emit any warnings.
94  */
95 typedef unsigned long long u64;
96 typedef unsigned       int u32;
97 
98 extern void hw_w32x2(u32 hi, u32 lo);
99 
hw_w64(u64 val)100 inline void hw_w64(u64 val)
101 {
102 	hw_w32x2(val >> 32, (u32) val);
103 }
104 
hw_write(u32 val)105 void hw_write(u32 val)
106 {
107 	hw_w64(val);
108 }
109 
110 /*
111  * check-name: shift too big or negative
112  * check-command: sparse -Wno-decl $file
113  *
114  * check-error-start
115 shift-undef.c:3:18: warning: shift too big (100) for type int
116 shift-undef.c:4:18: warning: shift too big (101) for type unsigned int
117 shift-undef.c:5:18: warning: shift too big (102) for type unsigned int
118 shift-undef.c:6:19: warning: shift count is negative (-1)
119 shift-undef.c:7:19: warning: shift count is negative (-2)
120 shift-undef.c:8:19: warning: shift count is negative (-3)
121 shift-undef.c:21:29: warning: shift too big (109) for type int
122 shift-undef.c:22:29: warning: shift too big (110) for type unsigned int
123 shift-undef.c:23:29: warning: shift too big (111) for type unsigned int
124 shift-undef.c:24:29: warning: shift count is negative (-10)
125 shift-undef.c:25:29: warning: shift count is negative (-11)
126 shift-undef.c:26:29: warning: shift count is negative (-12)
127 shift-undef.c:32:15: warning: shift too big (100) for type int
128 shift-undef.c:33:15: warning: shift too big (101) for type unsigned int
129 shift-undef.c:34:15: warning: shift too big (102) for type unsigned int
130 shift-undef.c:35:16: warning: shift count is negative (-1)
131 shift-undef.c:36:16: warning: shift count is negative (-2)
132 shift-undef.c:37:16: warning: shift count is negative (-3)
133 shift-undef.c:50:26: warning: shift too big (109) for type int
134 shift-undef.c:51:26: warning: shift too big (110) for type unsigned int
135 shift-undef.c:52:26: warning: shift too big (111) for type unsigned int
136 shift-undef.c:53:26: warning: shift count is negative (-10)
137 shift-undef.c:54:26: warning: shift count is negative (-11)
138 shift-undef.c:55:26: warning: shift count is negative (-12)
139  * check-error-end
140  */
141