adlint 3.0.10 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +67 -0
- data/MANIFEST +2 -0
- data/NEWS +10 -3
- data/etc/mesg.d/c_builtin/en_US/messages.yml +29 -1
- data/etc/mesg.d/c_builtin/ja_JP/messages.yml +29 -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/W0003.feature +5 -0
- data/features/code_check/W0023.feature +32 -0
- data/features/code_check/W0024.feature +22 -0
- data/features/code_check/W0093.feature +71 -0
- data/features/code_check/W0097.feature +4 -0
- data/features/code_check/W0100.feature +10 -0
- data/features/code_check/W0119.feature +8 -0
- data/features/code_check/W0133.feature +8 -0
- data/features/code_check/W0134.feature +8 -0
- data/features/code_check/W0136.feature +8 -0
- data/features/code_check/W0138.feature +8 -0
- data/features/code_check/W0140.feature +8 -0
- data/features/code_check/W0142.feature +8 -0
- data/features/code_check/W0143.feature +8 -0
- data/features/code_check/W0144.feature +8 -0
- data/features/code_check/W0145.feature +8 -0
- data/features/code_check/W0146.feature +8 -0
- data/features/code_check/W0147.feature +8 -0
- data/features/code_check/W0148.feature +8 -0
- data/features/code_check/W0149.feature +8 -0
- data/features/code_check/W0150.feature +8 -0
- data/features/code_check/W0151.feature +8 -0
- data/features/code_check/W0152.feature +8 -0
- data/features/code_check/W0153.feature +8 -0
- data/features/code_check/W0154.feature +8 -0
- data/features/code_check/W0155.feature +8 -0
- data/features/code_check/W0156.feature +8 -0
- data/features/code_check/W0157.feature +8 -0
- data/features/code_check/W0158.feature +8 -0
- data/features/code_check/W0159.feature +8 -0
- data/features/code_check/W0160.feature +8 -0
- data/features/code_check/W0161.feature +8 -0
- data/features/code_check/W0162.feature +8 -0
- data/features/code_check/W0163.feature +8 -0
- data/features/code_check/W0164.feature +8 -0
- data/features/code_check/W0165.feature +8 -0
- data/features/code_check/W0166.feature +8 -0
- data/features/code_check/W0167.feature +8 -0
- data/features/code_check/W0168.feature +8 -0
- data/features/code_check/W0169.feature +8 -0
- data/features/code_check/W0170.feature +8 -0
- data/features/code_check/W0171.feature +8 -0
- data/features/code_check/W0172.feature +8 -0
- data/features/code_check/W0173.feature +8 -0
- data/features/code_check/W0174.feature +8 -0
- data/features/code_check/W0175.feature +8 -0
- data/features/code_check/W0176.feature +8 -0
- data/features/code_check/W0177.feature +8 -0
- data/features/code_check/W0178.feature +8 -0
- data/features/code_check/W0179.feature +8 -0
- data/features/code_check/W0180.feature +8 -0
- data/features/code_check/W0181.feature +8 -0
- data/features/code_check/W0250.feature +8 -0
- data/features/code_check/W0422.feature +194 -0
- data/features/code_check/W0459.feature +16 -0
- data/features/code_check/W0460.feature +342 -0
- data/features/code_check/W0461.feature +5 -0
- data/features/code_check/W0497.feature +12 -0
- data/features/code_check/W0499.feature +6 -0
- data/features/code_check/W0502.feature +6 -0
- data/features/code_check/W0570.feature +47 -0
- data/features/code_check/W0573.feature +8 -0
- data/features/code_check/W0582.feature +4 -0
- data/features/code_check/W0583.feature +4 -0
- data/features/code_check/W0584.feature +10 -0
- data/features/code_check/W0599.feature +10 -0
- data/features/code_check/W0644.feature +2 -0
- data/features/code_check/W0649.feature +14 -0
- data/features/code_check/W0650.feature +12 -0
- data/features/code_check/W0685.feature +10 -0
- data/features/code_check/W0686.feature +8 -0
- data/features/code_check/W0711.feature +2 -0
- data/features/code_check/W0712.feature +2 -0
- data/features/code_check/W0713.feature +2 -0
- data/features/code_check/W0714.feature +2 -0
- data/features/code_check/W0715.feature +2 -0
- data/features/code_check/W0718.feature +2 -0
- data/features/code_check/W0719.feature +8 -0
- data/features/code_check/W0732.feature +18 -0
- data/features/code_check/W0733.feature +18 -0
- data/features/code_check/W0734.feature +24 -0
- data/features/code_check/W0735.feature +24 -0
- data/features/code_check/W0747.feature +8 -0
- data/features/code_check/W0749.feature +8 -0
- data/features/code_check/W0750.feature +8 -0
- data/features/code_check/W0753.feature +8 -0
- data/features/code_check/W0754.feature +8 -0
- data/features/code_check/W0759.feature +8 -0
- data/features/code_check/W0760.feature +8 -0
- data/features/code_check/W0761.feature +8 -0
- data/features/code_check/W0762.feature +8 -0
- data/features/code_check/W0794.feature +6 -0
- data/features/code_check/W1050.feature +8 -0
- data/features/code_check/W1066.feature +8 -0
- data/features/code_check/W1067.feature +8 -0
- data/features/code_check/W1068.feature +8 -0
- data/features/code_check/W1071.feature +4 -0
- data/features/code_check/W9003.feature +2 -0
- data/lib/adlint/cc1.rb +1 -0
- data/lib/adlint/cc1/branch.rb +34 -13
- data/lib/adlint/cc1/conv.rb +3 -3
- data/lib/adlint/cc1/ctrlexpr.rb +12 -7
- data/lib/adlint/cc1/environ.rb +12 -2
- data/lib/adlint/cc1/expr.rb +10 -8
- data/lib/adlint/cc1/interp.rb +56 -49
- data/lib/adlint/cc1/mediator.rb +9 -5
- data/lib/adlint/cc1/object.rb +37 -34
- data/lib/adlint/cc1/trace.rb +287 -0
- data/lib/adlint/cc1/type.rb +15 -15
- data/lib/adlint/cc1/value.rb +823 -427
- data/lib/adlint/cpp/eval.rb +5 -2
- data/lib/adlint/cpp/source.rb +21 -22
- data/lib/adlint/exam/c_builtin/cc1_check.rb +1636 -1067
- data/lib/adlint/exam/c_builtin/cc1_check_shima.rb +28 -22
- data/lib/adlint/exam/c_builtin/cc1_code.rb +4 -4
- data/lib/adlint/exam/c_builtin/cc1_metric.rb +14 -14
- data/lib/adlint/location.rb +5 -7
- data/lib/adlint/metric.rb +2 -2
- data/lib/adlint/prelude.rb +6 -2
- data/lib/adlint/report.rb +2 -2
- data/lib/adlint/version.rb +3 -3
- data/share/doc/developers_guide_ja.html +10 -4
- data/share/doc/developers_guide_ja.texi +8 -2
- data/share/doc/users_guide_en.html +679 -72
- data/share/doc/users_guide_en.texi +557 -12
- data/share/doc/users_guide_ja.html +678 -74
- data/share/doc/users_guide_ja.texi +554 -13
- data/spec/adlint/cc1/ctrlexpr_spec.rb +20 -11
- data/spec/adlint/cc1/domain_spec.rb +9 -0
- metadata +4 -2
data/lib/adlint/cc1/conv.rb
CHANGED
@@ -108,7 +108,7 @@ module Cc1 #:nodoc:
|
|
108
108
|
when from_type.pointer?
|
109
109
|
void_pointer?(from_type) || void_pointer?(to_type)
|
110
110
|
when from_type.integer?
|
111
|
-
!from_type.enum? && from_val.
|
111
|
+
!from_type.enum? && from_val.test_must_be_null.true?
|
112
112
|
else
|
113
113
|
void_pointer?(to_type)
|
114
114
|
end
|
@@ -121,12 +121,12 @@ module Cc1 #:nodoc:
|
|
121
121
|
case
|
122
122
|
when orig_var.type.signed? && to_type.unsigned?
|
123
123
|
min_val = scalar_value_of(to_type.min)
|
124
|
-
if (orig_var.value < min_val).
|
124
|
+
if (orig_var.value < min_val).test_may_be_true.true?
|
125
125
|
return min_val - orig_var.value + scalar_value_of(1)
|
126
126
|
end
|
127
127
|
when orig_var.type.unsigned? && to_type.signed?
|
128
128
|
max_val = scalar_value_of(to_type.max)
|
129
|
-
if (orig_var.value > max_val).
|
129
|
+
if (orig_var.value > max_val).test_may_be_true.true?
|
130
130
|
return max_val - orig_var.value + scalar_value_of(1)
|
131
131
|
end
|
132
132
|
end
|
data/lib/adlint/cc1/ctrlexpr.rb
CHANGED
@@ -67,10 +67,10 @@ module Cc1 #:nodoc:
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def ensure_true_by_narrowing(alt_expr = nil)
|
70
|
-
|
70
|
+
expr = alt_expr || @target_expr
|
71
71
|
|
72
|
-
if
|
73
|
-
new_manip = ValueDomainNarrower.new(@interpreter,
|
72
|
+
if expr
|
73
|
+
new_manip = ValueDomainNarrower.new(@interpreter, expr)
|
74
74
|
if @branch.implicit_condition?
|
75
75
|
eval_quietly { new_manip.prepare! }
|
76
76
|
else
|
@@ -85,10 +85,10 @@ module Cc1 #:nodoc:
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def ensure_true_by_widening(alt_expr = nil)
|
88
|
-
|
88
|
+
expr = alt_expr || @target_expr
|
89
89
|
|
90
|
-
if
|
91
|
-
new_manip = ValueDomainWidener.new(@interpreter,
|
90
|
+
if expr
|
91
|
+
new_manip = ValueDomainWidener.new(@interpreter, expr)
|
92
92
|
if @branch.implicit_condition?
|
93
93
|
eval_quietly { new_manip.prepare! }
|
94
94
|
else
|
@@ -124,6 +124,10 @@ module Cc1 #:nodoc:
|
|
124
124
|
@target_expr && !collect_logical_and_expressions(@target_expr).empty?
|
125
125
|
end
|
126
126
|
|
127
|
+
def to_expr
|
128
|
+
@target_expr
|
129
|
+
end
|
130
|
+
|
127
131
|
private
|
128
132
|
def eval_quietly(&block)
|
129
133
|
originally_quiet = @interpreter.quiet?
|
@@ -919,7 +923,7 @@ module Cc1 #:nodoc:
|
|
919
923
|
@phantom_val
|
920
924
|
end
|
921
925
|
|
922
|
-
def assign!(val)
|
926
|
+
def assign!(val, *)
|
923
927
|
@phantom_val = val
|
924
928
|
end
|
925
929
|
|
@@ -932,6 +936,7 @@ module Cc1 #:nodoc:
|
|
932
936
|
end
|
933
937
|
|
934
938
|
Summary = Struct.new(:object_id, :name, :type, :value)
|
939
|
+
private_constant :Summary
|
935
940
|
end
|
936
941
|
|
937
942
|
end
|
data/lib/adlint/cc1/environ.rb
CHANGED
@@ -81,8 +81,10 @@ module Cc1 #:nodoc:
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def enter_branch_group(*opts)
|
84
|
-
@branch_groups[@branch_depth]
|
85
|
-
|
84
|
+
if trunk_group = @branch_groups[@branch_depth - 1]
|
85
|
+
trunk = trunk_group.current_branch
|
86
|
+
end
|
87
|
+
@branch_groups[@branch_depth] = BranchGroup.new(self, trunk, *opts)
|
86
88
|
end
|
87
89
|
|
88
90
|
def current_branch_group
|
@@ -105,6 +107,14 @@ module Cc1 #:nodoc:
|
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
110
|
+
def current_branch
|
111
|
+
if cur_group = current_branch_group
|
112
|
+
cur_group.current_branch
|
113
|
+
else
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
108
118
|
def leave_branch
|
109
119
|
# NOTE: Don't delete current branch!
|
110
120
|
@branch_depth -= 1
|
data/lib/adlint/cc1/expr.rb
CHANGED
@@ -304,7 +304,7 @@ module Cc1 #:nodoc:
|
|
304
304
|
notify_sequence_point_reached(SequencePoint.new(node.lhs_operand))
|
305
305
|
lhs_val = lhs_var.value
|
306
306
|
|
307
|
-
if lhs_val.scalar? && lhs_val.
|
307
|
+
if lhs_val.scalar? && lhs_val.test_must_be_false.true?
|
308
308
|
# NOTE: Doing the short-circuit evaluation.
|
309
309
|
notify_variable_value_referred(node, lhs_var)
|
310
310
|
return create_tmpvar(int_t, scalar_value_of_false)
|
@@ -356,7 +356,7 @@ module Cc1 #:nodoc:
|
|
356
356
|
notify_sequence_point_reached(SequencePoint.new(node.lhs_operand))
|
357
357
|
lhs_val = lhs_var.value
|
358
358
|
|
359
|
-
if lhs_val.scalar? && lhs_val.
|
359
|
+
if lhs_val.scalar? && lhs_val.test_must_be_true.true?
|
360
360
|
# NOTE: Doing the short-circuit evaluation.
|
361
361
|
notify_variable_value_referred(node, lhs_var)
|
362
362
|
return create_tmpvar(int_t, scalar_value_of_true)
|
@@ -634,7 +634,7 @@ module Cc1 #:nodoc:
|
|
634
634
|
# _notify_variable_value_referred(node, var)
|
635
635
|
|
636
636
|
if var.value.scalar?
|
637
|
-
var.assign!(var.value + scalar_value_of(1))
|
637
|
+
var.assign!(var.value + scalar_value_of(1), node, current_branch)
|
638
638
|
_notify_variable_value_updated(node, var)
|
639
639
|
end
|
640
640
|
|
@@ -657,7 +657,7 @@ module Cc1 #:nodoc:
|
|
657
657
|
# _notify_variable_value_referred(node, var)
|
658
658
|
|
659
659
|
if var.value.scalar?
|
660
|
-
var.assign!(var.value - scalar_value_of(1))
|
660
|
+
var.assign!(var.value - scalar_value_of(1), node, current_branch)
|
661
661
|
_notify_variable_value_updated(node, var)
|
662
662
|
end
|
663
663
|
|
@@ -680,7 +680,7 @@ module Cc1 #:nodoc:
|
|
680
680
|
# _notify_variable_value_referred(node, var)
|
681
681
|
|
682
682
|
if var.value.scalar?
|
683
|
-
var.assign!(var.value + scalar_value_of(1))
|
683
|
+
var.assign!(var.value + scalar_value_of(1), node, current_branch)
|
684
684
|
_notify_variable_value_updated(node, var)
|
685
685
|
end
|
686
686
|
|
@@ -703,7 +703,7 @@ module Cc1 #:nodoc:
|
|
703
703
|
# _notify_variable_value_referred(node, var)
|
704
704
|
|
705
705
|
if var.value.scalar?
|
706
|
-
var.assign!(var.value - scalar_value_of(1))
|
706
|
+
var.assign!(var.value - scalar_value_of(1), node, current_branch)
|
707
707
|
_notify_variable_value_updated(node, var)
|
708
708
|
end
|
709
709
|
|
@@ -1166,7 +1166,8 @@ module Cc1 #:nodoc:
|
|
1166
1166
|
# NOTE: Even if rhs_obj is a NamedVariable, new value will be
|
1167
1167
|
# instantiated in value-coercing.
|
1168
1168
|
# So, value-aliasing never occurs.
|
1169
|
-
|
1169
|
+
defined_val = rhs_conved.value.to_defined_value
|
1170
|
+
lhs_var.assign!(defined_val, node, current_branch)
|
1170
1171
|
_notify_variable_value_referred(node, rhs_var)
|
1171
1172
|
_notify_variable_value_updated(node, lhs_var)
|
1172
1173
|
|
@@ -1453,7 +1454,8 @@ module Cc1 #:nodoc:
|
|
1453
1454
|
|
1454
1455
|
# NOTE: Domain of the arithmetic result value will be restricted by
|
1455
1456
|
# min-max of the variable type.
|
1456
|
-
|
1457
|
+
defined_val = rhs_conved.value.to_defined_value
|
1458
|
+
lhs_var.assign!(defined_val, node, current_branch)
|
1457
1459
|
_notify_variable_value_updated(node, lhs_var)
|
1458
1460
|
|
1459
1461
|
notify_assignment_expr_evaled(node, lhs_var, rhs_conved)
|
data/lib/adlint/cc1/interp.rb
CHANGED
@@ -346,7 +346,7 @@ module Cc1 #:nodoc:
|
|
346
346
|
def_plugin_and_notifier :goto_stmt_evaled, :stmt, :label_name
|
347
347
|
|
348
348
|
# NOTE: Notified when the interpreter evaluates a return-statement.
|
349
|
-
def_plugin_and_notifier :return_stmt_evaled, :stmt, :
|
349
|
+
def_plugin_and_notifier :return_stmt_evaled, :stmt, :ret_var
|
350
350
|
|
351
351
|
# NOTE: Notified when the interpreter evaluates an implicit return.
|
352
352
|
def_plugin_and_notifier :implicit_return_evaled, :loc
|
@@ -554,7 +554,7 @@ module Cc1 #:nodoc:
|
|
554
554
|
dcl.mark_as_referred_by(node.identifier)
|
555
555
|
end
|
556
556
|
|
557
|
-
var = declare_variable(node)
|
557
|
+
var = declare_variable(node, current_branch)
|
558
558
|
notify_variable_declared(node, var)
|
559
559
|
evaluate_sequence_point(node.declarator)
|
560
560
|
end
|
@@ -572,21 +572,23 @@ module Cc1 #:nodoc:
|
|
572
572
|
# NOTE: Unable to define variable of incomplete type such as an array
|
573
573
|
# without length.
|
574
574
|
init_var, init_conved = evaluate_initializer(node)
|
575
|
-
var = define_variable(node,
|
575
|
+
var = define_variable(node, current_branch,
|
576
|
+
init_conved.value.to_defined_value)
|
576
577
|
else
|
577
578
|
# NOTE: Declare variable first in order to correctly evaluate
|
578
579
|
# sizeof-expression that refers to the defining variable in the
|
579
580
|
# initializer.
|
580
|
-
declare_variable(node)
|
581
|
+
declare_variable(node, current_branch)
|
581
582
|
init_var, init_conved = evaluate_initializer(node)
|
582
|
-
var = define_variable(node,
|
583
|
+
var = define_variable(node, current_branch,
|
584
|
+
init_conved.value.to_defined_value)
|
583
585
|
end
|
584
586
|
|
585
587
|
notify_variable_value_referred(node, init_var)
|
586
588
|
notify_variable_defined(node, var)
|
587
589
|
notify_variable_initialized(node, var, init_var)
|
588
590
|
else
|
589
|
-
notify_variable_defined(node, define_variable(node))
|
591
|
+
notify_variable_defined(node, define_variable(node, current_branch))
|
590
592
|
end
|
591
593
|
|
592
594
|
evaluate_sequence_point(node.init_declarator.declarator)
|
@@ -859,7 +861,7 @@ module Cc1 #:nodoc:
|
|
859
861
|
end
|
860
862
|
|
861
863
|
if id
|
862
|
-
var = define_variable(node.to_variable_definition,
|
864
|
+
var = define_variable(node.to_variable_definition, nil,
|
863
865
|
node.type.parameter_value)
|
864
866
|
notify_parameter_defined(node, var)
|
865
867
|
end
|
@@ -1013,11 +1015,11 @@ module Cc1 #:nodoc:
|
|
1013
1015
|
notify_if_ctrlexpr_evaled(node, ctrlexpr_val)
|
1014
1016
|
|
1015
1017
|
case
|
1016
|
-
when ctrlexpr_val.
|
1018
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1017
1019
|
branched_eval(ctrlexpr, NARROWING, FINAL, IMPLICIT_COND, COMPLETE) do
|
1018
1020
|
interpret(node.statement)
|
1019
1021
|
end
|
1020
|
-
when ctrlexpr_val.
|
1022
|
+
when ctrlexpr_val.test_may_be_true.true?
|
1021
1023
|
branched_eval(ctrlexpr, NARROWING, FINAL, IMPLICIT_COND) do
|
1022
1024
|
interpret(node.statement)
|
1023
1025
|
end
|
@@ -1047,12 +1049,12 @@ module Cc1 #:nodoc:
|
|
1047
1049
|
notify_if_else_ctrlexpr_evaled(node, ctrlexpr_val)
|
1048
1050
|
|
1049
1051
|
case
|
1050
|
-
when ctrlexpr_val.
|
1052
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1051
1053
|
branched_eval(ctrlexpr, NARROWING, FINAL, IMPLICIT_COND, COMPLETE) do
|
1052
1054
|
interpret(node.then_statement)
|
1053
1055
|
end
|
1054
1056
|
return
|
1055
|
-
when ctrlexpr_val.
|
1057
|
+
when ctrlexpr_val.test_may_be_true.true?
|
1056
1058
|
branched_eval(ctrlexpr, NARROWING, IMPLICIT_COND) do
|
1057
1059
|
interpret(node.then_statement)
|
1058
1060
|
end
|
@@ -1074,11 +1076,10 @@ module Cc1 #:nodoc:
|
|
1074
1076
|
node.executed = true
|
1075
1077
|
notify_while_stmt_started(node)
|
1076
1078
|
|
1077
|
-
|
1078
|
-
|
1079
|
-
ctrlexpr_obj = interpret(node.expression)
|
1079
|
+
ctrlexpr_obj = interpret_iteration_ctrlexpr(node, node.expression)
|
1080
1080
|
ctrlexpr_var = object_to_variable(ctrlexpr_obj, node.expression)
|
1081
1081
|
ctrlexpr_val = value_of(ctrlexpr_var)
|
1082
|
+
|
1082
1083
|
notify_variable_value_referred(node.expression, ctrlexpr_var)
|
1083
1084
|
notify_sequence_point_reached(SequencePoint.new(node.expression))
|
1084
1085
|
notify_while_ctrlexpr_evaled(node, ctrlexpr_val)
|
@@ -1086,7 +1087,7 @@ module Cc1 #:nodoc:
|
|
1086
1087
|
orig_ctrlexpr, ctrlexpr = node.deduct_controlling_expression
|
1087
1088
|
|
1088
1089
|
case
|
1089
|
-
when ctrlexpr_val.
|
1090
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1090
1091
|
begin
|
1091
1092
|
enter_iteration_statement(orig_ctrlexpr)
|
1092
1093
|
branch_opts = [ITERATION, NARROWING, FINAL, IMPLICIT_COND, COMPLETE]
|
@@ -1094,7 +1095,7 @@ module Cc1 #:nodoc:
|
|
1094
1095
|
ensure
|
1095
1096
|
leave_iteration_statement(orig_ctrlexpr)
|
1096
1097
|
end
|
1097
|
-
when ctrlexpr_val.
|
1098
|
+
when ctrlexpr_val.test_may_be_true.true?
|
1098
1099
|
begin
|
1099
1100
|
enter_iteration_statement(orig_ctrlexpr)
|
1100
1101
|
branch_opts = [ITERATION, NARROWING, FINAL, IMPLICIT_COND]
|
@@ -1150,9 +1151,9 @@ module Cc1 #:nodoc:
|
|
1150
1151
|
end
|
1151
1152
|
|
1152
1153
|
case
|
1153
|
-
when ctrlexpr_val.
|
1154
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1154
1155
|
interpret_for_body_statement(node, true)
|
1155
|
-
when ctrlexpr_val.
|
1156
|
+
when ctrlexpr_val.test_may_be_true.true?
|
1156
1157
|
interpret_for_body_statement(node, false)
|
1157
1158
|
end
|
1158
1159
|
ensure
|
@@ -1175,9 +1176,9 @@ module Cc1 #:nodoc:
|
|
1175
1176
|
end
|
1176
1177
|
|
1177
1178
|
case
|
1178
|
-
when ctrlexpr_val.
|
1179
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1179
1180
|
interpret_for_body_statement(node, true)
|
1180
|
-
when ctrlexpr_val.
|
1181
|
+
when ctrlexpr_val.test_may_be_true.true?
|
1181
1182
|
interpret_for_body_statement(node, false)
|
1182
1183
|
end
|
1183
1184
|
end
|
@@ -1221,11 +1222,11 @@ module Cc1 #:nodoc:
|
|
1221
1222
|
notify_variable_value_referred(node.expression, var)
|
1222
1223
|
|
1223
1224
|
if active_fun = interpreter._active_function and
|
1224
|
-
|
1225
|
-
if var.type.same_as?(
|
1225
|
+
ret_type = active_fun.type.return_type
|
1226
|
+
if var.type.same_as?(ret_type)
|
1226
1227
|
conved = var
|
1227
1228
|
else
|
1228
|
-
conved = do_conversion(var,
|
1229
|
+
conved = do_conversion(var, ret_type) || create_tmpvar(ret_type)
|
1229
1230
|
notify_implicit_conv_performed(node.expression, var, conved)
|
1230
1231
|
end
|
1231
1232
|
else
|
@@ -1246,9 +1247,8 @@ module Cc1 #:nodoc:
|
|
1246
1247
|
ctrlexpr_var = object_to_variable(ctrlexpr_obj, ctrlexpr)
|
1247
1248
|
ctrlexpr_val = value_of(ctrlexpr_var)
|
1248
1249
|
|
1249
|
-
|
1250
|
-
ctrlexpr_var =
|
1251
|
-
|
1250
|
+
ctrlexpr_obj = interpret_iteration_ctrlexpr(node, ctrlexpr)
|
1251
|
+
ctrlexpr_var = object_to_variable(ctrlexpr_obj, ctrlexpr)
|
1252
1252
|
notify_variable_value_referred(ctrlexpr, ctrlexpr_var)
|
1253
1253
|
notify_sequence_point_reached(SequencePoint.new(ctrlexpr))
|
1254
1254
|
else
|
@@ -1314,27 +1314,35 @@ module Cc1 #:nodoc:
|
|
1314
1314
|
end
|
1315
1315
|
end
|
1316
1316
|
|
1317
|
-
def
|
1318
|
-
|
1319
|
-
|
1320
|
-
if var = variable_named(name)
|
1321
|
-
varying_vars[var] = var.value.dup
|
1322
|
-
var.widen_value_domain!(Operator::EQ, var.type.arbitrary_value)
|
1323
|
-
end
|
1317
|
+
def interpret_iteration_ctrlexpr(iter_stmt, ctrlexpr)
|
1318
|
+
environment.enter_branch(FINAL).execute(interpreter, nil) do
|
1319
|
+
widen_varying_variable_value_domain(iter_stmt)
|
1324
1320
|
end
|
1321
|
+
interpret(ctrlexpr)
|
1322
|
+
ensure
|
1323
|
+
environment.leave_branch_group
|
1324
|
+
environment.leave_branch
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
def widen_varying_variable_value_domain(iter_stmt)
|
1328
|
+
iter_stmt.varying_variable_names.each do |name|
|
1329
|
+
if var = variable_named(name)
|
1330
|
+
widened_sval = var.type.arbitrary_value
|
1331
|
+
|
1332
|
+
case deduct_variable_varying_path(var, iter_stmt)
|
1333
|
+
when :increase
|
1334
|
+
widened_sval.narrow_domain!(Operator::GE, var.value)
|
1335
|
+
when :decrease
|
1336
|
+
widened_sval.narrow_domain!(Operator::LE, var.value)
|
1337
|
+
end
|
1325
1338
|
|
1326
|
-
|
1327
|
-
case deduct_variable_varying_path(var, iteration_stmt)
|
1328
|
-
when :increase
|
1329
|
-
var.narrow_value_domain!(Operator::GE, orig_val)
|
1330
|
-
when :decrease
|
1331
|
-
var.narrow_value_domain!(Operator::LE, orig_val)
|
1339
|
+
var.widen_value_domain!(Operator::EQ, widened_sval)
|
1332
1340
|
end
|
1333
1341
|
end
|
1334
1342
|
end
|
1335
1343
|
|
1336
|
-
def deduct_variable_varying_path(var,
|
1337
|
-
histogram =
|
1344
|
+
def deduct_variable_varying_path(var, iter_stmt)
|
1345
|
+
histogram = iter_stmt.varying_expressions.map { |expr|
|
1338
1346
|
case expr
|
1339
1347
|
when SimpleAssignmentExpression
|
1340
1348
|
deduct_ctrl_var_path_by_simple_assignment_expr(var, expr)
|
@@ -1491,9 +1499,9 @@ module Cc1 #:nodoc:
|
|
1491
1499
|
end
|
1492
1500
|
|
1493
1501
|
case
|
1494
|
-
when ctrlexpr_val.
|
1502
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1495
1503
|
branch_opts.push(FINAL, COMPLETE)
|
1496
|
-
when ctrlexpr_val.
|
1504
|
+
when ctrlexpr_val.test_must_be_false.true?
|
1497
1505
|
# NOTE: To end the current branch group of switch-statement if this
|
1498
1506
|
# case-clause is the final one.
|
1499
1507
|
branched_eval(ctrlexpr, *branch_opts) {}
|
@@ -1555,14 +1563,13 @@ module Cc1 #:nodoc:
|
|
1555
1563
|
ctrlexpr_val = value_of(interpret(ctrlexpr, QUIET))
|
1556
1564
|
|
1557
1565
|
case
|
1558
|
-
when ctrlexpr_val.
|
1566
|
+
when ctrlexpr_val.test_must_be_true.true?
|
1559
1567
|
branch_opts.push(FINAL, COMPLETE)
|
1560
|
-
when ctrlexpr_val.
|
1568
|
+
when ctrlexpr_val.test_must_be_false.true?
|
1561
1569
|
return
|
1562
1570
|
end
|
1563
1571
|
|
1564
|
-
value_domain_manip =
|
1565
|
-
branch.controlling_expression.ensure_true_by_widening(ctrlexpr)
|
1572
|
+
value_domain_manip = branch.ctrlexpr.ensure_true_by_widening(ctrlexpr)
|
1566
1573
|
end
|
1567
1574
|
|
1568
1575
|
value_domain_manip.commit!
|
@@ -1689,7 +1696,7 @@ module Cc1 #:nodoc:
|
|
1689
1696
|
ctrlexpr = ctrlexpr.to_normalized_logical
|
1690
1697
|
|
1691
1698
|
then_var = nil
|
1692
|
-
if ctrlexpr_val.
|
1699
|
+
if ctrlexpr_val.test_may_be_true.true?
|
1693
1700
|
branched_eval(ctrlexpr, NARROWING, IMPLICIT_COND) do
|
1694
1701
|
then_var = object_to_variable(interpret(node.then_expression),
|
1695
1702
|
node.then_expression)
|
@@ -1697,7 +1704,7 @@ module Cc1 #:nodoc:
|
|
1697
1704
|
end
|
1698
1705
|
|
1699
1706
|
else_var = nil
|
1700
|
-
if ctrlexpr_val.
|
1707
|
+
if ctrlexpr_val.test_may_be_false.true?
|
1701
1708
|
branched_eval(nil, NARROWING, FINAL, COMPLETE) do
|
1702
1709
|
else_var = object_to_variable(interpret(node.else_expression),
|
1703
1710
|
node.else_expression)
|
data/lib/adlint/cc1/mediator.rb
CHANGED
@@ -254,6 +254,10 @@ module Cc1 #:nodoc:
|
|
254
254
|
environment.reset
|
255
255
|
end
|
256
256
|
|
257
|
+
def current_branch
|
258
|
+
environment.current_branch
|
259
|
+
end
|
260
|
+
|
257
261
|
def scalar_value_of(numeric)
|
258
262
|
ScalarValue.of(numeric, logical_right_shift?)
|
259
263
|
end
|
@@ -307,12 +311,12 @@ module Cc1 #:nodoc:
|
|
307
311
|
end
|
308
312
|
|
309
313
|
def branched_eval(expr = nil, *opts, &block)
|
310
|
-
|
311
|
-
interpreter.notify_branch_started(
|
312
|
-
|
314
|
+
cur_branch = environment.enter_branch(*opts)
|
315
|
+
interpreter.notify_branch_started(cur_branch)
|
316
|
+
cur_branch.execute(interpreter, expr, &block)
|
313
317
|
ensure
|
314
|
-
interpreter.notify_branch_ended(
|
315
|
-
environment.leave_branch_group if
|
318
|
+
interpreter.notify_branch_ended(cur_branch)
|
319
|
+
environment.leave_branch_group if cur_branch.final?
|
316
320
|
environment.leave_branch
|
317
321
|
end
|
318
322
|
|