aboutsummaryrefslogtreecommitdiffstats
path: root/cfrontend/C2C.ml
diff options
context:
space:
mode:
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 =