diff --git a/src/kernel_internals/typing/infer_annotations.ml b/src/kernel_internals/typing/infer_annotations.ml index d4d4103964a90292cadc12908ab670513e9f0b7a..3c2df0758a8283cee4da65e3a56fdd3f9afa4452 100644 --- a/src/kernel_internals/typing/infer_annotations.ml +++ b/src/kernel_internals/typing/infer_annotations.ml @@ -34,7 +34,14 @@ let assigns_from_prototype kf = try let formals = getFormalsDecl vi in (* Do ignore anonymous names *) - List.filter (fun vi -> vi.vname <> "") formals + let anonymous v = v.vname = "" in + (* Do ignore ghost if the function is not ghost *) + let ignorable_ghost v = + v.vghost && not vi.vghost in + let filter v = + not (anonymous v || ignorable_ghost v) + in + List.filter filter formals with Not_found -> [] (* this may happen for function pointer used as formal parameters.*) in diff --git a/src/plugins/variadic/extends.ml b/src/plugins/variadic/extends.ml index 3b796f36c97be94451b34b454527c86ec004f633..c838e0a5b4a0b1aa44070f36a322129e79274d40 100644 --- a/src/plugins/variadic/extends.ml +++ b/src/plugins/variadic/extends.ml @@ -35,6 +35,11 @@ module Typ = struct | TFun (_,args,_,_) -> Cil.argsToList args | _ -> invalid_arg "params" + let ghost_partitioned_params typ = + match Cil.unrollType typ with + | TFun (_,args,_,_) -> Cil.argsToPairOfLists args + | _ -> invalid_arg "params" + let params_types typ = List.map (fun (_,typ,_) -> typ) (params typ) diff --git a/src/plugins/variadic/extends.mli b/src/plugins/variadic/extends.mli index 93f8e685daabc9cd856d1c19942679921ba8803f..916c7322a4b20634c4b64fa8294f03b7c01a9b9f 100644 --- a/src/plugins/variadic/extends.mli +++ b/src/plugins/variadic/extends.mli @@ -25,6 +25,9 @@ open Cil_types module Typ : sig val attributes_less_equal : typ -> typ -> bool val params : typ -> (string * typ * attributes) list + val ghost_partitioned_params : typ -> + (string * typ * attributes) list * + (string * typ * attributes) list val params_types : typ -> typ list val params_count : typ -> int val is_variadic : typ -> bool diff --git a/src/plugins/variadic/generic.ml b/src/plugins/variadic/generic.ml index ace7d6b5d8b31e3f93c60628c24609cec8fff14d..b1a9b9fa1bcf198f845547386c31b2b1c5c46fc5 100644 --- a/src/plugins/variadic/generic.ml +++ b/src/plugins/variadic/generic.ml @@ -42,7 +42,9 @@ let translate_type = function | TFun (ret_typ, args, is_variadic, attributes) -> let new_args = if is_variadic - then Some (Cil.argsToList args @ [vpar]) + then + let ng_args, g_args = Cil.argsToPairOfLists args in + Some (ng_args @ [vpar] @ g_args) else args in TFun (ret_typ, new_args, false, attributes) @@ -142,8 +144,11 @@ let translate_call ~fundec block loc mk_call callee pars = "Generic translation of call to variadic function."; (* Split params into static and variadic part *) - let static_size = List.length (Typ.params (Cil.typeOf callee)) - 1 in - let s_exps, v_exps = List.break static_size pars in + let ng_params, g_params = Typ.ghost_partitioned_params (Cil.typeOf callee) in + let static_size = List.length ng_params - 1 in + let s_exps, r_exps = List.break static_size pars in + let variadic_size = (List.length r_exps) - (List.length g_params) in + let v_exps, g_exps = List.break variadic_size r_exps in (* Create temporary variables to hold parameters *) let add_var i exp = @@ -168,6 +173,6 @@ let translate_call ~fundec block loc mk_call callee pars = (* Translate the call *) let exp_vargs = Cil.mkAddrOrStartOf ~loc (Cil.var vargs) in let new_arg = Cil.mkCast ~force:false ~e:exp_vargs ~newt:(vpar_typ []) in - let new_args = s_exps @ [new_arg] in + let new_args = s_exps @ [new_arg] @ g_exps in let call = mk_call callee new_args in instrs @ [call]