From d0123698e87a33a8579b844fbb1ce685ef3b56e5 Mon Sep 17 00:00:00 2001 From: xleroy Date: Mon, 8 Aug 2011 12:54:53 +0000 Subject: Improved treatment of structs/unions as r-values git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1701 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/StructByValue.ml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'cparser/StructByValue.ml') diff --git a/cparser/StructByValue.ml b/cparser/StructByValue.ml index 60c11540..07a6acfd 100644 --- a/cparser/StructByValue.ml +++ b/cparser/StructByValue.ml @@ -55,6 +55,14 @@ and transf_funarg env (id, t) = then (id, TPtr(add_attributes_type [AConst] t, [])) else (id, t) +(* Smart constructor that "bubble up" sequence expressions *) + +let rec addrof e = + match e.edesc with + | EBinop(Ocomma, e1, e2, _) -> ecomma e1 (addrof e2) + | EUnop(Oderef, e1) -> e1 + | _ -> eaddrof e + (* Expressions: transform calls + rewrite the types *) type context = Val | Effects @@ -101,7 +109,7 @@ let rec transf_expr env ctx e = and transf_arg env e = let e' = transf_expr env Val e in - if is_composite_type env e'.etyp then eaddrof e' else e' + if is_composite_type env e'.etyp then addrof e' else e' (* Function calls returning a composite: add first argument. ctx = Effects: lv = f(...) -> f(&lv, ...) @@ -117,17 +125,17 @@ and transf_composite_call env ctx opt_lhs fn args ty = match ctx, opt_lhs with | Effects, None -> let tmp = new_temp ~name:"_res" ty in - {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []} + {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []} | Effects, Some lhs -> let lhs = transf_expr env Val lhs in - {edesc = ECall(fn, eaddrof lhs :: args); etyp = TVoid []} + {edesc = ECall(fn, addrof lhs :: args); etyp = TVoid []} | Val, None -> let tmp = new_temp ~name:"_res" ty in - ecomma {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []} tmp + ecomma {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []} tmp | Val, Some lhs -> let lhs = transf_expr env Val lhs in let tmp = new_temp ~name:"_res" ty in - ecomma (ecomma {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []} + ecomma (ecomma {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []} (eassign lhs tmp)) tmp -- cgit