Skip to content

Commit eedecaa

Browse files
committed
CHB: update offset handling
1 parent 7dd6fc4 commit eedecaa

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

CodeHawk/CHB/bchlib/bCHFloc.ml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ object (self)
14201420
let memref_r = self#env#mk_base_variable_reference base in
14211421
let memoff_r =
14221422
match offset with
1423+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
14231424
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
14241425
| _ ->
14251426
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
@@ -1497,6 +1498,7 @@ object (self)
14971498
let memref_r = self#env#mk_base_variable_reference base in
14981499
let memoff_r =
14991500
match offset with
1501+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
15001502
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
15011503
| _ ->
15021504
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
@@ -1704,7 +1706,24 @@ object (self)
17041706
__FILE__ __LINE__
17051707
["x: " ^ (x2s x) ^ "; exp: " ^ (x2s exp)] in
17061708
Ok exp in
1707-
aux x
1709+
let result = aux x in
1710+
match result with
1711+
| Ok okresult ->
1712+
let _ =
1713+
log_diagnostics_result
1714+
~msg:(p2s self#l#toPretty)
1715+
~tag:"convert-xpr-offsets:result"
1716+
__FILE__ __LINE__
1717+
["x: " ^ (x2s x) ^ "; exp: " ^ (x2s okresult)] in
1718+
result
1719+
| Error e ->
1720+
let _ =
1721+
log_diagnostics_result
1722+
~msg:(p2s self#l#toPretty)
1723+
~tag:"convert-xpr-offsets:failure"
1724+
__FILE__ __LINE__
1725+
["x: " ^ (x2s x) ^ "; " ^ (String.concat "; " e)] in
1726+
result
17081727

17091728
method get_xpr_type (x: xpr_t): btype_t traceresult =
17101729
match x with
@@ -1726,6 +1745,7 @@ object (self)
17261745
(* let memoff_r = address_memory_offset t_unknown offset in *)
17271746
let memoff_r =
17281747
match offset with
1748+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
17291749
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
17301750
| _ ->
17311751
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__) ^ ": "
@@ -1745,6 +1765,7 @@ object (self)
17451765
let offset = simplify_xpr (XOp (XMinus, [x; num_constant_expr maxC])) in
17461766
let gmemoff_r =
17471767
match offset with
1768+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
17481769
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
17491770
| XOp (XMult, [XConst (IntConst n); XVar v]) ->
17501771
Ok (IndexOffset (v, n#toInt, NoOffset))
@@ -1775,6 +1796,7 @@ object (self)
17751796
let memref_r = self#env#mk_base_variable_reference base in
17761797
let memoff_r =
17771798
match offset with
1799+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
17781800
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
17791801
| XOp (XMult, [XConst (IntConst n); XVar v]) ->
17801802
Ok (IndexOffset (v, n#toInt, NoOffset))
@@ -1805,6 +1827,7 @@ object (self)
18051827
(fun base ->
18061828
let offset = simplify_xpr (XOp (XMinus, [x; XVar base])) in
18071829
match offset with
1830+
| XConst (IntConst n) when n#equal numerical_zero -> Ok NoOffset
18081831
| XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
18091832
| XOp (XMult, [XConst (IntConst n); XVar v]) ->
18101833
Ok (IndexOffset (v, n#toInt, NoOffset))
@@ -1967,6 +1990,7 @@ object (self)
19671990
(log_error "decompose_address" "invalid memref")
19681991
~ok:(fun memref ->
19691992
let offset = match xoffset with
1993+
| XConst (IntConst n) when n#equal numerical_zero -> NoOffset
19701994
| XConst (IntConst n) -> ConstantOffset (n, NoOffset)
19711995
| XOp (XMult, [XConst (IntConst n); XVar v]) ->
19721996
IndexOffset (v, n#toInt, NoOffset)
@@ -1976,6 +2000,7 @@ object (self)
19762000
(self#env#mk_base_variable_reference v)
19772001
| Some (XConst (IntConst n), xoffset) ->
19782002
let offset = match xoffset with
2003+
| XConst (IntConst n) when n#equal numerical_zero -> NoOffset
19792004
| XConst (IntConst n) -> ConstantOffset (n, NoOffset)
19802005
| XOp (XMult, [XConst (IntConst n); XVar v]) ->
19812006
IndexOffset (v, n#toInt, NoOffset)

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,11 @@ object (self)
765765
| BaseVar v when variable_names#has v#getName#getSeqNumber ->
766766
Some (variable_names#get v#getName#getSeqNumber)
767767
| _ -> None in
768-
let offset = ConstantOffset (offset, NoOffset) in
768+
let offset =
769+
if offset#equal numerical_zero then
770+
NoOffset
771+
else
772+
ConstantOffset (offset, NoOffset) in
769773
let avar = varmgr#make_memory_variable ~size memref offset in
770774
let v = self#mk_variable avar in
771775
let _ = match optName with

CodeHawk/CHB/bchlib/bCHGlobalMemoryMap.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ object (self)
152152

153153
method is_initialized: bool = grec.gloc_is_initialized
154154

155+
method is_function_address: bool =
156+
BCHFunctionData.functions_data#is_function_entry_point self#address
157+
155158
method contains_address (addr: doubleword_int): bool =
156159
(self#address#equal addr)
157160
|| (match self#size with

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,6 +4332,7 @@ class type global_location_int =
43324332
method is_typed: bool
43334333
method is_struct: bool
43344334
method is_array: bool
4335+
method is_function_address: bool
43354336
method initialvalue: globalvalue_t option
43364337
method desc: string option
43374338
method contains_address: doubleword_int -> bool

CodeHawk/CHB/bchlib/bCHVersion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ end
9595

9696

9797
let version = new version_info_t
98-
~version:"0.6.0_20250713"
99-
~date:"2025-07-13"
98+
~version:"0.6.0_20250714"
99+
~date:"2025-07-14"
100100
~licensee: None
101101
~maxfilesize: None
102102
()

0 commit comments

Comments
 (0)