1/// Find assignments to unsigned variables and add an 'U' to the value
2// Copyright: (C) 2018 Intel Corporation
3// Copyright: (C) 2018 Himanshu Jha
4// Copyright: (C) 2018 Julia Lawall, Inria/LIP6
5// SPDX-License-Identifier: Apache-2.0
6// Confidence: High
7
8virtual patch
9virtual report
10
11@r_unsigned@
12typedef uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t;
13{unsigned char, unsigned short, unsigned int, uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t} v;
14constant C;
15position p;
16@@
17
18(
19  v = C@p
20|
21  v == C@p
22|
23  v != C@p
24|
25  v <= C@p
26|
27  v >= C@p
28|
29  v += C@p
30|
31  v -= C@p
32|
33  v * C@p
34|
35  v / C@p
36|
37  v *= C@p
38|
39  v /= C@p
40)
41
42@script:python r_rewrite@
43C << r_unsigned.C;
44z;
45@@
46
47if C.isdigit() != True:
48    cocci.include_match(False)
49
50coccinelle.z = C + "U"
51
52@r_subst depends on patch@
53{unsigned char, unsigned short, unsigned int, uint8_t, uint16_t, uint32_t, uint64_t, u8_t, u16_t, u32_t, u64_t} r_unsigned.v;
54constant r_unsigned.C;
55identifier r_rewrite.z;
56@@
57
58(
59  v =
60- C
61+ z
62|
63  v ==
64- C
65+ z
66|
67  v !=
68- C
69+ z
70|
71  v <=
72- C
73+ z
74|
75  v >=
76- C
77+ z
78|
79  v +=
80- C
81+ z
82|
83  v -=
84- C
85+ z
86|
87  v +
88- C
89+ z
90|
91  v -
92- C
93+ z
94|
95  v +=
96- C
97+ z
98|
99  v -=
100- C
101+ z
102|
103- v * C
104+ v * z
105|
106  v /
107- C
108+ z
109|
110  v *=
111- C
112+ z
113|
114  v /=
115- C
116+ z
117)
118
119@script: python depends on report@
120p << r_unsigned.p;
121@@
122
123msg="WARNING: Unsigned 'U' suffix missing"
124coccilib.report.print_report(p[0], msg)
125