adlint 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +0 -1
- data/ChangeLog +185 -1
- data/MANIFEST +3 -0
- data/NEWS +28 -5
- data/bin/adlintize +70 -7
- data/etc/conf.d/fallback/traits.erb +12 -3
- data/etc/conf.d/i686-cygwin/traits-gcc_4.3.4.erb +12 -3
- data/etc/conf.d/i686-devkit/traits-gcc_4.5.2.erb +12 -3
- data/etc/conf.d/i686-linux/traits-gcc_4.5.1.erb +12 -3
- data/etc/conf.d/i686-mingw/traits-gcc_4.6.1.erb +12 -3
- data/etc/conf.d/x86_64-ubuntu_12.04/traits-gcc_4.6.3.erb +12 -4
- data/etc/mesg.d/c_builtin/en_US/messages.yml +1 -1
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +1 -1
- data/etc/mesg.d/core/en_US/messages.yml +1 -1
- data/etc/mesg.d/core/ja_JP/messages.yml +1 -1
- data/features/code_check/W0070.feature +51 -0
- data/features/code_check/W0071.feature +51 -0
- data/features/code_check/W0425.feature +279 -0
- data/features/code_check/W0692.feature +14 -1
- data/features/code_check/W0834.feature +7 -5
- data/features/code_check/W1073.feature +0 -1
- data/features/code_check/W1074.feature +6 -0
- data/features/code_check/W9003.feature +54 -0
- data/features/support/env.rb +15 -3
- data/lib/adlint/c/expr.rb +30 -6
- data/lib/adlint/c/interp.rb +4 -0
- data/lib/adlint/cpp/eval.rb +24 -14
- data/lib/adlint/cpp/macro.rb +52 -40
- data/lib/adlint/exam/c_builtin/c_check.rb +76 -42
- data/lib/adlint/exam/c_builtin/cpp_check.rb +4 -2
- data/lib/adlint/traits.rb +37 -23
- data/lib/adlint/util.rb +6 -0
- data/lib/adlint/version.rb +3 -3
- data/share/doc/developers_guide_ja.html +3 -3
- data/share/doc/developers_guide_ja.texi +1 -1
- data/share/doc/users_guide_en.html +1679 -1651
- data/share/doc/users_guide_en.texi +56 -24
- data/share/doc/users_guide_ja.html +1697 -1669
- data/share/doc/users_guide_ja.texi +57 -24
- data/share/sample/bison-2.5/adlint/adlint_traits.yml +13 -4
- data/share/sample/bison-2.5/adlint/lib/adlint_traits.yml +13 -4
- data/share/sample/bison-2.5/adlint/src/adlint_traits.yml +13 -4
- data/share/sample/ctags-5.8/adlint/adlint_traits.yml +13 -4
- data/share/sample/flex-2.5.35/adlint/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/core/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/enc/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/enc-trans/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-bigdecimal/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-continuation/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-coverage/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-curses/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-date/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dbm/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-bubblebabble/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-md5/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-rmd160/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha1/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-digest-sha2/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-dl-callback/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-etc/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fcntl/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiber/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-fiddle/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-gdbm/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-iconv/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-console/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-nonblock/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-io-wait/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-generator/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-json-parser/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-complex/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-mathn-rational/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-nkf/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-openssl/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pathname/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-psych/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-pty/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-racc-cparse/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-readline/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-ripper/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-sdbm/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-socket/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-stringio/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-strscan/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syck/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-syslog/adlint_traits.yml +13 -4
- data/share/sample/ruby-1.9.3-p0/adlint/ext-zlib/adlint_traits.yml +13 -4
- data/share/sample/screen-4.0.3/adlint/adlint_traits.yml +13 -4
- data/share/sample/vim-7.3/adlint/vim/adlint_traits.yml +13 -4
- data/share/sample/vim-7.3/adlint/xxd/adlint_traits.yml +13 -4
- data/share/sample/zsh-4.3.15/adlint/adlint_traits.yml +13 -4
- data/share/sample/zsh-4.3.15/adlint/builtins/adlint_traits.yml +13 -4
- data/share/sample/zsh-4.3.15/adlint/core/adlint_traits.yml +13 -4
- data/share/sample/zsh-4.3.15/adlint/modules/adlint_traits.yml +13 -4
- data/share/sample/zsh-4.3.15/adlint/zle/adlint_traits.yml +13 -4
- data/spec/conf.d/default_traits.yml +12 -4
- metadata +5 -2
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: W0071
|
2
|
+
|
3
|
+
W0071 detects that contents of a header included by #include "..." directive
|
4
|
+
are not referred by other files in a translation-unit.
|
5
|
+
|
6
|
+
Scenario: a typedef in the header and no reference to it
|
7
|
+
Given a target source named "fixture.c" with:
|
8
|
+
"""
|
9
|
+
#include "test.h" /* W0071 */
|
10
|
+
|
11
|
+
int bar(void) { return 0; }
|
12
|
+
"""
|
13
|
+
And a target source named "test.h" with:
|
14
|
+
"""
|
15
|
+
#if !defined(TEST_H)
|
16
|
+
#define TEST_H
|
17
|
+
|
18
|
+
typedef int foo;
|
19
|
+
|
20
|
+
#endif
|
21
|
+
"""
|
22
|
+
When I successfully run `adlint fixture.c` on noarch
|
23
|
+
Then the output should exactly match with:
|
24
|
+
| mesg | line | column |
|
25
|
+
| W0117 | 3 | 5 |
|
26
|
+
| W0071 | 1 | 1 |
|
27
|
+
| W0628 | 3 | 5 |
|
28
|
+
|
29
|
+
Scenario: a typedef in the header and reference to it in other file.
|
30
|
+
Given a target source named "fixture.c" with:
|
31
|
+
"""
|
32
|
+
#include "test.h" /* OK */
|
33
|
+
|
34
|
+
foo bar(void) { return 0; }
|
35
|
+
"""
|
36
|
+
And a target source named "test.h" with:
|
37
|
+
"""
|
38
|
+
#if !defined(TEST_H)
|
39
|
+
#define TEST_H
|
40
|
+
|
41
|
+
typedef int foo;
|
42
|
+
|
43
|
+
#endif
|
44
|
+
"""
|
45
|
+
When I successfully run `adlint fixture.c` on noarch
|
46
|
+
Then the output should exactly match with:
|
47
|
+
| mesg | line | column |
|
48
|
+
| W0117 | 3 | 5 |
|
49
|
+
| W0628 | 3 | 5 |
|
50
|
+
|
51
|
+
# vim:ts=2:sw=2:sts=2:et:
|
@@ -0,0 +1,279 @@
|
|
1
|
+
Feature: W0425
|
2
|
+
|
3
|
+
W0425 detects that two or more declarations or statements are in a line.
|
4
|
+
|
5
|
+
Scenario: two declarations in a line
|
6
|
+
Given a target source named "fixture.c" with:
|
7
|
+
"""
|
8
|
+
int foo(void)
|
9
|
+
{
|
10
|
+
int i = 0; int j = 0; /* W0425 */
|
11
|
+
return i + j;
|
12
|
+
}
|
13
|
+
"""
|
14
|
+
When I successfully run `adlint fixture.c` on noarch
|
15
|
+
Then the output should exactly match with:
|
16
|
+
| mesg | line | column |
|
17
|
+
| W0117 | 1 | 5 |
|
18
|
+
| W0100 | 3 | 9 |
|
19
|
+
| W0100 | 3 | 20 |
|
20
|
+
| W0425 | 3 | 20 |
|
21
|
+
| W0628 | 1 | 5 |
|
22
|
+
|
23
|
+
Scenario: two declarators in a declaration
|
24
|
+
Given a target source named "fixture.c" with:
|
25
|
+
"""
|
26
|
+
int foo(void)
|
27
|
+
{
|
28
|
+
int i = 0, j = 0; /* W0425 */
|
29
|
+
return i + j;
|
30
|
+
}
|
31
|
+
"""
|
32
|
+
When I successfully run `adlint fixture.c` on noarch
|
33
|
+
Then the output should exactly match with:
|
34
|
+
| mesg | line | column |
|
35
|
+
| W0117 | 1 | 5 |
|
36
|
+
| W0100 | 3 | 9 |
|
37
|
+
| W0100 | 3 | 16 |
|
38
|
+
| W0425 | 3 | 16 |
|
39
|
+
| W0628 | 1 | 5 |
|
40
|
+
|
41
|
+
Scenario: a declaration and a jump-statement in a line
|
42
|
+
Given a target source named "fixture.c" with:
|
43
|
+
"""
|
44
|
+
int foo(void)
|
45
|
+
{
|
46
|
+
int i = 0; return i + 1; /* W0425 */
|
47
|
+
}
|
48
|
+
"""
|
49
|
+
When I successfully run `adlint fixture.c` on noarch
|
50
|
+
Then the output should exactly match with:
|
51
|
+
| mesg | line | column |
|
52
|
+
| W0117 | 1 | 5 |
|
53
|
+
| W0100 | 3 | 9 |
|
54
|
+
| W0425 | 3 | 16 |
|
55
|
+
| W0628 | 1 | 5 |
|
56
|
+
|
57
|
+
Scenario: a expression-statement and a jump-statement in a line
|
58
|
+
Given a target source named "fixture.c" with:
|
59
|
+
"""
|
60
|
+
int foo(void)
|
61
|
+
{
|
62
|
+
int i;
|
63
|
+
i = 0; return i + 1; /* W0425 */
|
64
|
+
}
|
65
|
+
"""
|
66
|
+
When I successfully run `adlint fixture.c` on noarch
|
67
|
+
Then the output should exactly match with:
|
68
|
+
| mesg | line | column |
|
69
|
+
| W0117 | 1 | 5 |
|
70
|
+
| W0100 | 3 | 9 |
|
71
|
+
| W0425 | 4 | 12 |
|
72
|
+
| W0628 | 1 | 5 |
|
73
|
+
|
74
|
+
Scenario: a if-else-statement in a line
|
75
|
+
Given a target source named "fixture.c" with:
|
76
|
+
"""
|
77
|
+
int foo(int i)
|
78
|
+
{
|
79
|
+
if (i == 0) return 0; else return 1; /* OK */
|
80
|
+
}
|
81
|
+
"""
|
82
|
+
When I successfully run `adlint fixture.c` on noarch
|
83
|
+
Then the output should exactly match with:
|
84
|
+
| mesg | line | column |
|
85
|
+
| W0117 | 1 | 5 |
|
86
|
+
| W0104 | 1 | 13 |
|
87
|
+
| W1071 | 1 | 5 |
|
88
|
+
| W0414 | 3 | 17 |
|
89
|
+
| W0414 | 3 | 32 |
|
90
|
+
| W0628 | 1 | 5 |
|
91
|
+
|
92
|
+
Scenario: a if-else-statement with compound-statements in a line
|
93
|
+
Given a target source named "fixture.c" with:
|
94
|
+
"""
|
95
|
+
int foo(int i)
|
96
|
+
{
|
97
|
+
if (i == 0) { return 0; } else { return 1; } /* OK */
|
98
|
+
}
|
99
|
+
"""
|
100
|
+
When I successfully run `adlint fixture.c` on noarch
|
101
|
+
Then the output should exactly match with:
|
102
|
+
| mesg | line | column |
|
103
|
+
| W0117 | 1 | 5 |
|
104
|
+
| W0104 | 1 | 13 |
|
105
|
+
| W1071 | 1 | 5 |
|
106
|
+
| W0628 | 1 | 5 |
|
107
|
+
|
108
|
+
Scenario: a if-statement with compound-statements in a line
|
109
|
+
Given a target source named "fixture.c" with:
|
110
|
+
"""
|
111
|
+
int foo(int i)
|
112
|
+
{
|
113
|
+
if (i == 0) { return 0; } /* OK */
|
114
|
+
return 1;
|
115
|
+
}
|
116
|
+
"""
|
117
|
+
When I successfully run `adlint fixture.c` on noarch
|
118
|
+
Then the output should exactly match with:
|
119
|
+
| mesg | line | column |
|
120
|
+
| W0117 | 1 | 5 |
|
121
|
+
| W0104 | 1 | 13 |
|
122
|
+
| W1071 | 1 | 5 |
|
123
|
+
| W0628 | 1 | 5 |
|
124
|
+
|
125
|
+
Scenario: a if-statement in a line
|
126
|
+
Given a target source named "fixture.c" with:
|
127
|
+
"""
|
128
|
+
int foo(int i)
|
129
|
+
{
|
130
|
+
if (i == 0) return 0; /* OK */
|
131
|
+
return 1;
|
132
|
+
}
|
133
|
+
"""
|
134
|
+
When I successfully run `adlint fixture.c` on noarch
|
135
|
+
Then the output should exactly match with:
|
136
|
+
| mesg | line | column |
|
137
|
+
| W0117 | 1 | 5 |
|
138
|
+
| W0104 | 1 | 13 |
|
139
|
+
| W1071 | 1 | 5 |
|
140
|
+
| W0414 | 3 | 17 |
|
141
|
+
| W0628 | 1 | 5 |
|
142
|
+
|
143
|
+
Scenario: a for-statement in a line
|
144
|
+
Given a target source named "fixture.c" with:
|
145
|
+
"""
|
146
|
+
int foo(int i)
|
147
|
+
{
|
148
|
+
int j, k = 1; /* W0425 */
|
149
|
+
for (j = 0; j < i; j++) k *= 2; /* OK */
|
150
|
+
return k;
|
151
|
+
}
|
152
|
+
"""
|
153
|
+
When I successfully run `adlint fixture.c` on noarch
|
154
|
+
Then the output should exactly match with:
|
155
|
+
| mesg | line | column |
|
156
|
+
| W0117 | 1 | 5 |
|
157
|
+
| W0104 | 1 | 13 |
|
158
|
+
| W0414 | 4 | 29 |
|
159
|
+
| W0425 | 3 | 12 |
|
160
|
+
| W0628 | 1 | 5 |
|
161
|
+
|
162
|
+
Scenario: a for-statement with a compound-statement in a line
|
163
|
+
Given a target source named "fixture.c" with:
|
164
|
+
"""
|
165
|
+
int foo(int i)
|
166
|
+
{
|
167
|
+
int j, k = 1; /* W0425 */
|
168
|
+
for (j = 0; j < i; j++) { k *= 2; } /* OK */
|
169
|
+
return k;
|
170
|
+
}
|
171
|
+
"""
|
172
|
+
When I successfully run `adlint fixture.c` on noarch
|
173
|
+
Then the output should exactly match with:
|
174
|
+
| mesg | line | column |
|
175
|
+
| W0117 | 1 | 5 |
|
176
|
+
| W0104 | 1 | 13 |
|
177
|
+
| W0425 | 3 | 12 |
|
178
|
+
| W0628 | 1 | 5 |
|
179
|
+
|
180
|
+
Scenario: extra statement after if-statement in a line
|
181
|
+
Given a target source named "fixture.c" with:
|
182
|
+
"""
|
183
|
+
int foo(int i)
|
184
|
+
{
|
185
|
+
if (i == 0) return 0; return 1; /* W0425 */
|
186
|
+
}
|
187
|
+
"""
|
188
|
+
When I successfully run `adlint fixture.c` on noarch
|
189
|
+
Then the output should exactly match with:
|
190
|
+
| mesg | line | column |
|
191
|
+
| W0117 | 1 | 5 |
|
192
|
+
| W0104 | 1 | 13 |
|
193
|
+
| W1071 | 1 | 5 |
|
194
|
+
| W0414 | 3 | 17 |
|
195
|
+
| W0425 | 3 | 27 |
|
196
|
+
| W0628 | 1 | 5 |
|
197
|
+
|
198
|
+
Scenario: extra statement after for-statement in a line
|
199
|
+
Given a target source named "fixture.c" with:
|
200
|
+
"""
|
201
|
+
int foo(int i)
|
202
|
+
{
|
203
|
+
int j, k = 1; /* W0425 */
|
204
|
+
for (j = 0; j < i; j++) k *= 2; return k; /* W0425 */
|
205
|
+
}
|
206
|
+
"""
|
207
|
+
When I successfully run `adlint fixture.c` on noarch
|
208
|
+
Then the output should exactly match with:
|
209
|
+
| mesg | line | column |
|
210
|
+
| W0117 | 1 | 5 |
|
211
|
+
| W0104 | 1 | 13 |
|
212
|
+
| W0414 | 4 | 29 |
|
213
|
+
| W0425 | 3 | 12 |
|
214
|
+
| W0425 | 4 | 37 |
|
215
|
+
| W0628 | 1 | 5 |
|
216
|
+
|
217
|
+
Scenario: two member-declarations in a line
|
218
|
+
Given a target source named "fixture.c" with:
|
219
|
+
"""
|
220
|
+
struct foo { int i; int j; }; /* W0425 */
|
221
|
+
union bar { int i; int j; }; /* W0425 */
|
222
|
+
"""
|
223
|
+
When I successfully run `adlint fixture.c` on noarch
|
224
|
+
Then the output should exactly match with:
|
225
|
+
| mesg | line | column |
|
226
|
+
| W0551 | 2 | 7 |
|
227
|
+
| W0425 | 1 | 25 |
|
228
|
+
| W0425 | 2 | 24 |
|
229
|
+
|
230
|
+
Scenario: two declarators in a member-declaration
|
231
|
+
Given a target source named "fixture.c" with:
|
232
|
+
"""
|
233
|
+
struct foo { int *p, i; }; /* W0425 */
|
234
|
+
union bar { int *p, i; }; /* W0425 */
|
235
|
+
"""
|
236
|
+
When I successfully run `adlint fixture.c` on noarch
|
237
|
+
Then the output should exactly match with:
|
238
|
+
| mesg | line | column |
|
239
|
+
| W0551 | 2 | 7 |
|
240
|
+
| W0425 | 1 | 22 |
|
241
|
+
| W0425 | 2 | 21 |
|
242
|
+
|
243
|
+
Scenario: two declarators in a member-declaration
|
244
|
+
Given a target source named "fixture.c" with:
|
245
|
+
"""
|
246
|
+
extern struct { int i; } foo; /* OK */
|
247
|
+
extern union { int i; } bar; /* OK */
|
248
|
+
typedef struct { int i; } baz; /* OK */
|
249
|
+
typedef union { int i; } qux; /* OK */
|
250
|
+
"""
|
251
|
+
When I successfully run `adlint fixture.c` on noarch
|
252
|
+
Then the output should exactly match with:
|
253
|
+
| mesg | line | column |
|
254
|
+
| W0118 | 1 | 26 |
|
255
|
+
| W0118 | 2 | 25 |
|
256
|
+
| W0551 | 2 | 8 |
|
257
|
+
| W0551 | 4 | 9 |
|
258
|
+
|
259
|
+
Scenario: two declarators in a member-declaration
|
260
|
+
Given a target source named "fixture.c" with:
|
261
|
+
"""
|
262
|
+
extern struct { int *p, i; } foo; /* W0425 */
|
263
|
+
extern union { int *p, i; } bar; /* W0425 */
|
264
|
+
typedef struct { int *p, i; } baz; /* W0425 */
|
265
|
+
typedef union { int *p, i; } qux; /* W0425 */
|
266
|
+
"""
|
267
|
+
When I successfully run `adlint fixture.c` on noarch
|
268
|
+
Then the output should exactly match with:
|
269
|
+
| mesg | line | column |
|
270
|
+
| W0118 | 1 | 30 |
|
271
|
+
| W0118 | 2 | 29 |
|
272
|
+
| W0551 | 2 | 8 |
|
273
|
+
| W0551 | 4 | 9 |
|
274
|
+
| W0425 | 1 | 25 |
|
275
|
+
| W0425 | 2 | 24 |
|
276
|
+
| W0425 | 3 | 26 |
|
277
|
+
| W0425 | 4 | 25 |
|
278
|
+
|
279
|
+
# vim:ts=2:sw=2:sts=2:et:
|
@@ -2,7 +2,7 @@ Feature: W0692
|
|
2
2
|
|
3
3
|
W0692 detects that no argument is given to a function-like macro.
|
4
4
|
|
5
|
-
Scenario:
|
5
|
+
Scenario: empty argument to a function-like macro
|
6
6
|
Given a target source named "fixture.c" with:
|
7
7
|
"""
|
8
8
|
#define MACRO(a) #a
|
@@ -29,4 +29,17 @@ Feature: W0692
|
|
29
29
|
| W0442 | 1 | 1 |
|
30
30
|
| W0117 | 3 | 13 |
|
31
31
|
|
32
|
+
Scenario: no argument to a function-like macro
|
33
|
+
Given a target source named "fixture.c" with:
|
34
|
+
"""
|
35
|
+
#define MACRO() 0
|
36
|
+
|
37
|
+
const int i = MACRO(); /* W0692 */
|
38
|
+
"""
|
39
|
+
When I successfully run `adlint fixture.c` on noarch
|
40
|
+
Then the output should exactly match with:
|
41
|
+
| mesg | line | column |
|
42
|
+
| W0442 | 1 | 1 |
|
43
|
+
| W0117 | 3 | 11 |
|
44
|
+
|
32
45
|
# vim:ts=2:sw=2:sts=2:et:
|
@@ -116,7 +116,9 @@ Feature: W0834
|
|
116
116
|
Scenario: `long long' in sizeof-expression
|
117
117
|
Given a target source named "fixture.c" with:
|
118
118
|
"""
|
119
|
-
|
119
|
+
#include <stddef.h>
|
120
|
+
|
121
|
+
static size_t foo(void)
|
120
122
|
{
|
121
123
|
return sizeof(long long); /* W0834 */
|
122
124
|
}
|
@@ -124,10 +126,10 @@ Feature: W0834
|
|
124
126
|
When I successfully run `adlint fixture.c` on noarch
|
125
127
|
Then the output should exactly match with:
|
126
128
|
| mesg | line | column |
|
127
|
-
| W1076 |
|
128
|
-
| W0629 |
|
129
|
-
| W0834 |
|
130
|
-
| W0628 |
|
129
|
+
| W1076 | 3 | 15 |
|
130
|
+
| W0629 | 3 | 15 |
|
131
|
+
| W0834 | 5 | 19 |
|
132
|
+
| W0628 | 3 | 15 |
|
131
133
|
|
132
134
|
Scenario: multiple `long long' parameters in function declaration
|
133
135
|
Given a target source named "fixture.c" with:
|
@@ -23,6 +23,7 @@ Feature: W1074
|
|
23
23
|
| mesg | line | column |
|
24
24
|
| W1076 | 1 | 12 |
|
25
25
|
| W0612 | 5 | 21 |
|
26
|
+
| W0168 | 5 | 24 |
|
26
27
|
| W0609 | 5 | 21 |
|
27
28
|
| W0629 | 1 | 12 |
|
28
29
|
| W1074 | 5 | 15 |
|
@@ -49,6 +50,8 @@ Feature: W1074
|
|
49
50
|
| mesg | line | column |
|
50
51
|
| W1076 | 1 | 12 |
|
51
52
|
| W0613 | 5 | 33 |
|
53
|
+
| W0168 | 5 | 16 |
|
54
|
+
| W0168 | 5 | 36 |
|
52
55
|
| W0610 | 5 | 33 |
|
53
56
|
| W0629 | 1 | 12 |
|
54
57
|
| W1074 | 5 | 26 |
|
@@ -75,6 +78,7 @@ Feature: W1074
|
|
75
78
|
| mesg | line | column |
|
76
79
|
| W1076 | 1 | 12 |
|
77
80
|
| W0612 | 5 | 20 |
|
81
|
+
| W0168 | 5 | 23 |
|
78
82
|
| W0609 | 5 | 20 |
|
79
83
|
| W0629 | 1 | 12 |
|
80
84
|
| W1074 | 5 | 17 |
|
@@ -102,6 +106,7 @@ Feature: W1074
|
|
102
106
|
| W0118 | 1 | 12 |
|
103
107
|
| W1076 | 3 | 12 |
|
104
108
|
| W0612 | 5 | 23 |
|
109
|
+
| W0168 | 5 | 26 |
|
105
110
|
| W0609 | 5 | 23 |
|
106
111
|
| W1073 | 5 | 19 |
|
107
112
|
| W0629 | 3 | 12 |
|
@@ -131,6 +136,7 @@ Feature: W1074
|
|
131
136
|
| W1077 | 1 | 12 |
|
132
137
|
| W1076 | 3 | 12 |
|
133
138
|
| W0612 | 5 | 22 |
|
139
|
+
| W0168 | 5 | 25 |
|
134
140
|
| W0609 | 5 | 22 |
|
135
141
|
| W0629 | 3 | 12 |
|
136
142
|
| W9001 | 9 | 9 |
|
@@ -127,4 +127,58 @@ Feature: W9003
|
|
127
127
|
| W0502 | 5 | 9 |
|
128
128
|
| W0628 | 3 | 12 |
|
129
129
|
|
130
|
+
Scenario: no implicit conversion of size_t value
|
131
|
+
Given a target source named "fixture.c" with:
|
132
|
+
"""
|
133
|
+
#include <stddef.h>
|
134
|
+
|
135
|
+
size_t foo(int a)
|
136
|
+
{
|
137
|
+
return sizeof(a); /* OK */
|
138
|
+
}
|
139
|
+
"""
|
140
|
+
When I successfully run `adlint fixture.c` on noarch
|
141
|
+
Then the output should exactly match with:
|
142
|
+
| mesg | line | column |
|
143
|
+
| W0117 | 3 | 8 |
|
144
|
+
| W0104 | 3 | 16 |
|
145
|
+
| W0628 | 3 | 8 |
|
146
|
+
|
147
|
+
Scenario: implicit conversion of size_t value
|
148
|
+
Given a target source named "fixture.c" with:
|
149
|
+
"""
|
150
|
+
#include <stddef.h>
|
151
|
+
|
152
|
+
int foo(int a)
|
153
|
+
{
|
154
|
+
return sizeof(a); /* W9003 */
|
155
|
+
}
|
156
|
+
"""
|
157
|
+
When I successfully run `adlint fixture.c` on noarch
|
158
|
+
Then the output should exactly match with:
|
159
|
+
| mesg | line | column |
|
160
|
+
| W0117 | 3 | 5 |
|
161
|
+
| W0150 | 5 | 12 |
|
162
|
+
| W9003 | 5 | 12 |
|
163
|
+
| W0286 | 5 | 5 |
|
164
|
+
| W0104 | 3 | 13 |
|
165
|
+
| W0628 | 3 | 5 |
|
166
|
+
|
167
|
+
Scenario: explicit conversion of size_t value
|
168
|
+
Given a target source named "fixture.c" with:
|
169
|
+
"""
|
170
|
+
#include <stddef.h>
|
171
|
+
|
172
|
+
int foo(int a)
|
173
|
+
{
|
174
|
+
return (int) sizeof(a); /* OK */
|
175
|
+
}
|
176
|
+
"""
|
177
|
+
When I successfully run `adlint fixture.c` on noarch
|
178
|
+
Then the output should exactly match with:
|
179
|
+
| mesg | line | column |
|
180
|
+
| W0117 | 3 | 5 |
|
181
|
+
| W0104 | 3 | 13 |
|
182
|
+
| W0628 | 3 | 5 |
|
183
|
+
|
130
184
|
# vim:ts=2:sw=2:sts=2:et:
|
data/features/support/env.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
NOARCH_TRAITS = <<EOF
|
2
|
-
version: "2.
|
2
|
+
version: "2.4.0"
|
3
3
|
|
4
4
|
exam_packages:
|
5
5
|
- "c_builtin"
|
6
6
|
|
7
7
|
project_traits:
|
8
8
|
project_name: "features"
|
9
|
+
project_root: "."
|
9
10
|
include_path:
|
10
11
|
initial_header: "empty_pinit.h"
|
11
12
|
coding_style:
|
@@ -71,7 +72,8 @@ linker_traits:
|
|
71
72
|
message_traits:
|
72
73
|
language: "ja_JP"
|
73
74
|
message_with_class: false
|
74
|
-
|
75
|
+
warn_files_in:
|
76
|
+
warn_files_not_in:
|
75
77
|
individual_selection: true
|
76
78
|
exclusion:
|
77
79
|
inclusion:
|
@@ -111,6 +113,15 @@ DUMMY_ASSERT_H = <<EOF
|
|
111
113
|
#endif
|
112
114
|
EOF
|
113
115
|
|
116
|
+
DUMMY_STDDEF_H = <<EOF
|
117
|
+
#if !defined(DUMMY_STDDEF_H)
|
118
|
+
#define DUMMY_STDDEF_H
|
119
|
+
|
120
|
+
typedef unsigned long size_t;
|
121
|
+
|
122
|
+
#endif
|
123
|
+
EOF
|
124
|
+
|
114
125
|
require "pathname"
|
115
126
|
require "stringio"
|
116
127
|
|
@@ -135,7 +146,7 @@ def run_adlint(cmd, *args)
|
|
135
146
|
create_adlint_files
|
136
147
|
cd_to_tmpdir do
|
137
148
|
$all_output = exec(cmd, *args).each_line.map { |line|
|
138
|
-
if line =~ /_pinit\.h|_cinit\.h|stdio\.h|math\.h|assert\.h/
|
149
|
+
if line =~ /_pinit\.h|_cinit\.h|stdio\.h|math\.h|assert\.h|stddef\.h/
|
139
150
|
nil
|
140
151
|
else
|
141
152
|
line.chomp
|
@@ -181,6 +192,7 @@ def create_adlint_files
|
|
181
192
|
create_file("stdio.h", DUMMY_STDIO_H)
|
182
193
|
create_file("math.h", DUMMY_MATH_H)
|
183
194
|
create_file("assert.h", DUMMY_ASSERT_H)
|
195
|
+
create_file("stddef.h", DUMMY_STDDEF_H)
|
184
196
|
end
|
185
197
|
end
|
186
198
|
|
data/lib/adlint/c/expr.rb
CHANGED
@@ -1664,14 +1664,20 @@ module C #:nodoc:
|
|
1664
1664
|
def visit_sizeof_expression(node)
|
1665
1665
|
checkpoint(node.location)
|
1666
1666
|
|
1667
|
+
if size_t_type = type_of(UserTypeId.new("size_t"))
|
1668
|
+
result_type = size_t_type
|
1669
|
+
else
|
1670
|
+
result_type = unsigned_long_type
|
1671
|
+
end
|
1672
|
+
|
1667
1673
|
object = node.operand.accept(self)
|
1668
1674
|
if object.variable?
|
1669
1675
|
variable = object
|
1670
1676
|
result = temporary_variable(
|
1671
|
-
|
1677
|
+
result_type, ScalarValue.of(variable.type.aligned_byte_size))
|
1672
1678
|
notify_sizeof_expr_evaled(node, variable, result)
|
1673
1679
|
else
|
1674
|
-
result = temporary_variable(
|
1680
|
+
result = temporary_variable(result_type)
|
1675
1681
|
end
|
1676
1682
|
|
1677
1683
|
result
|
@@ -1682,8 +1688,14 @@ module C #:nodoc:
|
|
1682
1688
|
|
1683
1689
|
resolve_unresolved_type(node.operand)
|
1684
1690
|
|
1691
|
+
if size_t_type = type_of(UserTypeId.new("size_t"))
|
1692
|
+
result_type = size_t_type
|
1693
|
+
else
|
1694
|
+
result_type = unsigned_long_type
|
1695
|
+
end
|
1696
|
+
|
1685
1697
|
result = temporary_variable(
|
1686
|
-
|
1698
|
+
result_type, ScalarValue.of(node.operand.type.aligned_byte_size))
|
1687
1699
|
notify_sizeof_type_expr_evaled(node, node.operand.type, result)
|
1688
1700
|
|
1689
1701
|
result
|
@@ -1692,13 +1704,19 @@ module C #:nodoc:
|
|
1692
1704
|
def visit_alignof_expression(node)
|
1693
1705
|
checkpoint(node.location)
|
1694
1706
|
|
1707
|
+
if size_t_type = type_of(UserTypeId.new("size_t"))
|
1708
|
+
result_type = size_t_type
|
1709
|
+
else
|
1710
|
+
result_type = unsigned_long_type
|
1711
|
+
end
|
1712
|
+
|
1695
1713
|
object = node.operand.accept(self)
|
1696
1714
|
if object.variable?
|
1697
1715
|
variable = object
|
1698
|
-
temporary_variable(
|
1716
|
+
temporary_variable(result_type,
|
1699
1717
|
ScalarValue.of(variable.type.byte_alignment))
|
1700
1718
|
else
|
1701
|
-
temporary_variable(
|
1719
|
+
temporary_variable(result_type)
|
1702
1720
|
end
|
1703
1721
|
end
|
1704
1722
|
|
@@ -1707,7 +1725,13 @@ module C #:nodoc:
|
|
1707
1725
|
|
1708
1726
|
resolve_unresolved_type(node.operand)
|
1709
1727
|
|
1710
|
-
|
1728
|
+
if size_t_type = type_of(UserTypeId.new("size_t"))
|
1729
|
+
result_type = size_t_type
|
1730
|
+
else
|
1731
|
+
result_type = unsigned_long_type
|
1732
|
+
end
|
1733
|
+
|
1734
|
+
temporary_variable(result_type,
|
1711
1735
|
ScalarValue.of(node.operand.type.aligned_byte_size))
|
1712
1736
|
end
|
1713
1737
|
|
data/lib/adlint/c/interp.rb
CHANGED
@@ -924,6 +924,10 @@ module C #:nodoc:
|
|
924
924
|
end
|
925
925
|
|
926
926
|
def lookup_or_define_function(function_definition)
|
927
|
+
function_definition.type.declarations.each do |decl|
|
928
|
+
decl.mark_as_referred_by(function_definition.identifier)
|
929
|
+
end
|
930
|
+
|
927
931
|
if function = function_named(function_definition.identifier.value)
|
928
932
|
function.declarations_and_definitions.each do |decl_or_def|
|
929
933
|
decl_or_def.mark_as_referred_by(function_definition.identifier)
|
data/lib/adlint/cpp/eval.rb
CHANGED
@@ -684,14 +684,19 @@ module Cpp #:nodoc:
|
|
684
684
|
include_paths += Traits.instance.of_project.include_path
|
685
685
|
include_paths += Traits.instance.of_compiler.include_path
|
686
686
|
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
result
|
692
|
-
|
687
|
+
base_fpath = Pathname.new(basename)
|
688
|
+
if base_fpath.absolute? && base_fpath.readable?
|
689
|
+
return [base_fpath]
|
690
|
+
else
|
691
|
+
result = []
|
692
|
+
include_paths.each do |dpath|
|
693
|
+
fpath = dpath.join(base_fpath)
|
694
|
+
fpath = Pathname.new(fpath.to_s.gsub(/\\\\|\\/, "/"))
|
695
|
+
result.push(fpath) if fpath.readable?
|
696
|
+
break if result.size == max_num
|
697
|
+
end
|
698
|
+
result
|
693
699
|
end
|
694
|
-
result
|
695
700
|
end
|
696
701
|
|
697
702
|
def resolve_first_system_header(basename)
|
@@ -706,14 +711,19 @@ module Cpp #:nodoc:
|
|
706
711
|
include_paths = Traits.instance.of_project.include_path
|
707
712
|
include_paths += Traits.instance.of_compiler.include_path
|
708
713
|
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
result
|
714
|
-
|
714
|
+
base_fpath = Pathname.new(basename)
|
715
|
+
if base_fpath.absolute? && base_fpath.readable?
|
716
|
+
return [base_fpath]
|
717
|
+
else
|
718
|
+
result = []
|
719
|
+
include_paths.each do |dpath|
|
720
|
+
fpath = dpath.join(base_fpath)
|
721
|
+
fpath = Pathname.new(fpath.to_s.gsub(/\\\\|\\/, "/"))
|
722
|
+
result.push(fpath) if fpath.readable?
|
723
|
+
break if result.size == max_num
|
724
|
+
end
|
725
|
+
result
|
715
726
|
end
|
716
|
-
result
|
717
727
|
end
|
718
728
|
|
719
729
|
def macro_defined?(context, identifier)
|