Skip to content

Commit c402f7f

Browse files
committed
CHB: correct for stackpointer wrap-around
1 parent 075b061 commit c402f7f

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎CodeHawk/CHB/bchlib/bCHFloc.ml‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ object (self)
19151915
let tresult =
19161916
let is_pointer (y: xpr_t) =
19171917
TR.tfold_default BCHBCTypeUtil.is_pointer false (self#get_xpr_type y) in
1918+
let is_integer (y: xpr_t) =
1919+
TR.tfold_default BCHBCTypeUtil.is_int false (self#get_xpr_type y) in
19181920
let default () = self#convert_xpr_offsets ~xtype ~size x in
19191921
match x with
19201922
| XOp (XPlus, [y; XOp (XMult, [XConst (IntConst n); XVar v])]) ->
@@ -1969,6 +1971,21 @@ object (self)
19691971
result)
19701972
(self#xpr_to_cxpr y)
19711973
(BCHBCTypeUtil.size_of_btype derefty)
1974+
1975+
| XOp (XPlus, [y; XConst (IntConst n)])
1976+
when is_integer y && n#geq (mkNumerical 0x100000000) ->
1977+
let rresult =
1978+
simplify_xpr (XOp (XMinus, [x; int_constant_expr 0x100000000])) in
1979+
begin
1980+
log_diagnostics_result
1981+
~msg:(p2s self#l#toPretty)
1982+
~tag:"xpr_to_cxpr:subtract 2^32"
1983+
__FILE__ __LINE__
1984+
["x: " ^ (x2s x);
1985+
"rresult: " ^ (x2s rresult)];
1986+
Ok rresult
1987+
end
1988+
19721989
| _ ->
19731990
match xtype with
19741991
| None -> default ()
@@ -2130,7 +2147,7 @@ object (self)
21302147
let _ =
21312148
log_diagnostics_result
21322149
~msg:(p2s self#l#toPretty)
2133-
~tag:"convert-variable-offsets"
2150+
~tag:"convert_variable_offsets:basevar_memory_variable"
21342151
__FILE__ __LINE__
21352152
["tgttype: " ^ (TR.tfold_default btype_to_string "?" tgttype_r);
21362153
"tgtbtype: " ^ (btype_to_string optvtype);
@@ -2148,7 +2165,7 @@ object (self)
21482165
let _ =
21492166
log_diagnostics_result
21502167
~msg:(p2s self#l#toPretty)
2151-
~tag:"convert-variable-offsets:default"
2168+
~tag:"convert_variable_offsets:default"
21522169
__FILE__ __LINE__
21532170
[(p2s v#toPretty)] in
21542171
Ok v in

‎CodeHawk/CHB/bchlib/bCHFunctionStackframe.ml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
(* chlib *)
3030
open CHLanguage
31+
open CHNumerical
3132
open CHPretty
3233

3334
(* chutil *)
@@ -154,6 +155,19 @@ object (self)
154155
method frame2object_offset_value (xpr: xpr_t): xpr_t traceresult =
155156
let xoff =
156157
simplify_xpr (XOp (XMinus, [xpr; int_constant_expr self#offset])) in
158+
let xoff =
159+
match xoff with
160+
| XOp (XPlus, [_; XConst (IntConst n)]) when n#geq (mkNumerical 0x100000000) ->
161+
let rresult =
162+
simplify_xpr (XOp (XMinus, [xoff; int_constant_expr 0x100000000])) in
163+
begin
164+
log_diagnostics_result
165+
~tag:"frame2object_offset_value:correct for stackpointer wraparound"
166+
__FILE__ __LINE__
167+
["xpr: " ^ (x2s xpr); "rresult: " ^ (x2s rresult)];
168+
rresult
169+
end
170+
| _ -> xoff in
157171
Ok xoff
158172

159173
method frame_offset_memory_offset

0 commit comments

Comments
 (0)