aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/StructByValue.ml
diff options
context:
space:
mode:
authorxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-08-08 12:54:53 +0000
committerxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2011-08-08 12:54:53 +0000
commitd0123698e87a33a8579b844fbb1ce685ef3b56e5 (patch)
treec9acba24609917e1e4f999c5be159c8faf79e931 /cparser/StructByValue.ml
parent5909a0340ad0fe871dede1eaead855fb4b68fb0e (diff)
downloadcompcert-d0123698e87a33a8579b844fbb1ce685ef3b56e5.tar.gz
compcert-d0123698e87a33a8579b844fbb1ce685ef3b56e5.zip
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
Diffstat (limited to 'cparser/StructByValue.ml')
-rw-r--r--cparser/StructByValue.ml18
1 files changed, 13 insertions, 5 deletions
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