123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* 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). *)(* *)(**************************************************************************)letconcurrent_writesshared_bases=letmoduleAnalyzer=(valAnalysis.current_analyzer())inletmoduleALoc=Analysis_locationinmatchAnalyzer.Dom.getMt_domain.Domain.keywith(* Domain disabled, no information about writes *)|None->ALoc.Local.Set.empty(* Domain enabled *)|Some_extract->letadd_alocstmtcs_stateacc=letaloc=ALoc.Local(stmt,cs)in(* TODO: Maybe take the memory read/written for all callstacks of the
given statement? (can be done directly by Inout_memory). *)letfilter=Inout_memory.keep_globals_onlyinletmemory=Inout_memory.memory_at~filteralocinletwritten_bases=Locations.Zone.get_basesmemory.writteninifBase.SetLattice.(intersects(injectshared_bases)written_bases)thenALoc.Local.Set.add(stmt,cs)accelseaccinletadd_stmtaccstmt=letis_write_stmt=matchstmt.Cil_types.skindwith|Cil_types.Instr(Set_|Call_|Local_init_)->true|_->falseinifis_write_stmtthenmatchAnalyzer.get_stmt_state_by_callstack~after:truestmtwith|`Top|`Bottom->acc(* TODO: handle Tops *)|`Valuetable->Callstack.Hashtbl.fold(add_alocstmt)tableaccelseaccinletadd_kfkfacc=matchkf.Cil_types.fundecwith|Declaration_->acc|Definition(fundec,_)->List.fold_leftadd_stmtaccfundec.Cil_types.sallstmtsinGlobals.Functions.foldadd_kfALoc.Local.Set.emptyletshared_basesanalysis_state=letshared_zones=analysis_state.Mt_thread.concurrent_accessesinmatchLocations.Zone.get_basesshared_zoneswith|Top->assertfalse|Setzones->zonesletadd_last_analysisanalysis_state=letmoduleAnalyzer=(valAnalysis.current_analyzer())inletbases=shared_basesanalysis_stateinletwrites=concurrent_writesbasesinletthread=analysis_state.curr_thread.th_eva_threadinmatchAnalyzer.Interferences.add_last_analysisthreadwritesbaseswith|Updated->Mt_thread.iter_threadsanalysis_state(funth->Mt_thread.ThreadState.recompute_becausethInterferencesChanged)|NoChanges->()