(********************************************  Max length gfs field_at load store: semax_max_path_field_load_nth_ram. semax_max_path_field_cast_load_nth_ram. semax_max_path_field_store_nth_ram.  ********************************************)
Section LOADSTORE_FIELD_AT.
Context {cs: compspecs}.

(* TODO: delete it *)
Lemma semax_max_path_field_store_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh P Q R (e1 e2 : expr) Pre Post
(t_root: type) (efs: list efield) (gfs: list gfield) (tts: list type)
(p v : val) (v' : reptype (nested_field_type t_root gfs)) lr,
type_is_by_value (typeof (nested_efield e1 efs tts)) = true ->
writable_share sh ->
LR_of_type t_root = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
legal_nested_efield t_root e1 gfs tts lr = true ->
JMeq v v' ->
nth_error R n = Some Pre ->
Pre |-- field_at_ sh t_root gfs p *
(field_at sh t_root gfs v' p -* Post) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq p) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq v) (eval_expr (Ecast e2 (typeof (nested_efield e1 efs tts))))) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfs) &&
(tc_expr Delta (Ecast e2 (typeof (nested_efield e1 efs tts)))) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sassign (nested_efield e1 efs tts) e2)
(normal_ret_assert
(PROPx P
(LOCALx Q
(SEPx
(replace_nth n R Post))))).