End soundness.
End LegalAlignasStrictFacts.
Module LegalAlignasStrong <: LEGAL_ALIGNAS.
Section legal_alignas.
Context (cenv: composite_env) (ha_env: PTree.t Z).
Definition legal_alignas_obs: Type := bool.
Fixpoint legal_alignas_type (la_env: PTree.t bool) t: bool :=
match t with
| Tarray t' _ _ => (sizeof cenv t' mod hardware_alignof ha_env t' =? 0) && legal_alignas_type la_env t'
| Tstruct id _ =>
match la_env ! id with
| Some la => la
| None => false
end
| Tunion id _ =>
match la_env ! id with
| Some la => la
| None => false
end
| _ => match access_mode t with
| By_value ch => true
| _ => false
end
end.
Fixpoint legal_alignas_struct_members_rec (la_env: PTree.t bool) (m: members) (pos: Z): bool :=
match m with
| nil => true
| (_, t) :: m' => (align pos (alignof cenv t) mod hardware_alignof ha_env t =? 0) && (legal_alignas_type la_env t) && (legal_alignas_struct_members_rec la_env m' (align pos (alignof cenv t) + sizeof cenv t))
end.
Fixpoint legal_alignas_union_members_rec (la_env: PTree.t bool) (m: members): bool :=
match m with
| nil => true
| (_, t) :: m' => (legal_alignas_type la_env t) && (legal_alignas_union_members_rec la_env m')
end.
Definition legal_alignas_composite (la_env: PTree.t bool) (co: composite): bool :=
match co_su co with
| Struct => legal_alignas_struct_members_rec la_env (co_members co) 0
| Union => legal_alignas_union_members_rec la_env (co_members co)
end.
Definition legal_alignas_env: PTree.t bool :=
let l := composite_reorder.rebuild_composite_elements cenv in
fold_right (fun (ic: positive * composite) (T0: PTree.t bool) => let (i, co) := ic in let T := T0 in PTree.set i (legal_alignas_composite T co) T) (PTree.empty _) l.
Definition is_aligned_aux (b: bool) (ha: Z) (ofs: Z) := b && ((ofs mod ha) =? 0).
End legal_alignas.
End LegalAlignasStrong.
Module LegalAlignasStrongFacts: LEGAL_ALIGNAS_FACTS with Module LegalAlignas := LegalAlignasStrong.
Module LegalAlignas := LegalAlignasStrong.
Module LegalAlignasDefs := LegalAlignasDefsGen (LegalAlignas).
Export LegalAlignas LegalAlignasDefs.
Section legal_alignas.
Context (cenv: composite_env) (ha_env: PTree.t Z).

Lemma aux2:
(type_func.Env
(fun t : type =>
match access_mode t with
| By_value _ => true
| By_reference => false
| By_copy => false
| By_nothing => false
end)
(fun (la : bool) (t : type) (_ : Z) (_ : attr) =>
(sizeof cenv t mod hardware_alignof ha_env t =? 0) && la)
(fun (la : bool) (_ : ident) (_ : attr) => la)
(fun (la : bool) (_ : ident) (_ : attr) => la)
(fun su : struct_or_union =>
match su with
| Struct =>
(fix
fm (pos : Z) (l : list (ident * type * bool)) {struct l} :
bool :=
match l with
| nil => true
| (_, t, la) :: l' =>
(align pos (alignof cenv t)
mod hardware_alignof ha_env t =? 0) && la &&
fm (align pos (alignof cenv t) + sizeof cenv t) l'
end) 0
| Union =>
fix fm (l : list (ident * type * bool)) : bool :=
match l with
| nil => true
| (_, _, la) :: l' => la && fm l'
end
end) (composite_reorder.rebuild_composite_elements cenv)) =
legal_alignas_env cenv ha_env.