123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* CEA (Commissariat a l'energie atomique et aux energies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)openCil_typesmoduleFct=Cil_datatype.Kf.SetmoduleTargetKfs=State_builder.Set_ref(Fct)(structletdependencies=[Ast.self]letname="WpTarget.TargetKfs"end)letget_called_stmtstmt=matchstmt.skindwith|Instr(Call(_,fct,_,_))->beginmatchKernel_function.get_calledfctwith|Somekf->[kf]|None->Option.value~default:[]@@Option.mapsnd(Dyncall.getstmt)end|Instr(Local_init(_,ConsInit(vi,_,_),_))->[Globals.Functions.getvi]|_->[]moduleCallees=State_builder.Hashtbl(Cil_datatype.Kf.Hashtbl)(Fct)(structletdependencies=[Ast.self]letname="WpTarget.Callees"letsize=17end)(** Note: we add the kf received in parameter in the set only if it has a
definition (and thus if it does not have one, we add nothing as it has
no visible callee).
This prevent to warn on prototypes that have a contract but are unused. If
the function is used, it will be added to the set via its caller(s) if they
are under verification.
*)letwith_calleeskf=tryletstmts=(Kernel_function.get_definitionkf).sallstmtsinletfoldsstmt=List.fold_left(funskf->Fct.addkfs)s(get_called_stmtstmt)inList.fold_leftfold(Fct.singletonkf)stmtswithKernel_function.No_Definition->Fct.emptyletwith_callees=Callees.memowith_calleesletadd_with_calleeskf=letaddkf=letinsert_speckf=letspecs=ifKernel_function.has_definitionkfthen[`Exits;`Terminates]else[`Exits;`Terminates;`Assigns]inPopulate_spec.populate_funspec~do_body:truekfspecsininsert_speckf;TargetKfs.addkfinFct.iteradd(with_calleeskf)exceptionFoundletcheck_propertiesbehaviorspropskf=letopenPropertyinletexists_selected_behaviorl=behaviors=[]||List.exists(funb->List.membbehaviors)linletcheck_ipip=ifexists_selected_behavior(WpPropId.user_bhv_namesip)thenletnames=WpPropId.user_prop_namesipinifprops=[]||WpPropId.are_selected_namespropsnamesthenraiseFoundinletcheck_bhv_requireskfkinstrbv=List.iter(funp->check_ip(ip_of_requireskfkinstrbvp))bv.b_requiresinletcheck_bhv_ensureskfkinstrbv=List.iter(funp->check_ip(ip_of_ensureskfkinstrbvp))bv.b_post_condinletopt_check=functionNone->()|Somep->check_ippinletcheck_bhv_assignskfkinstrbv=opt_check(ip_assigns_of_behaviorkfkinstr~active:[]bv)inletcheck_bhv_allocationkfkinstrbv=opt_check(ip_allocation_of_behaviorkfkinstr~active:[]bv)inletcheck_complete_disjointkfkinstr=tryletspec=Annotations.funspeckfinletcomp=ip_complete_of_speckfkinstr~active:[]specinletdisj=ip_disjoint_of_speckfkinstr~active:[]specinList.itercheck_ipcomp;List.itercheck_ipdisj;withAnnotations.No_funspec_->()inletcheck_bhvkfkinstrbv=ifCfgInfos.is_entry_pointkfthencheck_bhv_requireskfkinstrbv;check_bhv_assignskfkinstrbv;check_bhv_allocationkfkinstrbv;check_bhv_ensureskfkinstrbv;check_complete_disjointkfkinstrinletcheck_code()=letstmts=try(Kernel_function.get_definitionkf).sallstmtswithKernel_function.No_Definition->[]inletcheckstmt_ca=List.itercheck_ip(ip_of_code_annotkfstmtca)inletcheck_callstmt=letcheck_calleekf=letkf_behaviors=Annotations.behaviorskfinList.iter(check_bhv_requireskfKglobal)kf_behaviorsinList.itercheck_callee(get_called_stmtstmt)inletcheck_stmtstmt=check_callstmt;Annotations.iter_code_annot(checkstmt)stmtinList.itercheck_stmtstmtsinletcheck_funbhvbv=check_bhvkfKglobalbvinAnnotations.iter_behaviorscheck_funbhvkf;check_code()letadd_with_behaviorsbehaviorspropskf=ifbehaviors=[]&&props=[]thenadd_with_calleeskfelsebegintrycheck_propertiesbehaviorspropskfwithFound->add_with_calleeskfendletcompute_kfmodelbhvpropkf=letrtes=Wp_parameters.RTE.get()inifrtesthenWpRTE.generatemodelkf;add_with_behaviorsbhvpropkfletcomputemodel?(fct=Wp_parameters.get_fct())?(bhv=Wp_parameters.Behaviors.get())?(prop=Wp_parameters.Properties.get())()=Wp_parameters.iter_fct(compute_kfmodelbhvprop)fctletcompute_kfmodelkf=compute_kfmodel[][]kfletiter=TargetKfs.iter