adlint 1.8.10 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +261 -3
- data/MANIFEST +25 -1
- data/NEWS +25 -5
- data/Rakefile +11 -0
- data/TODO +0 -1
- data/etc/mesg.d/en_US/messages.yml +1 -1
- data/etc/mesg.d/ja_JP/messages.yml +1 -1
- data/features/message_detection/W0001.feature +41 -0
- data/features/message_detection/W0002.feature +68 -0
- data/features/message_detection/W0003.feature +134 -0
- data/features/message_detection/W0007.feature +264 -0
- data/features/message_detection/W0010.feature +75 -0
- data/features/message_detection/W0013.feature +189 -0
- data/features/message_detection/W0109.feature +50 -0
- data/features/message_detection/W0583.feature +30 -0
- data/features/message_detection/W0606.feature +20 -0
- data/features/message_detection/W0698.feature +20 -0
- data/features/message_detection/W0699.feature +21 -0
- data/features/message_detection/W0703.feature +73 -0
- data/features/message_detection/W0716.feature +67 -0
- data/features/message_detection/W0717.feature +64 -0
- data/features/message_detection/W0718.feature +64 -0
- data/features/message_detection/W0723.feature +18 -0
- data/features/message_detection/W1031.feature +328 -0
- data/features/step_definitions/message_detection_steps.rb +45 -0
- data/features/support/env.rb +58 -0
- data/lib/adlint/c/branch.rb +16 -23
- data/lib/adlint/c/code.rb +1 -12
- data/lib/adlint/c/conv.rb +4 -4
- data/lib/adlint/c/ctrlexpr.rb +10 -6
- data/lib/adlint/c/domain.rb +2 -2
- data/lib/adlint/c/expr.rb +11 -33
- data/lib/adlint/c/format.rb +6 -6
- data/lib/adlint/c/interp.rb +137 -80
- data/lib/adlint/c/mediator.rb +5 -2
- data/lib/adlint/c/message.rb +123 -140
- data/lib/adlint/c/message_shima.rb +44 -0
- data/lib/adlint/c/object.rb +93 -26
- data/lib/adlint/c/option.rb +53 -0
- data/lib/adlint/c/phase.rb +4 -1
- data/lib/adlint/c/type.rb +112 -46
- data/lib/adlint/c.rb +1 -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 +35 -28
- data/share/doc/users_guide_en.texi +30 -22
- data/share/doc/users_guide_ja.html +35 -31
- data/share/doc/users_guide_ja.texi +30 -24
- data/spec/adlint/c/type_spec.rb +110 -0
- data/spec/conf.d/default_traits.yml +216 -0
- data/spec/conf.d/empty_cinit.h +11 -0
- data/spec/conf.d/empty_pinit.h +11 -0
- data/spec/spec_helper.rb +49 -0
- metadata +27 -3
- data/spec/MUST_WRITE_SPECS_WITH_RSPEC +0 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
require "aruba/cucumber"
|
2
|
+
|
3
|
+
NOARCH_TRAITS = <<EOF
|
4
|
+
version: "1.0.0"
|
5
|
+
|
6
|
+
project_traits:
|
7
|
+
project_name: "features"
|
8
|
+
include_path:
|
9
|
+
initial_header: "empty_pinit.h"
|
10
|
+
coding_style:
|
11
|
+
indent_style: "K&R"
|
12
|
+
tab_width: 8
|
13
|
+
indent_width: 4
|
14
|
+
file_encoding:
|
15
|
+
|
16
|
+
compiler_traits:
|
17
|
+
initial_header: "empty_cinit.h"
|
18
|
+
standard_type:
|
19
|
+
char_size: 8
|
20
|
+
char_alignment: 8
|
21
|
+
short_size: 16
|
22
|
+
short_alignment: 16
|
23
|
+
int_size: 32
|
24
|
+
int_alignment: 32
|
25
|
+
long_size: 32
|
26
|
+
long_alignment: 32
|
27
|
+
long_long_size: 64
|
28
|
+
long_long_alignment: 64
|
29
|
+
float_size: 32
|
30
|
+
float_alignment: 32
|
31
|
+
double_size: 64
|
32
|
+
double_alignment: 64
|
33
|
+
long_double_size: 96
|
34
|
+
long_double_alignment: 96
|
35
|
+
code_ptr_size: 32
|
36
|
+
code_ptr_alignment: 32
|
37
|
+
data_ptr_size: 32
|
38
|
+
data_ptr_alignment: 32
|
39
|
+
char_as_unsigned_char: true
|
40
|
+
include_path:
|
41
|
+
arithmetic:
|
42
|
+
logical_right_shift: true
|
43
|
+
extension_substitution:
|
44
|
+
arbitrary_substitution:
|
45
|
+
"typeof": "__typeof__"
|
46
|
+
"__typeof": "__typeof__"
|
47
|
+
"alignof": "__alignof__"
|
48
|
+
"__alignof": "__alignof__"
|
49
|
+
identifier_max: 128
|
50
|
+
|
51
|
+
linker_traits:
|
52
|
+
identifier_max: 128
|
53
|
+
identifier_ignore_case: false
|
54
|
+
|
55
|
+
message_traits:
|
56
|
+
language: "ja_JP"
|
57
|
+
change_list:
|
58
|
+
EOF
|
data/lib/adlint/c/branch.rb
CHANGED
@@ -30,19 +30,13 @@
|
|
30
30
|
#++
|
31
31
|
|
32
32
|
require "adlint/c/ctrlexpr"
|
33
|
+
require "adlint/c/option"
|
33
34
|
|
34
35
|
module AdLint #:nodoc:
|
35
36
|
module C #:nodoc:
|
36
37
|
|
37
38
|
class Branch
|
38
|
-
|
39
|
-
NARROWING = :narrowing
|
40
|
-
WIDENING = :widening
|
41
|
-
FIRST = :first
|
42
|
-
FINAL = :final
|
43
|
-
SMOTHER_BREAK = :smother_break
|
44
|
-
IMPLICIT_CONDITION = :implicit_condition
|
45
|
-
end
|
39
|
+
include BranchOptions
|
46
40
|
|
47
41
|
def initialize(branch_group, *options)
|
48
42
|
@group = branch_group
|
@@ -61,27 +55,27 @@ module C #:nodoc:
|
|
61
55
|
end
|
62
56
|
|
63
57
|
def narrowing?
|
64
|
-
@options.include?(
|
58
|
+
@options.include?(NARROWING)
|
65
59
|
end
|
66
60
|
|
67
61
|
def widening?
|
68
|
-
@options.include?(
|
62
|
+
@options.include?(WIDENING)
|
69
63
|
end
|
70
64
|
|
71
65
|
def first?
|
72
|
-
@options.include?(
|
66
|
+
@options.include?(FIRST)
|
73
67
|
end
|
74
68
|
|
75
69
|
def final?
|
76
|
-
@options.include?(
|
70
|
+
@options.include?(FINAL)
|
77
71
|
end
|
78
72
|
|
79
73
|
def smother_break?
|
80
|
-
@options.include?(
|
74
|
+
@options.include?(SMOTHER_BREAK)
|
81
75
|
end
|
82
76
|
|
83
77
|
def implicit_condition?
|
84
|
-
@options.include?(
|
78
|
+
@options.include?(IMPLICIT_CONDITION)
|
85
79
|
end
|
86
80
|
|
87
81
|
def execute(interpreter, expression = nil, &block)
|
@@ -134,7 +128,7 @@ module C #:nodoc:
|
|
134
128
|
else
|
135
129
|
raise "branch must be for narrowing or widening."
|
136
130
|
end
|
137
|
-
@group.
|
131
|
+
@group.all_controlling_variables_value_exist?
|
138
132
|
end
|
139
133
|
|
140
134
|
def rethrow_break_event
|
@@ -152,9 +146,8 @@ module C #:nodoc:
|
|
152
146
|
end
|
153
147
|
|
154
148
|
class BranchGroup
|
155
|
-
|
156
|
-
|
157
|
-
end
|
149
|
+
include BranchOptions
|
150
|
+
include BranchGroupOptions
|
158
151
|
|
159
152
|
def initialize(environment, *options)
|
160
153
|
@environment = environment
|
@@ -169,11 +162,11 @@ module C #:nodoc:
|
|
169
162
|
end
|
170
163
|
|
171
164
|
def complete?
|
172
|
-
@options.include?(
|
165
|
+
@options.include?(COMPLETE)
|
173
166
|
end
|
174
167
|
|
175
168
|
def create_first_branch(*options)
|
176
|
-
new_branch = Branch.new(self,
|
169
|
+
new_branch = Branch.new(self, FIRST, *options)
|
177
170
|
@branches.push(new_branch)
|
178
171
|
new_branch
|
179
172
|
end
|
@@ -184,15 +177,15 @@ module C #:nodoc:
|
|
184
177
|
new_branch
|
185
178
|
end
|
186
179
|
|
187
|
-
def
|
180
|
+
def all_controlling_variables
|
188
181
|
@branches.map { |branch|
|
189
182
|
branch.controlling_expression ?
|
190
183
|
branch.controlling_expression.affected_variables : []
|
191
184
|
}.flatten.uniq
|
192
185
|
end
|
193
186
|
|
194
|
-
def
|
195
|
-
|
187
|
+
def all_controlling_variables_value_exist?
|
188
|
+
all_controlling_variables.all? { |variable| variable.value.exist? }
|
196
189
|
end
|
197
190
|
|
198
191
|
def all_branches_break_with_break?
|
data/lib/adlint/c/code.rb
CHANGED
@@ -213,10 +213,7 @@ module C #:nodoc:
|
|
213
213
|
def initialize(context)
|
214
214
|
super
|
215
215
|
interp = context[:c_interpreter]
|
216
|
-
interp.
|
217
|
-
interp.on_block_started += method(:enter_block)
|
218
|
-
interp.on_block_ended += method(:leave_block)
|
219
|
-
@block_level = 0
|
216
|
+
interp.on_function_defined += method(:extract_function)
|
220
217
|
end
|
221
218
|
|
222
219
|
private
|
@@ -237,14 +234,6 @@ module C #:nodoc:
|
|
237
234
|
function_definition.lines)
|
238
235
|
end
|
239
236
|
end
|
240
|
-
|
241
|
-
def enter_block(*)
|
242
|
-
@block_level += 1
|
243
|
-
end
|
244
|
-
|
245
|
-
def leave_block(*)
|
246
|
-
@block_level -= 1
|
247
|
-
end
|
248
237
|
end
|
249
238
|
|
250
239
|
class LabelDefExtraction < CodeExtraction
|
data/lib/adlint/c/conv.rb
CHANGED
@@ -48,7 +48,7 @@ module C #:nodoc:
|
|
48
48
|
return original unless original.type.integer?
|
49
49
|
|
50
50
|
promoted_type = original.type.integer_promoted_type
|
51
|
-
if
|
51
|
+
if original.type.same_as?(promoted_type)
|
52
52
|
original
|
53
53
|
else
|
54
54
|
do_conversion(original, promoted_type) || original
|
@@ -62,13 +62,13 @@ module C #:nodoc:
|
|
62
62
|
|
63
63
|
arith_type = lhs_original.type.arithmetic_type_with(rhs_original.type)
|
64
64
|
|
65
|
-
if
|
65
|
+
if lhs_original.type.same_as?(arith_type)
|
66
66
|
lhs_converted = lhs_original
|
67
67
|
else
|
68
68
|
lhs_converted = do_conversion(lhs_original, arith_type) || lhs_original
|
69
69
|
end
|
70
70
|
|
71
|
-
if
|
71
|
+
if rhs_original.type.same_as?(arith_type)
|
72
72
|
rhs_converted = rhs_original
|
73
73
|
else
|
74
74
|
rhs_converted = do_conversion(rhs_original, arith_type) || rhs_original
|
@@ -79,7 +79,7 @@ module C #:nodoc:
|
|
79
79
|
|
80
80
|
def do_default_argument_promotion(original)
|
81
81
|
promoted_type = original.type.argument_promoted_type
|
82
|
-
if
|
82
|
+
if original.type.same_as?(promoted_type)
|
83
83
|
original
|
84
84
|
else
|
85
85
|
do_conversion(original, promoted_type) || original
|
data/lib/adlint/c/ctrlexpr.rb
CHANGED
@@ -64,12 +64,12 @@ module C #:nodoc:
|
|
64
64
|
new_manip = ValueDomainNarrower.new(@interpreter, expression)
|
65
65
|
begin
|
66
66
|
if @branch.implicit_condition?
|
67
|
-
@interpreter.
|
67
|
+
@interpreter._quiet = true
|
68
68
|
end
|
69
69
|
new_manip.prepare!
|
70
70
|
ensure
|
71
71
|
if @branch.implicit_condition?
|
72
|
-
@interpreter.
|
72
|
+
@interpreter._quiet = false
|
73
73
|
end
|
74
74
|
end
|
75
75
|
else
|
@@ -86,12 +86,12 @@ module C #:nodoc:
|
|
86
86
|
new_manip = ValueDomainWidener.new(@interpreter, expression)
|
87
87
|
begin
|
88
88
|
if @branch.implicit_condition?
|
89
|
-
@interpreter.
|
89
|
+
@interpreter._quiet = true
|
90
90
|
end
|
91
91
|
new_manip.prepare!
|
92
92
|
ensure
|
93
93
|
if @branch.implicit_condition?
|
94
|
-
@interpreter.
|
94
|
+
@interpreter._quiet = false
|
95
95
|
end
|
96
96
|
end
|
97
97
|
else
|
@@ -595,7 +595,7 @@ module C #:nodoc:
|
|
595
595
|
|
596
596
|
private
|
597
597
|
def commit_changes(narrowing)
|
598
|
-
@branch_group.
|
598
|
+
@branch_group.all_controlling_variables.each do |variable|
|
599
599
|
variable.narrow_value_domain!(:==, variable.type.arbitrary_value)
|
600
600
|
end
|
601
601
|
true
|
@@ -614,7 +614,7 @@ module C #:nodoc:
|
|
614
614
|
|
615
615
|
private
|
616
616
|
def commit_changes(narrowing)
|
617
|
-
@branch_group.
|
617
|
+
@branch_group.all_controlling_variables.each do |variable|
|
618
618
|
variable.widen_value_domain!(:==, variable.type.arbitrary_value)
|
619
619
|
end
|
620
620
|
true
|
@@ -649,6 +649,10 @@ module C #:nodoc:
|
|
649
649
|
@children.each do |narrowing|
|
650
650
|
@narrowed_values = narrowing.narrowed_values.merge(@narrowed_values)
|
651
651
|
end
|
652
|
+
ensure
|
653
|
+
if sequence_point = node.subsequent_sequence_point
|
654
|
+
notify_sequence_point_reached(sequence_point)
|
655
|
+
end
|
652
656
|
end
|
653
657
|
|
654
658
|
def ensure_result_equal_to(value)
|
data/lib/adlint/c/domain.rb
CHANGED
@@ -4849,10 +4849,10 @@ module C #:nodoc:
|
|
4849
4849
|
ValueDomain.of_unlimited
|
4850
4850
|
else
|
4851
4851
|
case
|
4852
|
-
when lhs_domain.value < 0
|
4853
|
-
ValueDomain.of_unlimited
|
4854
4852
|
when lhs_domain.value >= 0
|
4855
4853
|
ValueDomain.greater_than(0)
|
4854
|
+
when lhs_domain.value < 0
|
4855
|
+
ValueDomain.less_than(0)
|
4856
4856
|
end
|
4857
4857
|
end
|
4858
4858
|
end
|
data/lib/adlint/c/expr.rb
CHANGED
@@ -815,7 +815,7 @@ module C #:nodoc:
|
|
815
815
|
rhs_object, rhs_variable)
|
816
816
|
end
|
817
817
|
|
818
|
-
if
|
818
|
+
if rhs_variable.type.same_as?(lhs_variable.type)
|
819
819
|
rhs_converted = rhs_variable
|
820
820
|
else
|
821
821
|
rhs_converted =
|
@@ -911,7 +911,7 @@ module C #:nodoc:
|
|
911
911
|
notify_multiplicative_expr_evaled(node, lhs_variable, rhs_variable,
|
912
912
|
result_variable)
|
913
913
|
|
914
|
-
if
|
914
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
915
915
|
result_converted = result_variable
|
916
916
|
else
|
917
917
|
result_converted =
|
@@ -962,7 +962,7 @@ module C #:nodoc:
|
|
962
962
|
notify_multiplicative_expr_evaled(node, lhs_variable, rhs_variable,
|
963
963
|
result_variable)
|
964
964
|
|
965
|
-
if
|
965
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
966
966
|
result_converted = result_variable
|
967
967
|
else
|
968
968
|
result_converted =
|
@@ -1013,7 +1013,7 @@ module C #:nodoc:
|
|
1013
1013
|
notify_multiplicative_expr_evaled(node, lhs_variable, rhs_variable,
|
1014
1014
|
result_variable)
|
1015
1015
|
|
1016
|
-
if
|
1016
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1017
1017
|
result_converted = result_variable
|
1018
1018
|
else
|
1019
1019
|
result_converted =
|
@@ -1063,7 +1063,7 @@ module C #:nodoc:
|
|
1063
1063
|
notify_additive_expr_evaled(node, lhs_variable, rhs_variable,
|
1064
1064
|
result_variable)
|
1065
1065
|
|
1066
|
-
if
|
1066
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1067
1067
|
result_converted = result_variable
|
1068
1068
|
else
|
1069
1069
|
result_converted =
|
@@ -1113,7 +1113,7 @@ module C #:nodoc:
|
|
1113
1113
|
notify_additive_expr_evaled(node, lhs_variable, rhs_variable,
|
1114
1114
|
result_variable)
|
1115
1115
|
|
1116
|
-
if
|
1116
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1117
1117
|
result_converted = result_variable
|
1118
1118
|
else
|
1119
1119
|
result_converted =
|
@@ -1171,7 +1171,7 @@ module C #:nodoc:
|
|
1171
1171
|
notify_shift_expr_evaled(node, lhs_converted, rhs_converted,
|
1172
1172
|
result_variable)
|
1173
1173
|
|
1174
|
-
if
|
1174
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1175
1175
|
result_converted = result_variable
|
1176
1176
|
else
|
1177
1177
|
result_converted =
|
@@ -1229,7 +1229,7 @@ module C #:nodoc:
|
|
1229
1229
|
notify_shift_expr_evaled(node, lhs_converted, rhs_converted,
|
1230
1230
|
result_variable)
|
1231
1231
|
|
1232
|
-
if
|
1232
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1233
1233
|
result_converted = result_variable
|
1234
1234
|
else
|
1235
1235
|
result_converted =
|
@@ -1278,7 +1278,7 @@ module C #:nodoc:
|
|
1278
1278
|
|
1279
1279
|
notify_and_expr_evaled(node, lhs_variable, rhs_variable, result_variable)
|
1280
1280
|
|
1281
|
-
if
|
1281
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1282
1282
|
result_converted = result_variable
|
1283
1283
|
else
|
1284
1284
|
result_converted =
|
@@ -1328,7 +1328,7 @@ module C #:nodoc:
|
|
1328
1328
|
notify_exclusive_or_expr_evaled(node, lhs_variable, rhs_variable,
|
1329
1329
|
result_variable)
|
1330
1330
|
|
1331
|
-
if
|
1331
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1332
1332
|
result_converted = result_variable
|
1333
1333
|
else
|
1334
1334
|
result_converted =
|
@@ -1378,7 +1378,7 @@ module C #:nodoc:
|
|
1378
1378
|
notify_inclusive_or_expr_evaled(node, lhs_variable, rhs_variable,
|
1379
1379
|
result_variable)
|
1380
1380
|
|
1381
|
-
if
|
1381
|
+
if result_variable.type.same_as?(lhs_variable.type)
|
1382
1382
|
result_converted = result_variable
|
1383
1383
|
else
|
1384
1384
|
result_converted =
|
@@ -1796,28 +1796,6 @@ module C #:nodoc:
|
|
1796
1796
|
result
|
1797
1797
|
end
|
1798
1798
|
|
1799
|
-
def visit_conditional_expression(node)
|
1800
|
-
checkpoint(node.location)
|
1801
|
-
|
1802
|
-
condition_variable = object_to_variable(node.condition.accept(self))
|
1803
|
-
|
1804
|
-
case
|
1805
|
-
when condition_variable.value.must_be_true?
|
1806
|
-
result_variable = object_to_variable(node.then_expression.accept(self))
|
1807
|
-
when condition_variable.value.must_be_false?
|
1808
|
-
result_variable = object_to_variable(node.else_expression.accept(self))
|
1809
|
-
else
|
1810
|
-
then_var = object_to_variable(node.then_expression.accept(self))
|
1811
|
-
else_var = object_to_variable(node.else_expression.accept(self))
|
1812
|
-
result_value = then_var.value.single_value_unified_with(else_var.value)
|
1813
|
-
result_variable = temporary_variable(then_var.type, result_value)
|
1814
|
-
end
|
1815
|
-
|
1816
|
-
notify_conditional_expr_evaled(node, condition_variable, result_variable)
|
1817
|
-
|
1818
|
-
result_variable
|
1819
|
-
end
|
1820
|
-
|
1821
1799
|
def visit_simple_assignment_expression(node)
|
1822
1800
|
checkpoint(node.location)
|
1823
1801
|
|
data/lib/adlint/c/format.rb
CHANGED
@@ -765,15 +765,15 @@ module C #:nodoc:
|
|
765
765
|
# Boolean -- True if types of arguments match this directive.
|
766
766
|
def acceptable?
|
767
767
|
if @field_width_argument
|
768
|
-
unless
|
769
|
-
|
768
|
+
unless @field_width_argument.type.convertible?(signed_int_type) ||
|
769
|
+
@field_width_argument.type.convertible?(unsigned_int_type)
|
770
770
|
return false
|
771
771
|
end
|
772
772
|
end
|
773
773
|
|
774
774
|
if @precision_argument
|
775
|
-
unless
|
776
|
-
|
775
|
+
unless @precision_argument.type.convertible?(signed_int_type) ||
|
776
|
+
@precision_argument.type.convertible?(unsigned_int_type)
|
777
777
|
return false
|
778
778
|
end
|
779
779
|
end
|
@@ -781,7 +781,7 @@ module C #:nodoc:
|
|
781
781
|
if @conversion_argument
|
782
782
|
if argument_types
|
783
783
|
argument_types.any? do |arg_type|
|
784
|
-
|
784
|
+
@conversion_argument.type.convertible?(arg_type)
|
785
785
|
end
|
786
786
|
else
|
787
787
|
true
|
@@ -2502,7 +2502,7 @@ module C #:nodoc:
|
|
2502
2502
|
if @conversion_argument
|
2503
2503
|
if argument_types
|
2504
2504
|
argument_types.any? do |arg_type|
|
2505
|
-
|
2505
|
+
@conversion_argument.type.convertible?(arg_type)
|
2506
2506
|
end
|
2507
2507
|
else
|
2508
2508
|
true
|