Skip to content

Commit 20c7d8a

Browse files
committed
CHB:ARM: give priority to declared stack types
1 parent 99ae5b5 commit 20c7d8a

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,12 @@ object (self)
21302130
result
21312131

21322132
method get_xpr_type (x: xpr_t): btype_t traceresult =
2133+
let _ =
2134+
log_diagnostics_result
2135+
~msg:(p2s self#l#toPretty)
2136+
~tag:"get_xpr_type"
2137+
__FILE__ __LINE__
2138+
["x: " ^ (x2s x)] in
21332139
match x with
21342140
| XVar v -> self#get_variable_type v
21352141
| XOp (XPlus, [XVar v; XConst (IntConst _)]) -> self#get_variable_type v

CodeHawk/CHB/bchlibarm32/bCHFnARMTypeConstraints.ml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ object (self)
193193
let getopt_stackaddress_r (x_r: xpr_t traceresult): int option =
194194
TR.tfold_default getopt_stackaddress None x_r in
195195

196+
let getopt_stacklocation_type (x: xpr_t): btype_t option =
197+
match getopt_stackaddress x with
198+
| Some offset when fndata#has_stackvar_type_annotation offset ->
199+
TR.to_option (fndata#get_stackvar_type_annotation offset)
200+
| _ -> None in
201+
202+
let getopt_stacklocation_type_r (x_r: xpr_t traceresult): btype_t option =
203+
TR.tfold_default getopt_stacklocation_type None x_r in
204+
196205
let getopt_global_address (x: xpr_t): doubleword_int option =
197206
match (rewrite_expr x) with
198207
| XConst (IntConst num) ->
@@ -818,26 +827,30 @@ object (self)
818827
(regvar_type_introduction "LDR" rt);
819828

820829
(* loaded type may be known *)
821-
(let xmem_r = memop#to_expr floc in
822-
let xrmem_r =
823-
TR.tmap (fun x -> simplify_xpr (floc#inv#rewrite_expr x)) xmem_r in
824-
let xtype_r = TR.tbind floc#get_xpr_type xrmem_r in
825-
let rule = "LDR-memop-tc" in
826-
TR.titer
827-
~ok:(fun t ->
828-
let opttc = mk_btype_constraint rttypevar t in
829-
(match opttc with
830-
| Some tc ->
831-
if fndata#is_typing_rule_enabled iaddr rule then
832-
begin
833-
log_type_constraint __LINE__ rule tc;
834-
store#add_constraint faddr iaddr rule tc
835-
end
836-
else
837-
log_type_constraint_rule_disabled __LINE__ rule tc
838-
| _ -> ()))
839-
~error:(fun e -> log_error_result __FILE__ __LINE__ e)
840-
xtype_r);
830+
(match getopt_stacklocation_type_r (memop#to_address floc) with
831+
(* skip if stacklocation type has been declared in userdata *)
832+
| Some _ -> ()
833+
| _ ->
834+
(let xmem_r = memop#to_expr floc in
835+
let xrmem_r =
836+
TR.tmap (fun x -> simplify_xpr (floc#inv#rewrite_expr x)) xmem_r in
837+
let xtype_r = TR.tbind floc#get_xpr_type xrmem_r in
838+
let rule = "LDR-memop-tc" in
839+
TR.titer
840+
~ok:(fun t ->
841+
let opttc = mk_btype_constraint rttypevar t in
842+
(match opttc with
843+
| Some tc ->
844+
if fndata#is_typing_rule_enabled iaddr rule then
845+
begin
846+
log_type_constraint __LINE__ rule tc;
847+
store#add_constraint faddr iaddr rule tc
848+
end
849+
else
850+
log_type_constraint_rule_disabled __LINE__ rule tc
851+
| _ -> ()))
852+
~error:(fun e -> log_error_result __FILE__ __LINE__ e)
853+
xtype_r));
841854

842855
(* LDR rt, [rn, rm] : X_rndef.load <: X_rt *)
843856
(let xrdef = get_variable_rdefs_r (rn#to_variable floc) in

0 commit comments

Comments
 (0)