aboutsummaryrefslogtreecommitdiffstats
path: root/cfrontend/C2C.ml
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2015-12-08 11:20:33 +0100
committerXavier Leroy <xavier.leroy@inria.fr>2015-12-08 11:20:33 +0100
commit478093c1af181e6dd2c364e9bf954994bd312e12 (patch)
treef2b1a5a0fe7f4025f87165f1ef1c9e900f42a71b /cfrontend/C2C.ml
parentff9fedbbcc45993dfe2c4f0a372596782603921c (diff)
downloadcompcert-478093c1af181e6dd2c364e9bf954994bd312e12.tar.gz
compcert-478093c1af181e6dd2c364e9bf954994bd312e12.zip
Revise and simplify the -fstruct-return and -fstruct-passing options.
- Rename '-fstruct-return' into '-fstruct-passing', because this emulation affects both function result passing and function argument passing. Keep '-fstruct-return' as a deprecated synonymous for '-fstruct-passing' - Remove the ability to change the ABI for struct passing via the '-fstruct-passing=<abi>' and '-fstruct-return=<abi>' command-line flags. This was more confusing than useful. - Produce an error if a struct/union is passed as function argument and '-fstruct-passing' is not set. This used to be supported, using CompCert's default ABI for passing struct arguments. However, this default ABI does not match any of the standard ABIs of our target platforms, so it is better to reject than to silently produce ABI-incompatible code.
Diffstat (limited to 'cfrontend/C2C.ml')
-rw-r--r--cfrontend/C2C.ml29
1 files changed, 18 insertions, 11 deletions
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml
index 8c7ec6d8..e4001e6b 100644
--- a/cfrontend/C2C.ml
+++ b/cfrontend/C2C.ml
@@ -466,6 +466,21 @@ let convertFkind = function
if not !Clflags.option_flongdouble then unsupported "'long double' type";
F64
+let checkFunctionType env tres targs =
+ if not !Clflags.option_fstruct_passing then begin
+ if Cutil.is_composite_type env tres then
+ unsupported "function returning a struct or union (consider adding option -fstruct-passing)";
+ begin match targs with
+ | None -> ()
+ | Some l ->
+ List.iter
+ (fun (id, ty) ->
+ if Cutil.is_composite_type env ty then
+ unsupported "function parameter of struct or union type (consider adding option -fstruct-passing)")
+ l
+ end
+ end
+
let rec convertTyp env t =
match t with
| C.TVoid a -> Tvoid
@@ -487,8 +502,7 @@ let rec convertTyp env t =
| C.TArray(ty, Some sz, a) ->
Tarray(convertTyp env ty, convertInt sz, convertAttr a)
| C.TFun(tres, targs, va, a) ->
- if Cutil.is_composite_type env tres then
- unsupported "return type is a struct or union (consider adding option -fstruct-return)";
+ checkFunctionType env tres targs;
Tfunction(begin match targs with
| None -> Tnil
| Some tl -> convertParams env tl
@@ -549,11 +563,6 @@ let string_of_type ty =
Format.pp_print_flush fb ();
Buffer.contents b
-let supported_return_type env ty =
- match Cutil.unroll env ty with
- | C.TStruct _ | C.TUnion _ -> false
- | _ -> true
-
let is_longlong env ty =
match Cutil.unroll env ty with
| C.TInt((C.ILongLong|C.IULongLong), _) -> true
@@ -826,12 +835,11 @@ let rec convertExpr env e =
targs, convertExprList env args, tres)
| C.ECall(fn, args) ->
- if not (supported_return_type env e.etyp) then
- unsupported ("function returning a result of type " ^ string_of_type e.etyp ^ " (consider adding option -fstruct-return)");
begin match projFunType env fn.etyp with
| None ->
error "wrong type for function part of a call"
| Some(tres, targs, va) ->
+ checkFunctionType env tres targs;
if targs = None && not !Clflags.option_funprototyped then
unsupported "call to unprototyped function (consider adding option -funprototyped)";
if va && not !Clflags.option_fvararg_calls then
@@ -1039,8 +1047,7 @@ and convertSwitch env is_64 = function
(** Function definitions *)
let convertFundef loc env fd =
- if Cutil.is_composite_type env fd.fd_ret then
- unsupported "function returning a struct or union (consider adding option -fstruct-return)";
+ checkFunctionType env fd.fd_ret (Some fd.fd_params);
if fd.fd_vararg && not !Clflags.option_fvararg_calls then
unsupported "variable-argument function (consider adding option -fvararg-calls)";
let ret =