From 55fa31e474c0f039330d6325ab33bbd86522d084 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 29 Aug 2016 10:18:24 +0200 Subject: Added check for duplicated members. Bug 19665 --- cparser/Elab.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 0c35638b..1039a91d 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -801,6 +801,11 @@ and elab_field_group keep_ty env (Field_group (spec, fieldlist, loc)) = and elab_struct_or_union_info keep_ty kind loc env members attrs = let (m, env') = mmap (elab_field_group keep_ty) env members in let m = List.flatten m in + ignore (List.fold_left (fun acc fld -> + let n = fld.fld_name in + if List.exists ((=) n) acc then + error loc "duplicate memeber '%s'" n; + n::acc) [] m); (* Check for incomplete types *) let rec check_incomplete = function | [] -> () -- cgit From 5daf835c454c31dcf29b8b9832d9050cf5822516 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 29 Aug 2016 11:59:31 +0200 Subject: Fixed spelling mistake and unnamed fields. The previous fix for duplicated members was also triggered for unnamed members. Bug 19665 --- cparser/Elab.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 1039a91d..a5032292 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -803,9 +803,12 @@ and elab_struct_or_union_info keep_ty kind loc env members attrs = let m = List.flatten m in ignore (List.fold_left (fun acc fld -> let n = fld.fld_name in - if List.exists ((=) n) acc then - error loc "duplicate memeber '%s'" n; - n::acc) [] m); + if n <> "" then begin + if List.exists ((=) n) acc then + error loc "duplicate member '%s'" n; + n::acc + end else + acc) [] m); (* Check for incomplete types *) let rec check_incomplete = function | [] -> () -- cgit From 64a1e734dfe24194bafd33cff1fbe4d9e1cfdf14 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 29 Aug 2016 12:56:41 +0200 Subject: Pass the environment of k&r param elaboration. The environment where the types are inserted is passed back to allow introducing structs in k&r parameters. Bug 19668 --- cparser/Elab.ml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cparser/Elab.ml b/cparser/Elab.ml index a5032292..aea4f2be 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -2028,8 +2028,9 @@ let elab_KR_function_parameters env params defs loc = | d -> (* Should never be produced by the parser *) fatal_error (get_definitionloc d) "Illegal declaration of function parameter" in - let kr_params_defs = - List.concat (fst (mmap elab_param_def env defs)) in + let kr_params_defs,paramsenv = + let params,paramsenv = mmap elab_param_def env defs in + List.concat params,paramsenv in (* Find the type of a parameter *) let type_of_param param = match List.filter (fun (p, _) -> p = param) kr_params_defs with @@ -2066,7 +2067,8 @@ let elab_KR_function_parameters env params defs loc = ps end in - match_params [] [] params + let a,b = match_params [] [] params in + a,b,paramsenv (* Look for varargs flag in previous definitions of a function *) @@ -2100,17 +2102,17 @@ let elab_fundef env spec name defs body loc = - [ty]: the full, prototyped type of the function - [extra_decls]: extra declarations to be inserted at the beginning of the function *) - let (ty, extra_decls) = + let (ty, extra_decls,env1) = match ty, kr_params with | TFun(ty_ret, None, vararg, attr), None -> - (TFun(ty_ret, Some [], vararg, attr), []) + (TFun(ty_ret, Some [], vararg, attr), [],env1) | ty, None -> - (ty, []) + (ty, [],env1) | TFun(ty_ret, None, false, attr), Some params -> warning loc "Non-prototype, pre-standard function definition.@ Converting to prototype form"; - let (params', extra_decls) = + let (params', extra_decls,env) = elab_KR_function_parameters env params defs loc in - (TFun(ty_ret, Some params', inherit_vararg env s sto ty, attr), extra_decls) + (TFun(ty_ret, Some params', inherit_vararg env s sto ty, attr), extra_decls,env) | _, Some params -> assert false in -- cgit