@@ -214,6 +214,31 @@ let memory_variables_in_region
214214 env#get_memory_variables
215215
216216
217+ (* The argument written by a block-write side effect on parameter [n] of a
218+ library summary, or None if the write has no effect on the program's
219+ memory: the call has no such argument (an optional parameter of a
220+ variadic function, e.g., ioctl or fcntl), the argument is a null pointer
221+ constant (e.g., strtol (s, NULL, 10), time (NULL)), or it is not a pointer
222+ (fcntl (fd, F_SETFL, flags)); casts are stripped for the latter two tests.
223+ Without this filter the dereference of such an argument translates to a
224+ temporary and all memory variables are abstracted. *)
225+ let block_write_arg
226+ (env : c_environment_int ) (args : exp list ) (n : int ): exp option =
227+ let rec strip_casts e = match e with CastE (_ , e' ) -> strip_casts e' | _ -> e in
228+ match List. nth_opt args (n - 1 ) with
229+ | None -> None
230+ | Some arg ->
231+ match strip_casts arg with
232+ | Const (CInt (i64 , _ , _ )) when Int64. compare i64 Int64. zero = 0 -> None
233+ | e ->
234+ match type_of_exp env#get_fdecls e with
235+ | Ok t ->
236+ (match fenv#get_type_unrolled t with
237+ | TPtr _ | TArray _ -> Some arg
238+ | _ -> None )
239+ | Error _ -> Some arg
240+
241+
217242(* Memory variables of the object denoted by region symbol [s] (a pointer
218243 value in the symbolic pointer-set domain): all memory variables of the
219244 stack or global variable that is the base of the region (the offset is not
@@ -921,6 +946,8 @@ object (self)
921946 let assignments =
922947 List. fold_left (fun acc (se , _ ) ->
923948 match se with
949+ | XBlockWrite (ArgValue (ParFormal n, ArgNoOffset ), _)
950+ when Option. is_none (block_write_arg env fnargs n) -> acc
924951 | XBlockWrite (ArgValue (ParFormal n , ArgNoOffset), _ ) ->
925952 let arg = List. nth fnargs (n - 1 ) in
926953 let lhs =
@@ -1401,6 +1428,8 @@ object (self)
14011428 let assignments =
14021429 List. fold_left (fun acc (se , _ ) ->
14031430 match se with
1431+ | XBlockWrite (ArgValue (ParFormal n, ArgNoOffset ), _)
1432+ when Option. is_none (block_write_arg env fnargs n) -> acc
14041433 | XBlockWrite (ArgValue (ParFormal n ,ArgNoOffset), _ ) ->
14051434 let arg = List. nth fnargs (n - 1 ) in
14061435 let lhs =
@@ -1865,84 +1894,18 @@ object (self)
18651894 ([(List. map (fun xsitevar ->
18661895 make_c_cmd (ASSIGN_SYM (xsitevar, SYM sitesym))) xsitevars)]
18671896 @ [[make_c_cmd SKIP ]]) in
1868- let rec compose_offset base offset =
1869- match base with
1870- | NoOffset -> offset
1871- | Field (fuse , NoOffset) -> Field (fuse,offset)
1872- | Field (fuse , foffset ) -> Field (fuse, compose_offset foffset offset)
1873- | Index _ ->
1874- begin
1875- ch_error_log#add
1876- " compose offset"
1877- (LBLOCK [
1878- STR " base: " ;
1879- offset_to_pretty base;
1880- STR " ; offset: " ;
1881- offset_to_pretty offset]);
1882- NoOffset
1883- end in
1884- let rec cancel_se_struct arg baseoffset comp =
1885- List. fold_left (fun acc f ->
1886- let foffset = Field ((f.fname,f.fckey),NoOffset ) in
1887- let offset = compose_offset baseoffset foffset in
1888- let lhs = exp_translator#translate_lhs context (Mem arg,offset) in
1889- if lhs#isTmp then
1890- let memoryvars = env#get_memory_variables in
1891- let _ =
1892- log_diagnostics_result
1893- ~tag: " abstract memory variables"
1894- ~msg: env#get_functionname
1895- __FILE__ __LINE__
1896- (List. map (fun v -> p2s v#toPretty) memoryvars) in
1897- [ make_c_cmd (ABSTRACT_VARS memoryvars)]
1898- else
1899- let cancel = make_c_cmd (ABSTRACT_VARS [lhs]) in
1900- let _ =
1901- log_diagnostics_result
1902- ~tag: " abstract memory variables"
1903- ~msg: env#get_functionname
1904- __FILE__ __LINE__
1905- [p2s lhs#toPretty] in
1906- let subcancels =
1907- match fenv#get_type_unrolled f.ftype with
1908- | TComp (ckey ,_ ) ->
1909- let comp = fenv#get_comp ckey in
1910- cancel_se_struct arg offset comp
1911- | _ -> [] in
1912- (cancel :: subcancels) @ acc) [] comp.cfields in
19131897 let seeffects =
19141898 List. concat
19151899 (List. map (fun (se ,_ ) ->
19161900 match se with
1917- | XBlockWrite (ArgValue (ParFormal n , ArgNoOffset), _ ) ->
1918- let arg = List. nth args (n - 1 ) in
1919- let lhs = exp_translator#translate_lhs context (Mem arg,NoOffset ) in
1920- if lhs#isTmp then
1921- let memoryvars = env#get_memory_variables in
1922- let _ =
1923- log_diagnostics_result
1924- ~tag: " abstract memory variables"
1925- ~msg: env#get_functionname
1926- __FILE__ __LINE__
1927- (List. map (fun v -> p2s v#toPretty) memoryvars) in
1928- [make_c_cmd (ABSTRACT_VARS memoryvars)]
1929- else
1930- let ty = fenv#get_type_unrolled (env#get_variable_type lhs) in
1931- let cancel = make_c_cmd (ABSTRACT_VARS [lhs]) in
1932- let _ =
1933- log_diagnostics_result
1934- ~tag: " abstract memory variables"
1935- ~msg: env#get_functionname
1936- __FILE__ __LINE__
1937- [p2s lhs#toPretty] in
1938- let subcancels =
1939- match ty with
1940- | TComp (ckey , _ ) ->
1941- let comp = fenv#get_comp ckey in
1942- cancel_se_struct arg NoOffset comp
1943- | _ ->
1944- [] in
1945- cancel :: subcancels
1901+ | XBlockWrite _ ->
1902+ (* Initialization domain: a block write cannot make a location
1903+ uninitialized (a location written is initialized, one not
1904+ written keeps its state), so nothing is abstracted; in
1905+ particular the initialization recorded by an
1906+ initializes-range side effect of the same call (memset,
1907+ memcpy, read) is kept. *)
1908+ []
19461909
19471910 | XFormattedInput (ArgValue (ParFormal n , ArgNoOffset)) ->
19481911 let (assignments, _) =
@@ -2344,6 +2307,8 @@ object (self)
23442307 List. concat
23452308 (List. map (fun (se ,_ ) ->
23462309 match se with
2310+ | XBlockWrite (ArgValue (ParFormal n, ArgNoOffset ), _)
2311+ when Option. is_none (block_write_arg env args n) -> []
23472312 | XBlockWrite (ArgValue (ParFormal n , ArgNoOffset), _ ) ->
23482313 let arg = List. nth args (n - 1 ) in
23492314 let regionabstract =
0 commit comments