Skip to content

Commit 26a9afb

Browse files
committed
Revised warning for non-prototyped function declarations
- Emit the warning even for functions without parameters `int f() {...}` - Show what the type is after prototyping - Refactor this part of `elab_fundef` slightly
1 parent b4e339e commit 26a9afb

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

cparser/Elab.ml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,30 +2767,35 @@ let elab_fundef genv spec name defs body loc =
27672767
the structs and unions defined in the parameter list. *)
27682768
let (ty, extra_decls, lenv) =
27692769
match ty, kr_params with
2770-
| TFun(ty_ret, None, vararg, attr), None ->
2771-
(TFun(ty_ret, Some [], vararg, attr), [], lenv)
2772-
| ty, None ->
2770+
| TFun(ty_ret, Some proto, vararg, attr), None ->
2771+
(ty, [], lenv)
2772+
| TFun(ty_ret, None, false, attr), None ->
2773+
let ty = TFun(ty_ret, Some [], inherit_vararg genv s sto ty, attr) in
2774+
warning loc CompCert_conformance "function definition without a prototype, converting to prototype form.@ New type is '%a'"
2775+
Cprint.simple_decl (fun_id, ty);
27732776
(ty, [], lenv)
27742777
| TFun(ty_ret, None, false, attr), Some params ->
2775-
warning loc CompCert_conformance "non-prototype, pre-standard function definition, converting to prototype form";
27762778
let (params', extra_decls, lenv) =
27772779
elab_KR_function_parameters lenv params defs loc in
2778-
(TFun(ty_ret, Some params', inherit_vararg genv s sto ty, attr), extra_decls, lenv)
2779-
| _, Some params ->
2780-
assert false
2780+
let ty =
2781+
TFun(ty_ret, Some params', inherit_vararg genv s sto ty, attr) in
2782+
warning loc CompCert_conformance "function definition without a prototype, converting to prototype form.@ New type is '%a'"
2783+
Cprint.simple_decl (fun_id, ty);
2784+
(ty, extra_decls, lenv)
2785+
| _, _ ->
2786+
fatal_error loc "wrong type for function definition"
27812787
in
2782-
(* Extract infos from the type of the function.
2783-
Checks on the return type must be done in the global environment. *)
2788+
(* Extract infos from the type of the function. *)
27842789
let (ty_ret, params, vararg, attr) =
27852790
match ty with
2786-
| TFun(ty_ret, Some params, vararg, attr) ->
2787-
if has_std_alignas genv ty then
2788-
error loc "alignment specified for function '%s'" s;
2789-
if wrap incomplete_type loc genv ty_ret && not (is_void_type genv ty_ret) then
2790-
fatal_error loc "incomplete result type %a in function definition"
2791-
(print_typ genv) ty_ret;
2792-
(ty_ret, params, vararg, attr)
2793-
| _ -> fatal_error loc "wrong type for function definition" in
2791+
| TFun(ty_ret, Some params, vararg, attr) -> (ty_ret, params, vararg, attr)
2792+
| _ -> assert false in
2793+
(* Checks on the return type must be done in the global environment. *)
2794+
if has_std_alignas genv ty then
2795+
error loc "alignment specified for function '%s'" s;
2796+
if wrap incomplete_type loc genv ty_ret && not (is_void_type genv ty_ret) then
2797+
fatal_error loc "incomplete result type %a in function definition"
2798+
(print_typ genv) ty_ret;
27942799
(* Enter function in the global environment *)
27952800
let (fun_id, sto1, genv, new_ty, _) =
27962801
enter_or_refine_function loc genv fun_id sto ty in

0 commit comments

Comments
 (0)