12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* 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). *)(* *)(**************************************************************************)openLangopenTacticalclassoverflow=objectinheritTactical.make~id:"Wp.overflow"~title:"Overflow"~descr:"Split integer overflow into in and out of range"~params:[]methodselect_feedbackselection=lete=Tactical.selectedselectioninletopenQed.LogicinmatchF.reprewith|Fun(f,[v])->letopenLang.FinletopenLang.Ninletmin,max=Ctypes.bounds@@Cint.to_cintfinletmin,max=e_zintmin,e_zintmaxinletlower=v<minandupper=max<vinletin_range=not(lower||:upper)inletlength=(max-min)+e_oneinletoverflow=min+((v-min)modlength)inletreplace_withv=funu->ifu==ethenvelseraiseNot_foundinApplicable(fun(hs,g)->["In-Range",Conditions.subst(replace_withv)(hs,in_range==>g);"Lower",Conditions.subst(replace_withoverflow)(hs,lower==>g);"Upper",Conditions.subst(replace_withoverflow)(hs,upper==>g)])|_->Not_applicableendletoverflow=Tactical.export(newoverflow)