Skip to content

Commit

Permalink
Clean up typsig race ignoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Sep 29, 2023
1 parent 1d3c7dd commit 52eac2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/domains/access.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,25 @@ let rec is_ignorable_type_offset (t: typ) (o: _ Offset.t): bool =
if is_ignorable_type t then
true (* type at offset so far ignorable, no need to recurse *)
else (
let blendAttributes baseAttrs = (* copied from Cilfacade.typeOffset *)
let (_, _, contageous) = partitionAttributes ~default:AttrName baseAttrs in
typeAddAttributes contageous
in
match o with
| `NoOffset -> false (* already checked t *)
| `Index (_, o') ->
begin match unrollType t with
| TArray (et, _, attrs) ->
let t' = blendAttributes attrs et in
let t' = Cilfacade.typeBlendAttributes attrs et in
is_ignorable_type_offset t' o'
| _ -> false (* index on non-array *)
end
| `Field (f, o') ->
begin match unrollType t with
| TComp (_, attrs) ->
let t' = blendAttributes attrs f.ftype in
let t' = Cilfacade.typeBlendAttributes attrs f.ftype in
is_ignorable_type_offset t' o'
| _ -> false (* field on non-compound *)
end
)

(** {!is_ignorable_type} for {!typsig}. *)
let is_ignorable_typsig (ts: typsig): bool =
(* efficient pattern matching first *)
match ts with
Expand All @@ -82,29 +79,25 @@ let is_ignorable_typsig (ts: typsig): bool =
| TSBase t -> is_ignorable_type t
| _ -> is_ignorable_attrs (typeSigAttrs ts)

(** {!is_ignorable_type_offset} for {!typsig}. *)
let rec is_ignorable_typsig_offset (ts: typsig) (o: _ Offset.t): bool =
(* similar to Cilfacade.typeOffset but we want to check types at all intermediate offsets as well *)
if is_ignorable_typsig ts then
true (* type at offset so far ignorable, no need to recurse *)
else (
let blendAttributes baseAttrs = (* copied from Cilfacade.typeOffset *)
let (_, _, contageous) = partitionAttributes ~default:AttrName baseAttrs in
typeSigAddAttrs contageous
in
match o with
| `NoOffset -> false (* already checked t *)
| `Index (_, o') ->
begin match ts with
| TSArray (et, _, attrs) ->
let t' = blendAttributes attrs et in
is_ignorable_typsig_offset t' o'
| TSArray (ets, _, attrs) ->
let ts' = Cilfacade.typeSigBlendAttributes attrs ets in
is_ignorable_typsig_offset ts' o'
| _ -> false (* index on non-array *)
end
| `Field (f, o') ->
begin match ts with
| TSComp (_, _, attrs) ->
let t' = blendAttributes attrs (typeSig f.ftype) in
is_ignorable_typsig_offset t' o'
let t' = Cilfacade.typeBlendAttributes attrs f.ftype in
is_ignorable_type_offset t' o' (* switch to type because it is more precise with TNamed *)
| _ -> false (* field on non-compound *)
end
)
Expand Down
9 changes: 9 additions & 0 deletions src/util/cilfacade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ and typeOffset basetyp =
| t -> raise (TypeOfError (Field_NonCompound (fi, t)))


let typeBlendAttributes baseAttrs = (* copied from Cilfacade.typeOffset *)
let (_, _, contageous) = partitionAttributes ~default:AttrName baseAttrs in
typeAddAttributes contageous

let typeSigBlendAttributes baseAttrs =
let (_, _, contageous) = partitionAttributes ~default:AttrName baseAttrs in
typeSigAddAttrs contageous


(** {!Cil.mkCast} using our {!typeOf}. *)
let mkCast ~(e: exp) ~(newt: typ) =
let oldt =
Expand Down

0 comments on commit 52eac2f

Please sign in to comment.