@@ -665,6 +665,8 @@ object (self)
665665 let xaofv_r = self#f#env#get_addressof_symbolic_expr var in
666666 let memvar_r =
667667 TR. tbind
668+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
669+ ^ " var: " ^ (x2s (XVar var)))
668670 (fun xaofv ->
669671 match xaofv with
670672 | XOp ((Xf "addressofvar" ), [XVar v ]) -> Ok v
@@ -675,6 +677,7 @@ object (self)
675677 xaofv_r in
676678 let memoff_r =
677679 TR. tbind
680+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
678681 (fun memvar ->
679682 let memtype = self#env#get_variable_type memvar in
680683 let memtype =
@@ -684,6 +687,7 @@ object (self)
684687 address_memory_offset memtype (num_constant_expr numoffset))
685688 memvar_r in
686689 TR. tbind
690+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
687691 (fun memvar ->
688692 TR. tbind
689693 (fun memoff -> self#f#env#add_memory_offset memvar memoff)
@@ -1291,10 +1295,12 @@ object (self)
12911295 when self#f#env#is_global_variable v ->
12921296 let gvaddr_r = self#f#env#get_global_variable_address v in
12931297 TR. tbind
1298+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
12941299 (fun gvaddr ->
12951300 if memmap#has_location gvaddr then
12961301 let gloc = memmap#get_location gvaddr in
12971302 TR. tmap
1303+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
12981304 (fun offset -> self#f#env#mk_gloc_variable gloc offset)
12991305 (gloc#address_offset_memory_offset
13001306 ~tgtsize: size ~tgtbtype: btype xoff)
@@ -1310,6 +1316,7 @@ object (self)
13101316 match memmap#xpr_containing_location addrvalue with
13111317 | Some gloc ->
13121318 (TR. tmap
1319+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13131320 (fun offset -> self#f#env#mk_gloc_variable gloc offset)
13141321 (gloc#address_memory_offset ~tgtsize: size ~tgtbtype: btype addrvalue))
13151322 | _ ->
@@ -1320,56 +1327,116 @@ object (self)
13201327 self#f#env#mk_offset_memory_variable memref memoff)
13211328 memref_r memoff_r
13221329
1323- method private get_variable_type (v : variable_t ): btype_t option =
1330+ method private get_variable_type (v : variable_t ): btype_t traceresult =
13241331 if self#f#env#is_initial_register_value v then
13251332 let reg_r = self#f#env#get_initial_register_value_register v in
1326- TR. tfold_default
1333+ TR. tbind
1334+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13271335 (fun reg ->
13281336 if self#f#get_summary#has_parameter_for_register reg then
13291337 let param = self#f#get_summary#get_parameter_for_register reg in
1330- Some param.apar_type
1338+ Ok param.apar_type
13311339 else
1332- self#env#get_variable_type v)
1333- None
1340+ let ty = self#env#get_variable_type v in
1341+ match ty with
1342+ | None ->
1343+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1344+ ^ " variable: " ^ (x2s (XVar v))]
1345+ | Some t -> Ok t)
13341346 reg_r
13351347 else if self#env#is_initial_memory_value v then
13361348 let memvar_r = self#env#get_init_value_variable v in
1337- TR. tfold
1338- ~ok: self#get_variable_type
1339- ~error: (fun e ->
1340- begin log_error_result __FILE__ __LINE__ e; None end )
1349+ TR. tbind
1350+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1351+ self#get_variable_type
13411352 memvar_r
1353+ else if self#env#is_memory_variable v then
1354+ let memref_r = self#env#get_memory_reference v in
1355+ let memoff_r = self#env#get_memvar_offset v in
1356+ let basevar_r =
1357+ TR. tbind
1358+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1359+ (fun memref ->
1360+ match memref#get_base with
1361+ | BaseVar v -> Ok v
1362+ | b ->
1363+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1364+ ^ " memory-base: " ^ (p2s (memory_base_to_pretty b))])
1365+ memref_r in
1366+ let basevar_type_r =
1367+ TR. tbind
1368+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1369+ self#get_variable_type
1370+ basevar_r in
1371+ TR. tbind
1372+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1373+ (fun basevartype ->
1374+ TR. tbind
1375+ (fun memoff ->
1376+ match memoff with
1377+ | NoOffset when is_pointer basevartype ->
1378+ Ok (ptr_deref basevartype)
1379+ | ConstantOffset (n , NoOffset) when is_pointer basevartype ->
1380+ let symmemoff_r =
1381+ address_memory_offset
1382+ (ptr_deref basevartype) (num_constant_expr n) in
1383+ TR. tbind
1384+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1385+ ^ " basevar type: " ^ (btype_to_string basevartype)
1386+ ^ " ; offset: " ^ n#toString)
1387+ (fun off ->
1388+ match off with
1389+ | FieldOffset ((fname , ckey ), NoOffset) ->
1390+ let cinfo = get_compinfo_by_key ckey in
1391+ let finfo = get_compinfo_field cinfo fname in
1392+ Ok finfo.bftype
1393+ | _ ->
1394+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1395+ ^ " symbolic offset: "
1396+ ^ (memory_offset_to_string off)
1397+ ^ " with basevar type: "
1398+ ^ (btype_to_string basevartype)
1399+ ^ " not yet handled" ])
1400+ symmemoff_r
1401+ | _ ->
1402+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1403+ ^ " memoff: " ^ (memory_offset_to_string memoff)
1404+ ^ " not yet handled" ])
1405+ memoff_r)
1406+ basevar_type_r
13421407 else
1343- self#env#get_variable_type v
1408+ let ty = self#env#get_variable_type v in
1409+ match ty with
1410+ | None ->
1411+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1412+ ^ " variable: " ^ (x2s (XVar v))]
1413+ | Some t -> Ok t
13441414
13451415 method convert_variable_offsets
13461416 ?(size =None ) (v : variable_t ): variable_t traceresult =
13471417 if self#env#is_basevar_memory_variable v then
13481418 let basevar_r = self#env#get_memvar_basevar v in
13491419 let offset_r = self#env#get_memvar_offset v in
13501420 let cbasevar_r = TR. tbind self#convert_value_offsets basevar_r in
1351- let basetype_r = TR. tmap self#get_variable_type cbasevar_r in
1421+ let basetype_r = TR. tbind self#get_variable_type cbasevar_r in
13521422 let tgttype_r =
13531423 TR. tbind
1424+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13541425 (fun basetype ->
13551426 match basetype with
1356- | Some ( TPtr (t , _ ) ) -> Ok t
1357- | Some t ->
1427+ | TPtr (t , _ ) -> Ok t
1428+ | t ->
13581429 Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
13591430 ^ " Type " ^ (btype_to_string t)
1360- ^ " is not a pointer" ]
1361- | _ ->
1362- Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1363- ^ " No type for variable "
1364- ^ (p2s v#toPretty)
1365- ^ " with basevar "
1366- ^ (p2s (TR. tget_ok cbasevar_r)#toPretty)]) basetype_r in
1431+ ^ " is not a pointer" ]) basetype_r in
13671432 let coffset_r =
13681433 TR. tbind
1434+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13691435 (fun offset ->
13701436 match offset with
13711437 | ConstantOffset (n , NoOffset) ->
13721438 TR. tbind
1439+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13731440 (fun tgttype ->
13741441 address_memory_offset
13751442 ~tgtsize: size tgttype (num_constant_expr n)) tgttype_r
@@ -1391,33 +1458,31 @@ object (self)
13911458 let basevar_r = self#env#get_memval_basevar v in
13921459 let offset_r = self#env#get_memval_offset v in
13931460 let cbasevar_r = TR. tbind self#convert_value_offsets basevar_r in
1394- let basetype_r = TR. tmap self#get_variable_type cbasevar_r in
1461+ let basetype_r = TR. tbind self#get_variable_type cbasevar_r in
13951462 let tgttype_r =
13961463 TR. tbind
1464+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
13971465 (fun basetype ->
13981466 match basetype with
1399- | Some ( TPtr (t , _ ) ) -> Ok t
1400- | Some t ->
1467+ | TPtr (t , _ ) -> Ok t
1468+ | t ->
14011469 Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
14021470 ^ " Type " ^ (btype_to_string t)
1403- ^ " is not a pointer" ]
1404- | _ ->
1405- Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1406- ^ " No type for variable "
1407- ^ (p2s v#toPretty)
1408- ^ " with basevar "
1409- ^ (p2s (TR. tget_ok cbasevar_r)#toPretty)]) basetype_r in
1471+ ^ " is not a pointer" ]) basetype_r in
14101472 let coffset_r =
14111473 TR. tbind
1474+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
14121475 (fun offset ->
14131476 match offset with
14141477 | NoOffset ->
14151478 TR. tbind
1479+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
14161480 (fun tgttype ->
14171481 address_memory_offset
14181482 ~tgtsize: size tgttype (int_constant_expr 0 )) tgttype_r
14191483 | ConstantOffset (n , NoOffset) ->
14201484 TR. tbind
1485+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
14211486 (fun tgttype ->
14221487 address_memory_offset
14231488 ~tgtsize: size tgttype (num_constant_expr n)) tgttype_r
@@ -1456,10 +1521,12 @@ object (self)
14561521 | _ -> Ok exp in
14571522 aux x
14581523
1459- method get_xpr_type (x : xpr_t ): btype_t option =
1524+ method get_xpr_type (x : xpr_t ): btype_t traceresult =
14601525 match x with
14611526 | XVar v -> self#get_variable_type v
1462- | _ -> None
1527+ | _ ->
1528+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1529+ ^ " xpr: " ^ (x2s x)]
14631530
14641531 method decompose_memaddr (x : xpr_t ):
14651532 (memory_reference_int traceresult * memory_offset_t traceresult) =
@@ -1468,15 +1535,39 @@ object (self)
14681535 let knownpointers = List. filter self#f#is_base_pointer vars in
14691536 match knownpointers with
14701537 (* one known pointer, must be the base *)
1538+ | [base] when self#f#env#is_initial_stackpointer_value base ->
1539+ let offset = simplify_xpr (XOp (XMinus , [x; XVar base])) in
1540+ let memref_r = self#env#mk_base_variable_reference base in
1541+ let memoff_r = address_memory_offset t_unknown offset in
1542+ (memref_r, memoff_r)
1543+
14711544 | [base] ->
14721545 let offset = simplify_xpr (XOp (XMinus , [x; XVar base])) in
14731546 let memref_r = self#env#mk_base_variable_reference base in
1474- let vartype = self#env#get_variable_type base in
1475- let vartype = match vartype with None -> t_unknown | Some t -> t in
1476- let rvartype = TR. tvalue (resolve_type vartype) ~default: t_unknown in
1477- let basetype =
1478- if is_pointer rvartype then ptr_deref rvartype else t_unknown in
1479- let memoff_r = address_memory_offset basetype offset in
1547+ let vartype_r = self#get_variable_type base in
1548+ let rvartype_r =
1549+ TR. tbind
1550+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1551+ resolve_type
1552+ vartype_r in
1553+ let basetype_r =
1554+ TR. tbind
1555+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__))
1556+ (fun t ->
1557+ if is_pointer t then
1558+ Ok (ptr_deref t)
1559+ else
1560+ Error [__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1561+ ^ " x: " ^ (x2s x) ^ " ; base: " ^ (x2s (XVar base))
1562+ ^ " ; offset: " ^ (x2s offset)])
1563+ rvartype_r in
1564+ let memoff_r =
1565+ TR. tbind
1566+ ~msg: (__FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
1567+ ^ " base pointer: " ^ (x2s (XVar base)))
1568+ (fun basetype -> address_memory_offset basetype offset)
1569+ basetype_r in
1570+
14801571 (*
14811572 (match offset with
14821573 | XConst (IntConst n) -> Ok (ConstantOffset (n, NoOffset))
0 commit comments