diff --git a/src/goto-instrument/accelerate/accelerate.sh b/regression/acceleration/accelerate.sh similarity index 100% rename from src/goto-instrument/accelerate/accelerate.sh rename to regression/acceleration/accelerate.sh diff --git a/src/aa-path-symex/path_symex.cpp b/src/aa-path-symex/path_symex.cpp index 0c18e34bb8e..f503f25c6e1 100644 --- a/src/aa-path-symex/path_symex.cpp +++ b/src/aa-path-symex/path_symex.cpp @@ -19,7 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "path_symex.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -133,26 +133,31 @@ bool path_symext::propagate(const exprt &src) else if(src.id()==ID_plus) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_array) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_vector) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_if) { const if_exprt &if_expr=to_if_expr(src); - if(!propagate(if_expr.true_case())) return false; - if(!propagate(if_expr.false_case())) return false; + if(!propagate(if_expr.true_case()) || + !propagate(if_expr.false_case())) + return false; + return true; } else if(src.id()==ID_array_of) @@ -244,7 +249,8 @@ inline static typet c_sizeof_type_rec(const exprt &expr) forall_operands(it, expr) { typet t=c_sizeof_type_rec(*it); - if(t.is_not_nil()) return t; + if(t.is_not_nil()) + return t; } } @@ -298,7 +304,8 @@ void path_symext::symex_malloc( mp_integer elements=alloc_size/elem_size; if(elements*elem_size==alloc_size) - object_type=array_typet(tmp_type, from_integer(elements, tmp_size.type())); + object_type= + array_typet(tmp_type, from_integer(elements, tmp_size.type())); } } } @@ -323,8 +330,6 @@ void path_symext::symex_malloc( size_symbol.type=tmp_size.type(); size_symbol.mode=ID_C; - //state.var_map(size_symbol.name, suffix, size_symbol.type); - assign(state, size_symbol.symbol_expr(), size); @@ -336,15 +341,14 @@ void path_symext::symex_malloc( // value symbolt value_symbol; - value_symbol.base_name="dynamic_object"+std::to_string(state.var_map.dynamic_count); + value_symbol.base_name= + "dynamic_object"+std::to_string(state.var_map.dynamic_count); value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name); value_symbol.is_lvalue=true; value_symbol.type=object_type; value_symbol.type.set("#dynamic", true); value_symbol.mode=ID_C; - //state.var_map(value_symbol.name, suffix, value_symbol.type); - address_of_exprt rhs; if(object_type.id()==ID_array) @@ -385,11 +389,11 @@ void path_symext::assign_rec( const exprt &ssa_lhs, const exprt &ssa_rhs) { - //const typet &ssa_lhs_type=state.var_map.ns.follow(ssa_lhs.type()); + // const typet &ssa_lhs_type=state.var_map.ns.follow(ssa_lhs.type()); #ifdef DEBUG std::cout << "assign_rec: " << ssa_lhs.pretty() << std::endl; - //std::cout << "ssa_lhs_type: " << ssa_lhs_type.id() << std::endl; + // std::cout << "ssa_lhs_type: " << ssa_lhs_type.id() << std::endl; #endif if(ssa_lhs.id()==ID_symbol) @@ -446,7 +450,8 @@ void path_symext::assign_rec( state.record_step(); path_symex_stept &step=*state.history; - if(!guard.empty()) step.guard=conjunction(guard); + if(!guard.empty()) + step.guard=conjunction(guard); step.full_lhs=ssa_lhs; step.ssa_lhs=new_lhs; step.ssa_rhs=ssa_rhs; @@ -579,7 +584,8 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(member_exprt(ssa_rhs, components[i].get_name(), components[i].type()), + simplify_expr( + member_exprt(ssa_rhs, components[i].get_name(), components[i].type()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -601,7 +607,11 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(index_exprt(ssa_rhs, from_integer(i, index_type()), array_type.subtype()), + simplify_expr( + index_exprt( + ssa_rhs, + from_integer(i, index_type()), + array_type.subtype()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -618,7 +628,11 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(index_exprt(ssa_rhs, from_integer(i, index_type()), vector_type.subtype()), + simplify_expr( + index_exprt( + ssa_rhs, + from_integer(i, index_type()), + vector_type.subtype()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -670,7 +684,9 @@ void path_symext::function_call_rec( state.locs.function_map.find(function_identifier); if(f_it==state.locs.function_map.end()) - throw "failed to find `"+id2string(function_identifier)+"' in function_map"; + throw + "failed to find `"+id2string(function_identifier)+ + "' in function_map"; const locst::function_entryt &function_entry=f_it->second; @@ -690,7 +706,8 @@ void path_symext::function_call_rec( } // push a frame on the call stack - path_symex_statet::threadt &thread=state.threads[state.get_current_thread()]; + path_symex_statet::threadt &thread= + state.threads[state.get_current_thread()]; thread.call_stack.push_back(path_symex_statet::framet()); thread.call_stack.back().current_function=function_identifier; thread.call_stack.back().return_location=thread.pc.next_loc(); @@ -741,7 +758,7 @@ void path_symext::function_call_rec( const if_exprt &if_expr=to_if_expr(function); exprt guard=if_expr.cond(); - if (state.is_lazy()) + if(state.is_lazy()) { const exprt &case_expr=state.restore_branch()? if_expr.true_case():if_expr.false_case(); @@ -755,7 +772,8 @@ void path_symext::function_call_rec( path_symex_statet &false_state=further_states.back(); false_state.record_branch_step(false); false_state.history->guard=not_exprt(guard); - function_call_rec(further_states.back(), call, if_expr.false_case(), further_states); + function_call_rec( + further_states.back(), call, if_expr.false_case(), further_states); } // do the true-case in 'state' @@ -767,6 +785,7 @@ void path_symext::function_call_rec( } } else + // NOLINTNEXTLINE(readability/throw) as message is correctly uppercase throw "TODO: function_call "+function.id_string(); } @@ -885,11 +904,10 @@ void path_symext::do_goto( #endif #ifdef PATH_SYMEX_FORK - if (pid==-1) - // forking failed so continue as if PATH_SYMEX_FORK were undefined + // forking failed so continue as if PATH_SYMEX_FORK were undefined + if(pid==-1) // NOLINT(readability/braces) #endif { - #ifdef PATH_SYMEX_LAZY_STATE // lazily copy the state into 'further_states' further_states.push_back(path_symex_statet::lazy_copy(state)); @@ -905,9 +923,9 @@ void path_symext::do_goto( } #ifdef PATH_SYMEX_FORK - if (pid!=0) - // parent process (regardless of any possible fork errors) - // should finish to explore all current 'further_states' + // parent process (regardless of any possible fork errors) + // should finish to explore all current 'further_states' + if(pid!=0) // NOLINT(readability/braces) #endif { // branch not taken case @@ -1016,7 +1034,8 @@ void path_symext::operator()( // ordering of the following matters due to vector instability path_symex_statet::threadt &new_thread=state.add_thread(); - path_symex_statet::threadt &old_thread=state.threads[state.get_current_thread()]; + path_symex_statet::threadt &old_thread= + state.threads[state.get_current_thread()]; new_thread.pc=loc.branch_target; new_thread.local_vars=old_thread.local_vars; } @@ -1028,7 +1047,7 @@ void path_symext::operator()( break; case GOTO: - if (state.is_lazy()) + if(state.is_lazy()) do_goto(state, state.restore_branch()); else do_goto(state, further_states); @@ -1042,7 +1061,7 @@ void path_symext::operator()( case THROW: state.record_step(); - throw "THROW not yet implemented"; + throw "THROW not yet implemented"; // NOLINT(readability/throw) case ASSUME: state.record_step(); @@ -1081,7 +1100,7 @@ void path_symext::operator()( case ATOMIC_END: if(!state.inside_atomic_section) - throw "ATOMIC_END unmatched"; + throw "ATOMIC_END unmatched"; // NOLINT(readability/throw) state.record_step(); state.next_pc(); @@ -1095,7 +1114,8 @@ void path_symext::operator()( case FUNCTION_CALL: state.record_step(); - function_call(state, to_code_function_call(instruction.code), further_states); + function_call( + state, to_code_function_call(instruction.code), further_states); break; case OTHER: diff --git a/src/aa-path-symex/path_symex_state.cpp b/src/aa-path-symex/path_symex_state.cpp index f0f21b1b8b5..b0c502f639d 100644 --- a/src/aa-path-symex/path_symex_state.cpp +++ b/src/aa-path-symex/path_symex_state.cpp @@ -20,7 +20,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "path_symex_state.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -131,7 +131,8 @@ path_symex_statet::var_statet &path_symex_statet::get_var_state( var_valt &var_val= var_info.is_shared()?shared_vars:threads[current_thread].local_vars; - if(var_val.size()<=var_info.number) var_val.resize(var_info.number+1); + if(var_val.size()<=var_info.number) + var_val.resize(var_info.number+1); return var_val[var_info.number]; } @@ -150,7 +151,7 @@ Function: path_symex_statet::read exprt path_symex_statet::read(const exprt &src, bool propagate) { #ifdef DEBUG - //std::cout << "path_symex_statet::read " << src.pretty() << std::endl; + // std::cout << "path_symex_statet::read " << src.pretty() << std::endl; #endif // This has five phases! @@ -174,7 +175,7 @@ exprt path_symex_statet::read(const exprt &src, bool propagate) exprt tmp5=simplify_expr(tmp4, var_map.ns); #ifdef DEBUG - //std::cout << " ==> " << tmp.pretty() << std::endl; + // std::cout << " ==> " << tmp.pretty() << std::endl; #endif return tmp5; @@ -633,7 +634,8 @@ exprt path_symex_statet::instantiate_rec_address( { if_exprt if_expr=to_if_expr(src); if_expr.true_case()=instantiate_rec_address(if_expr.true_case(), propagate); - if_expr.false_case()=instantiate_rec_address(if_expr.false_case(), propagate); + if_expr.false_case()= + instantiate_rec_address(if_expr.false_case(), propagate); if_expr.cond()=instantiate_rec(if_expr.cond(), propagate); return if_expr; } @@ -771,7 +773,8 @@ bool path_symex_statet::check_assertion( exprt assertion=read(instruction.guard); // trivial? - if(assertion.is_true()) return true; // no error + if(assertion.is_true()) + return true; // no error // the path constraint decision_procedure << history; diff --git a/src/aa-path-symex/path_symex_state.h b/src/aa-path-symex/path_symex_state.h index 1c3ad2d632e..dd10e43d8da 100644 --- a/src/aa-path-symex/path_symex_state.h +++ b/src/aa-path-symex/path_symex_state.h @@ -83,7 +83,7 @@ class path_symex_statet // like initial state except that branches are copied from "other" // and history will be 'nil' - static path_symex_statet lazy_copy(path_symex_statet& other) + static path_symex_statet lazy_copy(path_symex_statet &other) { // allow compiler to use RVO return path_symex_statet( @@ -154,12 +154,12 @@ class path_symex_statet bool inside_atomic_section; - inline unsigned get_current_thread() const + unsigned get_current_thread() const { return current_thread; } - inline void set_current_thread(unsigned _thread) + void set_current_thread(unsigned _thread) { current_thread=_thread; } @@ -167,30 +167,30 @@ class path_symex_statet goto_programt::const_targett get_instruction() const; // branch taken case - inline void record_true_branch() + void record_true_branch() { branches.push_back(true); } // branch not taken case - inline void record_false_branch() + void record_false_branch() { branches.push_back(false); } - inline bool is_lazy() const + bool is_lazy() const { return branches_restore < branches.size(); } // returns branch direction that should be taken - inline bool restore_branch() + bool restore_branch() { assert(is_lazy()); return branches[branches_restore++]; } - inline bool is_executable() const + bool is_executable() const { return !threads.empty() && threads[current_thread].active; @@ -207,28 +207,28 @@ class path_symex_statet // various state transformers - inline threadt &add_thread() + threadt &add_thread() { threads.resize(threads.size()+1); return threads.back(); } - inline void disable_current_thread() + void disable_current_thread() { threads[current_thread].active=false; } - inline loc_reft pc() const + loc_reft pc() const { return threads[current_thread].pc; } - inline void next_pc() + void next_pc() { threads[current_thread].pc.increase(); } - inline void set_pc(loc_reft new_pc) + void set_pc(loc_reft new_pc) { threads[current_thread].pc=new_pc; } @@ -238,13 +238,13 @@ class path_symex_statet void output(const threadt &thread, std::ostream &out) const; // instantiate expressions with propagation - inline exprt read(const exprt &src) + exprt read(const exprt &src) { return read(src, true); } // instantiate without constant propagation - inline exprt read_no_propagate(const exprt &src) + exprt read_no_propagate(const exprt &src) { return read(src, false); } @@ -253,12 +253,12 @@ class path_symex_statet std::string array_index_as_string(const exprt &) const; - inline unsigned get_no_thread_interleavings() const + unsigned get_no_thread_interleavings() const { return no_thread_interleavings; } - inline unsigned get_depth() const + unsigned get_depth() const { return depth; } @@ -281,7 +281,7 @@ class path_symex_statet // On first call, O(N) where N is the length of the execution path // leading to this state. Subsequent calls run in constant time. - const branchest& get_branches() + const branchest &get_branches() { if(!branches.empty() || history.is_nil()) return branches; diff --git a/src/aa-symex/path_search.cpp b/src/aa-symex/path_search.cpp index b6fdfdd70dd..5bfa680177f 100644 --- a/src/aa-symex/path_search.cpp +++ b/src/aa-symex/path_search.cpp @@ -177,7 +177,7 @@ path_searcht::resultt path_searcht::operator()( { // either a child found and reported a bug or // the parent's search partition is safe - switch (exit_status) + switch(exit_status) { case 0: return SAFE; case 10: return UNSAFE; @@ -218,7 +218,8 @@ int path_searcht::await() pid_t pid=wait(&status); if(pid==-1) { - if(errno==ECHILD) break; // no more child processes + if(errno==ECHILD) + break; // no more child processes } else { @@ -451,7 +452,8 @@ void path_searcht::check_assertion(statet &state) exprt assertion= state.read(instruction.guard); - if(assertion.is_true()) return; // no error, trivially + if(assertion.is_true()) + return; // no error, trivially // keep statistics number_of_VCCs_after_simplification++; diff --git a/src/aa-symex/path_search.h b/src/aa-symex/path_search.h index 7a6b270c040..51c67ac93f0 100644 --- a/src/aa-symex/path_search.h +++ b/src/aa-symex/path_search.h @@ -19,7 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com class path_searcht:public safety_checkert { public: - explicit inline path_searcht(const namespacet &_ns): + explicit path_searcht(const namespacet &_ns): safety_checkert(_ns), show_vcc(false), depth_limit_set(false), // no limit @@ -71,16 +71,15 @@ class path_searcht:public safety_checkert goto_tracet error_trace; source_locationt source_location; - inline bool is_success() const { return status==SUCCESS; } - inline bool is_failure() const { return status==FAILURE; } - inline bool is_not_reached() const { return status==NOT_REACHED; } + bool is_success() const { return status==SUCCESS; } + bool is_failure() const { return status==FAILURE; } + bool is_not_reached() const { return status==NOT_REACHED; } }; typedef std::map property_mapt; property_mapt property_map; protected: - #ifdef PATH_SYMEX_FORK // blocks until child processes have terminated int await(); diff --git a/src/analyses/ai.h b/src/analyses/ai.h index 10a9831d1c5..c506cbbeb08 100644 --- a/src/analyses/ai.h +++ b/src/analyses/ai.h @@ -36,8 +36,8 @@ class ai_domain_baset // how function calls are treated: // a) there is an edge from each call site to the function head - // b) there is an edge from the last instruction (END_FUNCTION) of the function - // to the instruction _following_ the call site + // b) there is an edge from the last instruction (END_FUNCTION) + // of the function to the instruction _following_ the call site // (this also needs to set the LHS, if applicable) virtual void transform( @@ -87,7 +87,7 @@ class ai_baset { } - inline void operator()( + void operator()( const goto_programt &goto_program, const namespacet &ns) { @@ -97,7 +97,7 @@ class ai_baset fixedpoint(goto_program, goto_functions, ns); } - inline void operator()( + void operator()( const goto_functionst &goto_functions, const namespacet &ns) { @@ -106,7 +106,7 @@ class ai_baset fixedpoint(goto_functions, ns); } - inline void operator()(const goto_modelt &goto_model) + void operator()(const goto_modelt &goto_model) { const namespacet ns(goto_model.symbol_table); initialize(goto_model.goto_functions); @@ -114,7 +114,7 @@ class ai_baset fixedpoint(goto_model.goto_functions, ns); } - inline void operator()( + void operator()( const goto_functionst::goto_functiont &goto_function, const namespacet &ns) { @@ -133,7 +133,7 @@ class ai_baset const goto_functionst &goto_functions, std::ostream &out) const; - inline void output( + void output( const goto_modelt &goto_model, std::ostream &out) const { @@ -141,7 +141,7 @@ class ai_baset output(ns, goto_model.goto_functions, out); } - inline void output( + void output( const namespacet &ns, const goto_programt &goto_program, std::ostream &out) const @@ -149,7 +149,7 @@ class ai_baset output(ns, goto_program, "", out); } - inline void output( + void output( const namespacet &ns, const goto_functionst::goto_functiont &goto_function, std::ostream &out) const @@ -254,21 +254,25 @@ class ait:public ai_baset typedef goto_programt::const_targett locationt; - inline domainT &operator[](locationt l) + domainT &operator[](locationt l) { typename state_mapt::iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } - inline const domainT &operator[](locationt l) const + const domainT &operator[](locationt l) const { typename state_mapt::const_iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } - virtual void clear() override + void clear() override { state_map.clear(); ai_baset::clear(); @@ -285,25 +289,28 @@ class ait:public ai_baset } // this one just finds states - virtual const statet &find_state(locationt l) const override + const statet &find_state(locationt l) const override { typename state_mapt::const_iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } - virtual bool merge(const statet &src, locationt from, locationt to) override + bool merge(const statet &src, locationt from, locationt to) override { statet &dest=get_state(to); - return static_cast(dest).merge(static_cast(src), from, to); + return static_cast(dest).merge( + static_cast(src), from, to); } - virtual statet *make_temporary_state(const statet &s) override + statet *make_temporary_state(const statet &s) override { return new domainT(static_cast(s)); } - virtual void fixedpoint( + void fixedpoint( const goto_functionst &goto_functions, const namespacet &ns) override { @@ -315,7 +322,7 @@ class ait:public ai_baset void dummy(const domainT &s) { const statet &x=s; (void)x; } // not implemented in sequential analyses - virtual bool merge_shared( + bool merge_shared( const statet &src, goto_programt::const_targett from, goto_programt::const_targett to, @@ -336,18 +343,19 @@ class concurrency_aware_ait:public ait { } - virtual bool merge_shared( + bool merge_shared( const statet &src, goto_programt::const_targett from, goto_programt::const_targett to, const namespacet &ns) override { statet &dest=this->get_state(to); - return static_cast(dest).merge_shared(static_cast(src), from, to, ns); + return static_cast(dest).merge_shared( + static_cast(src), from, to, ns); } protected: - virtual void fixedpoint( + void fixedpoint( const goto_functionst &goto_functions, const namespacet &ns) override { diff --git a/src/analyses/cfg_dominators.h b/src/analyses/cfg_dominators.h index 209a76852e6..687d84e1416 100644 --- a/src/analyses/cfg_dominators.h +++ b/src/analyses/cfg_dominators.h @@ -149,16 +149,18 @@ void cfg_dominators_templatet::fixedpoint(P &program) bool changed=false; typename cfgt::nodet &node=cfg[cfg.entry_map[current]]; if(node.dominators.empty()) - for(const auto & edge : (post_dom?node.out:node.in)) + { + for(const auto &edge : (post_dom ? node.out : node.in)) if(!cfg[edge.first].dominators.empty()) { node.dominators=cfg[edge.first].dominators; node.dominators.insert(current); changed=true; } + } // compute intersection of predecessors - for(const auto & edge : (post_dom?node.out:node.in)) + for(const auto &edge : (post_dom ? node.out : node.in)) { const target_sett &other=cfg[edge.first].dominators; if(other.empty()) @@ -170,10 +172,20 @@ void cfg_dominators_templatet::fixedpoint(P &program) // in-place intersection. not safe to use set_intersect while(n_it!=node.dominators.end() && o_it!=other.end()) { - if(*n_it==current) ++n_it; - else if(*n_it<*o_it) { changed=true; node.dominators.erase(n_it++); } - else if(*o_it<*n_it) ++o_it; - else { ++n_it; ++o_it; } + if(*n_it==current) + ++n_it; + else if(*n_it<*o_it) + { + changed=true; + node.dominators.erase(n_it++); + } + else if(*o_it<*n_it) + ++o_it; + else + { + ++n_it; + ++o_it; + } } while(n_it!=node.dominators.end()) @@ -190,7 +202,7 @@ void cfg_dominators_templatet::fixedpoint(P &program) if(changed) // fixed point for node reached? { - for(const auto & edge : (post_dom?node.in:node.out)) + for(const auto &edge : (post_dom ? node.in : node.out)) { worklist.push_back(cfg[edge.first].PC); } @@ -253,16 +265,18 @@ void cfg_dominators_templatet::output(std::ostream &out) const } } -typedef cfg_dominators_templatet +typedef cfg_dominators_templatet< + const goto_programt, goto_programt::const_targett, false> cfg_dominatorst; -typedef cfg_dominators_templatet +typedef cfg_dominators_templatet< + const goto_programt, goto_programt::const_targett, true> cfg_post_dominatorst; template<> inline void dominators_pretty_print_node( - const goto_programt::const_targett& node, - std::ostream& out) + const goto_programt::const_targett &node, + std::ostream &out) { out << node->location_number; } diff --git a/src/analyses/constant_propagator.cpp b/src/analyses/constant_propagator.cpp index c7d5879d858..1fe89a7b8f6 100644 --- a/src/analyses/constant_propagator.cpp +++ b/src/analyses/constant_propagator.cpp @@ -6,7 +6,7 @@ Author: Peter Schrammel \*******************************************************************/ -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -35,7 +35,7 @@ void constant_propagator_domaint::assign_rec( const exprt &lhs, const exprt &rhs, const namespacet &ns) { - const typet & rhs_type = ns.follow(rhs.type()); + const typet &rhs_type = ns.follow(rhs.type()); #ifdef DEBUG std::cout << "assign: " << from_expr(ns, "", lhs) @@ -52,7 +52,7 @@ void constant_propagator_domaint::assign_rec( values.set_to_top(to_symbol_expr(lhs)); } #if 0 - else //TODO: could make field or array element-sensitive + else // TODO: could make field or array element-sensitive { } #endif @@ -83,7 +83,7 @@ void constant_propagator_domaint::transform( #ifdef DEBUG std::cout << "before:\n"; - output(std::cout,ai,ns); + output(std::cout, ai, ns); #endif if(from->is_decl()) @@ -143,7 +143,7 @@ void constant_propagator_domaint::transform( } #ifdef DEBUG std::cout << "after:\n"; - output(std::cout,ai,ns); + output(std::cout, ai, ns); #endif } @@ -165,7 +165,7 @@ bool constant_propagator_domaint::two_way_propagate_rec( const namespacet &ns) { #ifdef DEBUG - std::cout << "two_way_propagate_rec: " << from_expr(ns,"",expr) << '\n'; + std::cout << "two_way_propagate_rec: " << from_expr(ns, "", expr) << '\n'; #endif bool change = false; @@ -273,7 +273,8 @@ Function: constant_propagator_domaint::valuest::is_constant_address_of \*******************************************************************/ -bool constant_propagator_domaint::valuest::is_constant_address_of(const exprt &expr) const +bool constant_propagator_domaint::valuest::is_constant_address_of( + const exprt &expr) const { if(expr.id()==ID_index) return is_constant_address_of(to_index_expr(expr).array()) && @@ -363,7 +364,7 @@ void constant_propagator_domaint::output( const ai_baset &ai, const namespacet &ns) const { - values.output(out,ns); + values.output(out, ns); } /*******************************************************************\ @@ -380,11 +381,11 @@ Function: constant_propagator_domaint::valuest::merge bool constant_propagator_domaint::valuest::merge(const valuest &src) { - //nothing to do + // nothing to do if(src.is_bottom) return false; - //just copy + // just copy if(is_bottom) { replace_const = src.replace_const; @@ -394,7 +395,7 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src) bool changed = false; - //set everything to top that is not in src + // set everything to top that is not in src for(replace_symbolt::expr_mapt::const_iterator it=replace_const.expr_map.begin(); it!=replace_const.expr_map.end(); @@ -403,7 +404,7 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src) if(src.replace_const.expr_map.find(it->first) == src.replace_const.expr_map.end()) { - //cannot use set_to_top here + // cannot use set_to_top here replace_const.expr_map.erase(it++); changed = true; } @@ -557,7 +558,8 @@ void constant_propagator_ait::replace( } else if(it->is_function_call()) { - s_it->second.values.replace_const(to_code_function_call(it->code).function()); + s_it->second.values.replace_const( + to_code_function_call(it->code).function()); simplify_expr(to_code_function_call(it->code).function(), ns); exprt::operandst &args = diff --git a/src/analyses/constant_propagator.h b/src/analyses/constant_propagator.h index 026bc96f970..935b74a1421 100644 --- a/src/analyses/constant_propagator.h +++ b/src/analyses/constant_propagator.h @@ -16,11 +16,18 @@ Author: Peter Schrammel class constant_propagator_domaint:public ai_domain_baset { public: - void transform(locationt, locationt, ai_baset &, const namespacet &) override final; - void output(std::ostream &, const ai_baset &, const namespacet &) const override final; - void make_top() override final { values.set_to_top(); } - void make_bottom() override final { values.set_to_bottom(); } - void make_entry() override final { values.set_to_top(); } + void transform( + locationt, + locationt, + ai_baset &, + const namespacet &) final; + void output( + std::ostream &, + const ai_baset &, + const namespacet &) const final; + void make_top() final { values.set_to_top(); } + void make_bottom() final { values.set_to_bottom(); } + void make_entry() final { values.set_to_top(); } bool merge(const constant_propagator_domaint &, locationt, locationt); struct valuest @@ -37,19 +44,19 @@ class constant_propagator_domaint:public ai_domain_baset bool merge(const valuest &src); bool meet(const valuest &src); - inline void set_to_bottom() + void set_to_bottom() { replace_const.clear(); is_bottom = true; } - inline void set_to(const irep_idt &lhs_id, const exprt &rhs_val) + void set_to(const irep_idt &lhs_id, const exprt &rhs_val) { replace_const.expr_map[lhs_id] = rhs_val; is_bottom = false; } - inline void set_to(const symbol_exprt &lhs, const exprt &rhs_val) + void set_to(const symbol_exprt &lhs, const exprt &rhs_val) { set_to(lhs.get_identifier(), rhs_val); } @@ -58,12 +65,12 @@ class constant_propagator_domaint:public ai_domain_baset bool is_constant_address_of(const exprt &expr) const; bool set_to_top(const irep_idt &id); - inline bool set_to_top(const symbol_exprt &expr) + bool set_to_top(const symbol_exprt &expr) { return set_to_top(expr.get_identifier()); } - inline void set_to_top() + void set_to_top() { replace_const.clear(); is_bottom = false; @@ -72,19 +79,22 @@ class constant_propagator_domaint:public ai_domain_baset valuest values; -protected: +private: void assign( valuest &dest, const symbol_exprt &lhs, exprt rhs, const namespacet &ns) const; - void assign_rec(valuest &values, - const exprt &lhs, const exprt &rhs, - const namespacet &ns); + void assign_rec( + valuest &values, + const exprt &lhs, + const exprt &rhs, + const namespacet &ns); - bool two_way_propagate_rec(const exprt &expr, - const namespacet &ns); + bool two_way_propagate_rec( + const exprt &expr, + const namespacet &ns); }; class constant_propagator_ait:public ait @@ -107,8 +117,6 @@ class constant_propagator_ait:public ait } protected: - friend class constant_propagator_domaint; - void replace( goto_functionst::goto_functiont &, const namespacet &); diff --git a/src/analyses/custom_bitvector_analysis.cpp b/src/analyses/custom_bitvector_analysis.cpp index 5155d13b7e5..01947636402 100644 --- a/src/analyses/custom_bitvector_analysis.cpp +++ b/src/analyses/custom_bitvector_analysis.cpp @@ -68,7 +68,8 @@ void custom_bitvector_domaint::set_bit( modet mode) { irep_idt id=object2id(lhs); - if(!id.empty()) set_bit(id, bit_nr, mode); + if(!id.empty()) + set_bit(id, bit_nr, mode); } /*******************************************************************\ @@ -133,7 +134,8 @@ void custom_bitvector_domaint::assign_lhs( const vectorst &vectors) { irep_idt id=object2id(lhs); - if(!id.empty()) assign_lhs(id, vectors); + if(!id.empty()) + assign_lhs(id, vectors); } /*******************************************************************\ @@ -183,10 +185,12 @@ custom_bitvector_domaint::vectorst vectorst vectors; bitst::const_iterator may_it=may_bits.find(identifier); - if(may_it!=may_bits.end()) vectors.may_bits=may_it->second; + if(may_it!=may_bits.end()) + vectors.may_bits=may_it->second; bitst::const_iterator must_it=must_bits.find(identifier); - if(must_it!=must_bits.end()) vectors.must_bits=must_it->second; + if(must_it!=must_bits.end()) + vectors.must_bits=must_it->second; return vectors; } @@ -323,7 +327,8 @@ void custom_bitvector_domaint::transform( ai_baset &ai, const namespacet &ns) { - if(has_values.is_false()) return; + if(has_values.is_false()) + return; // upcast of ai custom_bitvector_analysist &cba= @@ -382,7 +387,8 @@ void custom_bitvector_domaint::transform( case FUNCTION_CALL: { - const code_function_callt &code_function_call=to_code_function_call(instruction.code); + const code_function_callt &code_function_call= + to_code_function_call(instruction.code); const exprt &function=code_function_call.function(); if(function.id()==ID_symbol) @@ -526,7 +532,8 @@ void custom_bitvector_domaint::transform( { exprt guard=instruction.guard; - if(to!=from->get_target()) guard.make_not(); + if(to!=from->get_target()) + guard.make_not(); exprt result=eval(guard, cba); exprt result2=simplify_expr(result, ns); @@ -536,7 +543,9 @@ void custom_bitvector_domaint::transform( } break; - default:; + default: + { + } } } @@ -633,7 +642,8 @@ bool custom_bitvector_domaint::merge( bit_vectort &a_bits=may_bits[bit.first]; bit_vectort old=a_bits; a_bits|=bit.second; - if(old!=a_bits) changed=true; + if(old!=a_bits) + changed=true; } // now do MUST @@ -651,7 +661,8 @@ bool custom_bitvector_domaint::merge( { bit_vectort old=bit.second; bit.second&=bit.second; - if(old!=bit.second) changed=true; + if(old!=bit.second) + changed=true; } } @@ -706,7 +717,8 @@ bool custom_bitvector_domaint::has_get_must_or_may(const exprt &src) return true; forall_operands(it, src) - if(has_get_must_or_may(*it)) return true; + if(has_get_must_or_may(*it)) + return true; return false; } @@ -742,9 +754,8 @@ exprt custom_bitvector_domaint::eval( if(src.id()=="get_may") { for(const auto &bit : may_bits) - { - if(get_bit(bit.second, bit_nr)) return true_exprt(); - } + if(get_bit(bit.second, bit_nr)) + return true_exprt(); return false_exprt(); } @@ -824,8 +835,10 @@ void custom_bitvector_analysist::check( forall_goto_functions(f_it, goto_functions) { - if(!f_it->second.body.has_assertion()) continue; + if(!f_it->second.body.has_assertion()) + continue; + // TODO this is a hard-coded hack if(f_it->first=="__actual_thread_spawn") continue; @@ -842,7 +855,8 @@ void custom_bitvector_analysist::check( if(!custom_bitvector_domaint::has_get_must_or_may(i_it->guard)) continue; - if(operator[](i_it).has_values.is_false()) continue; + if(operator[](i_it).has_values.is_false()) + continue; exprt tmp=eval(i_it->guard, i_it); result=simplify_expr(tmp, ns); diff --git a/src/analyses/custom_bitvector_analysis.h b/src/analyses/custom_bitvector_analysis.h index 3cdf0895ddb..ceb2ba691be 100644 --- a/src/analyses/custom_bitvector_analysis.h +++ b/src/analyses/custom_bitvector_analysis.h @@ -32,28 +32,28 @@ class custom_bitvector_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) final override; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const final override; + const namespacet &ns) const final; - void make_bottom() final override + void make_bottom() final { may_bits.clear(); must_bits.clear(); has_values=tvt(false); } - void make_top() final override + void make_top() final { may_bits.clear(); must_bits.clear(); has_values=tvt(true); } - void make_entry() final override + void make_entry() final { make_top(); } @@ -101,7 +101,7 @@ class custom_bitvector_domaint:public ai_domain_baset const exprt &src, custom_bitvector_analysist &) const; -protected: +private: typedef enum { SET_MUST, CLEAR_MUST, SET_MAY, CLEAR_MAY } modet; void set_bit(const exprt &, unsigned bit_nr, modet); @@ -132,7 +132,10 @@ class custom_bitvector_analysist:public ait { public: void instrument(goto_functionst &); - void check(const namespacet &, const goto_functionst &, bool xml, std::ostream &); + void check( + const namespacet &, + const goto_functionst &, + bool xml, std::ostream &); exprt eval(const exprt &src, locationt loc) { diff --git a/src/analyses/dependence_graph.cpp b/src/analyses/dependence_graph.cpp index ddabac0c522..538f2c70dee 100644 --- a/src/analyses/dependence_graph.cpp +++ b/src/analyses/dependence_graph.cpp @@ -308,7 +308,8 @@ void dep_graph_domaint::output( it!=control_deps.end(); ++it) { - if(it!=control_deps.begin()) out << ","; + if(it!=control_deps.begin()) + out << ","; out << (*it)->location_number; } out << std::endl; @@ -322,7 +323,8 @@ void dep_graph_domaint::output( it!=data_deps.end(); ++it) { - if(it!=data_deps.begin()) out << ","; + if(it!=data_deps.begin()) + out << ","; out << (*it)->location_number; } out << std::endl; @@ -353,7 +355,7 @@ void dependence_grapht::add_dep( // add_edge is redundant as the subsequent operations also insert // entries into the edge maps (implicitly) - //add_edge(n_from, n_to); + // add_edge(n_from, n_to); nodes[n_from].out[n_to].add(kind); nodes[n_to].in[n_from].add(kind); } diff --git a/src/analyses/dependence_graph.h b/src/analyses/dependence_graph.h index 07bf28baa1b..f82d6f369ec 100644 --- a/src/analyses/dependence_graph.h +++ b/src/analyses/dependence_graph.h @@ -41,7 +41,8 @@ class dep_edget break; case DATA: case CTRL: - if(kind!=_kind) kind=BOTH; + if(kind!=_kind) + kind=BOTH; break; case BOTH: break; @@ -68,7 +69,7 @@ struct dep_nodet:public graph_nodet class dep_graph_domaint:public ai_domain_baset { public: - typedef graph::node_indext node_indext; + typedef grapht::node_indext node_indext; dep_graph_domaint(): has_values(false), @@ -85,14 +86,14 @@ class dep_graph_domaint:public ai_domain_baset goto_programt::const_targett from, goto_programt::const_targett to, ai_baset &ai, - const namespacet &ns) final override; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const final override; + const namespacet &ns) const final; - void make_top() final override + void make_top() final { assert(node_id!=std::numeric_limits::max()); @@ -101,7 +102,7 @@ class dep_graph_domaint:public ai_domain_baset data_deps.clear(); } - void make_bottom() final override + void make_bottom() final { assert(node_id!=std::numeric_limits::max()); @@ -110,7 +111,7 @@ class dep_graph_domaint:public ai_domain_baset data_deps.clear(); } - void make_entry() final override + void make_entry() final { make_top(); } @@ -126,7 +127,7 @@ class dep_graph_domaint:public ai_domain_baset return node_id; } -protected: +private: tvt has_values; node_indext node_id; @@ -147,11 +148,11 @@ class dep_graph_domaint:public ai_domain_baset class dependence_grapht: public ait, - public graph + public grapht { public: using ait::operator[]; - using graph::operator[]; + using grapht::operator[]; explicit dependence_grapht(const namespacet &_ns): ns(_ns), diff --git a/src/analyses/dirty.h b/src/analyses/dirty.h index 61ab0b0cb40..f60b86703c4 100644 --- a/src/analyses/dirty.h +++ b/src/analyses/dirty.h @@ -35,17 +35,17 @@ class dirtyt void output(std::ostream &out) const; - inline bool operator()(const irep_idt &id) const + bool operator()(const irep_idt &id) const { return dirty.find(id)!=dirty.end(); } - inline bool operator()(const symbol_exprt &expr) const + bool operator()(const symbol_exprt &expr) const { return operator()(expr.get_identifier()); } - inline const id_sett& get_dirty_ids() const + const id_sett &get_dirty_ids() const { return dirty; } @@ -60,8 +60,9 @@ class dirtyt void find_dirty_address_of(const exprt &expr); }; -static inline std::ostream &operator << ( - std::ostream &out, const dirtyt &dirty) +inline std::ostream &operator<<( + std::ostream &out, + const dirtyt &dirty) { dirty.output(out); return out; diff --git a/src/analyses/escape_analysis.cpp b/src/analyses/escape_analysis.cpp index 15c25eefea7..1382e9d1689 100644 --- a/src/analyses/escape_analysis.cpp +++ b/src/analyses/escape_analysis.cpp @@ -260,10 +260,11 @@ void escape_domaint::transform( ai_baset &ai, const namespacet &ns) { - if(has_values.is_false()) return; + if(has_values.is_false()) + return; // upcast of ai - //escape_analysist &ea= + // escape_analysist &ea= // static_cast(ai); const goto_programt::instructiont &instruction=*from; @@ -302,7 +303,8 @@ void escape_domaint::transform( case FUNCTION_CALL: { - const code_function_callt &code_function_call=to_code_function_call(instruction.code); + const code_function_callt &code_function_call= + to_code_function_call(instruction.code); const exprt &function=code_function_call.function(); if(function.id()==ID_symbol) @@ -338,7 +340,9 @@ void escape_domaint::transform( // This is the edge to the call site. break; - default:; + default: + { + } } } @@ -386,12 +390,17 @@ void escape_domaint::output( if(aliases.is_root(a_it1) && a_it1!=a_it2 && aliases.same_set(a_it1, a_it2)) { - if(first) { out << "Aliases: " << *a_it1; first=false; } + if(first) + { + out << "Aliases: " << *a_it1; + first=false; + } out << ' ' << *a_it2; } } - if(!first) out << '\n'; + if(!first) + out << '\n'; } } @@ -429,7 +438,8 @@ bool escape_domaint::merge( std::set &a_cleanup=cleanup_map[cleanup.first].cleanup_functions; unsigned old_size=a_cleanup.size(); a_cleanup.insert(b_cleanup.begin(), b_cleanup.end()); - if(a_cleanup.size()!=old_size) changed=true; + if(a_cleanup.size()!=old_size) + changed=true; } // kill empty ones @@ -554,8 +564,10 @@ void escape_analysist::insert_cleanup( { typet param_type=function_type.parameters().front().type(); exprt arg=lhs; - if(is_object) arg=address_of_exprt(arg); - if(arg.type()!=param_type) arg.make_typecast(param_type); + if(is_object) + arg=address_of_exprt(arg); + if(arg.type()!=param_type) + arg.make_typecast(param_type); code.arguments().push_back(arg); } @@ -596,7 +608,13 @@ void escape_analysist::instrument( std::set cleanup_functions; operator[](i_it).check_lhs(code_assign.lhs(), cleanup_functions); - insert_cleanup(f_it->second, i_it, code_assign.lhs(), cleanup_functions, false, ns); + insert_cleanup( + f_it->second, + i_it, + code_assign.lhs(), + cleanup_functions, + false, + ns); } break; @@ -623,8 +641,20 @@ void escape_analysist::instrument( d.check_lhs(code_dead.symbol(), cleanup_functions2); - insert_cleanup(f_it->second, i_it, code_dead.symbol(), cleanup_functions1, true, ns); - insert_cleanup(f_it->second, i_it, code_dead.symbol(), cleanup_functions2, false, ns); + insert_cleanup( + f_it->second, + i_it, + code_dead.symbol(), + cleanup_functions1, + true, + ns); + insert_cleanup( + f_it->second, + i_it, + code_dead.symbol(), + cleanup_functions2, + false, + ns); for(const auto &c : cleanup_functions1) { @@ -640,7 +670,9 @@ void escape_analysist::instrument( } break; - default:; + default: + { + } } } diff --git a/src/analyses/escape_analysis.h b/src/analyses/escape_analysis.h index 3cccec91a30..948bed3fea8 100644 --- a/src/analyses/escape_analysis.h +++ b/src/analyses/escape_analysis.h @@ -37,33 +37,33 @@ class escape_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) override final; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const override final; + const namespacet &ns) const final; bool merge( const escape_domaint &b, locationt from, locationt to); - void make_bottom() override final + void make_bottom() final { cleanup_map.clear(); aliases.clear(); has_values=tvt(false); } - void make_top() override final + void make_top() final { cleanup_map.clear(); aliases.clear(); has_values=tvt(true); } - void make_entry() override final + void make_entry() final { make_top(); } @@ -79,12 +79,11 @@ class escape_domaint:public ai_domain_baset // We track a set of 'cleanup functions' for specific // identifiers. The cleanup functions are executed // once the last pointer to an object is lost. - typedef std::map cleanup_mapt; + typedef std::map cleanup_mapt; cleanup_mapt cleanup_map; -protected: +private: tvt has_values; - void assign_lhs_cleanup(const exprt &, const std::set &); void get_rhs_cleanup(const exprt &, std::set &); void assign_lhs_aliases(const exprt &, const std::set &); @@ -110,8 +109,6 @@ class escape_analysist:public ait { } - friend class escape_domaint; - numbering bits; void insert_cleanup( diff --git a/src/analyses/flow_insensitive_analysis.cpp b/src/analyses/flow_insensitive_analysis.cpp index 257e4b70890..c2cd188352d 100644 --- a/src/analyses/flow_insensitive_analysis.cpp +++ b/src/analyses/flow_insensitive_analysis.cpp @@ -174,7 +174,8 @@ Function: flow_insensitive_analysis_baset::get_next \*******************************************************************/ -flow_insensitive_analysis_baset::locationt flow_insensitive_analysis_baset::get_next( +flow_insensitive_analysis_baset::locationt +flow_insensitive_analysis_baset::get_next( working_sett &working_set) { assert(!working_set.empty()); @@ -259,7 +260,7 @@ bool flow_insensitive_analysis_baset::visit( goto_program.get_successors(l, successors); seen_locations.insert(l); - if (statistics.find(l)==statistics.end()) + if(statistics.find(l)==statistics.end()) statistics[l]=1; else statistics[l]++; @@ -492,7 +493,7 @@ bool flow_insensitive_analysis_baset::do_function_call_rec( goto_functionst::function_mapt::const_iterator it= goto_functions.function_map.find(o.object().get(ID_identifier)); - if (it!=goto_functions.function_map.end()) + if(it!=goto_functions.function_map.end()) { new_data = do_function_call_rec( diff --git a/src/analyses/flow_insensitive_analysis.h b/src/analyses/flow_insensitive_analysis.h index 3c64f5a0f63..07d1f0f77cd 100644 --- a/src/analyses/flow_insensitive_analysis.h +++ b/src/analyses/flow_insensitive_analysis.h @@ -28,7 +28,7 @@ class flow_insensitive_abstract_domain_baset typedef goto_programt::const_targett locationt; - virtual void initialize( const namespacet &ns )=0; + virtual void initialize(const namespacet &ns)=0; virtual bool transform( const namespacet &ns, @@ -59,7 +59,6 @@ class flow_insensitive_abstract_domain_baset virtual void clear(void)=0; protected: - friend class flow_insensitive_analysis_baset; bool changed; // utilities @@ -81,12 +80,12 @@ class flow_insensitive_analysis_baset std::map statistics; - bool seen( const locationt& l ) + bool seen(const locationt &l) { return (seen_locations.find(l)!=seen_locations.end()); } - flow_insensitive_analysis_baset(const namespacet &_ns): + explicit flow_insensitive_analysis_baset(const namespacet &_ns): ns(_ns), initialized(false) { @@ -225,7 +224,7 @@ class flow_insensitive_analysist:public flow_insensitive_analysis_baset { public: // constructor - flow_insensitive_analysist(const namespacet &_ns): + explicit flow_insensitive_analysist(const namespacet &_ns): flow_insensitive_analysis_baset(_ns) { } @@ -238,8 +237,8 @@ class flow_insensitive_analysist:public flow_insensitive_analysis_baset flow_insensitive_analysis_baset::clear(); } - inline T& get_data() { return state; } - inline const T& get_data() const { return state; } + T &get_data() { return state; } + const T &get_data() const { return state; } protected: T state; // one global state diff --git a/src/analyses/global_may_alias.cpp b/src/analyses/global_may_alias.cpp index a3c5d4629e6..33ad0f7f186 100644 --- a/src/analyses/global_may_alias.cpp +++ b/src/analyses/global_may_alias.cpp @@ -126,7 +126,8 @@ void global_may_alias_domaint::transform( ai_baset &ai, const namespacet &ns) { - if(has_values.is_false()) return; + if(has_values.is_false()) + return; const goto_programt::instructiont &instruction=*from; @@ -156,7 +157,9 @@ void global_may_alias_domaint::transform( } break; - default:; + default: + { + } } } @@ -196,12 +199,17 @@ void global_may_alias_domaint::output( if(aliases.is_root(a_it1) && a_it1!=a_it2 && aliases.same_set(a_it1, a_it2)) { - if(first) { out << "Aliases: " << *a_it1; first=false; } + if(first) + { + out << "Aliases: " << *a_it1; + first=false; + } out << ' ' << *a_it2; } } - if(!first) out << '\n'; + if(!first) + out << '\n'; } } diff --git a/src/analyses/global_may_alias.h b/src/analyses/global_may_alias.h index 69eaa22404b..2f4a49b2d0a 100644 --- a/src/analyses/global_may_alias.h +++ b/src/analyses/global_may_alias.h @@ -37,31 +37,31 @@ class global_may_alias_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) final override; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const final override; + const namespacet &ns) const final; bool merge( const global_may_alias_domaint &b, locationt from, locationt to); - void make_bottom() final override + void make_bottom() final { aliases.clear(); has_values=tvt(false); } - void make_top() final override + void make_top() final { aliases.clear(); has_values=tvt(true); } - void make_entry() final override + void make_entry() final { make_top(); } @@ -69,7 +69,7 @@ class global_may_alias_domaint:public ai_domain_baset typedef union_find aliasest; aliasest aliases; -protected: +private: tvt has_values; void assign_lhs_aliases(const exprt &, const std::set &); diff --git a/src/analyses/goto_check.cpp b/src/analyses/goto_check.cpp index 038e7152230..4494aa33e76 100644 --- a/src/analyses/goto_check.cpp +++ b/src/analyses/goto_check.cpp @@ -39,12 +39,17 @@ class goto_checkt enable_pointer_check=_options.get_bool_option("pointer-check"); enable_memory_leak_check=_options.get_bool_option("memory-leak-check"); enable_div_by_zero_check=_options.get_bool_option("div-by-zero-check"); - enable_signed_overflow_check=_options.get_bool_option("signed-overflow-check"); - enable_unsigned_overflow_check=_options.get_bool_option("unsigned-overflow-check"); - enable_pointer_overflow_check=_options.get_bool_option("pointer-overflow-check"); + enable_signed_overflow_check= + _options.get_bool_option("signed-overflow-check"); + enable_unsigned_overflow_check= + _options.get_bool_option("unsigned-overflow-check"); + enable_pointer_overflow_check= + _options.get_bool_option("pointer-overflow-check"); enable_conversion_check=_options.get_bool_option("conversion-check"); - enable_undefined_shift_check=_options.get_bool_option("undefined-shift-check"); - enable_float_overflow_check=_options.get_bool_option("float-overflow-check"); + enable_undefined_shift_check= + _options.get_bool_option("undefined-shift-check"); + enable_float_overflow_check= + _options.get_bool_option("float-overflow-check"); enable_simplify=_options.get_bool_option("simplify"); enable_nan_check=_options.get_bool_option("nan-check"); retain_trivial=_options.get_bool_option("retain-trivial"); @@ -353,7 +358,8 @@ void goto_checkt::conversion_check( if(old_type.id()==ID_signedbv) // signed -> signed { std::size_t old_width=to_signedbv_type(old_type).get_width(); - if(new_width>=old_width) return; // always ok + if(new_width>=old_width) + return; // always ok binary_relation_exprt no_overflow_upper(ID_le); no_overflow_upper.lhs()=expr.op0(); @@ -374,7 +380,8 @@ void goto_checkt::conversion_check( else if(old_type.id()==ID_unsignedbv) // unsigned -> signed { std::size_t old_width=to_unsignedbv_type(old_type).get_width(); - if(new_width>=old_width+1) return; // always ok + if(new_width>=old_width+1) + return; // always ok binary_relation_exprt no_overflow_upper(ID_le); no_overflow_upper.lhs()=expr.op0(); @@ -458,7 +465,8 @@ void goto_checkt::conversion_check( else if(old_type.id()==ID_unsignedbv) // unsigned -> unsigned { std::size_t old_width=to_unsignedbv_type(old_type).get_width(); - if(new_width>=old_width) return; // always ok + if(new_width>=old_width) + return; // always ok binary_relation_exprt no_overflow_upper(ID_le); no_overflow_upper.lhs()=expr.op0(); @@ -845,9 +853,14 @@ void goto_checkt::nan_check( exprt plus_inf=ieee_floatt::plus_infinity(spec).to_expr(); exprt minus_inf=ieee_floatt::minus_infinity(spec).to_expr(); - isnan=or_exprt( - and_exprt(equal_exprt(expr.op0(), minus_inf), equal_exprt(expr.op1(), plus_inf)), - and_exprt(equal_exprt(expr.op0(), plus_inf), equal_exprt(expr.op1(), minus_inf))); + isnan= + or_exprt( + and_exprt( + equal_exprt(expr.op0(), minus_inf), + equal_exprt(expr.op1(), plus_inf)), + and_exprt( + equal_exprt(expr.op0(), plus_inf), + equal_exprt(expr.op1(), minus_inf))); } else if(expr.id()==ID_minus) { @@ -859,9 +872,14 @@ void goto_checkt::nan_check( exprt plus_inf=ieee_floatt::plus_infinity(spec).to_expr(); exprt minus_inf=ieee_floatt::minus_infinity(spec).to_expr(); - isnan=or_exprt( - and_exprt(equal_exprt(expr.op0(), plus_inf), equal_exprt(expr.op1(), plus_inf)), - and_exprt(equal_exprt(expr.op0(), minus_inf), equal_exprt(expr.op1(), minus_inf))); + isnan= + or_exprt( + and_exprt( + equal_exprt(expr.op0(), plus_inf), + equal_exprt(expr.op1(), plus_inf)), + and_exprt( + equal_exprt(expr.op0(), minus_inf), + equal_exprt(expr.op1(), minus_inf))); } else assert(false); @@ -1690,7 +1708,8 @@ void goto_checkt::goto_check(goto_functiont &goto_function) exprt pointer=i.code.op0().op0(); - if(pointer.type().subtype().get(ID_identifier)!="java::java.lang.AssertionError") + if(pointer.type().subtype().get(ID_identifier)!= + "java::java.lang.AssertionError") { notequal_exprt not_eq_null( pointer, @@ -1737,8 +1756,12 @@ void goto_checkt::goto_check(goto_functiont &goto_function) exprt lhs=ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr(); if(!base_type_eq(lhs.type(), address_of_expr.type(), ns)) address_of_expr.make_typecast(lhs.type()); - exprt rhs=if_exprt( - side_effect_expr_nondett(bool_typet()), address_of_expr, lhs, lhs.type()); + exprt rhs= + if_exprt( + side_effect_expr_nondett(bool_typet()), + address_of_expr, + lhs, + lhs.type()); t->source_location=i.source_location; t->code=code_assignt(lhs, rhs); t->code.add_source_location()=i.source_location; @@ -1787,13 +1810,15 @@ void goto_checkt::goto_check(goto_functiont &goto_function) i_it->source_location.set_line(it->source_location.get_line()); if(it->source_location.get_function()!=irep_idt()) - i_it->source_location.set_function(it->source_location.get_function()); + i_it->source_location.set_function( + it->source_location.get_function()); if(it->source_location.get_column()!=irep_idt()) i_it->source_location.set_column(it->source_location.get_column()); } - if(i_it->function==irep_idt()) i_it->function=it->function; + if(i_it->function==irep_idt()) + i_it->function=it->function; } // insert new instructions -- make sure targets are not moved diff --git a/src/analyses/goto_check.h b/src/analyses/goto_check.h index 73f9b2caac4..7ad04f99f79 100644 --- a/src/analyses/goto_check.h +++ b/src/analyses/goto_check.h @@ -40,10 +40,10 @@ void goto_check( " --pointer-check enable pointer checks\n" \ " --memory-leak-check enable memory leak checks\n" \ " --div-by-zero-check enable division by zero checks\n" \ - " --signed-overflow-check enable signed arithmetic over- and underflow checks\n" \ - " --unsigned-overflow-check enable arithmetic over- and underflow checks\n" \ - " --pointer-overflow-check enable pointer arithmetic over- and underflow checks\n" \ - " --conversion-check check whether values can be represented after type cast\n" \ + " --signed-overflow-check enable signed arithmetic over- and underflow checks\n" /* NOLINT(whitespace/line_length) */ \ + " --unsigned-overflow-check enable arithmetic over- and underflow checks\n" /* NOLINT(whitespace/line_length) */ \ + " --pointer-overflow-check enable pointer arithmetic over- and underflow checks\n" /* NOLINT(whitespace/line_length) */ \ + " --conversion-check check whether values can be represented after type cast\n" /* NOLINT(whitespace/line_length) */ \ " --undefined-shift-check check shift greater than bit-width\n" \ " --float-overflow-check check floating-point for +/-Inf\n" \ " --nan-check check floating-point for NaN\n" \ @@ -53,12 +53,12 @@ void goto_check( options.set_option("pointer-check", cmdline.isset("pointer-check")); \ options.set_option("memory-leak-check", cmdline.isset("memory-leak-check")); \ options.set_option("div-by-zero-check", cmdline.isset("div-by-zero-check")); \ - options.set_option("signed-overflow-check", cmdline.isset("signed-overflow-check")); \ - options.set_option("unsigned-overflow-check", cmdline.isset("unsigned-overflow-check")); \ - options.set_option("pointer-overflow-check", cmdline.isset("pointer-overflow-check")); \ + options.set_option("signed-overflow-check", cmdline.isset("signed-overflow-check")); /* NOLINT(whitespace/line_length) */ \ + options.set_option("unsigned-overflow-check", cmdline.isset("unsigned-overflow-check")); /* NOLINT(whitespace/line_length) */ \ + options.set_option("pointer-overflow-check", cmdline.isset("pointer-overflow-check")); /* NOLINT(whitespace/line_length) */ \ options.set_option("conversion-check", cmdline.isset("conversion-check")); \ - options.set_option("undefined-shift-check", cmdline.isset("undefined-shift-check")); \ - options.set_option("float-overflow-check", cmdline.isset("float-overflow-check")); \ + options.set_option("undefined-shift-check", cmdline.isset("undefined-shift-check")); /* NOLINT(whitespace/line_length) */ \ + options.set_option("float-overflow-check", cmdline.isset("float-overflow-check")); /* NOLINT(whitespace/line_length) */ \ options.set_option("nan-check", cmdline.isset("nan-check")) #endif // CPROVER_ANALYSES_GOTO_CHECK_H diff --git a/src/analyses/goto_rw.cpp b/src/analyses/goto_rw.cpp index 2d84edc27ea..239918240ab 100644 --- a/src/analyses/goto_rw.cpp +++ b/src/analyses/goto_rw.cpp @@ -61,7 +61,8 @@ void range_domaint::output( itr!=end(); ++itr) { - if(itr!=begin()) out << ";"; + if(itr!=begin()) + out << ";"; out << itr->first << ":" << itr->second; } out << "]"; @@ -552,7 +553,7 @@ void rw_range_sett::get_objects_typecast( const range_spect &range_start, const range_spect &size) { - const exprt& op=tc.op(); + const exprt &op=tc.op(); range_spect new_size= to_range_spect(pointer_offset_bits(op.type(), ns)); @@ -652,7 +653,8 @@ void rw_range_sett::add( const range_spect &range_end) { objectst::iterator entry=(mode==LHS_W ? w_range_set : r_range_set). - insert(std::make_pair(identifier, 0)).first; + insert( + std::pair(identifier, 0)).first; if(entry->second==0) entry->second=new range_domaint(); @@ -870,7 +872,8 @@ void guarded_range_domaint::output( itr!=end(); ++itr) { - if(itr!=begin()) out << ";"; + if(itr!=begin()) + out << ";"; out << itr->first << ":" << itr->second.first; out << " if " << from_expr(ns, "", itr->second.second); } @@ -934,7 +937,8 @@ void rw_guarded_range_set_value_sett::add( const range_spect &range_end) { objectst::iterator entry=(mode==LHS_W ? w_range_set : r_range_set). - insert(std::make_pair(identifier, 0)).first; + insert( + std::pair(identifier, 0)).first; if(entry->second==0) entry->second=new guarded_range_domaint(); @@ -1038,8 +1042,8 @@ void goto_rw(goto_programt::const_targett target, break; case OTHER: - //if it's printf, mark the operands as read here - if (target->code.get(ID_statement)==ID_printf) + // if it's printf, mark the operands as read here + if(target->code.get(ID_statement)==ID_printf) { forall_expr(it, target->code.operands()) rw_set.get_objects_rec(target, rw_range_sett::READ, *it); diff --git a/src/analyses/goto_rw.h b/src/analyses/goto_rw.h index f4b289e9491..6c9ae6d9dec 100644 --- a/src/analyses/goto_rw.h +++ b/src/analyses/goto_rw.h @@ -84,7 +84,8 @@ class rw_range_sett #ifdef USE_DSTRING typedef std::map objectst; #else - typedef std::unordered_map objectst; + typedef std::unordered_map + objectst; #endif virtual ~rw_range_sett(); @@ -94,17 +95,17 @@ class rw_range_sett { } - const objectst & get_r_set() const + const objectst &get_r_set() const { return r_range_set; } - const objectst & get_w_set() const + const objectst &get_w_set() const { return w_range_set; } - const range_domaint& get_ranges(objectst::const_iterator it) const + const range_domaint &get_ranges(objectst::const_iterator it) const { assert(dynamic_cast(it->second)!=0); return *static_cast(it->second); @@ -210,7 +211,7 @@ class rw_range_sett const range_spect &range_end); }; -inline std::ostream & operator << ( +inline std::ostream &operator << ( std::ostream &out, const rw_range_sett &rw_set) { @@ -273,7 +274,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett { } - const guarded_range_domaint& get_ranges(objectst::const_iterator it) const + const guarded_range_domaint &get_ranges(objectst::const_iterator it) const { assert(dynamic_cast(it->second)!=0); return *static_cast(it->second); diff --git a/src/analyses/interval_domain.cpp b/src/analyses/interval_domain.cpp index 0d5ca3d80aa..cc10fd89b00 100644 --- a/src/analyses/interval_domain.cpp +++ b/src/analyses/interval_domain.cpp @@ -6,8 +6,6 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG - #ifdef DEBUG #include #endif @@ -43,7 +41,8 @@ void interval_domaint::output( for(const auto &interval : int_map) { - if(interval.second.is_top()) continue; + if(interval.second.is_top()) + continue; if(interval.second.lower_set) out << interval.second.lower << " <= "; out << interval.first; @@ -54,7 +53,8 @@ void interval_domaint::output( for(const auto &interval : float_map) { - if(interval.second.is_top()) continue; + if(interval.second.is_top()) + continue; if(interval.second.lower_set) out << interval.second.lower << " <= "; out << interval.first; @@ -121,7 +121,9 @@ void interval_domaint::transform( } break; - default:; + default: + { + } } } @@ -142,8 +144,13 @@ bool interval_domaint::merge( locationt from, locationt to) { - if(b.bottom) return false; - if(bottom) { *this=b; return true; } + if(b.bottom) + return false; + if(bottom) + { + *this=b; + return true; + } bool result=false; @@ -160,7 +167,8 @@ bool interval_domaint::merge( { integer_intervalt previous=it->second; it->second.join(b_it->second); - if(it->second!=previous) result=true; + if(it->second!=previous) + result=true; it++; } @@ -179,7 +187,8 @@ bool interval_domaint::merge( { ieee_float_intervalt previous=it->second; it->second.join(b_it->second); - if(it->second!=previous) result=true; + if(it->second!=previous) + result=true; it++; } @@ -296,18 +305,22 @@ void interval_domaint::assume_rec( { mp_integer tmp; to_integer(rhs, tmp); - if(id==ID_lt) --tmp; + if(id==ID_lt) + --tmp; integer_intervalt &ii=int_map[lhs_identifier]; ii.make_le_than(tmp); - if(ii.is_bottom()) make_bottom(); + if(ii.is_bottom()) + make_bottom(); } else if(is_float(lhs.type()) && is_float(rhs.type())) { ieee_floatt tmp(to_constant_expr(rhs)); - if(id==ID_lt) tmp.decrement(); + if(id==ID_lt) + tmp.decrement(); ieee_float_intervalt &fi=float_map[lhs_identifier]; fi.make_le_than(tmp); - if(fi.is_bottom()) make_bottom(); + if(fi.is_bottom()) + make_bottom(); } } else if(lhs.id()==ID_constant && rhs.id()==ID_symbol) @@ -318,18 +331,22 @@ void interval_domaint::assume_rec( { mp_integer tmp; to_integer(lhs, tmp); - if(id==ID_lt) ++tmp; + if(id==ID_lt) + ++tmp; integer_intervalt &ii=int_map[rhs_identifier]; ii.make_ge_than(tmp); - if(ii.is_bottom()) make_bottom(); + if(ii.is_bottom()) + make_bottom(); } else if(is_float(lhs.type()) && is_float(rhs.type())) { ieee_floatt tmp(to_constant_expr(lhs)); - if(id==ID_lt) tmp.increment(); + if(id==ID_lt) + tmp.increment(); ieee_float_intervalt &fi=float_map[rhs_identifier]; fi.make_ge_than(tmp); - if(fi.is_bottom()) make_bottom(); + if(fi.is_bottom()) + make_bottom(); } } else if(lhs.id()==ID_symbol && rhs.id()==ID_symbol) @@ -343,7 +360,8 @@ void interval_domaint::assume_rec( integer_intervalt &rhs_i=int_map[rhs_identifier]; lhs_i.meet(rhs_i); rhs_i=lhs_i; - if(rhs_i.is_bottom()) make_bottom(); + if(rhs_i.is_bottom()) + make_bottom(); } else if(is_float(lhs.type()) && is_float(rhs.type())) { @@ -351,7 +369,8 @@ void interval_domaint::assume_rec( ieee_float_intervalt &rhs_i=float_map[rhs_identifier]; lhs_i.meet(rhs_i); rhs_i=lhs_i; - if(rhs_i.is_bottom()) make_bottom(); + if(rhs_i.is_bottom()) + make_bottom(); } } } @@ -450,10 +469,14 @@ exprt interval_domaint::make_expression(const symbol_exprt &src) const if(is_int(src.type())) { int_mapt::const_iterator i_it=int_map.find(src.get_identifier()); - if(i_it==int_map.end()) return true_exprt(); + if(i_it==int_map.end()) + return true_exprt(); + const integer_intervalt &interval=i_it->second; - if(interval.is_top()) return true_exprt(); - if(interval.is_bottom()) return false_exprt(); + if(interval.is_top()) + return true_exprt(); + if(interval.is_bottom()) + return false_exprt(); exprt::operandst conjuncts; @@ -474,10 +497,14 @@ exprt interval_domaint::make_expression(const symbol_exprt &src) const else if(is_float(src.type())) { float_mapt::const_iterator i_it=float_map.find(src.get_identifier()); - if(i_it==float_map.end()) return true_exprt(); + if(i_it==float_map.end()) + return true_exprt(); + const ieee_float_intervalt &interval=i_it->second; - if(interval.is_top()) return true_exprt(); - if(interval.is_bottom()) return false_exprt(); + if(interval.is_top()) + return true_exprt(); + if(interval.is_bottom()) + return false_exprt(); exprt::operandst conjuncts; diff --git a/src/analyses/interval_domain.h b/src/analyses/interval_domain.h index f9ffd291b12..7e95c65e9de 100644 --- a/src/analyses/interval_domain.h +++ b/src/analyses/interval_domain.h @@ -24,7 +24,7 @@ class interval_domaint:public ai_domain_baset // Trivial, conjunctive interval domain for both float // and integers. The categorization 'float' and 'integers' // is done by is_int and is_float. - + interval_domaint():bottom(true) { } @@ -33,12 +33,12 @@ class interval_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) override final; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const override final; + const namespacet &ns) const final; bool merge( const interval_domaint &b, @@ -46,7 +46,7 @@ class interval_domaint:public ai_domain_baset locationt to); // no states - void make_bottom() override final + void make_bottom() final { int_map.clear(); float_map.clear(); @@ -54,14 +54,14 @@ class interval_domaint:public ai_domain_baset } // all states - void make_top() override final + void make_top() final { int_map.clear(); float_map.clear(); bottom=false; } - void make_entry() override final + void make_entry() final { make_top(); } @@ -70,22 +70,22 @@ class interval_domaint:public ai_domain_baset void assume(const exprt &, const namespacet &); - inline static bool is_int(const typet &src) + static bool is_int(const typet &src) { return src.id()==ID_signedbv || src.id()==ID_unsignedbv; } - inline static bool is_float(const typet &src) + static bool is_float(const typet &src) { return src.id()==ID_floatbv; } - inline bool is_bottom() const + bool is_bottom() const { return bottom; } -protected: +private: bool bottom; typedef std::map int_mapt; diff --git a/src/analyses/interval_template.h b/src/analyses/interval_template.h index 97ccf7a10d7..f59d1da1f8f 100644 --- a/src/analyses/interval_template.h +++ b/src/analyses/interval_template.h @@ -6,8 +6,8 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -#ifndef CPROVER_UTIL_INTERVAL_TEMPLATE_H -#define CPROVER_UTIL_INTERVAL_TEMPLATE_H +#ifndef CPROVER_ANALYSES_INTERVAL_TEMPLATE_H +#define CPROVER_ANALYSES_INTERVAL_TEMPLATE_H #include #include @@ -17,12 +17,12 @@ Author: Daniel Kroening, kroening@kroening.com template class interval_template { public: - inline interval_template():lower_set(false), upper_set(false) + interval_template():lower_set(false), upper_set(false) { // this is 'top' } - inline explicit interval_template(const T &x): + explicit interval_template(const T &x): lower_set(true), upper_set(true), lower(x), @@ -30,7 +30,7 @@ template class interval_template { } - inline explicit interval_template(const T &l, const T &u): + explicit interval_template(const T &l, const T &u): lower_set(true), upper_set(true), lower(l), @@ -41,32 +41,32 @@ template class interval_template bool lower_set, upper_set; T lower, upper; - inline const T &get_lower() const + const T &get_lower() const { return lower; } - inline const T &get_upper() const + const T &get_upper() const { return upper; } - inline bool empty() const + bool empty() const { return upper_set && lower_set && lower>upper; } - inline bool is_bottom() const // equivalent to 'false' + bool is_bottom() const // equivalent to 'false' { return empty(); } - inline bool is_top() const // equivalent to 'true' + bool is_top() const // equivalent to 'true' { return !lower_set && !upper_set; } - inline bool singleton() const + bool singleton() const { return upper_set && lower_set && lower==upper; } @@ -76,7 +76,8 @@ template class interval_template { if(upper_set) { - if(upper>v) upper=v; + if(upper>v) + upper=v; } else { @@ -89,7 +90,8 @@ template class interval_template { if(lower_set) { - if(lower class interval_template } // Union or disjunction - inline void join(const interval_template &i) + void join(const interval_template &i) { approx_union_with(i); } // Intersection or conjunction - inline void meet(const interval_template &i) + void meet(const interval_template &i) { intersect_with(i); } @@ -154,43 +156,52 @@ template class interval_template }; template -tvt operator <= (const interval_template &a, const interval_template &b) +tvt operator<=(const interval_template &a, const interval_template &b) { - if(a.upper_set && b.lower_set && a.upper<=b.lower) return tvt(true); - if(a.lower_set && b.upper_set && a.lower>b.upper) return tvt(false); + if(a.upper_set && b.lower_set && a.upper<=b.lower) + return tvt(true); + if(a.lower_set && b.upper_set && a.lower>b.upper) + return tvt(false); + return tvt::unknown(); } template -tvt operator >= (const interval_template &a, const interval_template &b) +tvt operator>=(const interval_template &a, const interval_template &b) { return b<=a; } template -tvt operator < (const interval_template &a, const interval_template &b) +tvt operator<(const interval_template &a, const interval_template &b) { return !(a>=b); } template -tvt operator > (const interval_template &a, const interval_template &b) +tvt operator>(const interval_template &a, const interval_template &b) { return !(a<=b); } template -bool operator == (const interval_template &a, const interval_template &b) +bool operator==(const interval_template &a, const interval_template &b) { - if(a.lower_set!=b.lower_set) return false; - if(a.upper_set!=b.upper_set) return false; - if(a.lower_set && a.lower!=b.lower) return false; - if(a.upper_set && a.upper!=b.upper) return false; + if(a.lower_set!=b.lower_set) + return false; + if(a.upper_set!=b.upper_set) + return false; + + if(a.lower_set && a.lower!=b.lower) + return false; + if(a.upper_set && a.upper!=b.upper) + return false; + return true; } template -bool operator != (const interval_template &a, const interval_template &b) +bool operator!=(const interval_template &a, const interval_template &b) { return !(a==b); } @@ -231,4 +242,4 @@ std::ostream &operator << (std::ostream &out, const interval_template &i) return out; } -#endif // CPROVER_UTIL_INTERVAL_TEMPLATE_H +#endif // CPROVER_ANALYSES_INTERVAL_TEMPLATE_H diff --git a/src/analyses/invariant_propagation.cpp b/src/analyses/invariant_propagation.cpp index 8e73d7e151b..2da2d7278f4 100644 --- a/src/analyses/invariant_propagation.cpp +++ b/src/analyses/invariant_propagation.cpp @@ -73,7 +73,8 @@ void invariant_propagationt::add_objects( goto_program.get_decl_identifiers(locals); // cache the list for the locals to speed things up - typedef std::unordered_map object_cachet; + typedef std::unordered_map + object_cachet; object_cachet object_cache; forall_goto_program_instructions(i_it, goto_program) @@ -169,8 +170,8 @@ void invariant_propagationt::get_objects_rec( } else if(t.id()==ID_array) { - //get_objects_rec(identifier, suffix+"[]", t.subtype(), dest); - //we don't track these + // get_objects_rec(identifier, suffix+"[]", t.subtype(), dest); + // we don't track these } else if(check_type(t)) { @@ -206,7 +207,8 @@ void invariant_propagationt::add_objects( const goto_programt &goto_program=f_it->second.body; // cache the list for the locals to speed things up - typedef std::unordered_map object_cachet; + typedef std::unordered_map + object_cachet; object_cachet object_cache; forall_goto_program_instructions(i_it, goto_program) @@ -382,12 +384,13 @@ void invariant_propagationt::simplify(goto_programt &goto_program) { Forall_goto_program_instructions(i_it, goto_program) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; // find invariant set state_mapt::const_iterator s_it=state_map.find(i_it); - - if(s_it==state_map.end()) continue; + if(s_it==state_map.end()) + continue; const invariant_sett &invariant_set=s_it->second.invariant_set; diff --git a/src/analyses/invariant_propagation.h b/src/analyses/invariant_propagation.h index 2cb25851500..0884ba85d07 100644 --- a/src/analyses/invariant_propagation.h +++ b/src/analyses/invariant_propagation.h @@ -35,7 +35,7 @@ class invariant_propagationt:public virtual void initialize(const goto_programt &goto_program); virtual void initialize(const goto_functionst &goto_functions); - + void make_all_true(); void make_all_false(); @@ -43,7 +43,7 @@ class invariant_propagationt:public void simplify(goto_functionst &goto_functions); typedef ait baset; - + protected: const namespacet &ns; value_setst &value_sets; diff --git a/src/analyses/invariant_set.cpp b/src/analyses/invariant_set.cpp index 725a0fbc648..15c350f0e0f 100644 --- a/src/analyses/invariant_set.cpp +++ b/src/analyses/invariant_set.cpp @@ -54,7 +54,8 @@ Function: inv_object_storet::get bool inv_object_storet::get(const exprt &expr, unsigned &n) { std::string s=build_string(expr); - if(s=="") return true; + if(s.empty()) + return true; // if it's a constant, we add it in any case if(is_constant(expr)) @@ -304,10 +305,14 @@ void invariant_sett::add( unsigned s_r=eq_set.find(p.second); for(unsigned f=0; f(f, s)); + } + } } /*******************************************************************\ @@ -333,7 +338,9 @@ void invariant_sett::add_eq(const std::pair &p) mp_integer c; for(unsigned i=0; iis_constant(i)) { if(constant_seen) @@ -345,6 +352,8 @@ void invariant_sett::add_eq(const std::pair &p) else constant_seen=true; } + } + } // replicate <= and != constraints @@ -540,7 +549,8 @@ Function: invariant_sett::strengthen void invariant_sett::add_type_bounds(const exprt &expr, const typet &type) { - if(expr.type()==type) return; + if(expr.type()==type) + return; if(type.id()==ID_unsignedbv) { @@ -549,7 +559,8 @@ void invariant_sett::add_type_bounds(const exprt &expr, const typet &type) if(op_width<=8) { unsigned a; - if(get_object(expr, a)) return; + if(get_object(expr, a)) + return; add_bounds(a, boundst(0, power(2, op_width)-1)); } @@ -863,14 +874,16 @@ tvt invariant_sett::implies_rec(const exprt &expr) const bool ob0=get_object(expr.op0(), p.first); bool ob1=get_object(expr.op1(), p.second); - if(ob0 || ob1) return tvt::unknown(); + if(ob0 || ob1) + return tvt::unknown(); tvt r; if(expr.id()==ID_le) { r=is_le(p); - if(!r.is_unknown()) return r; + if(!r.is_unknown()) + return r; boundst b0, b1; get_bounds(p.first, b0); @@ -881,7 +894,8 @@ tvt invariant_sett::implies_rec(const exprt &expr) const else if(expr.id()==ID_lt) { r=is_lt(p); - if(!r.is_unknown()) return r; + if(!r.is_unknown()) + return r; boundst b0, b1; get_bounds(p.first, b0); @@ -932,7 +946,8 @@ void invariant_sett::get_bounds(unsigned a, boundst &bounds) const bounds_mapt::const_iterator it=bounds_map.find(a); - if(it!=bounds_map.end()) bounds=it->second; + if(it!=bounds_map.end()) + bounds=it->second; } /*******************************************************************\ @@ -954,11 +969,13 @@ void invariant_sett::nnf(exprt &expr, bool negate) if(expr.is_true()) { - if(negate) expr=false_exprt(); + if(negate) + expr=false_exprt(); } else if(expr.is_false()) { - if(negate) expr=true_exprt(); + if(negate) + expr=true_exprt(); } else if(expr.id()==ID_not) { @@ -970,14 +987,16 @@ void invariant_sett::nnf(exprt &expr, bool negate) } else if(expr.id()==ID_and) { - if(negate) expr.id(ID_or); + if(negate) + expr.id(ID_or); Forall_operands(it, expr) nnf(*it, negate); } else if(expr.id()==ID_or) { - if(negate) expr.id(ID_and); + if(negate) + expr.id(ID_and); Forall_operands(it, expr) nnf(*it, negate); @@ -997,7 +1016,8 @@ void invariant_sett::nnf(exprt &expr, bool negate) } else { - if(negate) expr.make_not(); + if(negate) + expr.make_not(); } } else if(expr.id()==ID_le) @@ -1040,11 +1060,13 @@ void invariant_sett::nnf(exprt &expr, bool negate) } else if(expr.id()==ID_equal) { - if(negate) expr.id(ID_notequal); + if(negate) + expr.id(ID_notequal); } else if(expr.id()==ID_notequal) { - if(negate) expr.id(ID_equal); + if(negate) + expr.id(ID_equal); } else { @@ -1166,7 +1188,7 @@ std::string inv_object_storet::to_string( unsigned a, const irep_idt &identifier) const { - //return from_expr(ns, "", get_expr(a)); + // return from_expr(ns, "", get_expr(a)); return id2string(map[a]); } @@ -1245,9 +1267,10 @@ bool invariant_sett::make_union(const invariant_sett &other) if(make_union_bounds_map(other.bounds_map)) return true; - if(old_eq_roots!=eq_set.count_roots()) return true; - if(old_ne_set!=ne_set.size()) return true; - if(old_le_set!=le_set.size()) return true; + if(old_eq_roots!=eq_set.count_roots() || + old_ne_set!=ne_set.size() || + old_le_set!=le_set.size()) + return true; return false; // no change } @@ -1287,7 +1310,8 @@ bool invariant_sett::make_union_bounds_map(const bounds_mapt &other) { boundst old(it->second); it->second.approx_union_with(o_it->second); - if(it->second!=old) changed=true; + if(it->second!=old) + changed=true; it++; } } @@ -1333,7 +1357,8 @@ void invariant_sett::modifies(const exprt &lhs) lhs.id()==ID_member) { unsigned a; - if(!get_object(lhs, a)) modifies(a); + if(!get_object(lhs, a)) + modifies(a); } else if(lhs.id()==ID_index) { diff --git a/src/analyses/invariant_set.h b/src/analyses/invariant_set.h index fc9ad07d59f..d5f0a31003c 100644 --- a/src/analyses/invariant_set.h +++ b/src/analyses/invariant_set.h @@ -22,7 +22,7 @@ Author: Daniel Kroening, kroening@kroening.com class inv_object_storet { public: - inv_object_storet(const namespacet &_ns):ns(_ns) + explicit inv_object_storet(const namespacet &_ns):ns(_ns) { } diff --git a/src/analyses/invariant_set_domain.cpp b/src/analyses/invariant_set_domain.cpp index 6ee0be8e6e0..5f8512c55b5 100644 --- a/src/analyses/invariant_set_domain.cpp +++ b/src/analyses/invariant_set_domain.cpp @@ -36,7 +36,8 @@ void invariant_set_domaint::transform( goto_programt::const_targett next=from_l; next++; - if(next==to_l) tmp.make_not(); + if(next==to_l) + tmp.make_not(); simplify(tmp, ns); invariant_set.strengthen(tmp); @@ -80,7 +81,9 @@ void invariant_set_domaint::transform( invariant_set.make_threaded(); break; - default:; - // do nothing + default: + { + // do nothing + } } } diff --git a/src/analyses/invariant_set_domain.h b/src/analyses/invariant_set_domain.h index 99923f536f9..2e231524cbb 100644 --- a/src/analyses/invariant_set_domain.h +++ b/src/analyses/invariant_set_domain.h @@ -26,7 +26,7 @@ class invariant_set_domaint:public ai_domain_baset // overloading - inline bool merge( + bool merge( const invariant_set_domaint &other, locationt from, locationt to) @@ -41,7 +41,7 @@ class invariant_set_domaint:public ai_domain_baset void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const override final + const namespacet &ns) const final { if(has_values.is_known()) out << has_values.to_string() << '\n'; @@ -53,21 +53,21 @@ class invariant_set_domaint:public ai_domain_baset locationt from_l, locationt to_l, ai_baset &ai, - const namespacet &ns) override final; + const namespacet &ns) final; - void make_top() override final + void make_top() final { invariant_set.make_true(); has_values=tvt(true); } - void make_bottom() override final + void make_bottom() final { invariant_set.make_false(); has_values=tvt(false); } - void make_entry() override final + void make_entry() final { invariant_set.make_true(); has_values=tvt(true); diff --git a/src/analyses/is_threaded.cpp b/src/analyses/is_threaded.cpp index a808609497e..812041903f0 100644 --- a/src/analyses/is_threaded.cpp +++ b/src/analyses/is_threaded.cpp @@ -56,9 +56,10 @@ class is_threaded_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) override final + const namespacet &ns) final { - if(!reachable) return; + if(!reachable) + return; if(from->is_start_thread() || to->is_end_thread()) { @@ -67,17 +68,17 @@ class is_threaded_domaint:public ai_domain_baset } } - void make_bottom() override final + void make_bottom() final { reachable=has_spawn=is_threaded=false; } - void make_top() override final + void make_top() final { reachable=has_spawn=is_threaded=true; } - void make_entry() override final + void make_entry() final { reachable=true; has_spawn=is_threaded=false; diff --git a/src/analyses/is_threaded.h b/src/analyses/is_threaded.h index 931baabb7db..ceb10494665 100644 --- a/src/analyses/is_threaded.h +++ b/src/analyses/is_threaded.h @@ -24,7 +24,7 @@ class is_threadedt compute(goto_functions); } - inline bool operator()(const goto_programt::const_targett t) const + bool operator()(const goto_programt::const_targett t) const { return is_threaded_set.find(t)!=is_threaded_set.end(); } diff --git a/src/analyses/local_bitvector_analysis.cpp b/src/analyses/local_bitvector_analysis.cpp index d6d15a19abd..43cb5c1d360 100644 --- a/src/analyses/local_bitvector_analysis.cpp +++ b/src/analyses/local_bitvector_analysis.cpp @@ -32,14 +32,22 @@ Function: local_bitvector_analysist::flagst::print void local_bitvector_analysist::flagst::print(std::ostream &out) const { - if(is_unknown()) out << "+unknown"; - if(is_uninitialized()) out << "+uninitialized"; - if(is_uses_offset()) out << "+uses_offset"; - if(is_dynamic_local()) out << "+dynamic_local"; - if(is_dynamic_heap()) out << "+dynamic_heap"; - if(is_null()) out << "+null"; - if(is_static_lifetime()) out << "+static_lifetime"; - if(is_integer_address()) out << "+integer_address"; + if(is_unknown()) + out << "+unknown"; + if(is_uninitialized()) + out << "+uninitialized"; + if(is_uses_offset()) + out << "+uses_offset"; + if(is_dynamic_local()) + out << "+dynamic_local"; + if(is_dynamic_heap()) + out << "+dynamic_heap"; + if(is_null()) + out << "+null"; + if(is_static_lifetime()) + out << "+static_lifetime"; + if(is_integer_address()) + out << "+integer_address"; } /*******************************************************************\ @@ -86,9 +94,11 @@ Function: local_bitvector_analysist::is_tracked bool local_bitvector_analysist::is_tracked(const irep_idt &identifier) { localst::locals_mapt::const_iterator it=locals.locals_map.find(identifier); - if(it==locals.locals_map.end()) return false; - if(it->second.id()!=ID_pointer) return false; - if(dirty(identifier)) return false; + if(it==locals.locals_map.end() || + it->second.id()!=ID_pointer || + dirty(identifier)) + return false; + return true; } @@ -130,7 +140,8 @@ void local_bitvector_analysist::assign_lhs( } else if(lhs.id()==ID_member) { - assign_lhs(to_member_expr(lhs).struct_op(), rhs, loc_info_src, loc_info_dest); + assign_lhs( + to_member_expr(lhs).struct_op(), rhs, loc_info_src, loc_info_dest); } else if(lhs.id()==ID_typecast) { @@ -313,7 +324,8 @@ Function: local_bitvector_analysist::build void local_bitvector_analysist::build(const goto_functiont &goto_function) { - if(cfg.nodes.empty()) return; + if(cfg.nodes.empty()) + return; work_queuet work_queue; work_queue.push(0); @@ -342,33 +354,46 @@ void local_bitvector_analysist::build(const goto_functiont &goto_function) case ASSIGN: { const code_assignt &code_assign=to_code_assign(instruction.code); - assign_lhs(code_assign.lhs(), code_assign.rhs(), loc_info_src, loc_info_dest); + assign_lhs( + code_assign.lhs(), code_assign.rhs(), loc_info_src, loc_info_dest); } break; case DECL: { const code_declt &code_decl=to_code_decl(instruction.code); - assign_lhs(code_decl.symbol(), exprt(ID_uninitialized), loc_info_src, loc_info_dest); + assign_lhs( + code_decl.symbol(), + exprt(ID_uninitialized), + loc_info_src, + loc_info_dest); } break; case DEAD: { const code_deadt &code_dead=to_code_dead(instruction.code); - assign_lhs(code_dead.symbol(), exprt(ID_uninitialized), loc_info_src, loc_info_dest); + assign_lhs( + code_dead.symbol(), + exprt(ID_uninitialized), + loc_info_src, + loc_info_dest); } break; case FUNCTION_CALL: { - const code_function_callt &code_function_call=to_code_function_call(instruction.code); + const code_function_callt &code_function_call= + to_code_function_call(instruction.code); if(code_function_call.lhs().is_not_nil()) - assign_lhs(code_function_call.lhs(), nil_exprt(), loc_info_src, loc_info_dest); + assign_lhs( + code_function_call.lhs(), nil_exprt(), loc_info_src, loc_info_dest); } break; - default:; + default: + { + } } for(const auto &succ : node.successors) diff --git a/src/analyses/local_bitvector_analysis.h b/src/analyses/local_bitvector_analysis.h index ad0035b9e5e..a902d19b099 100644 --- a/src/analyses/local_bitvector_analysis.h +++ b/src/analyses/local_bitvector_analysis.h @@ -51,7 +51,7 @@ class local_bitvector_analysist // categories of things one can point to struct flagst { - inline flagst():bits(0) + flagst():bits(0) { } @@ -73,114 +73,108 @@ class local_bitvector_analysist B_integer_address=1<<7 } bitst; - explicit inline flagst(const bitst _bits):bits(_bits) + explicit flagst(const bitst _bits):bits(_bits) { } unsigned bits; - inline bool merge(const flagst &other) + bool merge(const flagst &other) { unsigned old=bits; bits|=other.bits; // bit-wise or return old!=bits; } - inline static flagst mk_unknown() + static flagst mk_unknown() { return flagst(B_unknown); } - inline bool is_unknown() const + bool is_unknown() const { return (bits&B_unknown)!=0; } - inline static flagst mk_uninitialized() + static flagst mk_uninitialized() { return flagst(B_uninitialized); } - inline bool is_uninitialized() const + bool is_uninitialized() const { return (bits&B_uninitialized)!=0; } - inline static flagst mk_uses_offset() + static flagst mk_uses_offset() { return flagst(B_uses_offset); } - inline bool is_uses_offset() const + bool is_uses_offset() const { return (bits&B_uses_offset)!=0; } - inline static flagst mk_dynamic_local() + static flagst mk_dynamic_local() { return flagst(B_dynamic_local); } - inline bool is_dynamic_local() const + bool is_dynamic_local() const { return (bits&B_dynamic_local)!=0; } - inline static flagst mk_dynamic_heap() + static flagst mk_dynamic_heap() { return flagst(B_dynamic_heap); } - inline bool is_dynamic_heap() const + bool is_dynamic_heap() const { return (bits&B_dynamic_heap)!=0; } - inline static flagst mk_null() + static flagst mk_null() { return flagst(B_null); } - inline bool is_null() const + bool is_null() const { return (bits&B_null)!=0; } - inline static flagst mk_static_lifetime() + static flagst mk_static_lifetime() { return flagst(B_static_lifetime); } - inline bool is_static_lifetime() const + bool is_static_lifetime() const { return (bits&B_static_lifetime)!=0; } - inline static flagst mk_integer_address() + static flagst mk_integer_address() { return flagst(B_integer_address); } - inline bool is_integer_address() const + bool is_integer_address() const { return (bits&B_integer_address)!=0; } void print(std::ostream &) const; - }; - - friend std::ostream & operator << (std::ostream &out, const flagst f) - { - f.print(out); - return out; - } - inline friend flagst operator|(const flagst f1, const flagst f2) - { - flagst result=f1; - result.bits|=f2.bits; - return result; - } + flagst operator|(const flagst other) const + { + flagst result(*this); + result.bits|=other.bits; + return result; + } + }; flagst get( const goto_programt::const_targett t, @@ -195,7 +189,7 @@ class local_bitvector_analysist // pointers -> flagst // This is a vector, so it's fast. - typedef expanding_vector points_tot; + typedef expanding_vectort points_tot; // the information tracked per program location class loc_infot @@ -222,4 +216,12 @@ class local_bitvector_analysist bool is_tracked(const irep_idt &identifier); }; +inline std::ostream &operator<<( + std::ostream &out, + const local_bitvector_analysist::flagst &flags) +{ + flags.print(out); + return out; +} + #endif // CPROVER_ANALYSES_LOCAL_BITVECTOR_ANALYSIS_H diff --git a/src/analyses/local_cfg.h b/src/analyses/local_cfg.h index ab6ee2cc345..a0187be8177 100644 --- a/src/analyses/local_cfg.h +++ b/src/analyses/local_cfg.h @@ -40,7 +40,7 @@ class local_cfgt typedef std::vector nodest; nodest nodes; - inline explicit local_cfgt(const goto_programt &_goto_program) + explicit local_cfgt(const goto_programt &_goto_program) { build(_goto_program); } diff --git a/src/analyses/local_may_alias.cpp b/src/analyses/local_may_alias.cpp index 25e3c4d5211..53d089b9544 100644 --- a/src/analyses/local_may_alias.cpp +++ b/src/analyses/local_may_alias.cpp @@ -101,14 +101,14 @@ void local_may_aliast::assign_lhs( { if(objects[i].id()==ID_symbol) { - const irep_idt &identifier=to_symbol_expr(objects[i]).get_identifier(); + const irep_idt &identifier= + to_symbol_expr(objects[i]).get_identifier(); if(dirty(identifier) || !locals.is_local(identifier)) { loc_info_dest.aliases.isolate(i); loc_info_dest.aliases.make_union(i, unknown_object); } - } } } @@ -119,7 +119,8 @@ void local_may_aliast::assign_lhs( } else if(lhs.id()==ID_member) { - assign_lhs(to_member_expr(lhs).struct_op(), rhs, loc_info_src, loc_info_dest); + assign_lhs( + to_member_expr(lhs).struct_op(), rhs, loc_info_src, loc_info_dest); } else if(lhs.id()==ID_typecast) { @@ -382,7 +383,8 @@ Function: local_may_aliast::build void local_may_aliast::build(const goto_functiont &goto_function) { - if(cfg.nodes.empty()) return; + if(cfg.nodes.empty()) + return; work_queuet work_queue; @@ -403,7 +405,8 @@ void local_may_aliast::build(const goto_functiont &goto_function) { const irep_idt &identifier=it->get_identifier(); if(is_tracked(identifier)) - loc_infos[0].points_to[objects.number(identifier)].objects.insert(unknown_object); + loc_infos[0].points_to[objects.number(identifier)].objects.insert( + unknown_object); } #endif @@ -414,7 +417,8 @@ void local_may_aliast::build(const goto_functiont &goto_function) l_it++) { if(is_tracked(l_it->first)) - loc_infos[0].aliases.make_union(objects.number(l_it->second), unknown_object); + loc_infos[0].aliases.make_union( + objects.number(l_it->second), unknown_object); } #endif @@ -433,29 +437,34 @@ void local_may_aliast::build(const goto_functiont &goto_function) case ASSIGN: { const code_assignt &code_assign=to_code_assign(instruction.code); - assign_lhs(code_assign.lhs(), code_assign.rhs(), loc_info_src, loc_info_dest); + assign_lhs( + code_assign.lhs(), code_assign.rhs(), loc_info_src, loc_info_dest); } break; case DECL: { const code_declt &code_decl=to_code_decl(instruction.code); - assign_lhs(code_decl.symbol(), nil_exprt(), loc_info_src, loc_info_dest); + assign_lhs( + code_decl.symbol(), nil_exprt(), loc_info_src, loc_info_dest); } break; case DEAD: { const code_deadt &code_dead=to_code_dead(instruction.code); - assign_lhs(code_dead.symbol(), nil_exprt(), loc_info_src, loc_info_dest); + assign_lhs( + code_dead.symbol(), nil_exprt(), loc_info_src, loc_info_dest); } break; case FUNCTION_CALL: { - const code_function_callt &code_function_call=to_code_function_call(instruction.code); + const code_function_callt &code_function_call= + to_code_function_call(instruction.code); if(code_function_call.lhs().is_not_nil()) - assign_lhs(code_function_call.lhs(), nil_exprt(), loc_info_src, loc_info_dest); + assign_lhs( + code_function_call.lhs(), nil_exprt(), loc_info_src, loc_info_dest); // this might invalidate all pointers that are // a) local and dirty @@ -464,20 +473,22 @@ void local_may_aliast::build(const goto_functiont &goto_function) { if(objects[i].id()==ID_symbol) { - const irep_idt &identifier=to_symbol_expr(objects[i]).get_identifier(); + const irep_idt &identifier= + to_symbol_expr(objects[i]).get_identifier(); if(dirty(identifier) || !locals.is_local(identifier)) { loc_info_dest.aliases.isolate(i); loc_info_dest.aliases.make_union(i, unknown_object); } - } } } break; - default:; + default: + { + } } for(local_cfgt::successorst::const_iterator diff --git a/src/analyses/local_may_alias.h b/src/analyses/local_may_alias.h index 33ddf22bee9..109ca2b5e19 100644 --- a/src/analyses/local_may_alias.h +++ b/src/analyses/local_may_alias.h @@ -99,11 +99,11 @@ class local_may_aliast class local_may_alias_factoryt { public: - inline local_may_alias_factoryt():goto_functions(NULL) + local_may_alias_factoryt():goto_functions(NULL) { } - inline void operator()(const goto_functionst &_goto_functions) + void operator()(const goto_functionst &_goto_functions) { goto_functions=&_goto_functions; @@ -112,11 +112,13 @@ class local_may_alias_factoryt target_map[i_it]=f_it->first; } - local_may_aliast & operator()(const irep_idt &fkt) + local_may_aliast &operator()(const irep_idt &fkt) { assert(goto_functions!=NULL); fkt_mapt::iterator f_it=fkt_map.find(fkt); - if(f_it!=fkt_map.end()) return *f_it->second; + if(f_it!=fkt_map.end()) + return *f_it->second; + goto_functionst::function_mapt::const_iterator f_it2= goto_functions->function_map.find(fkt); assert(f_it2!=goto_functions->function_map.end()); @@ -124,7 +126,7 @@ class local_may_alias_factoryt new local_may_aliast(f_it2->second))); } - local_may_aliast & operator()(goto_programt::const_targett t) + local_may_aliast &operator()(goto_programt::const_targett t) { target_mapt::const_iterator t_it= target_map.find(t); diff --git a/src/analyses/locals.h b/src/analyses/locals.h index 8690d48d817..3cd52254c41 100644 --- a/src/analyses/locals.h +++ b/src/analyses/locals.h @@ -28,7 +28,7 @@ class localst // Returns true for all procedure-local variables, // not including those with static storage duration, // but including the function parameters. - inline bool is_local(const irep_idt &identifier) const + bool is_local(const irep_idt &identifier) const { return locals_map.find(identifier)!=locals_map.end(); } @@ -40,7 +40,7 @@ class localst void build(const goto_functiont &goto_function); }; -static inline std::ostream &operator << ( +inline std::ostream &operator<<( std::ostream &out, const localst &locals) { locals.output(out); diff --git a/src/analyses/natural_loops.cpp b/src/analyses/natural_loops.cpp index 92a1dc1efce..16985daa5e9 100644 --- a/src/analyses/natural_loops.cpp +++ b/src/analyses/natural_loops.cpp @@ -10,7 +10,7 @@ Author: Georg Weissenbacher, georg@weissenbacher.name #include "natural_loops.h" -//#define DEBUG +// #define DEBUG /*******************************************************************\ diff --git a/src/analyses/natural_loops.h b/src/analyses/natural_loops.h index 53d96aaf54d..327ebbdf112 100644 --- a/src/analyses/natural_loops.h +++ b/src/analyses/natural_loops.h @@ -29,23 +29,23 @@ class natural_loops_templatet loop_mapt loop_map; - inline void operator()(P &program) + void operator()(P &program) { compute(program); } void output(std::ostream &) const; - inline const cfg_dominators_templatet& get_dominator_info() const + const cfg_dominators_templatet &get_dominator_info() const { return cfg_dominators; } - inline natural_loops_templatet() + natural_loops_templatet() { } - inline natural_loops_templatet(P &program) + explicit natural_loops_templatet(P &program) { compute(program); } @@ -59,7 +59,8 @@ class natural_loops_templatet }; class natural_loopst: - public natural_loops_templatet + public natural_loops_templatet { }; @@ -80,7 +81,7 @@ Function: natural_loops_templatet::compute \*******************************************************************/ -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -96,9 +97,9 @@ void natural_loops_templatet::compute(P &program) #endif // find back-edges m->n - for (T m_it = program.instructions.begin(); - m_it != program.instructions.end(); - ++m_it) + for(T m_it=program.instructions.begin(); + m_it!=program.instructions.end(); + ++m_it) { if(m_it->is_backwards_goto()) { @@ -149,7 +150,7 @@ void natural_loops_templatet::compute_natural_loop(T m, T n) loop.insert(n); loop.insert(m); - if (n!=m) + if(n!=m) stack.push(m); while(!stack.empty()) @@ -194,7 +195,8 @@ void natural_loops_templatet::output(std::ostream &out) const for(typename natural_loopt::const_iterator l_it=loop.second.begin(); l_it!=loop.second.end(); ++l_it) { - if(l_it!=loop.second.begin()) out << ", "; + if(l_it!=loop.second.begin()) + out << ", "; out << (*l_it)->location_number; } out << " }\n"; diff --git a/src/analyses/reaching_definitions.cpp b/src/analyses/reaching_definitions.cpp index 10c303bcb7d..81c3c1c5069 100644 --- a/src/analyses/reaching_definitions.cpp +++ b/src/analyses/reaching_definitions.cpp @@ -145,7 +145,7 @@ void rd_range_domaint::transform_dead( const namespacet &ns, locationt from) { - const irep_idt& identifier= + const irep_idt &identifier= to_symbol_expr(to_code_dead(from->code).symbol()).get_identifier(); valuest::iterator entry=values.find(identifier); @@ -243,7 +243,7 @@ void rd_range_domaint::transform_function_call( ++it; } - const symbol_exprt& fn_symbol_expr=to_symbol_expr(code.function()); + const symbol_exprt &fn_symbol_expr=to_symbol_expr(code.function()); const code_typet &code_type= to_code_type(ns.lookup(fn_symbol_expr.get_identifier()).type); @@ -302,11 +302,13 @@ void rd_range_domaint::transform_end_function( if(!rd.get_is_threaded()(call) || (!ns.lookup(identifier).is_shared() && !rd.get_is_dirty()(identifier))) + { for(const auto &id : new_value.second) { const reaching_definitiont &v=bv_container->get(id); kill(v.identifier, v.bit_begin, v.bit_end); } + } for(const auto &id : new_value.second) { @@ -827,8 +829,8 @@ bool rd_range_domaint::merge_shared( { const irep_idt &identifier=value.first; - if(!ns.lookup(identifier).is_shared() /*&& - !rd.get_is_dirty()(identifier)*/) + if(!ns.lookup(identifier).is_shared() + /*&& !rd.get_is_dirty()(identifier)*/) continue; while(it!=values.end() && it->first class sparse_bitvector_analysist { public: - inline const V& get(const std::size_t value_index) const + const V &get(const std::size_t value_index) const { assert(value_indexfirst; } - inline std::size_t add(const V& value) + std::size_t add(const V &value) { inner_mapt &m=value_map[value.identifier]; @@ -70,14 +70,20 @@ inline bool operator<( const reaching_definitiont &a, const reaching_definitiont &b) { - if(a.definition_at &_bv_container) { bv_container=&_bv_container; @@ -106,31 +112,33 @@ class rd_range_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) override final; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const override final + const namespacet &ns) const final { output(out); } - void make_top() override final + void make_top() final { values.clear(); - if(bv_container) bv_container->clear(); + if(bv_container) + bv_container->clear(); has_values=tvt(true); } - void make_bottom() override final + void make_bottom() final { values.clear(); - if(bv_container) bv_container->clear(); + if(bv_container) + bv_container->clear(); has_values=tvt(false); } - void make_entry() override final + void make_entry() final { make_top(); } @@ -151,13 +159,13 @@ class rd_range_domaint:public ai_domain_baset typedef std::multimap rangest; typedef std::map ranges_at_loct; - const ranges_at_loct& get(const irep_idt &identifier) const; - inline const void clear_cache(const irep_idt &identifier) const + const ranges_at_loct &get(const irep_idt &identifier) const; + const void clear_cache(const irep_idt &identifier) const { export_cache[identifier].clear(); } -protected: +private: tvt has_values; sparse_bitvector_analysist *bv_container; @@ -222,7 +230,7 @@ class rd_range_domaint:public ai_domain_baset const values_innert &other); }; -class reaching_definitions_analysist : +class reaching_definitions_analysist: public concurrency_aware_ait, public sparse_bitvector_analysist { diff --git a/src/analyses/replace_symbol_ext.cpp b/src/analyses/replace_symbol_ext.cpp index 801ce69e881..568ea45e090 100644 --- a/src/analyses/replace_symbol_ext.cpp +++ b/src/analyses/replace_symbol_ext.cpp @@ -70,7 +70,8 @@ bool replace_symbol_extt::replace(exprt &dest) const const irept &c_sizeof_type=dest.find(ID_C_c_sizeof_type); if(c_sizeof_type.is_not_nil() && - !replace_symbolt::replace(static_cast(dest.add(ID_C_c_sizeof_type)))) + !replace_symbolt::replace( + static_cast(dest.add(ID_C_c_sizeof_type)))) result=false; const irept &va_arg_type=dest.find(ID_C_va_arg_type); diff --git a/src/analyses/replace_symbol_ext.h b/src/analyses/replace_symbol_ext.h index 7d03d61ff6e..5a2152db17f 100644 --- a/src/analyses/replace_symbol_ext.h +++ b/src/analyses/replace_symbol_ext.h @@ -11,7 +11,7 @@ Author: Peter Schrammel #include -class replace_symbol_extt : public replace_symbolt +class replace_symbol_extt:public replace_symbolt { public: virtual bool replace(exprt &dest) const; diff --git a/src/analyses/static_analysis.cpp b/src/analyses/static_analysis.cpp index 266b0131580..96d7e5a9d9a 100644 --- a/src/analyses/static_analysis.cpp +++ b/src/analyses/static_analysis.cpp @@ -572,7 +572,8 @@ void static_analysis_baset::do_function_call_rec( { const object_descriptor_exprt &o=to_object_descriptor_expr(value); std::unique_ptr n2(make_temporary_state(new_state)); - do_function_call_rec(l_call, l_return, o.object(), arguments, *n2, goto_functions); + do_function_call_rec( + l_call, l_return, o.object(), arguments, *n2, goto_functions); merge(new_state, *n2, l_return); } } diff --git a/src/analyses/static_analysis.h b/src/analyses/static_analysis.h index 3e49425bbeb..2a390fb7e61 100644 --- a/src/analyses/static_analysis.h +++ b/src/analyses/static_analysis.h @@ -272,17 +272,21 @@ class static_analysist:public static_analysis_baset typedef goto_programt::const_targett locationt; - inline T &operator[](locationt l) + T &operator[](locationt l) { typename state_mapt::iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } - inline const T &operator[](locationt l) const + const T &operator[](locationt l) const { typename state_mapt::const_iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } @@ -304,14 +308,18 @@ class static_analysist:public static_analysis_baset virtual statet &get_state(locationt l) { typename state_mapt::iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } virtual const statet &get_state(locationt l) const { typename state_mapt::const_iterator it=state_map.find(l); - if(it==state_map.end()) throw "failed to find state"; + if(it==state_map.end()) + throw "failed to find state"; + return it->second; } diff --git a/src/analyses/uninitialized_domain.cpp b/src/analyses/uninitialized_domain.cpp index c671722843f..8a6e8dd52a5 100644 --- a/src/analyses/uninitialized_domain.cpp +++ b/src/analyses/uninitialized_domain.cpp @@ -31,7 +31,8 @@ void uninitialized_domaint::transform( ai_baset &ai, const namespacet &ns) { - if(has_values.is_false()) return; + if(has_values.is_false()) + return; switch(from->type) { diff --git a/src/analyses/uninitialized_domain.h b/src/analyses/uninitialized_domain.h index 93f1f2fd2b8..6ca27f341b0 100644 --- a/src/analyses/uninitialized_domain.h +++ b/src/analyses/uninitialized_domain.h @@ -30,26 +30,26 @@ class uninitialized_domaint:public ai_domain_baset locationt from, locationt to, ai_baset &ai, - const namespacet &ns) override final; + const namespacet &ns) final; void output( std::ostream &out, const ai_baset &ai, - const namespacet &ns) const override final; + const namespacet &ns) const final; - void make_top() override final + void make_top() final { uninitialized.clear(); has_values=tvt(true); } - void make_bottom() override final + void make_bottom() final { uninitialized.clear(); has_values=tvt(false); } - void make_entry() override final + void make_entry() final { make_top(); } @@ -60,7 +60,7 @@ class uninitialized_domaint:public ai_domain_baset locationt from, locationt to); -protected: +private: tvt has_values; void assign(const exprt &lhs); diff --git a/src/ansi-c/anonymous_member.cpp b/src/ansi-c/anonymous_member.cpp index 22f6d18b6e9..adaff8d4680 100644 --- a/src/ansi-c/anonymous_member.cpp +++ b/src/ansi-c/anonymous_member.cpp @@ -82,7 +82,8 @@ exprt get_component_rec( { exprt tmp=make_member_expr(struct_union, comp, ns); exprt result=get_component_rec(tmp, component_name, ns); - if(result.is_not_nil()) return result; + if(result.is_not_nil()) + return result; } } diff --git a/src/ansi-c/anonymous_member.h b/src/ansi-c/anonymous_member.h index df76e716427..d9b00394b6f 100644 --- a/src/ansi-c/anonymous_member.h +++ b/src/ansi-c/anonymous_member.h @@ -6,6 +6,9 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ +#ifndef CPROVER_ANSI_C_ANONYMOUS_MEMBER_H +#define CPROVER_ANSI_C_ANONYMOUS_MEMBER_H + #include #include @@ -18,3 +21,5 @@ bool has_component_rec( const typet &struct_union_type, const irep_idt &component_name, const namespacet &ns); + +#endif // CPROVER_ANSI_C_ANONYMOUS_MEMBER_H diff --git a/src/ansi-c/ansi_c_convert_type.cpp b/src/ansi-c/ansi_c_convert_type.cpp index 8fde8c57c4d..7dc6f2165cf 100644 --- a/src/ansi-c/ansi_c_convert_type.cpp +++ b/src/ansi-c/ansi_c_convert_type.cpp @@ -110,7 +110,8 @@ void ansi_c_convert_typet::read_rec(const typet &type) } else if(type.id()==ID_msc_based) { - const exprt &as_expr=static_cast(static_cast(type)); + const exprt &as_expr= + static_cast(static_cast(type)); assert(as_expr.operands().size()==1); msc_based=as_expr.op0(); } @@ -405,7 +406,8 @@ void ansi_c_convert_typet::write(typet &type) type.id(ID_bool); } - else if(complex_cnt && !char_cnt && !signed_cnt && !unsigned_cnt && !short_cnt && !gcc_int128_cnt) + else if(complex_cnt && !char_cnt && !signed_cnt && !unsigned_cnt && + !short_cnt && !gcc_int128_cnt) { // the "default" for complex is double type=double_type(); @@ -467,7 +469,8 @@ void ansi_c_convert_typet::write(typet &type) else if(int32_cnt) type=is_signed?signed_int_type():unsigned_int_type(); else if(int64_cnt) // Visual Studio: equivalent to long long int - type=is_signed?signed_long_long_int_type():unsigned_long_long_int_type(); + type= + is_signed?signed_long_long_int_type():unsigned_long_long_int_type(); else assert(false); } diff --git a/src/ansi-c/ansi_c_convert_type.h b/src/ansi-c/ansi_c_convert_type.h index 6b46a1a4f61..0fef20b4928 100644 --- a/src/ansi-c/ansi_c_convert_type.h +++ b/src/ansi-c/ansi_c_convert_type.h @@ -49,7 +49,7 @@ class ansi_c_convert_typet:public messaget std::list other; - ansi_c_convert_typet(message_handlert &_message_handler): + explicit ansi_c_convert_typet(message_handlert &_message_handler): messaget(_message_handler) { } diff --git a/src/ansi-c/ansi_c_declaration.cpp b/src/ansi-c/ansi_c_declaration.cpp index e8b57805c34..4c82adc307a 100644 --- a/src/ansi-c/ansi_c_declaration.cpp +++ b/src/ansi-c/ansi_c_declaration.cpp @@ -45,7 +45,6 @@ void ansi_c_declaratort::build(irept &src) else if(t.id()==irep_idt() || t.is_nil()) { - //std::cerr << "D: " << src.pretty() << std::endl; assert(0); } else if(t.id()==ID_abstract) @@ -82,16 +81,26 @@ Function: ansi_c_declarationt::output void ansi_c_declarationt::output(std::ostream &out) const { out << "Flags:"; - if(get_is_typedef()) out << " is_typedef"; - if(get_is_enum_constant()) out << " is_enum_constant"; - if(get_is_static()) out << " is_static"; - if(get_is_parameter()) out << " is_parameter"; - if(get_is_global()) out << " is_global"; - if(get_is_register()) out << " is_register"; - if(get_is_thread_local()) out << " is_thread_local"; - if(get_is_inline()) out << " is_inline"; - if(get_is_extern()) out << " is_extern"; - if(get_is_static_assert()) out << " is_static_assert"; + if(get_is_typedef()) + out << " is_typedef"; + if(get_is_enum_constant()) + out << " is_enum_constant"; + if(get_is_static()) + out << " is_static"; + if(get_is_parameter()) + out << " is_parameter"; + if(get_is_global()) + out << " is_global"; + if(get_is_register()) + out << " is_register"; + if(get_is_thread_local()) + out << " is_thread_local"; + if(get_is_inline()) + out << " is_inline"; + if(get_is_extern()) + out << " is_extern"; + if(get_is_static_assert()) + out << " is_static_assert"; out << "\n"; out << "Type: " << type().pretty() << "\n"; diff --git a/src/ansi-c/ansi_c_declaration.h b/src/ansi-c/ansi_c_declaration.h index 5a2b5649387..3143c2090a5 100644 --- a/src/ansi-c/ansi_c_declaration.h +++ b/src/ansi-c/ansi_c_declaration.h @@ -16,36 +16,36 @@ Author: Daniel Kroening, kroening@kroening.com class ansi_c_declaratort:public exprt { public: - inline ansi_c_declaratort():exprt(ID_declarator) + ansi_c_declaratort():exprt(ID_declarator) { } - inline exprt &value() + exprt &value() { return static_cast(add(ID_value)); } - inline const exprt &value() const + const exprt &value() const { return static_cast(find(ID_value)); } - inline void set_name(const irep_idt &name) + void set_name(const irep_idt &name) { return set(ID_name, name); } - inline irep_idt get_name() const + irep_idt get_name() const { return get(ID_name); } - inline irep_idt get_base_name() const + irep_idt get_base_name() const { return get(ID_base_name); } - inline void set_base_name(const irep_idt &base_name) + void set_base_name(const irep_idt &base_name) { return set(ID_base_name, base_name); } @@ -53,13 +53,13 @@ class ansi_c_declaratort:public exprt void build(irept &src); }; -extern inline ansi_c_declaratort &to_ansi_c_declarator(exprt &expr) +inline ansi_c_declaratort &to_ansi_c_declarator(exprt &expr) { assert(expr.id()==ID_declarator); return static_cast(expr); } -extern inline const ansi_c_declaratort &to_ansi_c_declarator(const exprt &expr) +inline const ansi_c_declaratort &to_ansi_c_declarator(const exprt &expr) { assert(expr.id()==ID_declarator); return static_cast(expr); @@ -68,126 +68,126 @@ extern inline const ansi_c_declaratort &to_ansi_c_declarator(const exprt &expr) class ansi_c_declarationt:public exprt { public: - inline ansi_c_declarationt():exprt(ID_declaration) + ansi_c_declarationt():exprt(ID_declaration) { } - inline bool get_is_typedef() const + bool get_is_typedef() const { return get_bool(ID_is_typedef); } - inline void set_is_typedef(bool is_typedef) + void set_is_typedef(bool is_typedef) { set(ID_is_typedef, is_typedef); } - inline bool get_is_enum_constant() const + bool get_is_enum_constant() const { return get_bool(ID_is_enum_constant); } - inline void set_is_enum_constant(bool is_enum_constant) + void set_is_enum_constant(bool is_enum_constant) { set(ID_is_enum_constant, is_enum_constant); } - inline bool get_is_static() const + bool get_is_static() const { return get_bool(ID_is_static); } - inline void set_is_static(bool is_static) + void set_is_static(bool is_static) { set(ID_is_static, is_static); } - inline bool get_is_parameter() const + bool get_is_parameter() const { return get_bool(ID_is_parameter); } - inline void set_is_parameter(bool is_parameter) + void set_is_parameter(bool is_parameter) { set(ID_is_parameter, is_parameter); } - inline bool get_is_member() const + bool get_is_member() const { return get_bool(ID_is_member); } - inline void set_is_member(bool is_member) + void set_is_member(bool is_member) { set(ID_is_member, is_member); } - inline bool get_is_global() const + bool get_is_global() const { return get_bool(ID_is_global); } - inline void set_is_global(bool is_global) + void set_is_global(bool is_global) { set(ID_is_global, is_global); } - inline bool get_is_register() const + bool get_is_register() const { return get_bool(ID_is_register); } - inline void set_is_register(bool is_register) + void set_is_register(bool is_register) { set(ID_is_register, is_register); } - inline bool get_is_thread_local() const + bool get_is_thread_local() const { return get_bool(ID_is_thread_local); } - inline void set_is_thread_local(bool is_thread_local) + void set_is_thread_local(bool is_thread_local) { set(ID_is_thread_local, is_thread_local); } - inline bool get_is_inline() const + bool get_is_inline() const { return get_bool(ID_is_inline); } - inline void set_is_inline(bool is_inline) + void set_is_inline(bool is_inline) { set(ID_is_inline, is_inline); } - inline bool get_is_extern() const + bool get_is_extern() const { return get_bool(ID_is_extern); } - inline void set_is_extern(bool is_extern) + void set_is_extern(bool is_extern) { set(ID_is_extern, is_extern); } - inline bool get_is_static_assert() const + bool get_is_static_assert() const { return get_bool(ID_is_static_assert); } - inline void set_is_static_assert(bool is_static_assert) + void set_is_static_assert(bool is_static_assert) { set(ID_is_static_assert, is_static_assert); } - inline bool get_is_weak() const + bool get_is_weak() const { return get_bool(ID_is_weak); } - inline void set_is_weak(bool is_weak) + void set_is_weak(bool is_weak) { set(ID_is_weak, is_weak); } @@ -200,24 +200,24 @@ class ansi_c_declarationt:public exprt typedef std::vector declaratorst; - inline const declaratorst &declarators() const + const declaratorst &declarators() const { return (const declaratorst &)operands(); } - inline declaratorst &declarators() + declaratorst &declarators() { return (declaratorst &)operands(); } // special case of a declaration with exactly one declarator - inline const ansi_c_declaratort &declarator() const + const ansi_c_declaratort &declarator() const { assert(declarators().size()==1); return declarators()[0]; } - inline ansi_c_declaratort &declarator() + ansi_c_declaratort &declarator() { assert(declarators().size()==1); return declarators()[0]; @@ -225,20 +225,20 @@ class ansi_c_declarationt:public exprt void output(std::ostream &) const; - inline void add_initializer(exprt &value) + void add_initializer(exprt &value) { assert(!declarators().empty()); declarators().back().value().swap(value); } }; -extern inline ansi_c_declarationt &to_ansi_c_declaration(exprt &expr) +inline ansi_c_declarationt &to_ansi_c_declaration(exprt &expr) { assert(expr.id()==ID_declaration); return static_cast(expr); } -extern inline const ansi_c_declarationt &to_ansi_c_declaration(const exprt &expr) +inline const ansi_c_declarationt &to_ansi_c_declaration(const exprt &expr) { assert(expr.id()==ID_declaration); return static_cast(expr); diff --git a/src/ansi-c/ansi_c_internal_additions.cpp b/src/ansi-c/ansi_c_internal_additions.cpp index 6e93a559eef..eb564038e2e 100644 --- a/src/ansi-c/ansi_c_internal_additions.cpp +++ b/src/ansi-c/ansi_c_internal_additions.cpp @@ -13,50 +13,50 @@ Author: Daniel Kroening, kroening@kroening.com const char gcc_builtin_headers_generic[]= "# 1 \"gcc_builtin_headers_generic.h\"\n" #include "gcc_builtin_headers_generic.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_ia32[]= "# 1 \"gcc_builtin_headers_ia32.h\"\n" #include "gcc_builtin_headers_ia32.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_ia32_2[]= #include "gcc_builtin_headers_ia32-2.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_alpha[]= "# 1 \"gcc_builtin_headers_alpha.h\"\n" #include "gcc_builtin_headers_alpha.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_arm[]= "# 1 \"gcc_builtin_headers_arm.h\"\n" #include "gcc_builtin_headers_arm.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_mips[]= "# 1 \"gcc_builtin_headers_mips.h\"\n" #include "gcc_builtin_headers_mips.inc" -; +; // NOLINT(whitespace/semicolon) const char gcc_builtin_headers_power[]= "# 1 \"gcc_builtin_headers_power.h\"\n" #include "gcc_builtin_headers_power.inc" -; +; // NOLINT(whitespace/semicolon) const char arm_builtin_headers[]= "# 1 \"arm_builtin_headers.h\"\n" #include "arm_builtin_headers.inc" -; +; // NOLINT(whitespace/semicolon) const char cw_builtin_headers[]= "# 1 \"cw_builtin_headers.h\"\n" #include "cw_builtin_headers.inc" -; +; // NOLINT(whitespace/semicolon) const char clang_builtin_headers[]= "# 1 \"clang_builtin_headers.h\"\n" #include "clang_builtin_headers.inc" -; +; // NOLINT(whitespace/semicolon) /*******************************************************************\ @@ -115,6 +115,7 @@ void ansi_c_internal_additions(std::string &code) "typedef __typeof__(sizeof(int)) __CPROVER_size_t;\n" "void __CPROVER_assume(__CPROVER_bool assumption);\n" "void __VERIFIER_assume(__CPROVER_bool assumption);\n" + // NOLINTNEXTLINE(whitespace/line_length) "void __CPROVER_assert(__CPROVER_bool assertion, const char *description);\n" "__CPROVER_bool __CPROVER_equal();\n" "__CPROVER_bool __CPROVER_same_object(const void *, const void *);\n" @@ -145,6 +146,7 @@ void ansi_c_internal_additions(std::string &code) "void __CPROVER_atomic_end();\n" "void __CPROVER_fence(const char *kind, ...);\n" "__CPROVER_thread_local unsigned long __CPROVER_thread_id=0;\n" + // NOLINTNEXTLINE(whitespace/line_length) "__CPROVER_bool __CPROVER_threads_exited[__CPROVER_constant_infinity_uint];\n" "unsigned long __CPROVER_next_thread_id=0;\n" @@ -163,14 +165,17 @@ void ansi_c_internal_additions(std::string &code) "const void *__CPROVER_dead_object=0;\n" "const void *__CPROVER_malloc_object=0;\n" "__CPROVER_size_t __CPROVER_malloc_size;\n" - "__CPROVER_bool __CPROVER_malloc_is_new_array=0;\n" // for the benefit of C++ + "__CPROVER_bool __CPROVER_malloc_is_new_array=0;\n" // for C++ "const void *__CPROVER_memory_leak=0;\n" // this is ANSI-C + // NOLINTNEXTLINE(whitespace/line_length) "extern __CPROVER_thread_local const char __func__[__CPROVER_constant_infinity_uint];\n" // this is GCC + // NOLINTNEXTLINE(whitespace/line_length) "extern __CPROVER_thread_local const char __FUNCTION__[__CPROVER_constant_infinity_uint];\n" + // NOLINTNEXTLINE(whitespace/line_length) "extern __CPROVER_thread_local const char __PRETTY_FUNCTION__[__CPROVER_constant_infinity_uint];\n" // float stuff @@ -192,7 +197,8 @@ void ansi_c_internal_additions(std::string &code) "double __CPROVER_inf(void);\n" "float __CPROVER_inff(void);\n" "long double __CPROVER_infl(void);\n" - "int __CPROVER_thread_local __CPROVER_rounding_mode="+std::to_string(config.ansi_c.rounding_mode)+";\n" + "int __CPROVER_thread_local __CPROVER_rounding_mode="+ + std::to_string(config.ansi_c.rounding_mode)+";\n" // absolute value "int __CPROVER_abs(int x);\n" @@ -203,6 +209,7 @@ void ansi_c_internal_additions(std::string &code) "float __CPROVER_fabsf(float x);\n" // arrays + // NOLINTNEXTLINE(whitespace/line_length) "__CPROVER_bool __CPROVER_array_equal(const void *array1, const void *array2);\n" "void __CPROVER_array_copy(const void *dest, const void *src);\n" "void __CPROVER_array_set(const void *dest, ...);\n" @@ -221,6 +228,7 @@ void ansi_c_internal_additions(std::string &code) " short next_avail;\n" " short next_unread;\n" "};\n" + // NOLINTNEXTLINE(whitespace/line_length) "extern struct __CPROVER_pipet __CPROVER_pipes[__CPROVER_constant_infinity_uint];\n" // offset to make sure we don't collide with other fds "extern const int __CPROVER_pipe_offset;\n" @@ -328,19 +336,19 @@ void ansi_c_architecture_strings(std::string &code) code+=architecture_string(config.ansi_c.bool_width, "bool_width"); code+=architecture_string(config.ansi_c.char_width, "char_width"); code+=architecture_string(config.ansi_c.short_int_width, "short_int_width"); - code+=architecture_string(config.ansi_c.long_long_int_width, "long_long_int_width"); + code+=architecture_string(config.ansi_c.long_long_int_width, "long_long_int_width"); // NOLINT(whitespace/line_length) code+=architecture_string(config.ansi_c.pointer_width, "pointer_width"); code+=architecture_string(config.ansi_c.single_width, "single_width"); code+=architecture_string(config.ansi_c.double_width, "double_width"); - code+=architecture_string(config.ansi_c.long_double_width, "long_double_width"); + code+=architecture_string(config.ansi_c.long_double_width, "long_double_width"); // NOLINT(whitespace/line_length) code+=architecture_string(config.ansi_c.wchar_t_width, "wchar_t_width"); code+=architecture_string(config.ansi_c.char_is_unsigned, "char_is_unsigned"); - code+=architecture_string(config.ansi_c.wchar_t_is_unsigned, "wchar_t_is_unsigned"); - code+=architecture_string(config.ansi_c.use_fixed_for_float, "fixed_for_float"); + code+=architecture_string(config.ansi_c.wchar_t_is_unsigned, "wchar_t_is_unsigned"); // NOLINT(whitespace/line_length) + code+=architecture_string(config.ansi_c.use_fixed_for_float, "fixed_for_float"); // NOLINT(whitespace/line_length) code+=architecture_string(config.ansi_c.alignment, "alignment"); - code+=architecture_string(config.ansi_c.memory_operand_size, "memory_operand_size"); - code+=architecture_string(int(config.ansi_c.endianness), "endianness"); + code+=architecture_string(config.ansi_c.memory_operand_size, "memory_operand_size"); // NOLINT(whitespace/line_length) + code+=architecture_string(static_cast(config.ansi_c.endianness), "endianness"); // NOLINT(whitespace/line_length) code+=architecture_string(id2string(config.ansi_c.arch), "arch"); - code+=architecture_string(configt::ansi_ct::os_to_string(config.ansi_c.os), "os"); + code+=architecture_string(configt::ansi_ct::os_to_string(config.ansi_c.os), "os"); // NOLINT(whitespace/line_length) code+=architecture_string(config.ansi_c.NULL_is_zero, "NULL_is_zero"); } diff --git a/src/ansi-c/ansi_c_parser.cpp b/src/ansi-c/ansi_c_parser.cpp index 88787d4b519..a32d31bac61 100644 --- a/src/ansi-c/ansi_c_parser.cpp +++ b/src/ansi-c/ansi_c_parser.cpp @@ -46,7 +46,8 @@ ansi_c_id_classt ansi_c_parsert::lookup( if(n_it!=it->name_map.end()) { - assert(id2string(n_it->second.prefixed_name)==it->prefix+id2string(scope_name)); + assert(id2string(n_it->second.prefixed_name)== + it->prefix+id2string(scope_name)); identifier=n_it->second.prefixed_name; return n_it->second.id_class; } diff --git a/src/ansi-c/ansi_c_scope.h b/src/ansi-c/ansi_c_scope.h index 3e1d81e09f8..722774c01cc 100644 --- a/src/ansi-c/ansi_c_scope.h +++ b/src/ansi-c/ansi_c_scope.h @@ -30,7 +30,8 @@ class ansi_c_scopet public: // This maps "scope names" (tag-X, label-X, X) to // ansi_c_identifiert. - typedef std::unordered_map name_mapt; + typedef std::unordered_map + name_mapt; name_mapt name_map; std::string prefix; diff --git a/src/ansi-c/c_misc.h b/src/ansi-c/c_misc.h index a315a1efab2..40f9d0db5b8 100644 --- a/src/ansi-c/c_misc.h +++ b/src/ansi-c/c_misc.h @@ -6,11 +6,11 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -#ifndef CPROVER_UTIL_C_MISC_H -#define CPROVER_UTIL_C_MISC_H +#ifndef CPROVER_ANSI_C_C_MISC_H +#define CPROVER_ANSI_C_C_MISC_H #include std::string MetaString(const std::string &in); -#endif // CPROVER_UTIL_C_MISC_H +#endif // CPROVER_ANSI_C_C_MISC_H diff --git a/src/ansi-c/c_preprocess.cpp b/src/ansi-c/c_preprocess.cpp index 50b412ea5b5..9582d6f3b00 100644 --- a/src/ansi-c/c_preprocess.cpp +++ b/src/ansi-c/c_preprocess.cpp @@ -157,7 +157,8 @@ static std::string shell_quote(const std::string &src) for(const char ch : src) { - if(ch=='"') result+='"'; // quotes are doubled + if(ch=='"') + result+='"'; // quotes are doubled result+=ch; } @@ -193,7 +194,8 @@ static std::string shell_quote(const std::string &src) for(const char ch : src) { - if(ch=='\'') result+="'\\''"; + if(ch=='\'') + result+="'\\''"; result+=ch; } @@ -378,7 +380,7 @@ bool c_preprocess( temporary_filet tmp_file("tmp.stdin", ".c"); std::ofstream tmp(tmp_file()); - + if(!tmp) { messaget message(message_handler); @@ -410,9 +412,11 @@ Function: is_dot_i_file static bool is_dot_i_file(const std::string &path) { const char *ext=strrchr(path.c_str(), '.'); - if(ext==NULL) return false; + if(ext==NULL) + return false; if(std::string(ext)==".i" || - std::string(ext)==".ii") return true; + std::string(ext)==".ii") + return true; return false; } @@ -428,11 +432,19 @@ Function: c_preprocess \*******************************************************************/ -bool c_preprocess_codewarrior(const std::string &, std::ostream &, message_handlert &); -bool c_preprocess_arm(const std::string &, std::ostream &, message_handlert &); -bool c_preprocess_gcc_clang(const std::string &, std::ostream &, message_handlert &, configt::ansi_ct::preprocessort); -bool c_preprocess_none(const std::string &, std::ostream &, message_handlert &); -bool c_preprocess_visual_studio(const std::string &, std::ostream &, message_handlert &); +bool c_preprocess_codewarrior( + const std::string &, std::ostream &, message_handlert &); +bool c_preprocess_arm( + const std::string &, std::ostream &, message_handlert &); +bool c_preprocess_gcc_clang( + const std::string &, + std::ostream &, + message_handlert &, + configt::ansi_ct::preprocessort); +bool c_preprocess_none( + const std::string &, std::ostream &, message_handlert &); +bool c_preprocess_visual_studio( + const std::string &, std::ostream &, message_handlert &); bool c_preprocess( const std::string &path, @@ -445,10 +457,14 @@ bool c_preprocess( return c_preprocess_codewarrior(path, outstream, message_handler); case configt::ansi_ct::preprocessort::GCC: - return c_preprocess_gcc_clang(path, outstream, message_handler, config.ansi_c.preprocessor); + return + c_preprocess_gcc_clang( + path, outstream, message_handler, config.ansi_c.preprocessor); case configt::ansi_ct::preprocessort::CLANG: - return c_preprocess_gcc_clang(path, outstream, message_handler, config.ansi_c.preprocessor); + return + c_preprocess_gcc_clang( + path, outstream, message_handler, config.ansi_c.preprocessor); case configt::ansi_ct::preprocessort::VISUAL_STUDIO: return c_preprocess_visual_studio(path, outstream, message_handler); @@ -806,6 +822,7 @@ bool c_preprocess_gcc_clang( command+=" -D__DEC64_MAX__=9.999999999999999E384DD"; command+=" -D__DEC64_MANT_DIG__=16"; command+=" -D__DEC32_MAX_EXP__=96"; + // NOLINTNEXTLINE(whitespace/line_length) command+=" -D__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL"; command+=" -D__LDBL_MANT_DIG__=64"; command+=" -D__CONSTANT_CFSTRINGS__=1"; @@ -814,7 +831,7 @@ bool c_preprocess_gcc_clang( command+=" -D__pic__=2"; command+=" -D__FLT_DIG__=6"; command+=" -D__FLT_MAX_EXP__=128"; - //command+=" -D__BLOCKS__=1"; + // command+=" -D__BLOCKS__=1"; command+=" -D__DBL_MANT_DIG__=53"; command+=" -D__DEC64_MIN__=1E-383DD"; command+=" -D__LDBL_MIN_EXP__=\"(-16381)\""; @@ -952,7 +969,9 @@ bool c_preprocess_gcc_clang( { case configt::ansi_ct::flavourt::GCC_C: command+=" -x c"; break; case configt::ansi_ct::flavourt::GCC_CPP: command+=" -x c++"; break; - default:; + default: + { + } } #endif @@ -1058,10 +1077,10 @@ bool c_preprocess_arm( // command+=" -D__sizeof_int="+std::to_string(config.ansi_c.int_width/8); // command+=" -D__sizeof_long="+std::to_string(config.ansi_c.long_int_width/8); // command+=" -D__sizeof_ptr="+std::to_string(config.ansi_c.pointer_width/8); - //command+=" -D__EDG_VERSION__=308"; - //command+=" -D__EDG__"; + // command+=" -D__EDG_VERSION__=308"; + // command+=" -D__EDG__"; // command+=" -D__CC_ARM=1"; - //command+=" -D__ARMCC_VERSION=410000"; + // command+=" -D__ARMCC_VERSION=410000"; // command+=" -D__arm__"; // if(config.ansi_c.endianness==configt::ansi_ct::IS_BIG_ENDIAN) @@ -1084,7 +1103,7 @@ bool c_preprocess_arm( // Standard Defines, ANSI9899 6.10.8 command+=" -D__STDC__"; - //command+=" -D__STDC_VERSION__=199901L"; + // command+=" -D__STDC_VERSION__=199901L"; for(const auto &define : config.ansi_c.defines) command+=" "+shell_quote("-D"+define); diff --git a/src/ansi-c/c_qualifiers.h b/src/ansi-c/c_qualifiers.h index 3d0da08b8a6..45e5d01d782 100644 --- a/src/ansi-c/c_qualifiers.h +++ b/src/ansi-c/c_qualifiers.h @@ -68,29 +68,24 @@ class c_qualifierst // is_transparent_union isn't checked } - friend bool operator == ( - const c_qualifierst &a, - const c_qualifierst &b) + bool operator==(const c_qualifierst &other) const { - return a.is_constant==b.is_constant && - a.is_volatile==b.is_volatile && - a.is_restricted==b.is_restricted && - a.is_atomic==b.is_atomic && - a.is_ptr32==b.is_ptr32 && - a.is_ptr64==b.is_ptr64 && - a.is_transparent_union==b.is_transparent_union && - a.is_noreturn==b.is_noreturn; + return is_constant==other.is_constant && + is_volatile==other.is_volatile && + is_restricted==other.is_restricted && + is_atomic==other.is_atomic && + is_ptr32==other.is_ptr32 && + is_ptr64==other.is_ptr64 && + is_transparent_union==other.is_transparent_union && + is_noreturn==other.is_noreturn; } - friend bool operator != ( - const c_qualifierst &a, - const c_qualifierst &b) + bool operator!=(const c_qualifierst &other) const { - return !(a==b); + return !(*this==other); } - c_qualifierst &operator += ( - const c_qualifierst &b) + c_qualifierst &operator+=(const c_qualifierst &b) { is_constant|=b.is_constant; is_volatile|=b.is_volatile; @@ -103,10 +98,10 @@ class c_qualifierst return *this; } - friend unsigned count(const c_qualifierst &q) + unsigned count() const { - return q.is_constant+q.is_volatile+q.is_restricted+q.is_atomic+ - q.is_ptr32+q.is_ptr64+q.is_noreturn; + return is_constant+is_volatile+is_restricted+is_atomic+ + is_ptr32+is_ptr64+is_noreturn; } }; diff --git a/src/ansi-c/c_sizeof.cpp b/src/ansi-c/c_sizeof.cpp index 8a9bc21c713..85c91870208 100644 --- a/src/ansi-c/c_sizeof.cpp +++ b/src/ansi-c/c_sizeof.cpp @@ -43,7 +43,8 @@ exprt c_sizeoft::sizeof_rec(const typet &type) // See special treatment for bit-fields below. std::size_t bits=to_bitvector_type(type).get_width(); std::size_t bytes=bits/8; - if((bits%8)!=0) bytes++; + if((bits%8)!=0) + bytes++; dest=from_integer(bytes, size_type()); } else if(type.id()==ID_incomplete_c_enum) @@ -69,7 +70,8 @@ exprt c_sizeoft::sizeof_rec(const typet &type) std::size_t bits=config.ansi_c.pointer_width; std::size_t bytes=bits/8; - if((bits%8)!=0) bytes++; + if((bits%8)!=0) + bytes++; dest=from_integer(bytes, size_type()); } else if(type.id()==ID_bool) diff --git a/src/ansi-c/c_sizeof.h b/src/ansi-c/c_sizeof.h index 2ec8508f928..40329726b75 100644 --- a/src/ansi-c/c_sizeof.h +++ b/src/ansi-c/c_sizeof.h @@ -6,13 +6,16 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ +#ifndef CPROVER_ANSI_C_C_SIZEOF_H +#define CPROVER_ANSI_C_C_SIZEOF_H + #include #include class c_sizeoft { public: - c_sizeoft(const namespacet &_ns):ns(_ns) + explicit c_sizeoft(const namespacet &_ns):ns(_ns) { } @@ -43,3 +46,5 @@ exprt c_offsetof( const struct_typet &src, const irep_idt &component_name, const namespacet &ns); + +#endif // CPROVER_ANSI_C_C_SIZEOF_H diff --git a/src/ansi-c/c_storage_spec.cpp b/src/ansi-c/c_storage_spec.cpp index 48674e659a2..df4cdb2381c 100644 --- a/src/ansi-c/c_storage_spec.cpp +++ b/src/ansi-c/c_storage_spec.cpp @@ -50,7 +50,8 @@ void c_storage_spect::read(const typet &type) } else if(type.id()==ID_msc_declspec) { - const exprt &as_expr=static_cast(static_cast(type)); + const exprt &as_expr= + static_cast(static_cast(type)); forall_operands(it, as_expr) if(it->id()==ID_thread) is_thread_local=true; diff --git a/src/ansi-c/c_storage_spec.h b/src/ansi-c/c_storage_spec.h index 9394552b5ca..d735e578426 100644 --- a/src/ansi-c/c_storage_spec.h +++ b/src/ansi-c/c_storage_spec.h @@ -49,42 +49,36 @@ class c_storage_spect irep_idt asm_label; irep_idt section; - friend bool operator == ( - const c_storage_spect &a, - const c_storage_spect &b) + bool operator==(const c_storage_spect &other) const { - return a.is_typedef==b.is_typedef && - a.is_extern==b.is_extern && - a.is_static==b.is_static && - a.is_register==b.is_register && - a.is_thread_local==b.is_thread_local && - a.is_inline==b.is_inline && - a.is_weak==b.is_weak && - a.alias==b.alias && - a.asm_label==b.asm_label && - a.section==b.section; + return is_typedef==other.is_typedef && + is_extern==other.is_extern && + is_static==other.is_static && + is_register==other.is_register && + is_thread_local==other.is_thread_local && + is_inline==other.is_inline && + is_weak==other.is_weak && + alias==other.alias && + asm_label==other.asm_label && + section==other.section; } - friend bool operator != ( - const c_storage_spect &a, - const c_storage_spect &b) + bool operator!=(const c_storage_spect &other) const { - return !(a==b); + return !(*this==other); } - friend c_storage_spect &operator |= ( - c_storage_spect &a, - const c_storage_spect &b) + c_storage_spect &operator|=(const c_storage_spect &other) { - a.is_typedef |=b.is_typedef; - a.is_extern |=b.is_extern; - a.is_static |=b.is_static; - a.is_register |=b.is_register; - a.is_inline |=b.is_inline; - a.is_thread_local |=b.is_thread_local; + is_typedef |=other.is_typedef; + is_extern |=other.is_extern; + is_static |=other.is_static; + is_register |=other.is_register; + is_inline |=other.is_inline; + is_thread_local |=other.is_thread_local; // attributes belong to the declarator, don't replace them - return a; + return *this; } void read(const typet &type); diff --git a/src/ansi-c/c_typecast.cpp b/src/ansi-c/c_typecast.cpp index 06698fbd564..52070e29257 100644 --- a/src/ansi-c/c_typecast.cpp +++ b/src/ansi-c/c_typecast.cpp @@ -137,7 +137,8 @@ bool check_c_implicit_typecast( !dest_type.subtype().get_bool(ID_C_constant)) return true; - if(src_type==dest_type) return false; + if(src_type==dest_type) + return false; const irep_idt &src_type_id=src_type.id(); @@ -149,60 +150,65 @@ bool check_c_implicit_typecast( if(src_type_id==ID_natural) { - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_integer) return false; - if(dest_type.id()==ID_real) return false; - if(dest_type.id()==ID_complex) return false; - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_signedbv) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_integer || + dest_type.id()==ID_real || + dest_type.id()==ID_complex || + dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_signedbv || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_integer) { - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_real) return false; - if(dest_type.id()==ID_complex) return false; - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_signedbv) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_pointer) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_real || + dest_type.id()==ID_complex || + dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_signedbv || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_pointer || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_real) { - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_complex) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_complex || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_rational) { - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_complex) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_complex || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_bool) { - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_integer) return false; - if(dest_type.id()==ID_real) return false; - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_signedbv) return false; - if(dest_type.id()==ID_pointer) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_c_enum) return false; - if(dest_type.id()==ID_c_enum_tag) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_c_bool || + dest_type.id()==ID_integer || + dest_type.id()==ID_real || + dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_signedbv || + dest_type.id()==ID_pointer || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_c_enum || + dest_type.id()==ID_c_enum_tag || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_unsignedbv || src_type_id==ID_signedbv || @@ -211,34 +217,36 @@ bool check_c_implicit_typecast( src_type_id==ID_incomplete_c_enum || src_type_id==ID_c_bool) { - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_integer) return false; - if(dest_type.id()==ID_real) return false; - if(dest_type.id()==ID_rational) return false; - if(dest_type.id()==ID_signedbv) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_pointer) return false; - if(dest_type.id()==ID_c_enum) return false; - if(dest_type.id()==ID_c_enum_tag) return false; - if(dest_type.id()==ID_incomplete_c_enum) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_integer || + dest_type.id()==ID_real || + dest_type.id()==ID_rational || + dest_type.id()==ID_signedbv || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_pointer || + dest_type.id()==ID_c_enum || + dest_type.id()==ID_c_enum_tag || + dest_type.id()==ID_incomplete_c_enum || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_floatbv || src_type_id==ID_fixedbv) { - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_integer) return false; - if(dest_type.id()==ID_real) return false; - if(dest_type.id()==ID_rational) return false; - if(dest_type.id()==ID_signedbv) return false; - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_floatbv) return false; - if(dest_type.id()==ID_fixedbv) return false; - if(dest_type.id()==ID_complex) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_integer || + dest_type.id()==ID_real || + dest_type.id()==ID_rational || + dest_type.id()==ID_signedbv || + dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_floatbv || + dest_type.id()==ID_fixedbv || + dest_type.id()==ID_complex) + return false; } else if(src_type_id==ID_complex) { @@ -272,12 +280,14 @@ bool check_c_implicit_typecast( } if(dest_type.id()==ID_array && - src_type.subtype()==dest_type.subtype()) return false; + src_type.subtype()==dest_type.subtype()) + return false; - if(dest_type.id()==ID_bool) return false; - if(dest_type.id()==ID_c_bool) return false; - if(dest_type.id()==ID_unsignedbv) return false; - if(dest_type.id()==ID_signedbv) return false; + if(dest_type.id()==ID_bool || + dest_type.id()==ID_c_bool || + dest_type.id()==ID_unsignedbv || + dest_type.id()==ID_signedbv) + return false; } else if(src_type_id==ID_vector) { @@ -312,7 +322,8 @@ Function: c_typecastt::follow_with_qualifiers typet c_typecastt::follow_with_qualifiers(const typet &src_type) { - if(src_type.id()!=ID_symbol) return src_type; + if(src_type.id()!=ID_symbol) + return src_type; typet result_type=src_type; @@ -475,6 +486,7 @@ void c_typecastt::implicit_typecast_arithmetic( case SINGLE: new_type=float_type(); break; case DOUBLE: new_type=double_type(); break; case LONGDOUBLE: new_type=long_double_type(); break; + // NOLINTNEXTLINE(whitespace/line_length) case FLOAT128: new_type=ieee_float_spect::quadruple_precision().to_type(); break; case RATIONAL: new_type=rational_typet(); break; case REAL: new_type=real_typet(); break; @@ -620,7 +632,7 @@ void c_typecastt::implicit_typecast_followed( // build union constructor exprt union_expr(ID_union, orig_dest_type); union_expr.move_to_operands(expr); - if(!full_eq(src_type, src_type_no_const)) + if(!src_type.full_eq(src_type_no_const)) do_typecast(union_expr.op0(), src_type_no_const); union_expr.set(ID_component_name, comp.get_name()); expr=union_expr; @@ -667,8 +679,12 @@ void c_typecastt::implicit_typecast_followed( { // ok } - else if((is_number(src_sub) || src_sub.id()==ID_c_enum || src_sub.id()==ID_c_enum_tag) && - (is_number(dest_sub) || dest_sub.id()==ID_c_enum || src_sub.id()==ID_c_enum_tag)) + else if((is_number(src_sub) || + src_sub.id()==ID_c_enum || + src_sub.id()==ID_c_enum_tag) && + (is_number(dest_sub) || + dest_sub.id()==ID_c_enum || + src_sub.id()==ID_c_enum_tag)) { // Also generous: between any to scalar types it's ok. // We should probably check the size. @@ -758,7 +774,7 @@ void c_typecastt::implicit_typecast_arithmetic( else if(max_type==FIXEDBV) { typet result_type; - + if(c_type1==FIXEDBV && c_type2==FIXEDBV) { // get bigger of both @@ -776,7 +792,7 @@ void c_typecastt::implicit_typecast_arithmetic( do_typecast(expr1, result_type); do_typecast(expr2, result_type); - + return; } else if(max_type==COMPLEX) diff --git a/src/ansi-c/c_typecast.h b/src/ansi-c/c_typecast.h index d444fb45f66..cfc3eb79aa5 100644 --- a/src/ansi-c/c_typecast.h +++ b/src/ansi-c/c_typecast.h @@ -38,7 +38,7 @@ bool c_implicit_typecast_arithmetic( class c_typecastt { public: - c_typecastt(const namespacet &_ns):ns(_ns) + explicit c_typecastt(const namespacet &_ns):ns(_ns) { } diff --git a/src/ansi-c/c_typecheck_base.cpp b/src/ansi-c/c_typecheck_base.cpp index 8d81099916e..8597eef3852 100644 --- a/src/ansi-c/c_typecheck_base.cpp +++ b/src/ansi-c/c_typecheck_base.cpp @@ -9,7 +9,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include -#include #include "c_typecheck_base.h" #include "expr2c.h" @@ -146,7 +145,8 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol) } // see if we have it already - symbol_tablet::symbolst::iterator old_it=symbol_table.symbols.find(symbol.name); + symbol_tablet::symbolst::iterator old_it= + symbol_table.symbols.find(symbol.name); if(old_it==symbol_table.symbols.end()) { @@ -501,7 +501,8 @@ void c_typecheck_baset::typecheck_redefinition_non_type( const irep_idt identifier= to_symbol_type(old_symbol.type).get_identifier(); - symbol_tablet::symbolst::iterator s_it=symbol_table.symbols.find(identifier); + symbol_tablet::symbolst::iterator s_it= + symbol_table.symbols.find(identifier); if(s_it==symbol_table.symbols.end()) { diff --git a/src/ansi-c/c_typecheck_base.h b/src/ansi-c/c_typecheck_base.h index 6e3a566fd21..68191f54fe9 100644 --- a/src/ansi-c/c_typecheck_base.h +++ b/src/ansi-c/c_typecheck_base.h @@ -175,11 +175,15 @@ class c_typecheck_baset: virtual void typecheck_expr_sizeof(exprt &expr); virtual void typecheck_expr_alignof(exprt &expr); virtual void typecheck_expr_function_identifier(exprt &expr); - virtual void typecheck_side_effect_gcc_conditional_expression(side_effect_exprt &expr); - virtual void typecheck_side_effect_function_call(side_effect_expr_function_callt &expr); + virtual void typecheck_side_effect_gcc_conditional_expression( + side_effect_exprt &expr); + virtual void typecheck_side_effect_function_call( + side_effect_expr_function_callt &expr); virtual void typecheck_side_effect_assignment(side_effect_exprt &expr); - virtual void typecheck_side_effect_statement_expression(side_effect_exprt &expr); - virtual void typecheck_function_call_arguments(side_effect_expr_function_callt &expr); + virtual void typecheck_side_effect_statement_expression( + side_effect_exprt &expr); + virtual void typecheck_function_call_arguments( + side_effect_expr_function_callt &expr); virtual exprt do_special_functions(side_effect_expr_function_callt &expr); virtual void make_index_type(exprt &expr); @@ -235,12 +239,13 @@ class c_typecheck_baset: void typecheck_symbol(symbolt &symbol); void typecheck_new_symbol(symbolt &symbol); void typecheck_redefinition_type(symbolt &old_symbol, symbolt &new_symbol); - void typecheck_redefinition_non_type(symbolt &old_symbol, symbolt &new_symbol); + void typecheck_redefinition_non_type( + symbolt &old_symbol, symbolt &new_symbol); void typecheck_function_body(symbolt &symbol); virtual void do_initializer(symbolt &symbol); - inline static bool is_numeric_type(const typet &src) + static bool is_numeric_type(const typet &src) { return src.id()==ID_complex || src.id()==ID_unsignedbv || diff --git a/src/ansi-c/c_typecheck_code.cpp b/src/ansi-c/c_typecheck_code.cpp index db02693b26d..dfbac98940c 100644 --- a/src/ansi-c/c_typecheck_code.cpp +++ b/src/ansi-c/c_typecheck_code.cpp @@ -249,7 +249,8 @@ void c_typecheck_baset::typecheck_block(codet &code) Forall_operands(it1, code) { - if(it1->is_nil()) continue; + if(it1->is_nil()) + continue; codet &code_op=to_code(*it1); @@ -264,7 +265,7 @@ void c_typecheck_baset::typecheck_block(codet &code) code_ptr=&to_code(code_ptr->op0()); } - //codet &label_op=*code_ptr; + // codet &label_op=*code_ptr; new_ops.move_to_operands(code_op); } @@ -470,7 +471,8 @@ bool c_typecheck_baset::is_complete_type(const typet &type) const return false; else if(type.id()==ID_array) { - if(to_array_type(type).size().is_nil()) return false; + if(to_array_type(type).size().is_nil()) + return false; return is_complete_type(type.subtype()); } else if(type.id()==ID_struct || type.id()==ID_union) @@ -598,13 +600,17 @@ void c_typecheck_baset::typecheck_for(codet &code) code_blockt code_block; code_block.add_source_location()=code.source_location(); if(to_code(code.op3()).get_statement()==ID_block) + { code_block.set( ID_C_end_location, to_code_block(to_code(code.op3())).end_location()); + } else + { code_block.set( ID_C_end_location, - code.op3().source_location());; + code.op3().source_location()); + } code_block.reserve_operands(2); code_block.move_to_operands(code.op0()); @@ -899,7 +905,9 @@ void c_typecheck_baset::typecheck_return(codet &code) { // gcc doesn't actually complain, it just warns! // We'll put a zero here, which is dubious. - exprt zero=zero_initializer(return_type, code.source_location(), *this, get_message_handler()); + exprt zero= + zero_initializer( + return_type, code.source_location(), *this, get_message_handler()); code.copy_to_operands(zero); } } diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 1b9e8edae81..5961f64142e 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -157,7 +157,8 @@ bool c_typecheck_baset::gcc_types_compatible_p( else if(type1.id()==ID_array && type2.id()==ID_array) { - return gcc_types_compatible_p(type1.subtype(), type2.subtype()); // ignore size + return + gcc_types_compatible_p(type1.subtype(), type2.subtype()); // ignore size } else if(type1.id()==ID_code && type2.id()==ID_code) @@ -426,7 +427,8 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr) { if(it->get(ID_type_arg)==ID_default) default_match=static_cast(it->find(ID_value)); - else if(op_type==follow(static_cast(it->find(ID_type_arg)))) + else if(op_type== + follow(static_cast(it->find(ID_type_arg)))) assoc_match=static_cast(it->find(ID_value)); } @@ -677,7 +679,8 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr) { if(type.id()==ID_struct) { - exprt o=c_offsetof(to_struct_type(type), c_it->get_name(), *this); + exprt o= + c_offsetof(to_struct_type(type), c_it->get_name(), *this); if(o.is_nil()) { @@ -730,7 +733,8 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr) typecheck_expr(index); exprt sub_size=c_sizeof(type.subtype(), *this); - if(index.type()!=size_type()) index.make_typecast(size_type()); + if(index.type()!=size_type()) + index.make_typecast(size_type()); result=plus_exprt(result, mult_exprt(sub_size, index)); typet tmp=type.subtype(); @@ -890,7 +894,9 @@ void c_typecheck_baset::typecheck_expr_symbol(exprt &expr) if(symbol.is_macro) { // preserve enum key - //irep_idt base_name=expr.get(ID_C_base_name); + #if 0 + irep_idt base_name=expr.get(ID_C_base_name); + #endif follow_macros(expr); @@ -2168,7 +2174,8 @@ void c_typecheck_baset::typecheck_expr_side_effect(side_effect_exprt &expr) else if(has_prefix(id2string(statement), "assign")) typecheck_side_effect_assignment(expr); else if(statement==ID_function_call) - typecheck_side_effect_function_call(to_side_effect_expr_function_call(expr)); + typecheck_side_effect_function_call( + to_side_effect_expr_function_call(expr)); else if(statement==ID_statement_expression) typecheck_side_effect_statement_expression(expr); else if(statement==ID_gcc_conditional_expression) @@ -2334,7 +2341,8 @@ exprt c_typecheck_baset::do_special_functions( throw 0; } - exprt same_object_expr=same_object(expr.arguments()[0], expr.arguments()[1]); + exprt same_object_expr= + same_object(expr.arguments()[0], expr.arguments()[1]); same_object_expr.add_source_location()=source_location; return same_object_expr; @@ -2351,7 +2359,8 @@ exprt c_typecheck_baset::do_special_functions( typecheck_function_call_arguments(expr); exprt get_must_expr= - binary_predicate_exprt(expr.arguments()[0], "get_must", expr.arguments()[1]); + binary_predicate_exprt( + expr.arguments()[0], "get_must", expr.arguments()[1]); get_must_expr.add_source_location()=source_location; return get_must_expr; @@ -2368,7 +2377,8 @@ exprt c_typecheck_baset::do_special_functions( typecheck_function_call_arguments(expr); exprt get_may_expr= - binary_predicate_exprt(expr.arguments()[0], "get_may", expr.arguments()[1]); + binary_predicate_exprt( + expr.arguments()[0], "get_may", expr.arguments()[1]); get_may_expr.add_source_location()=source_location; return get_may_expr; @@ -2538,7 +2548,8 @@ exprt c_typecheck_baset::do_special_functions( identifier=="__builtin_inf") { constant_exprt inf_expr= - ieee_floatt::plus_infinity(ieee_float_spect::double_precision()).to_expr(); + ieee_floatt::plus_infinity( + ieee_float_spect::double_precision()).to_expr(); inf_expr.add_source_location()=source_location; return inf_expr; @@ -2546,7 +2557,8 @@ exprt c_typecheck_baset::do_special_functions( else if(identifier==CPROVER_PREFIX "inff") { constant_exprt inff_expr= - ieee_floatt::plus_infinity(ieee_float_spect::single_precision()).to_expr(); + ieee_floatt::plus_infinity( + ieee_float_spect::single_precision()).to_expr(); inff_expr.add_source_location()=source_location; return inff_expr; @@ -2735,8 +2747,8 @@ exprt c_typecheck_baset::do_special_functions( else if(to_integer(expr.arguments()[1], arg1)) { err_location(f_op); - error() << "__builtin_object_size expects constant as second argument, but got " - << to_string(expr.arguments()[1]) << eom; + error() << "__builtin_object_size expects constant as second argument, " + << "but got " << to_string(expr.arguments()[1]) << eom; throw 0; } @@ -3128,14 +3140,20 @@ bool c_typecheck_baset::gcc_vector_types_compatible( // compare dimension mp_integer s0, s1; - if(to_integer(type0.size(), s0)) return false; - if(to_integer(type1.size(), s1)) return false; - if(s0!=s1) return false; + if(to_integer(type0.size(), s0)) + return false; + if(to_integer(type1.size(), s1)) + return false; + if(s0!=s1) + return false; // comparse subtype - if((type0.subtype().id()==ID_signedbv || type0.subtype().id()==ID_unsignedbv) && - (type1.subtype().id()==ID_signedbv || type1.subtype().id()==ID_unsignedbv) && - to_bitvector_type(type0.subtype()).get_width()==to_bitvector_type(type1.subtype()).get_width()) + if((type0.subtype().id()==ID_signedbv || + type0.subtype().id()==ID_unsignedbv) && + (type1.subtype().id()==ID_signedbv || + type1.subtype().id()==ID_unsignedbv) && + to_bitvector_type(type0.subtype()).get_width()== + to_bitvector_type(type1.subtype()).get_width()) return true; return type0.subtype()==type1.subtype(); @@ -3172,11 +3190,13 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr) if(o_type0.id()==ID_vector && o_type1.id()==ID_vector) { - if(gcc_vector_types_compatible(to_vector_type(o_type0), to_vector_type(o_type1)) && + if(gcc_vector_types_compatible( + to_vector_type(o_type0), to_vector_type(o_type1)) && is_number(follow(o_type0.subtype()))) { // Vector arithmetic has fairly strict typing rules, no promotion - if(o_type0!=o_type1) op1.make_typecast(op0.type()); + if(o_type0!=o_type1) + op1.make_typecast(op0.type()); expr.type()=op0.type(); return; } @@ -3280,7 +3300,8 @@ void c_typecheck_baset::typecheck_expr_shifts(shift_exprt &expr) if(follow(o_type0.subtype())==follow(o_type1.subtype()) && is_number(follow(o_type0.subtype()))) { - // {a0, a1, ..., an} >> {b0, b1, ..., bn} == {a0 >> b0, a1 >> b1, ..., an >> bn} + // {a0, a1, ..., an} >> {b0, b1, ..., bn} == + // {a0 >> b0, a1 >> b1, ..., an >> bn} // Fairly strict typing rules, no promotion expr.type()=op0.type(); return; @@ -3509,7 +3530,8 @@ Function: c_typecheck_baset::typecheck_side_effect_assignment \*******************************************************************/ -void c_typecheck_baset::typecheck_side_effect_assignment(side_effect_exprt &expr) +void c_typecheck_baset::typecheck_side_effect_assignment( + side_effect_exprt &expr) { if(expr.operands().size()!=2) { diff --git a/src/ansi-c/c_typecheck_initializer.cpp b/src/ansi-c/c_typecheck_initializer.cpp index 4448f8f8de0..79dabc9f0e9 100644 --- a/src/ansi-c/c_typecheck_initializer.cpp +++ b/src/ansi-c/c_typecheck_initializer.cpp @@ -136,8 +136,12 @@ exprt c_typecheck_baset::do_initializer_rec( { // fill up tmp.type()=type; - exprt zero=zero_initializer(full_type.subtype(), value.source_location(), - *this, get_message_handler()); + exprt zero= + zero_initializer( + full_type.subtype(), + value.source_location(), + *this, + get_message_handler()); tmp.operands().resize(integer2size_t(array_size), zero); } } @@ -189,8 +193,12 @@ exprt c_typecheck_baset::do_initializer_rec( { // fill up tmp2.type()=type; - exprt zero=zero_initializer(full_type.subtype(), value.source_location(), - *this, get_message_handler()); + exprt zero= + zero_initializer( + full_type.subtype(), + value.source_location(), + *this, + get_message_handler()); tmp2.operands().resize(integer2size_t(array_size), zero); } } @@ -441,7 +449,12 @@ void c_typecheck_baset::do_designated_initializer( to_array_type(full_type).size().is_nil())) { // we are willing to grow an incomplete or zero-sized array - exprt zero=zero_initializer(full_type.subtype(), value.source_location(), *this, get_message_handler()); + exprt zero= + zero_initializer( + full_type.subtype(), + value.source_location(), + *this, + get_message_handler()); dest->operands().resize(integer2size_t(index)+1, zero); // todo: adjust type! @@ -500,7 +513,12 @@ void c_typecheck_baset::do_designated_initializer( // Note that gcc issues a warning if the union component is switched. // Build a union expression from given component. union_exprt union_expr(type); - union_expr.op()=zero_initializer(component.type(), value.source_location(), *this, get_message_handler()); + union_expr.op()= + zero_initializer( + component.type(), + value.source_location(), + *this, + get_message_handler()); union_expr.add_source_location()=value.source_location(); union_expr.set_component_name(component.get_name()); *dest=union_expr; @@ -554,10 +572,16 @@ void c_typecheck_baset::do_designated_initializer( if(!components.empty()) { - const union_typet::componentt &component=union_type.components().front(); + const union_typet::componentt &component= + union_type.components().front(); union_exprt union_expr(type); - union_expr.op()=zero_initializer(component.type(), value.source_location(), *this, get_message_handler()); + union_expr.op()= + zero_initializer( + component.type(), + value.source_location(), + *this, + get_message_handler()); union_expr.add_source_location()=value.source_location(); union_expr.set_component_name(component.get_name()); *dest=union_expr; @@ -669,9 +693,11 @@ void c_typecheck_baset::increment_designator(designatort &designator) entry.subtype=components[entry.index].type(); } - if(entry.indexmax_value) max_value=value; + if(valuemax_value) + max_value=value; typet constant_type= enum_constant_type(min_value, max_value); @@ -1579,8 +1588,10 @@ void c_typecheck_baset::typecheck_symbol_type(typet &type) type=symbol.type; c_qualifiers.write(type); - if(is_packed) type.set(ID_C_packed, true); - if(alignment.is_not_nil()) type.set(ID_C_alignment, alignment); + if(is_packed) + type.set(ID_C_packed, true); + if(alignment.is_not_nil()) + type.set(ID_C_alignment, alignment); } // CPROVER extensions diff --git a/src/ansi-c/cprover_library.cpp b/src/ansi-c/cprover_library.cpp index bc05e0eb749..382ec324636 100644 --- a/src/ansi-c/cprover_library.cpp +++ b/src/ansi-c/cprover_library.cpp @@ -19,7 +19,7 @@ struct cprover_library_entryt const char *model; } cprover_library[]= #include "cprover_library.inc" -; +; // NOLINT(whitespace/semicolon) /*******************************************************************\ @@ -118,7 +118,8 @@ void add_library( symbol_tablet &symbol_table, message_handlert &message_handler) { - if(src.empty()) return; + if(src.empty()) + return; std::istringstream in(src); diff --git a/src/ansi-c/designator.cpp b/src/ansi-c/designator.cpp index 1ce7e8de02f..88657e71407 100644 --- a/src/ansi-c/designator.cpp +++ b/src/ansi-c/designator.cpp @@ -28,7 +28,8 @@ void designatort::print(std::ostream &out) const it!=index_list.end(); ++it) { - if(it!=index_list.begin()) out << ", "; + if(it!=index_list.begin()) + out << ", "; out << it->type.id() << " " << it->index << "/" << it->size; } } diff --git a/src/ansi-c/designator.h b/src/ansi-c/designator.h index d1e6ac720c5..019f622ef63 100644 --- a/src/ansi-c/designator.h +++ b/src/ansi-c/designator.h @@ -32,8 +32,8 @@ class designatort size_t size() const { return index_list.size(); } const entryt &operator[](size_t i) const { return index_list[i]; } entryt &operator[](size_t i) { return index_list[i]; } - const entryt &back() const { return index_list.back(); }; - const entryt &front() const { return index_list.front(); }; + const entryt &back() const { return index_list.back(); } + const entryt &front() const { return index_list.front(); } designatort() { } diff --git a/src/ansi-c/expr2c.cpp b/src/ansi-c/expr2c.cpp index 7a61cd205ea..a6975bdab19 100644 --- a/src/ansi-c/expr2c.cpp +++ b/src/ansi-c/expr2c.cpp @@ -141,7 +141,8 @@ void expr2ct::get_shorthands(const exprt &expr) const symbolt *symbol; bool is_param=!ns.lookup(*it, symbol) && symbol->is_parameter; - if(!is_param) continue; + if(!is_param) + continue; irep_idt sh=id_shorthand(*it); @@ -289,7 +290,9 @@ std::string expr2ct::convert_rec( return q+"long double"+d; } const std::size_t fraction_bits=to_fixedbv_type(src).get_fraction_bits(); - return q+"__CPROVER_fixedbv["+std::to_string(width)+"]["+std::to_string(fraction_bits)+"]"+d; + return + q+"__CPROVER_fixedbv["+std::to_string(width)+"]["+ + std::to_string(fraction_bits)+"]"+d; } else if(src.id()==ID_c_bit_field) { @@ -323,12 +326,14 @@ std::string expr2ct::convert_rec( if(width==config.ansi_c.int_width) { - if(is_signed) sign_str=""; + if(is_signed) + sign_str=""; return q+sign_str+"int"+d; } else if(width==config.ansi_c.long_int_width) { - if(is_signed) sign_str=""; + if(is_signed) + sign_str=""; return q+sign_str+"long int"+d; } else if(width==config.ansi_c.char_width) @@ -338,17 +343,20 @@ std::string expr2ct::convert_rec( } else if(width==config.ansi_c.short_int_width) { - if(is_signed) sign_str=""; + if(is_signed) + sign_str=""; return q+sign_str+"short int"+d; } else if(width==config.ansi_c.long_long_int_width) { - if(is_signed) sign_str=""; + if(is_signed) + sign_str=""; return q+sign_str+"long long int"+d; } else if(width==128) { - if(is_signed) sign_str=""; + if(is_signed) + sign_str=""; return q+sign_str+"__int128"; } else @@ -366,7 +374,8 @@ std::string expr2ct::convert_rec( std::string dest=q+"struct"; const std::string &tag=src.get_string(ID_tag); - if(tag!="") dest+=" "+tag; + if(tag!="") + dest+=" "+tag; dest+=d; return dest; @@ -378,7 +387,8 @@ std::string expr2ct::convert_rec( std::string dest=q+"union"; const irep_idt &tag=union_type.get_tag(); - if(tag!="") dest+=" "+id2string(tag); + if(tag!="") + dest+=" "+id2string(tag); dest+=" {"; for(union_typet::componentst::const_iterator @@ -402,7 +412,8 @@ std::string expr2ct::convert_rec( std::string dest=q+"union"; const std::string &tag=src.get_string(ID_tag); - if(tag!="") dest+=" "+tag; + if(tag!="") + dest+=" "+tag; dest+=d; return dest; @@ -436,7 +447,8 @@ std::string expr2ct::convert_rec( it!=members.end(); it++) { - if(it!=members.begin()) result+=','; + if(it!=members.begin()) + result+=','; result+=' '; result+=id2string(it->get_base_name()); result+='='; @@ -512,7 +524,8 @@ std::string expr2ct::convert_rec( { std::string dest=q+"struct"; const irep_idt &tag=to_struct_type(followed).get_tag(); - if(tag!="") dest+=" "+id2string(tag); + if(tag!="") + dest+=" "+id2string(tag); dest+=d; return dest; } @@ -520,7 +533,8 @@ std::string expr2ct::convert_rec( { std::string dest=q+"union"; const irep_idt &tag=to_union_type(followed).get_tag(); - if(tag!="") dest+=" "+id2string(tag); + if(tag!="") + dest+=" "+id2string(tag); dest+=d; return dest; } @@ -534,7 +548,8 @@ std::string expr2ct::convert_rec( std::string dest=q+"struct"; const std::string &tag=ns.follow_tag(struct_tag_type).get_string(ID_tag); - if(tag!="") dest+=" "+tag; + if(tag!="") + dest+=" "+tag; dest+=d; return dest; @@ -546,7 +561,8 @@ std::string expr2ct::convert_rec( std::string dest=q+"union"; const std::string &tag=ns.follow_tag(union_tag_type).get_string(ID_tag); - if(tag!="") dest+=" "+tag; + if(tag!="") + dest+=" "+tag; dest+=d; return dest; @@ -864,9 +880,11 @@ std::string expr2ct::convert_typecast( unsigned p; std::string tmp=convert(src.op(), p); - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=tmp; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; return dest; } @@ -905,25 +923,31 @@ std::string expr2ct::convert_trinary( std::string dest; - if(precedence>=p0) dest+='('; + if(precedence>=p0) + dest+='('; dest+=s_op0; - if(precedence>=p0) dest+=')'; + if(precedence>=p0) + dest+=')'; dest+=' '; dest+=symbol1; dest+=' '; - if(precedence>=p1) dest+='('; + if(precedence>=p1) + dest+='('; dest+=s_op1; - if(precedence>=p1) dest+=')'; + if(precedence>=p1) + dest+=')'; dest+=' '; dest+=symbol2; dest+=' '; - if(precedence>=p2) dest+='('; + if(precedence>=p2) + dest+='('; dest+=s_op2; - if(precedence>=p2) dest+=')'; + if(precedence>=p2) + dest+=')'; return dest; } @@ -986,9 +1010,11 @@ std::string expr2ct::convert_with( std::string dest; - if(precedence>p0) dest+='('; + if(precedence>p0) + dest+='('; dest+=op0; - if(precedence>p0) dest+=')'; + if(precedence>p0) + dest+=')'; dest+=" WITH ["; @@ -997,7 +1023,8 @@ std::string expr2ct::convert_with( std::string op1, op2; unsigned p1, p2; - if(i!=1) dest+=", "; + if(i!=1) + dest+=", "; if(src.operands()[i].id()==ID_member_name) { @@ -1069,9 +1096,11 @@ std::string expr2ct::convert_update( op0=convert(src.op0(), p0); op2=convert(src.op2(), p2); - if(precedence>p0) dest+='('; + if(precedence>p0) + dest+='('; dest+=op0; - if(precedence>p0) dest+=')'; + if(precedence>p0) + dest+=')'; dest+=", "; @@ -1082,9 +1111,11 @@ std::string expr2ct::convert_update( dest+=", "; - if(precedence>p2) dest+='('; + if(precedence>p2) + dest+='('; dest+=op2; - if(precedence>p2) dest+=')'; + if(precedence>p2) + dest+=')'; dest+=')'; @@ -1119,7 +1150,8 @@ std::string expr2ct::convert_cond( unsigned p; std::string op=convert(*it, p); - if(condition) dest+=" "; + if(condition) + dest+=" "; dest+=op; @@ -1166,7 +1198,8 @@ std::string expr2ct::convert_binary( first=false; else { - if(symbol!=", ") dest+=' '; + if(symbol!=", ") + dest+=' '; dest+=symbol; dest+=' '; } @@ -1186,9 +1219,11 @@ std::string expr2ct::convert_binary( (precedence==p && full_parentheses) || (precedence==p && src.id()!=it->id()); - if(use_parentheses) dest+='('; + if(use_parentheses) + dest+='('; dest+=op; - if(use_parentheses) dest+=')'; + if(use_parentheses) + dest+=')'; } return dest; @@ -1432,7 +1467,8 @@ std::string expr2ct::convert_function( unsigned p; std::string op=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; dest+=op; } @@ -1530,7 +1566,8 @@ std::string expr2ct::convert_complex( unsigned p; std::string op=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; dest+=op; } @@ -1665,9 +1702,11 @@ std::string expr2ct::convert_unary_post( std::string op=convert(src.op0(), p); std::string dest; - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+=symbol; return dest; @@ -1696,9 +1735,11 @@ std::string expr2ct::convert_index( std::string op=convert(src.op0(), p); std::string dest; - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+='['; dest+=convert(src.op1()); @@ -1736,16 +1777,20 @@ std::string expr2ct::convert_pointer_arithmetic( dest+=", "; op=convert(src.op0(), p); - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+=", "; op=convert(src.op1(), p); - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+=')'; @@ -1781,16 +1826,20 @@ std::string expr2ct::convert_pointer_difference( dest+=", "; op=convert(src.op0(), p); - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+=", "; op=convert(src.op1(), p); - if(precedence>p) dest+='('; + if(precedence>p) + dest+='('; dest+=op; - if(precedence>p) dest+=')'; + if(precedence>p) + dest+=')'; dest+=')'; @@ -1868,9 +1917,11 @@ std::string expr2ct::convert_member( { std::string op=convert(src.op0().op0(), p); - if(precedence>p || src.op0().op0().id()==ID_typecast) dest+='('; + if(precedence>p || src.op0().op0().id()==ID_typecast) + dest+='('; dest+=op; - if(precedence>p || src.op0().op0().id()==ID_typecast) dest+=')'; + if(precedence>p || src.op0().op0().id()==ID_typecast) + dest+=')'; dest+="->"; } @@ -1878,9 +1929,11 @@ std::string expr2ct::convert_member( { std::string op=convert(src.op0(), p); - if(precedence>p || src.op0().id()==ID_typecast) dest+='('; + if(precedence>p || src.op0().id()==ID_typecast) + dest+='('; dest+=op; - if(precedence>p || src.op0().id()==ID_typecast) dest+=')'; + if(precedence>p || src.op0().id()==ID_typecast) + dest+=')'; dest+='.'; } @@ -2034,7 +2087,8 @@ std::string expr2ct::convert_symbol( { if(sizeof_nesting++ == 0) dest+=" /*"+convert(src.type()); - if(--sizeof_nesting == 0) dest+="*/"; + if(--sizeof_nesting == 0) + dest+="*/"; } #endif } @@ -2286,7 +2340,9 @@ std::string expr2ct::convert_constant( { dest=convert_constant_bool(int_value!=0); } - else if(type==char_type() && type!=signed_int_type() && type!=unsigned_int_type()) + else if(type==char_type() && + type!=signed_int_type() && + type!=unsigned_int_type()) { if(int_value=='\n') dest+="'\\n'"; @@ -2301,7 +2357,7 @@ std::string expr2ct::convert_constant( else if(int_value>=' ' && int_value<126) { dest+='\''; - dest+=char(integer2ulong(int_value)); + dest+=static_cast(integer2ulong(int_value)); dest+='\''; } else @@ -2737,7 +2793,7 @@ std::string expr2ct::convert_array( default: if(ch>=' ' && ch!=127 && ch<0xff) - dest+=(char)ch; + dest+=static_cast(ch); else { char hexbuf[10]; @@ -2765,7 +2821,8 @@ std::string expr2ct::convert_array( if((it+1)!=src.operands().end()) { tmp+=", "; - if(tmp.size()>40) tmp+="\n "; + if(tmp.size()>40) + tmp+="\n "; } dest+=tmp; @@ -2810,7 +2867,8 @@ std::string expr2ct::convert_array_list( if((it+1)!=src.operands().end()) { tmp+=", "; - if(tmp.size()>40) tmp+="\n "; + if(tmp.size()>40) + tmp+="\n "; } dest+=tmp; @@ -2838,7 +2896,8 @@ std::string expr2ct::convert_initializer_list( unsigned &precedence) { std::string dest; - if(src.id()!=ID_compound_literal) dest+="{ "; + if(src.id()!=ID_compound_literal) + dest+="{ "; forall_operands(it, src) { @@ -2847,13 +2906,15 @@ std::string expr2ct::convert_initializer_list( if((it+1)!=src.operands().end()) { tmp+=", "; - if(tmp.size()>40) tmp+="\n "; + if(tmp.size()>40) + tmp+="\n "; } dest+=tmp; } - if(src.id()!=ID_compound_literal) dest+=" }"; + if(src.id()!=ID_compound_literal) + dest+=" }"; return dest; } @@ -2919,7 +2980,8 @@ std::string expr2ct::convert_function_application( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.arguments().begin()) dest+=", "; + if(it!=src.arguments().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -2960,7 +3022,8 @@ std::string expr2ct::convert_side_effect_expr_function_call( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.arguments().begin()) dest+=", "; + if(it!=src.arguments().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -3361,7 +3424,8 @@ std::string expr2ct::convert_code_switch( forall_operands(it, src) { - if(it==src.operands().begin()) continue; + if(it==src.operands().begin()) + continue; const exprt &op=*it; if(op.get(ID_statement)!=ID_block) @@ -3625,7 +3689,8 @@ std::string expr2ct::convert_code_expression( } dest+=expr_str; - if(dest.empty() || *dest.rbegin()!=';') dest+=';'; + if(dest.empty() || *dest.rbegin()!=';') + dest+=';'; return dest; } @@ -3758,7 +3823,8 @@ std::string expr2ct::convert_code( if(statement=="set_may" || statement=="set_must") - return indent_str(indent)+convert_function(src, id2string(statement), 16)+";"; + return + indent_str(indent)+convert_function(src, id2string(statement), 16)+";"; unsigned precedence; return convert_norep(src, precedence); @@ -3932,7 +3998,8 @@ std::string expr2ct::convert_code_function_call( unsigned p; std::string arg_str=convert(*it, p); - if(it!=arguments.begin()) dest+=", "; + if(it!=arguments.begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -3965,7 +4032,8 @@ std::string expr2ct::convert_code_printf( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -4040,7 +4108,8 @@ std::string expr2ct::convert_code_input( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -4073,7 +4142,8 @@ std::string expr2ct::convert_code_output( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; dest+=arg_str; } @@ -4105,7 +4175,8 @@ std::string expr2ct::convert_code_array_set( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -4138,7 +4209,8 @@ std::string expr2ct::convert_code_array_copy( unsigned p; std::string arg_str=convert(*it, p); - if(it!=src.operands().begin()) dest+=", "; + if(it!=src.operands().begin()) + dest+=", "; // TODO: ggf. Klammern je nach p dest+=arg_str; } @@ -4477,9 +4549,11 @@ std::string expr2ct::convert( unsigned p0; std::string tmp0=convert(src.op0(), p0); - if(p0<=1) dest+='('; + if(p0<=1) + dest+='('; dest+=tmp0; - if(p0<=1) dest+=')'; + if(p0<=1) + dest+=')'; const typet &to_type=ns.follow(src.type()); dest+=", "; @@ -4489,9 +4563,11 @@ std::string expr2ct::convert( unsigned p1; std::string tmp1=convert(src.op1(), p1); - if(p1<=1) dest+='('; + if(p1<=1) + dest+='('; dest+=tmp1; - if(p1<=1) dest+=')'; + if(p1<=1) + dest+=')'; dest+=')'; return dest; @@ -4673,7 +4749,9 @@ std::string expr2ct::convert( return convert_struct_member_value(src, precedence=16); else if(src.id()==ID_function_application) - return convert_function_application(to_function_application_expr(src), precedence); + return + convert_function_application( + to_function_application_expr(src), precedence); else if(src.id()==ID_side_effect) { @@ -4709,7 +4787,9 @@ std::string expr2ct::convert( else if(statement==ID_assign) return convert_binary(src, "=", precedence=2, true); else if(statement==ID_function_call) - return convert_side_effect_expr_function_call(to_side_effect_expr_function_call(src), precedence); + return + convert_side_effect_expr_function_call( + to_side_effect_expr_function_call(src), precedence); else if(statement==ID_malloc) return convert_malloc(src, precedence=15); else if(statement==ID_printf) @@ -4985,6 +5065,6 @@ Function: type2c std::string type2c(const typet &type, const namespacet &ns) { expr2ct expr2c(ns); - //expr2c.get_shorthands(expr); + // expr2c.get_shorthands(expr); return expr2c.convert(type); } diff --git a/src/ansi-c/expr2c_class.h b/src/ansi-c/expr2c_class.h index a4b8ff2bd66..b0647fb7fbb 100644 --- a/src/ansi-c/expr2c_class.h +++ b/src/ansi-c/expr2c_class.h @@ -22,7 +22,7 @@ class namespacet; class expr2ct { public: - expr2ct(const namespacet &_ns):ns(_ns), sizeof_nesting(0) { } + explicit expr2ct(const namespacet &_ns):ns(_ns), sizeof_nesting(0) { } virtual ~expr2ct() { } virtual std::string convert(const typet &src); @@ -75,10 +75,12 @@ class expr2ct std::string convert_typecast( const typecast_exprt &src, unsigned &precedence); - std::string convert_pointer_arithmetic(const exprt &src, + std::string convert_pointer_arithmetic( + const exprt &src, unsigned &precedence); - std::string convert_pointer_difference(const exprt &src, + std::string convert_pointer_difference( + const exprt &src, unsigned &precedence); std::string convert_binary( @@ -169,11 +171,13 @@ class expr2ct std::string convert_code(const codet &src); virtual std::string convert_code(const codet &src, unsigned indent); std::string convert_code_label(const code_labelt &src, unsigned indent); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_code_switch_case(const code_switch_caset &src, unsigned indent); std::string convert_code_asm(const code_asmt &src, unsigned indent); std::string convert_code_assign(const code_assignt &src, unsigned indent); std::string convert_code_free(const codet &src, unsigned indent); std::string convert_code_init(const codet &src, unsigned indent); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_code_ifthenelse(const code_ifthenelset &src, unsigned indent); std::string convert_code_for(const code_fort &src, unsigned indent); std::string convert_code_while(const code_whilet &src, unsigned indent); @@ -190,6 +194,7 @@ class expr2ct std::string convert_code_decl(const codet &src, unsigned indent); std::string convert_code_decl_block(const codet &src, unsigned indent); std::string convert_code_dead(const codet &src, unsigned indent); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_code_function_call(const code_function_callt &src, unsigned indent); std::string convert_code_lock(const codet &src, unsigned indent); std::string convert_code_unlock(const codet &src, unsigned indent); @@ -202,23 +207,29 @@ class expr2ct virtual std::string convert(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_function_application(const function_application_exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_side_effect_expr_function_call(const side_effect_expr_function_callt &src, unsigned &precedence); std::string convert_malloc(const exprt &src, unsigned &precedence); std::string convert_nondet(const exprt &src, unsigned &precedence); std::string convert_prob_coin(const exprt &src, unsigned &precedence); std::string convert_prob_uniform(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_statement_expression(const exprt &src, unsigned &precendence); virtual std::string convert_symbol(const exprt &src, unsigned &precedence); std::string convert_predicate_symbol(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_predicate_next_symbol(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_predicate_passive_symbol(const exprt &src, unsigned &precedence); std::string convert_nondet_symbol(const exprt &src, unsigned &precedence); std::string convert_quantified_symbol(const exprt &src, unsigned &precedence); std::string convert_nondet_bool(const exprt &src, unsigned &precedence); std::string convert_object_descriptor(const exprt &src, unsigned &precedence); std::string convert_literal(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) virtual std::string convert_constant(const constant_exprt &src, unsigned &precedence); virtual std::string convert_constant_bool(bool boolean_value); @@ -230,6 +241,7 @@ class expr2ct std::string convert_array(const exprt &src, unsigned &precedence); std::string convert_array_list(const exprt &src, unsigned &precedence); std::string convert_initializer_list(const exprt &src, unsigned &precedence); + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_designated_initializer(const exprt &src, unsigned &precedence); std::string convert_concatenation(const exprt &src, unsigned &precedence); std::string convert_sizeof(const exprt &src, unsigned &precedence); diff --git a/src/ansi-c/file_converter.cpp b/src/ansi-c/file_converter.cpp index ebb7867af18..1a3aecab1a3 100644 --- a/src/ansi-c/file_converter.cpp +++ b/src/ansi-c/file_converter.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Convert file contents to C strings + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #include #include diff --git a/src/ansi-c/library/cegis.c b/src/ansi-c/library/cegis.c index da3dd90d451..5be866cee6d 100644 --- a/src/ansi-c/library/cegis.c +++ b/src/ansi-c/library/cegis.c @@ -65,7 +65,7 @@ void __CPROVER_danger_execute(struct __CPROVER_cegis_instructiont *program, else if (opcode < 2) __CPROVER_cegis_opcode_1: result=op0 * op1; else - __CPROVER_cegis_opcode_2: result=op0 & op1; + __CPROVER_cegis_opcode_2: result=op0 &op1; else if (opcode < 5) if (opcode < 4) diff --git a/src/ansi-c/library/converter.cpp b/src/ansi-c/library/converter.cpp index 905a566d9bf..e114c5c2409 100644 --- a/src/ansi-c/library/converter.cpp +++ b/src/ansi-c/library/converter.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #include #include @@ -17,14 +25,19 @@ int main() { if(has_prefix(line, "/* FUNCTION: ")) { - if(first) first=false; else std::cout << "},\n"; + if(first) + first=false; + else + std::cout << "},\n"; std::string function=std::string(line, 13, std::string::npos); std::size_t pos=function.find(' '); - if(pos!=std::string::npos) function=std::string(function, 0, pos); + if(pos!=std::string::npos) + function=std::string(function, 0, pos); std::cout << "{ \"" << function << "\",\n"; - std::cout << " \"#line 1 \\\"\\\"\\n\"\n"; + std::cout << " \"#line 1 \\\"\\\"\\n\"\n"; } else if(!first) { @@ -48,7 +61,8 @@ int main() } } - if(!first) std::cout << "},\n"; + if(!first) + std::cout << "},\n"; std::cout << "{ 0, 0 }\n" diff --git a/src/ansi-c/library/jsa.h b/src/ansi-c/library/jsa.h index 9fff04bb0b5..c7b7400426e 100644 --- a/src/ansi-c/library/jsa.h +++ b/src/ansi-c/library/jsa.h @@ -1,3 +1,12 @@ +/*******************************************************************\ + +Module: Counterexample-Guided Inductive Synthesis + +Author: Daniel Kroening, kroening@kroening.com + Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk + +\*******************************************************************/ + /* FUNCTION: __CPROVER_jsa_synthesise */ #ifndef CPROVER_ANSI_C_LIBRARY_JSA_H @@ -34,7 +43,8 @@ extern jmp_buf __CPROVER_jsa_jump_buffer; #define __CPROVER_JSA_MAX_ABSTRACT_NODES __CPROVER_JSA_MAX_CONCRETE_NODES #endif #ifndef __CPROVER_JSA_MAX_NODES -#define __CPROVER_JSA_MAX_NODES __CPROVER_JSA_MAX_CONCRETE_NODES + __CPROVER_JSA_MAX_ABSTRACT_NODES +#define __CPROVER_JSA_MAX_NODES __CPROVER_JSA_MAX_CONCRETE_NODES+\ + __CPROVER_JSA_MAX_ABSTRACT_NODES #endif #ifndef __CPROVER_JSA_MAX_ABSTRACT_RANGES #define __CPROVER_JSA_MAX_ABSTRACT_RANGES __CPROVER_JSA_MAX_ABSTRACT_NODES @@ -51,7 +61,7 @@ extern jmp_buf __CPROVER_jsa_jump_buffer; #if __CPROVER_JSA_MAX_LISTS < 1 #error "JSA needs at least one list variable for analysis." #endif -#if __CPROVER_JSA_MAX_ABSTRACT_NODES != 0 +#if __CPROVER_JSA_MAX_ABSTRACT_NODES!=0 #error "Currently in concrete-mode only." #endif @@ -118,13 +128,15 @@ typedef struct __CPROVER_jsa_abstract_heap __CPROVER_jsa_concrete_nodet concrete_nodes[__CPROVER_JSA_MAX_CONCRETE_NODES]; #if __CPROVER_JSA_MAX_ABSTRACT_NODES > 0 - __CPROVER_jsa_abstract_nodet abstract_nodes[__CPROVER_JSA_MAX_ABSTRACT_NODES]; + __CPROVER_jsa_abstract_nodet + abstract_nodes[__CPROVER_JSA_MAX_ABSTRACT_NODES]; #else __CPROVER_jsa_abstract_nodet *abstract_nodes; #endif #if __CPROVER_JSA_MAX_ABSTRACT_NODES > 0 - __CPROVER_jsa_abstract_ranget abstract_ranges[__CPROVER_JSA_MAX_ABSTRACT_RANGES]; + __CPROVER_jsa_abstract_ranget + abstract_ranges[__CPROVER_JSA_MAX_ABSTRACT_RANGES]; #else __CPROVER_jsa_abstract_ranget *abstract_ranges; #endif @@ -145,7 +157,6 @@ typedef struct __CPROVER_jsa_abstract_heap * Number of lists on the heap. */ __CPROVER_jsa_index_t list_count; - } __CPROVER_jsa_abstract_heapt; @@ -159,7 +170,12 @@ typedef struct __CPROVER_jsa_abstract_heap #define __CPROVER_jsa_assume(c) __CPROVER_assume(c) #define __CPROVER_jsa_assert(c, str) __CPROVER_assert(c, str) #else -#define __CPROVER_jsa_assume(c) do { if (!(c)) longjmp(__CPROVER_jsa_jump_buffer, 1); } while(false) +#define __CPROVER_jsa_assume(c) \ + do {\ + if(!(c))\ + longjmp(__CPROVER_jsa_jump_buffer, 1);\ + }\ + while(false) #define __CPROVER_jsa_assert(c, str) assert((c) && str) #endif @@ -168,50 +184,57 @@ typedef struct __CPROVER_jsa_abstract_heap #define __CPROVER_jsa__internal_are_heaps_equal(lhs, rhs) (*(lhs) == *(rhs)) #else __CPROVER_jsa_inline _Bool __CPROVER_jsa__internal_are_heaps_equal( - const __CPROVER_jsa_abstract_heapt * const lhs, - const __CPROVER_jsa_abstract_heapt * const rhs) + const __CPROVER_jsa_abstract_heapt *const lhs, + const __CPROVER_jsa_abstract_heapt *const rhs) { __CPROVER_jsa__internal_index_t i; - for (i=0; i < __CPROVER_JSA_MAX_ABSTRACT_NODES; ++i) + for(i=0; i < __CPROVER_JSA_MAX_ABSTRACT_NODES; ++i) { const __CPROVER_jsa_abstract_nodet lhs_node=lhs->abstract_nodes[i]; const __CPROVER_jsa_abstract_nodet rhs_node=rhs->abstract_nodes[i]; - if (lhs_node.list != rhs_node.list || - lhs_node.next != rhs_node.next || - lhs_node.previous != rhs_node.previous || - lhs_node.value_ref != rhs_node.value_ref) return false; + if(lhs_node.list!=rhs_node.list || + lhs_node.next!=rhs_node.next || + lhs_node.previous!=rhs_node.previous || + lhs_node.value_ref!=rhs_node.value_ref) + return false; } - for (i=0; i < __CPROVER_JSA_MAX_ABSTRACT_RANGES; ++i) + for(i=0; i < __CPROVER_JSA_MAX_ABSTRACT_RANGES; ++i) { const __CPROVER_jsa_abstract_ranget lhs_range=lhs->abstract_ranges[i]; const __CPROVER_jsa_abstract_ranget rhs_range=rhs->abstract_ranges[i]; - if (lhs_range.max != rhs_range.max || - lhs_range.min != rhs_range.min || - lhs_range.size != rhs_range.size) return false; + if(lhs_range.max!=rhs_range.max || + lhs_range.min!=rhs_range.min || + lhs_range.size!=rhs_range.size) + return false; } - for (i=0; i < __CPROVER_JSA_MAX_CONCRETE_NODES; ++i) + for(i=0; i < __CPROVER_JSA_MAX_CONCRETE_NODES; ++i) { const __CPROVER_jsa_concrete_nodet lhs_node=lhs->concrete_nodes[i]; const __CPROVER_jsa_concrete_nodet rhs_node=rhs->concrete_nodes[i]; - if (lhs_node.list != rhs_node.list || - lhs_node.next != rhs_node.next || - lhs_node.previous != rhs_node.previous || - lhs_node.value != rhs_node.value) return false; + if(lhs_node.list!=rhs_node.list || + lhs_node.next!=rhs_node.next || + lhs_node.previous!=rhs_node.previous || + lhs_node.value!=rhs_node.value) + return false; } - if (lhs->iterator_count != rhs->iterator_count) return false; - for (i=0; i < lhs->iterator_count; ++i) + if(lhs->iterator_count!=rhs->iterator_count) + return false; + for(i=0; i < lhs->iterator_count; ++i) { const __CPROVER_jsa_iteratort lhs_it=lhs->iterators[i]; const __CPROVER_jsa_iteratort rhs_it=rhs->iterators[i]; - if (lhs_it.index != rhs_it.index || - lhs_it.list != rhs_it.list || - lhs_it.node_id != rhs_it.node_id || - lhs_it.previous_index != rhs_it.previous_index || - lhs_it.previous_node_id != rhs_it.previous_node_id) return false; + if(lhs_it.index!=rhs_it.index || + lhs_it.list!=rhs_it.list || + lhs_it.node_id!=rhs_it.node_id || + lhs_it.previous_index!=rhs_it.previous_index || + lhs_it.previous_node_id!=rhs_it.previous_node_id) + return false; } - if (lhs->list_count != rhs->list_count) return false; - for (i=0; i < lhs->list_count; ++i) - if (lhs->list_head_nodes[i] != rhs->list_head_nodes[i]) return false; + if(lhs->list_count!=rhs->list_count) + return false; + for(i=0; ilist_count; ++i) + if(lhs->list_head_nodes[i]!=rhs->list_head_nodes[i]) + return false; return true; } #endif @@ -233,7 +256,9 @@ __CPROVER_jsa_inline _Bool __CPROVER_jsa__internal_are_heaps_equal( (__CPROVER_JSA_MAX_CONCRETE_NODES + node_index) #define __CPROVER_jsa__internal_get_list(heap_ptr, node) \ - (__CPROVER_jsa_null == node ? __CPROVER_jsa_null : __CPROVER_jsa__internal_is_concrete_node(node) ? (heap_ptr)->concrete_nodes[node].list : (heap_ptr)->abstract_nodes[node].list) + (__CPROVER_jsa_null == node ? __CPROVER_jsa_null :\ + __CPROVER_jsa__internal_is_concrete_node(node) ?\ + (heap_ptr)->concrete_nodes[node].list:(heap_ptr)->abstract_nodes[node].list) __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_next( __CPROVER_jsa_abstract_heapt * const heap, @@ -241,7 +266,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_next( const __CPROVER_jsa_node_id_t next_node) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (__CPROVER_jsa__internal_is_concrete_node(node)) + if(__CPROVER_jsa__internal_is_concrete_node(node)) { heap->concrete_nodes[node].next=next_node; } else @@ -256,7 +281,10 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_next( #endif #define __CPROVER_jsa__internal_get_next(heap_ptr, node) \ - (__CPROVER_jsa__internal_is_concrete_node(node) ? (heap_ptr)->concrete_nodes[node].next : (heap_ptr)->abstract_nodes[__CPROVER_jsa__internal_get_abstract_node_index(node)].next) + (__CPROVER_jsa__internal_is_concrete_node(node) ?\ + (heap_ptr)->concrete_nodes[node].next:\ + (heap_ptr)->abstract_nodes[\ + __CPROVER_jsa__internal_get_abstract_node_index(node)].next) __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_previous( __CPROVER_jsa_abstract_heapt * const heap, @@ -264,7 +292,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_previous( const __CPROVER_jsa_node_id_t previous_node) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (__CPROVER_jsa__internal_is_concrete_node(node)) + if(__CPROVER_jsa__internal_is_concrete_node(node)) { heap->concrete_nodes[node].previous=previous_node; } else @@ -279,26 +307,35 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_set_previous( #endif #define __CPROVER_jsa__internal_get_previous(heap_ptr, node) \ - (__CPROVER_jsa__internal_is_concrete_node(node) ? (heap_ptr)->concrete_nodes[node].previous : (heap_ptr)->abstract_nodes[__CPROVER_jsa__internal_get_abstract_node_index(node)].previous) + (__CPROVER_jsa__internal_is_concrete_node(node) ?\ + (heap_ptr)->concrete_nodes[node].previous:\ + (heap_ptr)->abstract_nodes[\ + __CPROVER_jsa__internal_get_abstract_node_index(node)].previous) __CPROVER_jsa_inline __CPROVER_jsa_node_id_t __CPROVER_jsa__internal_remove( __CPROVER_jsa_abstract_heapt * const heap, const __CPROVER_jsa_node_id_t node_id_to_remove) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_concrete_node(node_id_to_remove)); - const __CPROVER_jsa_id_t previous_node_id=heap->concrete_nodes[node_id_to_remove].previous; - const __CPROVER_jsa_id_t next_node_id=heap->concrete_nodes[node_id_to_remove].next; + __CPROVER_jsa_assume( + __CPROVER_jsa__internal_is_concrete_node(node_id_to_remove)); + const __CPROVER_jsa_id_t previous_node_id= + heap->concrete_nodes[node_id_to_remove].previous; + const __CPROVER_jsa_id_t next_node_id= + heap->concrete_nodes[node_id_to_remove].next; __CPROVER_jsa__internal_set_next(heap, node_id_to_remove, __CPROVER_jsa_null); - __CPROVER_jsa__internal_set_previous(heap, node_id_to_remove, __CPROVER_jsa_null); - if (__CPROVER_jsa_null != previous_node_id) - __CPROVER_jsa__internal_set_next(heap, previous_node_id, next_node_id); + __CPROVER_jsa__internal_set_previous( + heap, node_id_to_remove, __CPROVER_jsa_null); + if(__CPROVER_jsa_null!=previous_node_id) + __CPROVER_jsa__internal_set_next( + heap, previous_node_id, next_node_id); else { - const __CPROVER_jsa_list_id_t list=__CPROVER_jsa__internal_get_list(heap, node_id_to_remove); + const __CPROVER_jsa_list_id_t list= + __CPROVER_jsa__internal_get_list(heap, node_id_to_remove); heap->list_head_nodes[list]=next_node_id; } - if (__CPROVER_jsa_null != next_node_id) + if(__CPROVER_jsa_null!=next_node_id) __CPROVER_jsa__internal_set_previous(heap, next_node_id, previous_node_id); heap->concrete_nodes[node_id_to_remove].value=__CPROVER_jsa_null; heap->concrete_nodes[node_id_to_remove].list=__CPROVER_jsa_null; @@ -324,7 +361,8 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_make_null( #endif // Heap sanity functions -__CPROVER_jsa_inline _Bool __CPROVER_jsa__internal_is_valid_node_id(const __CPROVER_jsa_node_id_t node_id) +__CPROVER_jsa_inline _Bool __CPROVER_jsa__internal_is_valid_node_id( + const __CPROVER_jsa_node_id_t node_id) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { return __CPROVER_jsa_null == node_id || node_id < __CPROVER_JSA_MAX_NODES; @@ -338,7 +376,8 @@ __CPROVER_jsa_inline _Bool __CPROVER_jsa__internal_is_in_valid_list( const __CPROVER_jsa_node_id_t node_id) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - const __CPROVER_jsa_list_id_t list=__CPROVER_jsa__internal_get_list(heap, node_id); + const __CPROVER_jsa_list_id_t list= + __CPROVER_jsa__internal_get_list(heap, node_id); return __CPROVER_jsa_null == list || list < heap->list_count; } #else @@ -353,17 +392,20 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_assume_linking_correct( #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_in_valid_list(heap, node_id)); - if (__CPROVER_jsa_null != prev) + if(__CPROVER_jsa_null!=prev) { - __CPROVER_jsa_assume(node_id == __CPROVER_jsa__internal_get_next(heap, prev)); + __CPROVER_jsa_assume(node_id==__CPROVER_jsa__internal_get_next(heap, prev)); __CPROVER_jsa_assume(prev < node_id); - __CPROVER_jsa_assume(__CPROVER_jsa__internal_get_list(heap, node_id) == __CPROVER_jsa__internal_get_list(heap, prev)); + __CPROVER_jsa_assume(__CPROVER_jsa__internal_get_list(heap, node_id)== + __CPROVER_jsa__internal_get_list(heap, prev)); } - if (__CPROVER_jsa_null != next) + if(__CPROVER_jsa_null!=next) { - __CPROVER_jsa_assume(node_id == __CPROVER_jsa__internal_get_previous(heap, next)); - __CPROVER_jsa_assume(node_id < next); - __CPROVER_jsa_assume(__CPROVER_jsa__internal_get_list(heap, node_id) == __CPROVER_jsa__internal_get_list(heap, next)); + __CPROVER_jsa_assume(node_id== + __CPROVER_jsa__internal_get_previous(heap, next)); + __CPROVER_jsa_assume(node_idabstract_nodes[idx].value_ref; __CPROVER_jsa_assume(index < h->abstract_ranges[value_ref].size); } @@ -398,10 +442,13 @@ __CPROVER_jsa_inline __CPROVER_jsa_index_t __CPROVER_jsa__internal_get_max_inde const __CPROVER_jsa_node_id_t node_id) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (__CPROVER_jsa__internal_is_concrete_node(node_id)) return 0; - const __CPROVER_jsa__internal_index_t idx=__CPROVER_jsa__internal_get_abstract_node_index(node_id); + if(__CPROVER_jsa__internal_is_concrete_node(node_id)) + return 0; + const __CPROVER_jsa__internal_index_t idx= + __CPROVER_jsa__internal_get_abstract_node_index(node_id); const __CPROVER_jsa_id_t value_ref=heap->abstract_nodes[idx].value_ref; - const __CPROVER_jsa_index_t __CPROVER_jsa__internal_get_max_index_result=heap->abstract_ranges[value_ref].size - 1; + const __CPROVER_jsa_index_t __CPROVER_jsa__internal_get_max_index_result= + heap->abstract_ranges[value_ref].size - 1; return __CPROVER_jsa__internal_get_max_index_result; } #else @@ -416,15 +463,18 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_assume_is_neighbour( const __CPROVER_jsa_index_t rhs_index) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (__CPROVER_jsa__internal_is_concrete_node(lhs_node_id)) + if(__CPROVER_jsa__internal_is_concrete_node(lhs_node_id)) { - __CPROVER_jsa_assume(lhs_node_id != rhs_node_id); + __CPROVER_jsa_assume(lhs_node_id!=rhs_node_id); __CPROVER_jsa_assume(lhs_index == 0 || rhs_index == 0); - __CPROVER_jsa_assume(heap->concrete_nodes[lhs_node_id].next == rhs_node_id || heap->concrete_nodes[lhs_node_id].previous == rhs_node_id); + __CPROVER_jsa_assume(heap->concrete_nodes[lhs_node_id].next== + rhs_node_id || + heap->concrete_nodes[lhs_node_id].previous== + rhs_node_id); } - else if (lhs_node_id == rhs_node_id) + else if(lhs_node_id == rhs_node_id) { - if (lhs_index < rhs_index) + if(lhs_index < rhs_index) __CPROVER_jsa_assume((lhs_index - rhs_index) == 1); else __CPROVER_jsa_assume((rhs_index - lhs_index) == 1); @@ -432,16 +482,20 @@ __CPROVER_jsa_inline void __CPROVER_jsa__internal_assume_is_neighbour( else { const __CPROVER_jsa_abstract_nodet node=heap->abstract_nodes[lhs_node_id]; - if (node.next == rhs_node_id) + if(node.next == rhs_node_id) { __CPROVER_jsa_assume(rhs_index == 0); - __CPROVER_jsa_assume(lhs_index == __CPROVER_jsa__internal_get_max_index(heap, lhs_node_id)); + __CPROVER_jsa_assume(lhs_index== + __CPROVER_jsa__internal_get_max_index( + heap, lhs_node_id)); } else { __CPROVER_jsa_assume(node.previous == rhs_node_id); __CPROVER_jsa_assume(lhs_index == 0); - __CPROVER_jsa_assume(rhs_index == __CPROVER_jsa__internal_get_max_index(heap, rhs_node_id)); + __CPROVER_jsa_assume(rhs_index== + __CPROVER_jsa__internal_get_max_index( + heap, rhs_node_id)); } } } @@ -470,7 +524,8 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_new_list( #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { __CPROVER_jsa_assume_valid_list(h, list); - __CPROVER_jsa_assume(__CPROVER_jsa_null == __CPROVER_jsa__internal_get_head_node(h, list)); + __CPROVER_jsa_assume(__CPROVER_jsa_null== + __CPROVER_jsa__internal_get_head_node(h, list)); } #else ; @@ -487,60 +542,71 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_iterator( ; #endif -__CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap(const __CPROVER_jsa_abstract_heapt * const h) +__CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap( + const __CPROVER_jsa_abstract_heapt * const h) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { // Lists point to valid head nodes. // Enforce strictly ascending head node ids (unless null). __CPROVER_jsa_id_t max_head_node=0; __CPROVER_jsa_assume(h->list_count <= __CPROVER_JSA_MAX_LISTS); - for (__CPROVER_jsa_list_id_t list=0; list < __CPROVER_JSA_MAX_LISTS; ++list) + for(__CPROVER_jsa_list_id_t list=0; list < __CPROVER_JSA_MAX_LISTS; ++list) { const __CPROVER_jsa_id_t head_node=h->list_head_nodes[list]; - if (list >= h->list_count) + if(list >= h->list_count) __CPROVER_jsa_assume(__CPROVER_jsa_null == head_node); else { __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(head_node)); - if (list != 0) + if(list!=0) { __CPROVER_jsa_assume(head_node > max_head_node); max_head_node=head_node; } - if (__CPROVER_jsa_null != head_node) - __CPROVER_jsa_assume(list == __CPROVER_jsa__internal_get_list(h, head_node)); + if(__CPROVER_jsa_null!=head_node) + __CPROVER_jsa_assume(list== + __CPROVER_jsa__internal_get_list(h, head_node)); } } - // Next matches previous && prev < id < next. (Node is part of only one list, no cycles) - for (__CPROVER_jsa_id_t cnode=0; cnode < __CPROVER_JSA_MAX_CONCRETE_NODES; ++cnode) + // Next matches previous && prev < id < next. + // (Node is part of only one list, no cycles) + for(__CPROVER_jsa_id_t cnode=0; + cnode<__CPROVER_JSA_MAX_CONCRETE_NODES; + ++cnode) { const __CPROVER_jsa_list_id_t node_list=h->concrete_nodes[cnode].list; const __CPROVER_jsa_id_t nxt=h->concrete_nodes[cnode].next; const __CPROVER_jsa_id_t prev=h->concrete_nodes[cnode].previous; - if (__CPROVER_jsa_null == node_list) + if(__CPROVER_jsa_null == node_list) { - __CPROVER_jsa_assume(__CPROVER_jsa_null == nxt); - __CPROVER_jsa_assume(__CPROVER_jsa_null == prev); - __CPROVER_jsa_assume(__CPROVER_jsa_null == h->concrete_nodes[cnode].value); - } else + __CPROVER_jsa_assume(__CPROVER_jsa_null==nxt); + __CPROVER_jsa_assume(__CPROVER_jsa_null==prev); + __CPROVER_jsa_assume(__CPROVER_jsa_null==h->concrete_nodes[cnode].value); + } + else { - if (__CPROVER_jsa_null == h->concrete_nodes[cnode].previous) + if(__CPROVER_jsa_null == h->concrete_nodes[cnode].previous) __CPROVER_jsa_assume(h->list_head_nodes[node_list] == cnode); __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(nxt)); __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(prev)); __CPROVER_jsa__internal_assume_linking_correct(h, cnode, prev, nxt); } } - for (__CPROVER_jsa__internal_index_t anode=0; anode < __CPROVER_JSA_MAX_ABSTRACT_NODES; ++anode) + for(__CPROVER_jsa__internal_index_t anode=0; + anode<__CPROVER_JSA_MAX_ABSTRACT_NODES; + ++anode) { const __CPROVER_jsa_id_t nxt=h->abstract_nodes[anode].next; __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(nxt)); const __CPROVER_jsa_id_t prev=h->abstract_nodes[anode].previous; __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(prev)); - const __CPROVER_jsa_id_t nid=__CPROVER_jsa__internal_get_abstract_node_id(anode); + const __CPROVER_jsa_id_t nid= + __CPROVER_jsa__internal_get_abstract_node_id(anode); __CPROVER_jsa__internal_assume_linking_correct(h, nid, prev, nxt); } - for (__CPROVER_jsa__internal_index_t range=0; range < __CPROVER_JSA_MAX_ABSTRACT_RANGES; ++range) + for(__CPROVER_jsa__internal_index_t range=0; + range<__CPROVER_JSA_MAX_ABSTRACT_RANGES; + ++range) { const __CPROVER_jsa_abstract_ranget r=h->abstract_ranges[range]; __CPROVER_jsa_assume(r.size >= 1); @@ -548,7 +614,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap(const __CPROVER_jsa_ab } // Iterators point to valid nodes __CPROVER_jsa_assume(h->iterator_count <= __CPROVER_JSA_MAX_ITERATORS); - for (__CPROVER_jsa_iterator_id_t it=0; it < __CPROVER_JSA_MAX_ITERATORS; ++it) + for(__CPROVER_jsa_iterator_id_t it=0; it < __CPROVER_JSA_MAX_ITERATORS; ++it) { const __CPROVER_jsa_iteratort val=h->iterators[it]; const __CPROVER_jsa_id_t next_node=val.node_id; @@ -556,7 +622,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap(const __CPROVER_jsa_ab const __CPROVER_jsa_index_t prev_index=val.previous_index; const __CPROVER_jsa_id_t prev_node=val.previous_node_id; const __CPROVER_jsa_list_id_t list=val.list; - if (it >= h->iterator_count) + if(it >= h->iterator_count) { __CPROVER_jsa_assume(__CPROVER_jsa_null == next_node); __CPROVER_jsa_assume(__CPROVER_jsa_null == prev_node); @@ -567,21 +633,32 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap(const __CPROVER_jsa_ab else { __CPROVER_jsa_assume(list < h->list_count); - __CPROVER_jsa__internal_assume_valid_iterator_linking(h, list, next_node, next_index); - __CPROVER_jsa__internal_assume_valid_iterator_linking(h, list, prev_node, prev_index); - if (__CPROVER_jsa_null != next_node && __CPROVER_jsa_null != prev_node) - __CPROVER_jsa__internal_assume_is_neighbour(h, next_node, next_index, prev_node, prev_index); + __CPROVER_jsa__internal_assume_valid_iterator_linking( + h, list, next_node, next_index); + __CPROVER_jsa__internal_assume_valid_iterator_linking( + h, list, prev_node, prev_index); + if(__CPROVER_jsa_null!=next_node && __CPROVER_jsa_null != prev_node) + __CPROVER_jsa__internal_assume_is_neighbour( + h, next_node, next_index, prev_node, prev_index); } } // Limit list sizes in counterexamples - for (__CPROVER_jsa__internal_index_t listc=0; listc < __CPROVER_JSA_MAX_LISTS; ++listc) + for(__CPROVER_jsa__internal_index_t listc=0; + listc < __CPROVER_JSA_MAX_LISTS; + ++listc) { __CPROVER_jsa__internal_index_t count=0; - for (__CPROVER_jsa__internal_index_t cnodec=0; cnodec < __CPROVER_JSA_MAX_CONCRETE_NODES; ++cnodec) - if (h->concrete_nodes[cnodec].list == listc) ++count; - for (__CPROVER_jsa__internal_index_t anodec=0; anodec < __CPROVER_JSA_MAX_ABSTRACT_NODES; ++anodec) - if (h->abstract_nodes[anodec].list == listc) ++count; - __CPROVER_jsa_assume(count <= __CPROVER_JSA_MAX_NODES_PER_CE_LIST); + for(__CPROVER_jsa__internal_index_t cnodec=0; + cnodec<__CPROVER_JSA_MAX_CONCRETE_NODES; + ++cnodec) + if(h->concrete_nodes[cnodec].list == listc) + ++count; + for(__CPROVER_jsa__internal_index_t anodec=0; + anodec<__CPROVER_JSA_MAX_ABSTRACT_NODES; + ++anodec) + if(h->abstract_nodes[anodec].list==listc) + ++count; + __CPROVER_jsa_assume(count<=__CPROVER_JSA_MAX_NODES_PER_CE_LIST); } } #else @@ -589,7 +666,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_heap(const __CPROVER_jsa_ab #endif __CPROVER_jsa_inline __CPROVER_jsa_list_id_t __CPROVER_jsa_create_list( - __CPROVER_jsa_abstract_heapt * const heap) + __CPROVER_jsa_abstract_heapt *const heap) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { const __CPROVER_jsa_index_t new_list=heap->list_count; @@ -632,7 +709,8 @@ __CPROVER_jsa_inline __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator( ; #endif -#define __CPROVER_jsa_hasNext(heap, it) __CPROVER_jsa_null != (heap)->iterators[it].node_id +#define __CPROVER_jsa_hasNext(heap, it)\ + __CPROVER_jsa_null!=(heap)->iterators[it].node_id __CPROVER_jsa_inline __CPROVER_jsa_data_t __CPROVER_jsa_next( __CPROVER_jsa_abstract_heapt * const heap, @@ -655,8 +733,10 @@ __CPROVER_jsa_inline void __CPROVER_jsa_remove( const __CPROVER_jsa_iterator_id_t it) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - const __CPROVER_jsa_id_t node_id_to_remove=heap->iterators[it].previous_node_id; - heap->iterators[it].node_id=__CPROVER_jsa__internal_remove(heap, node_id_to_remove); + const __CPROVER_jsa_id_t node_id_to_remove= + heap->iterators[it].previous_node_id; + heap->iterators[it].node_id= + __CPROVER_jsa__internal_remove(heap, node_id_to_remove); heap->iterators[it].previous_node_id=__CPROVER_jsa_null; } #else @@ -670,9 +750,10 @@ __CPROVER_jsa_inline void __CPROVER_jsa_set( #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { const __CPROVER_jsa_id_t node_id_to_set=heap->iterators[it].previous_node_id; - if (__CPROVER_jsa_null != node_id_to_set) + if(__CPROVER_jsa_null!=node_id_to_set) { - __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_concrete_node(node_id_to_set)); + __CPROVER_jsa_assume( + __CPROVER_jsa__internal_is_concrete_node(node_id_to_set)); heap->concrete_nodes[node_id_to_set].value=value; } } @@ -687,14 +768,16 @@ __CPROVER_jsa_inline void __CPROVER_jsa_add( #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { __CPROVER_jsa_node_id_t new_node; - for (new_node=0; new_node < __CPROVER_JSA_MAX_CONCRETE_NODES; ++new_node) - if (__CPROVER_jsa_null == heap->concrete_nodes[new_node].list) break; + for(new_node=0; new_node < __CPROVER_JSA_MAX_CONCRETE_NODES; ++new_node) + if(__CPROVER_jsa_null == heap->concrete_nodes[new_node].list) + break; __CPROVER_jsa_assume(new_node < __CPROVER_JSA_MAX_CONCRETE_NODES); heap->concrete_nodes[new_node].list=list; heap->concrete_nodes[new_node].next=__CPROVER_jsa_null; heap->concrete_nodes[new_node].value=value; - const __CPROVER_jsa_node_id_t head_node=__CPROVER_jsa__internal_get_head_node(heap, list); - if (__CPROVER_jsa_null == head_node) + const __CPROVER_jsa_node_id_t head_node= + __CPROVER_jsa__internal_get_head_node(heap, list); + if(__CPROVER_jsa_null == head_node) { heap->list_head_nodes[list]=new_node; heap->concrete_nodes[new_node].previous=__CPROVER_jsa_null; @@ -703,19 +786,24 @@ __CPROVER_jsa_inline void __CPROVER_jsa_add( { #ifdef __CPROVER const __CPROVER_jsa_node_id_t last_node; - __CPROVER_jsa_assume(last_node != new_node); + __CPROVER_jsa_assume(last_node!=new_node); __CPROVER_jsa_assume(__CPROVER_jsa__internal_is_valid_node_id(last_node)); - __CPROVER_jsa_assume(list == __CPROVER_jsa__internal_get_list(heap, last_node)); - __CPROVER_jsa_assume(__CPROVER_jsa_null == __CPROVER_jsa__internal_get_next(heap, last_node)); + __CPROVER_jsa_assume(list== + __CPROVER_jsa__internal_get_list(heap, last_node)); + __CPROVER_jsa_assume(__CPROVER_jsa_null== + __CPROVER_jsa__internal_get_next(heap, last_node)); #else __CPROVER_jsa_node_id_t last_node=head_node; - for (__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_NODES; ++i) + for(__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_NODES; ++i) { - const __CPROVER_jsa_node_id_t next_node=__CPROVER_jsa__internal_get_next(heap, last_node); - if (__CPROVER_jsa_null == next_node) break; + const __CPROVER_jsa_node_id_t next_node= + __CPROVER_jsa__internal_get_next(heap, last_node); + if(__CPROVER_jsa_null==next_node) + break; last_node=next_node; } - __CPROVER_jsa_assume(__CPROVER_jsa_null == __CPROVER_jsa__internal_get_next(heap, last_node)); + __CPROVER_jsa_assume(__CPROVER_jsa_null== + __CPROVER_jsa__internal_get_next(heap, last_node)); #endif __CPROVER_jsa__internal_set_next(heap, last_node, new_node); heap->concrete_nodes[new_node].previous=last_node; @@ -730,8 +818,9 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_minus( const __CPROVER_jsa_word_t rhs) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (lhs >= rhs) return lhs - rhs; - return __CPROVER_jsa_word_max - rhs + lhs; + if(lhs>=rhs) + return lhs-rhs; + return __CPROVER_jsa_word_max-rhs+lhs; } #else ; @@ -742,7 +831,8 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_mod( const __CPROVER_jsa_word_t rhs) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (rhs == 0) return 0; + if(rhs==0) + return 0; return lhs % rhs; } #else @@ -755,8 +845,9 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_plus( #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { const __CPROVER_jsa_word_t diff=__CPROVER_jsa_word_max - lhs; - if (diff < rhs) return rhs - diff; - return lhs + rhs; + if(diff < rhs) + return rhs-diff; + return lhs+rhs; } #else ; @@ -767,7 +858,8 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_mult( const __CPROVER_jsa_word_t rhs) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (lhs != 0 && __CPROVER_jsa_word_max / lhs != rhs) { + if(lhs!=0 && __CPROVER_jsa_word_max/lhs!=rhs) + { return __CPROVER_jsa_word_max; } return lhs * rhs; @@ -781,8 +873,9 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_div( const __CPROVER_jsa_word_t rhs) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (rhs == 0) return __CPROVER_jsa_word_max; - return lhs / rhs; + if(rhs==0) + return __CPROVER_jsa_word_max; + return lhs/rhs; } #else ; @@ -794,7 +887,7 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_ite( const __CPROVER_jsa_word_t rhs) #ifdef __CPROVER_JSA_DEFINE_TRANSFORMERS { - if (res != 0) + if(res!=0) return lhs; return rhs; } @@ -822,15 +915,26 @@ __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_ite( #define __CPROVER_JSA_NUM_PREDS (__CPROVER_JSA_MAX_QUERY_SIZE - 1) #endif -__CPROVER_jsa_extern __CPROVER_jsa_word_t *__CPROVER_JSA_PRED_OPS[__CPROVER_JSA_NUM_PRED_OPS]; -__CPROVER_jsa_extern __CPROVER_jsa_word_t *__CPROVER_JSA_PRED_RESULT_OPS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; -__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_MAX_PRED_SIZE_RELAY[__CPROVER_JSA_MAX_PRED_SIZE]; -__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_MAX_QUERY_SIZE_RELAY[__CPROVER_JSA_MAX_QUERY_SIZE]; -__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_MAX_ITERATORS_RELAY[__CPROVER_JSA_MAX_ITERATORS]; -__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_MAX_LISTS_RELAY[__CPROVER_JSA_MAX_LISTS]; -//__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; -//__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_ORG_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; -//__CPROVER_jsa_extern __CPROVER_jsa_word_t __CPROVER_JSA_QUERIED_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + *__CPROVER_JSA_PRED_OPS[__CPROVER_JSA_NUM_PRED_OPS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + *__CPROVER_JSA_PRED_RESULT_OPS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_MAX_PRED_SIZE_RELAY[__CPROVER_JSA_MAX_PRED_SIZE]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_MAX_QUERY_SIZE_RELAY[__CPROVER_JSA_MAX_QUERY_SIZE]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_MAX_ITERATORS_RELAY[__CPROVER_JSA_MAX_ITERATORS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_MAX_LISTS_RELAY[__CPROVER_JSA_MAX_LISTS]; +#if 0 +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_ORG_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; +__CPROVER_jsa_extern __CPROVER_jsa_word_t + __CPROVER_JSA_QUERIED_HEAP_VARS[__CPROVER_JSA_NUM_PRED_RESULT_OPS]; +#endif typedef __CPROVER_jsa_word_t __CPROVER_jsa_opcodet; typedef __CPROVER_jsa_word_t __CPROVER_jsa_opt; @@ -842,10 +946,14 @@ typedef struct __CPROVER_jsa_pred_instruction __CPROVER_jsa_opt op1; } __CPROVER_jsa_pred_instructiont; -__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t __CPROVER_JSA_PRED_OPS_COUNT; -__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t __CPROVER_JSA_PRED_RESULT_OPS_COUNT; -__CPROVER_jsa_extern const __CPROVER_jsa_pred_instructiont *__CPROVER_JSA_PREDICATES[__CPROVER_JSA_NUM_PREDS]; -__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t __CPROVER_JSA_PREDICATE_SIZES[__CPROVER_JSA_NUM_PREDS]; +__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t + __CPROVER_JSA_PRED_OPS_COUNT; +__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t + __CPROVER_JSA_PRED_RESULT_OPS_COUNT; +__CPROVER_jsa_extern const __CPROVER_jsa_pred_instructiont + *__CPROVER_JSA_PREDICATES[__CPROVER_JSA_NUM_PREDS]; +__CPROVER_jsa_extern __CPROVER_jsa__internal_index_t + __CPROVER_JSA_PREDICATE_SIZES[__CPROVER_JSA_NUM_PREDS]; #define __CPROVER_JSA_NUM_PRED_INSTRUCTIONS 8u @@ -854,16 +962,23 @@ typedef __CPROVER_jsa_word_t __CPROVER_jsa_pred_id_t; __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_pred( const __CPROVER_jsa_pred_id_t pred_id) { - __CPROVER_jsa_assert(__CPROVER_JSA_PRED_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_OPS, "__CPROVER_JSA_PRED_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_OPS"); - __CPROVER_jsa_assert(__CPROVER_JSA_PRED_RESULT_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_RESULT_OPS, "__CPROVER_JSA_PRED_RESULT_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_RESULT_OPS"); + __CPROVER_jsa_assert( + __CPROVER_JSA_PRED_OPS_COUNT<=__CPROVER_JSA_NUM_PRED_OPS, + "__CPROVER_JSA_PRED_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_OPS"); + __CPROVER_jsa_assert( + __CPROVER_JSA_PRED_RESULT_OPS_COUNT<=__CPROVER_JSA_NUM_PRED_RESULT_OPS, + "__CPROVER_JSA_PRED_RESULT_OPS_COUNT <= __CPROVER_JSA_NUM_PRED_RESULT_OPS"); __CPROVER_jsa_assume(pred_id < __CPROVER_JSA_NUM_PREDS); - const __CPROVER_jsa_pred_instructiont * const pred=__CPROVER_JSA_PREDICATES[pred_id]; - const __CPROVER_jsa__internal_index_t sz=__CPROVER_JSA_PREDICATE_SIZES[pred_id]; + const __CPROVER_jsa_pred_instructiont * const pred= + __CPROVER_JSA_PREDICATES[pred_id]; + const __CPROVER_jsa__internal_index_t sz= + __CPROVER_JSA_PREDICATE_SIZES[pred_id]; __CPROVER_jsa_assume(sz <= __CPROVER_JSA_MAX_PRED_SIZE); - for (__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_PRED_SIZE; ++i) + for(__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_PRED_SIZE; ++i) { - if (i >= sz) break; + if(i>=sz) + break; const __CPROVER_jsa_pred_instructiont instr=pred[i]; __CPROVER_jsa_assume(instr.op0 < __CPROVER_JSA_NUM_PRED_OPS); __CPROVER_jsa_assume(instr.op1 < __CPROVER_JSA_NUM_PRED_OPS); @@ -900,49 +1015,81 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_pred( __CPROVER_jsa_inline __CPROVER_jsa_word_t __CPROVER_jsa_execute_pred( const __CPROVER_jsa_pred_id_t pred_id) { - const __CPROVER_jsa_pred_instructiont * const pred=__CPROVER_JSA_PREDICATES[pred_id]; - const __CPROVER_jsa__internal_index_t pred_sz=__CPROVER_JSA_PREDICATE_SIZES[pred_id]; + const __CPROVER_jsa_pred_instructiont * const pred= + __CPROVER_JSA_PREDICATES[pred_id]; + const __CPROVER_jsa__internal_index_t pred_sz= + __CPROVER_JSA_PREDICATE_SIZES[pred_id]; __CPROVER_jsa_word_t result=0; - for (__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_PRED_SIZE; ++i) + for(__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_PRED_SIZE; ++i) { - if (i >= pred_sz) break; + if(i>=pred_sz) + break; const __CPROVER_jsa_pred_instructiont instr=pred[i]; #define __CPROVER_jsa_execute_pred_op0_ptr __CPROVER_JSA_PRED_OPS[instr.op0] #define __CPROVER_jsa_execute_pred_op1_ptr __CPROVER_JSA_PRED_OPS[instr.op1] -#define __CPROVER_jsa_execute_pred_result_op_ptr __CPROVER_JSA_PRED_RESULT_OPS[instr.result_op] +#define __CPROVER_jsa_execute_pred_result_op_ptr \ + __CPROVER_JSA_PRED_RESULT_OPS[instr.result_op] #define __CPROVER_jsa_execute_pred_op0 *__CPROVER_jsa_execute_pred_op0_ptr #define __CPROVER_jsa_execute_pred_op1 *__CPROVER_jsa_execute_pred_op1_ptr -#define __CPROVER_jsa_execute_pred_result *__CPROVER_jsa_execute_pred_result_op_ptr +#define __CPROVER_jsa_execute_pred_result \ + *__CPROVER_jsa_execute_pred_result_op_ptr switch (instr.opcode) { case 0: - __CPROVER_jsa_pred_opcode_0: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_op0 < __CPROVER_jsa_execute_pred_op1; + __CPROVER_jsa_pred_opcode_0: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_execute_pred_op0<__CPROVER_jsa_execute_pred_op1; break; case 1: - __CPROVER_jsa_pred_opcode_1: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_op0 <= __CPROVER_jsa_execute_pred_op1; + __CPROVER_jsa_pred_opcode_1: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_execute_pred_op0<=__CPROVER_jsa_execute_pred_op1; break; case 2: - __CPROVER_jsa_pred_opcode_first_2: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_mod(__CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); - __CPROVER_jsa_pred_opcode_last_2: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; + __CPROVER_jsa_pred_opcode_first_2: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_mod( + __CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); + __CPROVER_jsa_pred_opcode_last_2: + __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; break; case 3: - __CPROVER_jsa_pred_opcode_3: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_op0 != __CPROVER_jsa_execute_pred_op1; + __CPROVER_jsa_pred_opcode_3: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_execute_pred_op0!=__CPROVER_jsa_execute_pred_op1; break; case 4: - __CPROVER_jsa_pred_opcode_first_4: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_minus(__CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); - __CPROVER_jsa_pred_opcode_last_4: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; + __CPROVER_jsa_pred_opcode_first_4: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_minus( + __CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); + __CPROVER_jsa_pred_opcode_last_4: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_execute_pred_result; break; case 5: - __CPROVER_jsa_pred_opcode_first_5: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_plus(__CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); - __CPROVER_jsa_pred_opcode_last_5: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; + __CPROVER_jsa_pred_opcode_first_5: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_plus( + __CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); + __CPROVER_jsa_pred_opcode_last_5: + __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; break; case 6: - __CPROVER_jsa_pred_opcode_first_6: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_mult(__CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); - __CPROVER_jsa_pred_opcode_last_6: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; + __CPROVER_jsa_pred_opcode_first_6: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_mult( + __CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); + __CPROVER_jsa_pred_opcode_last_6: + __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; break; case 7: - __CPROVER_jsa_pred_opcode_first_7: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_div(__CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); - __CPROVER_jsa_pred_opcode_last_7: __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; + __CPROVER_jsa_pred_opcode_first_7: + __CPROVER_jsa_execute_pred_result= + __CPROVER_jsa_div( + __CPROVER_jsa_execute_pred_op0, __CPROVER_jsa_execute_pred_op1); + __CPROVER_jsa_pred_opcode_last_7: + __CPROVER_jsa_execute_pred_result=__CPROVER_jsa_execute_pred_result; break; } result=__CPROVER_jsa_execute_pred_result; @@ -971,48 +1118,58 @@ __CPROVER_jsa_inline void __CPROVER_jsa_stream_op( const __CPROVER_jsa__internal_index_t id) { const __CPROVER_jsa_list_id_t it_list=heap->iterators[it].list; - __CPROVER_jsa_node_id_t it_node=__CPROVER_jsa__internal_get_head_node(heap, it_list); + __CPROVER_jsa_node_id_t it_node= + __CPROVER_jsa__internal_get_head_node(heap, it_list); const __CPROVER_jsa_node_id_t it_range_end=heap->iterators[it].node_id; __CPROVER_jsa__internal_index_t distance; - for (distance=0; distance < __CPROVER_JSA_MAX_NODES; ++distance) - if (it_node == it_range_end || it_node == __CPROVER_jsa_null) break; - else it_node=__CPROVER_jsa__internal_get_next(heap, it_node); + for(distance=0; distance < __CPROVER_JSA_MAX_NODES; ++distance) + if(it_node==it_range_end || it_node==__CPROVER_jsa_null) + break; + else + it_node=__CPROVER_jsa__internal_get_next(heap, it_node); __CPROVER_jsa_node_id_t node; - if (__CPROVER_jsa_null == source) + if(__CPROVER_jsa_null == source) { - const __CPROVER_jsa_node_id_t head_node=__CPROVER_jsa__internal_get_head_node(heap, list); + const __CPROVER_jsa_node_id_t head_node= + __CPROVER_jsa__internal_get_head_node(heap, list); node=head_node; __CPROVER_jsa__internal_index_t node_count; - for (node_count=0; node_count < __CPROVER_JSA_MAX_NODES; ++node_count) + for(node_count=0; node_count < __CPROVER_JSA_MAX_NODES; ++node_count) { - if (__CPROVER_jsa_null == node) { break; } - else { node=__CPROVER_jsa__internal_get_next(heap, node); } + if(__CPROVER_jsa_null == node) + break; + else + node=__CPROVER_jsa__internal_get_next(heap, node); } node=head_node; - if (node_count > distance) + if(node_count > distance) { __CPROVER_jsa__internal_index_t skip_distance=node_count - distance; - for (node_count=0; node_count < __CPROVER_JSA_MAX_NODES; ++node_count) - if (node_count >= skip_distance) break; - else node=__CPROVER_jsa__internal_get_next(heap, node); + for(node_count=0; node_count < __CPROVER_JSA_MAX_NODES; ++node_count) + if(node_count>=skip_distance) + break; + else + node=__CPROVER_jsa__internal_get_next(heap, node); } } else node=__CPROVER_jsa__internal_get_head_node(heap, source); - for (__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_NODES; ++i) + for(__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_NODES; ++i) { - if (i >= distance || __CPROVER_jsa_null == node) break; + if(i>=distance || __CPROVER_jsa_null==node) + break; const _Bool is_concrete=__CPROVER_jsa__internal_is_concrete_node(node); - if (is_concrete) + if(is_concrete) { const __CPROVER_jsa_word_t value=heap->concrete_nodes[node].value; *__CPROVER_JSA_PRED_OPS[__CPROVER_jsa__internal_lambda_op_id]=value; - const __CPROVER_jsa_word_t pred_result=__CPROVER_jsa_execute_pred(pred_id); + const __CPROVER_jsa_word_t pred_result= + __CPROVER_jsa_execute_pred(pred_id); switch(id) { case FILTER: - if (pred_result == 0) + if(pred_result == 0) node=__CPROVER_jsa__internal_remove(heap, node); else node=__CPROVER_jsa__internal_get_next(heap, node); @@ -1027,7 +1184,8 @@ __CPROVER_jsa_inline void __CPROVER_jsa_stream_op( } else { - // TODO: Implement filtering abstract nodes. (Maybe ignore and handle on whole query level?) + // TODO: Implement filtering abstract nodes. + // (Maybe ignore and handle on whole query level?) } node=__CPROVER_jsa__internal_get_next(heap, node); } @@ -1053,9 +1211,10 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_query( __CPROVER_jsa_assume_valid_list(heap, query[0].opcode); __CPROVER_jsa_assume_valid_iterator(heap, query[0].op0); - for (__CPROVER_jsa__internal_index_t i=1; i < __CPROVER_JSA_MAX_QUERY_SIZE; ++i) + for(__CPROVER_jsa__internal_index_t i=1; i<__CPROVER_JSA_MAX_QUERY_SIZE; ++i) { - if (i >= query_size) break; + if(i>=query_size) + break; const __CPROVER_jsa_query_instructiont instr=query[i]; __CPROVER_jsa_assume(instr.op0 < __CPROVER_JSA_NUM_PREDS); switch(instr.opcode) @@ -1084,11 +1243,14 @@ __CPROVER_jsa_inline void __CPROVER_jsa_query_execute( __CPROVER_jsa_assume_valid_query(heap, query, query_size); const __CPROVER_jsa_list_id_t list=query[0].opcode; const __CPROVER_jsa_iterator_id_t it=query[0].op0; - for (__CPROVER_jsa__internal_index_t i=1; i < __CPROVER_JSA_MAX_QUERY_SIZE; ++i) + for(__CPROVER_jsa__internal_index_t i=1; i<__CPROVER_JSA_MAX_QUERY_SIZE; ++i) { - if (i >= query_size) break; + if(i>=query_size) + break; const __CPROVER_jsa_query_instructiont instr=query[i]; - __CPROVER_jsa_query_opcode_0: __CPROVER_jsa_stream_op(heap, list, it, instr.op1, instr.op0, instr.opcode); + __CPROVER_jsa_query_opcode_0: + __CPROVER_jsa_stream_op( + heap, list, it, instr.op1, instr.op0, instr.opcode); } } @@ -1108,7 +1270,7 @@ __CPROVER_jsa_inline void __CPROVER_jsa_verify_synchronise_iterator( __CPROVER_jsa_abstract_heapt * const queried_heap, const __CPROVER_jsa_iterator_id_t it) { - for (__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_ITERATORS; ++i) + for(__CPROVER_jsa__internal_index_t i=0; i < __CPROVER_JSA_MAX_ITERATORS; ++i) queried_heap->iterators[i]=heap->iterators[i]; } @@ -1128,11 +1290,18 @@ __CPROVER_jsa_inline _Bool __CPROVER_jsa_verify_invariant_execute( const __CPROVER_jsa_abstract_heapt * const queried_heap) { /*#ifdef __CPROVER - const _Bool vars_equal=__CPROVER_array_equal(__CPROVER_JSA_HEAP_VARS, __CPROVER_JSA_QUERIED_HEAP_VARS); + const _Bool vars_equal= + __CPROVER_array_equal( + __CPROVER_JSA_HEAP_VARS, __CPROVER_JSA_QUERIED_HEAP_VARS); #else - const _Bool vars_equal=memcmp(&__CPROVER_JSA_HEAP_VARS, &__CPROVER_JSA_QUERIED_HEAP_VARS, sizeof(__CPROVER_JSA_HEAP_VARS)) == 0; + const _Bool vars_equal= + memcmp( + &__CPROVER_JSA_HEAP_VARS, + &__CPROVER_JSA_QUERIED_HEAP_VARS, + sizeof(__CPROVER_JSA_HEAP_VARS)) == 0; #endif*/ - const _Bool heaps_equal=__CPROVER_jsa__internal_are_heaps_equal(heap, queried_heap); + const _Bool heaps_equal= + __CPROVER_jsa__internal_are_heaps_equal(heap, queried_heap); //return vars_equal && heaps_equal; return heaps_equal; } @@ -1160,7 +1329,8 @@ __CPROVER_jsa_inline void __CPROVER_jsa_assume_valid_invariant_iterator( const __CPROVER_jsa_iterator_id_t it) { __CPROVER_jsa_assume(it < h->iterator_count); - __CPROVER_jsa_assume(h->iterators[it].list == 0); // XXX: Debug: Only one iterator, always first list! + // XXX: Debug: Only one iterator, always first list! + __CPROVER_jsa_assume(h->iterators[it].list == 0); } #endif diff --git a/src/ansi-c/library/pthread_lib.c b/src/ansi-c/library/pthread_lib.c index d5bb0e1e759..ac3e6a18c3e 100644 --- a/src/ansi-c/library/pthread_lib.c +++ b/src/ansi-c/library/pthread_lib.c @@ -448,7 +448,7 @@ inline int pthread_rwlock_tryrdlock(pthread_rwlock_t *lock) { __CPROVER_HIDE:; __CPROVER_atomic_begin(); - if((*(signed char *)lock & 2)!=0) { __CPROVER_atomic_end(); return 1; } + if((*(signed char *)lock &2)!=0) { __CPROVER_atomic_end(); return 1; } (*(signed char *)lock)|=1; __CPROVER_atomic_end(); return 0; diff --git a/src/ansi-c/literals/convert_float_literal.cpp b/src/ansi-c/literals/convert_float_literal.cpp index 6eeaecb0dd8..7e72f6e6f53 100644 --- a/src/ansi-c/literals/convert_float_literal.cpp +++ b/src/ansi-c/literals/convert_float_literal.cpp @@ -39,9 +39,17 @@ exprt convert_float_literal(const std::string &src) bool is_decimal, is_float80, is_float128; // GCC extensions unsigned base; - parse_float(src, significand, exponent, base, - is_float, is_long, is_imaginary, - is_decimal, is_float80, is_float128); + parse_float( + src, + significand, + exponent, + base, + is_float, + is_long, + is_imaginary, + is_decimal, + is_float80, + is_float128); exprt result=exprt(ID_constant); @@ -121,9 +129,7 @@ exprt convert_float_literal(const std::string &src) } else { - ieee_floatt a; - - a.spec=to_floatbv_type(result.type()); + ieee_floatt a(to_floatbv_type(result.type())); if(base==10) a.from_base10(significand, exponent); @@ -132,7 +138,8 @@ exprt convert_float_literal(const std::string &src) else assert(false); - result.set(ID_value, + result.set( + ID_value, integer2binary(a.pack(), a.spec.width())); } diff --git a/src/ansi-c/literals/convert_integer_literal.cpp b/src/ansi-c/literals/convert_integer_literal.cpp index 705fa23c645..3412f02bd2c 100644 --- a/src/ansi-c/literals/convert_integer_literal.cpp +++ b/src/ansi-c/literals/convert_integer_literal.cpp @@ -141,7 +141,8 @@ exprt convert_integer_literal(const std::string &src) is_signed=true; c_type=ID_signed_long_int; } - else if(FITS(config.ansi_c.long_int_width, false) && long_cnt!=2) // unsigned long int + // unsigned long int + else if(FITS(config.ansi_c.long_int_width, false) && long_cnt!=2) { width=config.ansi_c.long_int_width; is_signed=false; @@ -153,7 +154,8 @@ exprt convert_integer_literal(const std::string &src) is_signed=true; c_type=ID_signed_long_long_int; } - else if(FITS(config.ansi_c.long_long_int_width, false)) // unsigned long long int + // unsigned long long int + else if(FITS(config.ansi_c.long_long_int_width, false)) { width=config.ansi_c.long_long_int_width; is_signed=false; diff --git a/src/ansi-c/literals/convert_string_literal.cpp b/src/ansi-c/literals/convert_string_literal.cpp index bf928e1cf6a..4176581afe2 100644 --- a/src/ansi-c/literals/convert_string_literal.cpp +++ b/src/ansi-c/literals/convert_string_literal.cpp @@ -109,8 +109,10 @@ exprt convert_string_literal(const std::string &src) if(ch!='L' && ch!='u' && ch!='U' && ch!='"') continue; - if(ch=='L') wide=ch; - if((ch=='u' || ch=='U') && i+1bit_field_bits; ++bytes, bit_field_bits+=8); + for(bytes=0; w>bit_field_bits; ++bytes, bit_field_bits+=8) {} bit_field_bits-=w; offset+=bytes; continue; @@ -319,7 +320,6 @@ void add_padding(struct_typet &type, const namespacet &ns) components.push_back(component); } } - } /*******************************************************************\ diff --git a/src/ansi-c/preprocessor_line.cpp b/src/ansi-c/preprocessor_line.cpp index 845ca937c60..a9b651fc3f7 100644 --- a/src/ansi-c/preprocessor_line.cpp +++ b/src/ansi-c/preprocessor_line.cpp @@ -37,7 +37,8 @@ void preprocessor_line( while(*ptr==' ' || *ptr=='\t') ptr++; // skip # - if(*ptr!='#') return; + if(*ptr!='#') + return; ptr++; // skip WS diff --git a/src/ansi-c/printf_formatter.cpp b/src/ansi-c/printf_formatter.cpp index 0efc0d93e8e..59e3dbcc20f 100644 --- a/src/ansi-c/printf_formatter.cpp +++ b/src/ansi-c/printf_formatter.cpp @@ -30,7 +30,8 @@ Function: printf_formattert::make_type const exprt printf_formattert::make_type( const exprt &src, const typet &dest) { - if(src.type()==dest) return src; + if(src.type()==dest) + return src; exprt tmp=src; tmp.make_typecast(dest); simplify(tmp, ns); @@ -79,7 +80,7 @@ void printf_formattert::print(std::ostream &out) while(!eol()) process_char(out); } - catch(eol_exception) + catch(eol_exceptiont) { } } @@ -160,22 +161,26 @@ void printf_formattert::process_format(std::ostream &out) case 'f': case 'F': - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), double_type())); break; case 'g': case 'G': - if(format_constant.precision==0) format_constant.precision=1; - if(next_operand==operands.end()) break; + if(format_constant.precision==0) + format_constant.precision=1; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), double_type())); break; case 's': { - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; // this is the address of a string const exprt &op=*(next_operand++); if(op.id()==ID_address_of && @@ -188,25 +193,29 @@ void printf_formattert::process_format(std::ostream &out) break; case 'd': - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), signed_int_type())); break; case 'D': - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), signed_long_int_type())); break; case 'u': - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), unsigned_int_type())); break; case 'U': - if(next_operand==operands.end()) break; + if(next_operand==operands.end()) + break; out << format_constant( make_type(*(next_operand++), unsigned_long_int_type())); break; diff --git a/src/ansi-c/printf_formatter.h b/src/ansi-c/printf_formatter.h index 1b7f56f3e72..4048af9a6a4 100644 --- a/src/ansi-c/printf_formatter.h +++ b/src/ansi-c/printf_formatter.h @@ -32,13 +32,14 @@ class printf_formattert std::list operands; std::list::const_iterator next_operand; unsigned format_pos; - inline bool eol() const { return format_pos>=format.size(); } + bool eol() const { return format_pos>=format.size(); } - class eol_exception { }; + class eol_exceptiont { }; char next() { - if(eol()) throw eol_exception(); + if(eol()) + throw eol_exceptiont(); return format[format_pos++]; } diff --git a/src/ansi-c/string_constant.cpp b/src/ansi-c/string_constant.cpp index 995eca61418..6576a99ea5b 100644 --- a/src/ansi-c/string_constant.cpp +++ b/src/ansi-c/string_constant.cpp @@ -109,8 +109,9 @@ array_exprt string_constantt::to_array_expr() const if(ch>=32 && ch<=126) { std::string ch_str="'"; - if(ch=='\'' || ch=='\\') ch_str+='\\'; - ch_str+=(char)ch; + if(ch=='\'' || ch=='\\') + ch_str+='\\'; + ch_str+=static_cast(ch); ch_str+="'"; } } @@ -147,9 +148,10 @@ bool string_constantt::from_array_expr(const array_exprt &src) forall_operands(it, src) { mp_integer int_value=0; - if(to_integer(*it, int_value)) return true; + if(to_integer(*it, int_value)) + return true; unsigned unsigned_value=integer2unsigned(int_value); - value+=(char)unsigned_value; + value+=static_cast(unsigned_value); } // Drop the implicit zero at the end. diff --git a/src/ansi-c/string_constant.h b/src/ansi-c/string_constant.h index ad38fa2dc43..40ef0a94366 100644 --- a/src/ansi-c/string_constant.h +++ b/src/ansi-c/string_constant.h @@ -18,21 +18,9 @@ class string_constantt:public exprt string_constantt(); explicit string_constantt(const irep_idt &value); - friend inline const string_constantt &to_string_constant(const exprt &expr) - { - assert(expr.id()==ID_string_constant); - return static_cast(expr); - } - - friend inline string_constantt &to_string_constant(exprt &expr) - { - assert(expr.id()==ID_string_constant); - return static_cast(expr); - } - void set_value(const irep_idt &value); - inline const irep_idt &get_value() const + const irep_idt &get_value() const { return get(ID_value); } @@ -41,7 +29,16 @@ class string_constantt:public exprt bool from_array_expr(const array_exprt &); }; -const string_constantt &to_string_constant(const exprt &expr); -string_constantt &to_string_constant(exprt &expr); +inline const string_constantt &to_string_constant(const exprt &expr) +{ + assert(expr.id()==ID_string_constant); + return static_cast(expr); +} + +inline string_constantt &to_string_constant(exprt &expr) +{ + assert(expr.id()==ID_string_constant); + return static_cast(expr); +} #endif // CPROVER_ANSI_C_STRING_CONSTANT_H diff --git a/src/ansi-c/type2name.cpp b/src/ansi-c/type2name.cpp index 8087f6a6845..fdcf6b0a276 100644 --- a/src/ansi-c/type2name.cpp +++ b/src/ansi-c/type2name.cpp @@ -132,7 +132,7 @@ static std::string type2name( result+='l'; if(type.id()==irep_idt()) - throw "Empty type encountered."; + throw "empty type encountered"; else if(type.id()==ID_empty) result+='V'; else if(type.id()==ID_signedbv) @@ -169,13 +169,15 @@ static std::string type2name( it!=parameters.end(); it++) { - if(it!=parameters.begin()) result+='|'; + if(it!=parameters.begin()) + result+='|'; result+=type2name(it->type(), ns, symbol_number); } if(t.has_ellipsis()) { - if(!parameters.empty()) result+='|'; + if(!parameters.empty()) + result+='|'; result+="..."; } @@ -206,8 +208,10 @@ static std::string type2name( { assert(parent_is_sym_check); parent_is_sym_check=false; - if(type.id()==ID_struct) result+="ST"; - if(type.id()==ID_union) result+="UN"; + if(type.id()==ID_struct) + result+="ST"; + if(type.id()==ID_union) + result+="UN"; const struct_union_typet &t=to_struct_union_type(type); const struct_union_typet::componentst &components = t.components(); result+='['; @@ -216,7 +220,8 @@ static std::string type2name( it!=components.end(); it++) { - if(it!=components.begin()) result+='|'; + if(it!=components.begin()) + result+='|'; result+=type2name(it->type(), ns, symbol_number); result+="'"+it->get_string(ID_name)+"'"; } @@ -237,7 +242,8 @@ static std::string type2name( it!=members.end(); ++it) { - if(it!=members.begin()) result+='|'; + if(it!=members.begin()) + result+='|'; result+=id2string(it->get_value()); result+="'"+id2string(it->get_identifier())+"'"; } @@ -249,9 +255,7 @@ static std::string type2name( else if(type.id()==ID_vector) result+="VEC"+type.get_string(ID_size); else - throw (std::string("Unknown type '") + - type.id_string() + - "' encountered."); + throw "unknown type '"+type.id_string()+"' encountered"; if(type.has_subtype()) { diff --git a/src/ansi-c/type2name.h b/src/ansi-c/type2name.h index 4e3159039f2..b7299617e7f 100644 --- a/src/ansi-c/type2name.h +++ b/src/ansi-c/type2name.h @@ -6,9 +6,14 @@ Author: Daniel Kroening, kroening@cs.cmu.edu \*******************************************************************/ +#ifndef CPROVER_ANSI_C_TYPE2NAME_H +#define CPROVER_ANSI_C_TYPE2NAME_H + #include #include std::string type2name(const typet &type); std::string type2name(const typet &type, const namespacet &ns); + +#endif // CPROVER_ANSI_C_TYPE2NAME_H diff --git a/src/assembler/assembler_parser.h b/src/assembler/assembler_parser.h index 970bb5a0bd2..7745ec21ed6 100644 --- a/src/assembler/assembler_parser.h +++ b/src/assembler/assembler_parser.h @@ -49,7 +49,7 @@ class assembler_parsert:public parsert { parsert::clear(); instructions.clear(); - //assembler_scanner_init(); + // assembler_scanner_init(); } }; diff --git a/src/cbmc/all_properties.cpp b/src/cbmc/all_properties.cpp index 628ac884c75..590b7696201 100644 --- a/src/cbmc/all_properties.cpp +++ b/src/cbmc/all_properties.cpp @@ -40,7 +40,8 @@ void bmc_all_propertiest::goal_covered(const cover_goalst::goalt &) for(auto &g : goal_map) { // failed already? - if(g.second.status==goalt::statust::FAILURE) continue; + if(g.second.status==goalt::statust::FAILURE) + continue; // check whether failed for(auto &c : g.second.instances) @@ -204,12 +205,14 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals) << eom; if(bmc.options.get_bool_option("trace")) + { for(const auto &g : goal_map) if(g.second.status==goalt::statust::FAILURE) { std::cout << "\n" << "Trace for " << g.first << ":" << "\n"; show_goto_trace(std::cout, bmc.ns, g.second.goto_trace); } + } status() << "\n** " << cover_goals.number_covered() << " of " << cover_goals.size() << " failed (" @@ -257,7 +260,6 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals) std::cout << ",\n" << json_result; } break; - } } diff --git a/src/cbmc/all_properties_class.h b/src/cbmc/all_properties_class.h index 837c3a39966..1f3fc27960a 100644 --- a/src/cbmc/all_properties_class.h +++ b/src/cbmc/all_properties_class.h @@ -45,7 +45,8 @@ class bmc_all_propertiest: struct goalt { // a property holds if all instances of it are true - typedef std::vector instancest; + typedef std::vector + instancest; instancest instances; std::string description; diff --git a/src/cbmc/bmc.cpp b/src/cbmc/bmc.cpp index b1078f8db05..2f39d97b1ce 100644 --- a/src/cbmc/bmc.cpp +++ b/src/cbmc/bmc.cpp @@ -436,7 +436,7 @@ safety_checkert::resultt bmct::run( const symbolt *init_symbol; if(!ns.lookup(CPROVER_PREFIX "initialize", init_symbol)) symex.language_mode=init_symbol->mode; - } + } status() << "Starting Bounded Model Checking" << eom; diff --git a/src/cbmc/bmc.h b/src/cbmc/bmc.h index 5b8a64e9adb..b81b2d94c38 100644 --- a/src/cbmc/bmc.h +++ b/src/cbmc/bmc.h @@ -33,7 +33,7 @@ class bmct:public safety_checkert const optionst &_options, const symbol_tablet &_symbol_table, message_handlert &_message_handler, - prop_convt& _prop_conv): + prop_convt &_prop_conv): safety_checkert(ns, _message_handler), options(_options), ns(_symbol_table, new_symbol_table), @@ -53,10 +53,6 @@ class bmct:public safety_checkert // additional stuff expr_listt bmc_constraints; - friend class cbmc_satt; - friend class hw_cbmc_satt; - friend class counterexample_beautification_greedyt; - void set_ui(language_uit::uit _ui) { ui=_ui; } // the safety_checkert interface @@ -107,7 +103,7 @@ class bmct:public safety_checkert void output_graphml( resultt result, const goto_functionst &goto_functions); - + bool cover( const goto_functionst &goto_functions, const optionst::value_listt &criteria); diff --git a/src/cbmc/bmc_cover.cpp b/src/cbmc/bmc_cover.cpp index 817f55c1b86..310aecfd957 100644 --- a/src/cbmc/bmc_cover.cpp +++ b/src/cbmc/bmc_cover.cpp @@ -171,7 +171,8 @@ void bmc_covert::satisfying_assignment() goalt &g=goal_pair.second; // covered already? - if(g.satisfied) continue; + if(g.satisfied) + continue; // check whether satisfied for(const auto &goal_inst : g.instances) @@ -200,13 +201,7 @@ void bmc_covert::satisfying_assignment() s_it1++) if(s_it1->is_assume() && !s_it1->cond_value) { - s_it1++; - - for(goto_tracet::stepst::iterator - s_it2=s_it1; - s_it2!=goto_trace.steps.end(); - s_it2=goto_trace.steps.erase(s_it2)); - + goto_trace.steps.erase(++s_it1, goto_trace.steps.end()); break; } @@ -257,7 +252,7 @@ bool bmc_covert::operator()() bmc.do_conversion(); - //bmc.equation.output(std::cout); + // bmc.equation.output(std::cout); // get the conditions for these goals from formula // collect all 'instances' of the goals @@ -269,7 +264,7 @@ bool bmc_covert::operator()() { assert(it->source.pc->is_assert()); exprt c= - conjunction({ + conjunction({ // NOLINT(whitespace/braces) literal_exprt(it->guard_literal), literal_exprt(!it->cond_literal) }); literalt l_c=solver.convert(c); @@ -307,7 +302,8 @@ bool bmc_covert::operator()() unsigned goals_covered=0; for(const auto &g : goal_map) - if(g.second.satisfied) goals_covered++; + if(g.second.satisfied) + goals_covered++; switch(bmc.ui) { @@ -324,7 +320,8 @@ bool bmc_covert::operator()() if(goal.source_location.is_not_nil()) status() << ' ' << goal.source_location; - if(!goal.description.empty()) status() << ' ' << goal.description; + if(!goal.description.empty()) + status() << ' ' << goal.description; status() << ": " << (goal.satisfied?"SATISFIED":"FAILED") << eom; diff --git a/src/cbmc/cbmc_dimacs.cpp b/src/cbmc/cbmc_dimacs.cpp index 8cbcd015287..4df2dfbbed9 100644 --- a/src/cbmc/cbmc_dimacs.cpp +++ b/src/cbmc/cbmc_dimacs.cpp @@ -73,7 +73,8 @@ bool cbmc_dimacst::write_dimacs(std::ostream &out) { const boolbv_mapt::literal_mapt &literal_map=m.second.literal_map; - if(literal_map.empty()) continue; + if(literal_map.empty()) + continue; out << "c " << m.first; diff --git a/src/cbmc/cbmc_parse_options.cpp b/src/cbmc/cbmc_parse_options.cpp index 7fad1e87d68..7364752d093 100644 --- a/src/cbmc/cbmc_parse_options.cpp +++ b/src/cbmc/cbmc_parse_options.cpp @@ -1091,7 +1091,7 @@ void cbmc_parse_optionst::help() "\n" "Analysis options:\n" " --show-properties show the properties, but don't run analysis\n" // NOLINT(*) - " --symex-coverage-report f generate a Cobertura XML coverage report in f\n" + " --symex-coverage-report f generate a Cobertura XML coverage report in f\n" // NOLINT(*) " --property id only check one specific property\n" " --stop-on-fail stop analysis once a failed property is detected\n" // NOLINT(*) " --trace give a counterexample trace for failed properties\n" //NOLINT(*) diff --git a/src/cbmc/cbmc_solvers.cpp b/src/cbmc/cbmc_solvers.cpp index 95d9b35cf38..9c13f9ce964 100644 --- a/src/cbmc/cbmc_solvers.cpp +++ b/src/cbmc/cbmc_solvers.cpp @@ -42,24 +42,24 @@ smt1_dect::solvert cbmc_solverst::get_smt1_solver_type() const { assert(options.get_bool_option("smt1")); - smt1_dect::solvert s = smt1_dect::GENERIC; + smt1_dect::solvert s=smt1_dect::GENERIC; if(options.get_bool_option("boolector")) - s = smt1_dect::BOOLECTOR; + s=smt1_dect::BOOLECTOR; else if(options.get_bool_option("mathsat")) - s = smt1_dect::MATHSAT; + s=smt1_dect::MATHSAT; else if(options.get_bool_option("cvc3")) - s = smt1_dect::CVC3; + s=smt1_dect::CVC3; else if(options.get_bool_option("cvc4")) - s = smt1_dect::CVC4; + s=smt1_dect::CVC4; else if(options.get_bool_option("opensmt")) - s = smt1_dect::OPENSMT; + s=smt1_dect::OPENSMT; else if(options.get_bool_option("yices")) - s = smt1_dect::YICES; + s=smt1_dect::YICES; else if(options.get_bool_option("z3")) - s = smt1_dect::Z3; + s=smt1_dect::Z3; else if(options.get_bool_option("generic")) - s = smt1_dect::GENERIC; + s=smt1_dect::GENERIC; return s; } @@ -80,24 +80,24 @@ smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const { assert(options.get_bool_option("smt2")); - smt2_dect::solvert s = smt2_dect::GENERIC; + smt2_dect::solvert s=smt2_dect::GENERIC; if(options.get_bool_option("boolector")) - s = smt2_dect::BOOLECTOR; + s=smt2_dect::BOOLECTOR; else if(options.get_bool_option("mathsat")) - s = smt2_dect::MATHSAT; + s=smt2_dect::MATHSAT; else if(options.get_bool_option("cvc3")) - s = smt2_dect::CVC3; + s=smt2_dect::CVC3; else if(options.get_bool_option("cvc4")) - s = smt2_dect::CVC4; + s=smt2_dect::CVC4; else if(options.get_bool_option("opensmt")) - s = smt2_dect::OPENSMT; + s=smt2_dect::OPENSMT; else if(options.get_bool_option("yices")) - s = smt2_dect::YICES; + s=smt2_dect::YICES; else if(options.get_bool_option("z3")) - s = smt2_dect::Z3; + s=smt2_dect::Z3; else if(options.get_bool_option("generic")) - s = smt2_dect::GENERIC; + s=smt2_dect::GENERIC; return s; } @@ -110,10 +110,9 @@ smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const \*******************************************************************/ -class cbmc_solver_with_propt: public cbmc_solverst::solvert +class cbmc_solver_with_propt:public cbmc_solverst::solvert { public: - cbmc_solver_with_propt( prop_convt *_prop_conv, propt *_prop): @@ -140,10 +139,9 @@ class cbmc_solver_with_propt: public cbmc_solverst::solvert \*******************************************************************/ -class cbmc_solver_with_aigpropt: public cbmc_solver_with_propt +class cbmc_solver_with_aigpropt:public cbmc_solver_with_propt { public: - cbmc_solver_with_aigpropt( prop_convt *_prop_conv, propt *_prop, @@ -218,31 +216,31 @@ cbmc_solverst::solvert* cbmc_solverst::get_default() !options.get_bool_option("sat-preprocessor")) // no simplifier { // simplifier won't work with beautification - propt* prop = new satcheck_no_simplifiert(); + propt *prop=new satcheck_no_simplifiert(); prop->set_message_handler(get_message_handler()); - bv_cbmct* bv_cbmc = new bv_cbmct(ns, *prop); + bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop); if(options.get_option("arrays-uf")=="never") bv_cbmc->unbounded_array=bv_cbmct::U_NONE; else if(options.get_option("arrays-uf")=="always") bv_cbmc->unbounded_array=bv_cbmct::U_ALL; - solver = new cbmc_solver_with_propt(bv_cbmc, prop); + solver=new cbmc_solver_with_propt(bv_cbmc, prop); } else // with simplifier { #if 1 - propt* prop = new satcheckt(); + propt *prop=new satcheckt(); prop->set_message_handler(get_message_handler()); - bv_cbmct* bv_cbmc = new bv_cbmct(ns, *prop); - solver = new cbmc_solver_with_propt(bv_cbmc, prop); + bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop); + solver=new cbmc_solver_with_propt(bv_cbmc, prop); #else - aigt* aig = new aigt(); - propt* prop = new aig_propt(*aig); + aigt *aig=new aigt(); + propt *prop=new aig_propt(*aig); prop->set_message_handler(get_message_handler()); - bv_cbmct* bv_cbmc = new bv_cbmct(ns, *prop); - solver = new cbmc_solver_with_aigpropt(bv_cbmc, prop, aig); + bv_cbmct *bv_cbmc=new bv_cbmct(ns, *prop); + solver=new cbmc_solver_with_aigpropt(bv_cbmc, prop, aig); #endif if(options.get_option("arrays-uf")=="never") @@ -276,7 +274,8 @@ cbmc_solverst::solvert* cbmc_solverst::get_dimacs() std::string filename=options.get_option("outfile"); - return new cbmc_solver_with_propt(new cbmc_dimacst(ns, *prop, filename), prop); + return + new cbmc_solver_with_propt(new cbmc_dimacst(ns, *prop, filename), prop); } /*******************************************************************\ @@ -306,7 +305,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_bv_refinement() prop->set_message_handler(get_message_handler()); - bv_refinementt *bv_refinement = new bv_refinementt(ns, *prop); + bv_refinementt *bv_refinement=new bv_refinementt(ns, *prop); bv_refinement->set_ui(ui); // we allow setting some parameters @@ -349,24 +348,26 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver) throw 0; } - smt1_dect* smt1_dec = new smt1_dect( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver); + smt1_dect *smt1_dec= + new smt1_dect( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver); return new solvert(smt1_dec); } else if(filename=="-") { - smt1_convt* smt1_conv = new smt1_convt( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver, - std::cout); + smt1_convt *smt1_conv= + new smt1_convt( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver, + std::cout); smt1_conv->set_message_handler(get_message_handler()); @@ -386,13 +387,14 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver) throw 0; } - smt1_convt* smt1_conv = new smt1_convt( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver, - *out); + smt1_convt *smt1_conv= + new smt1_convt( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver, + *out); smt1_conv->set_message_handler(get_message_handler()); @@ -426,12 +428,13 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) throw 0; } - smt2_dect* smt2_dec = new smt2_dect( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver); + smt2_dect *smt2_dec= + new smt2_dect( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver); if(options.get_bool_option("fpa")) smt2_dec->use_FPA_theory=true; @@ -440,13 +443,14 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) } else if(filename=="-") { - smt2_convt* smt2_conv = new smt2_convt( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver, - std::cout); + smt2_convt *smt2_conv= + new smt2_convt( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver, + std::cout); if(options.get_bool_option("fpa")) smt2_conv->use_FPA_theory=true; @@ -469,13 +473,14 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) throw 0; } - smt2_convt* smt2_conv = new smt2_convt( - ns, - "cbmc", - "Generated by CBMC " CBMC_VERSION, - "QF_AUFBV", - solver, - *out); + smt2_convt *smt2_conv= + new smt2_convt( + ns, + "cbmc", + "Generated by CBMC " CBMC_VERSION, + "QF_AUFBV", + solver, + *out); if(options.get_bool_option("fpa")) smt2_conv->use_FPA_theory=true; diff --git a/src/cbmc/cbmc_solvers.h b/src/cbmc/cbmc_solvers.h index 35ded2a5c92..4e31415743f 100644 --- a/src/cbmc/cbmc_solvers.h +++ b/src/cbmc/cbmc_solvers.h @@ -47,11 +47,11 @@ class cbmc_solverst:public messaget { } - //The solver class (that takes care of allocated objects) + // The solver class (that takes care of allocated objects) class solvert { public: - solvert(prop_convt* _prop_conv) + explicit solvert(prop_convt* _prop_conv) { assert(_prop_conv!=NULL); prop_conv_ptr = _prop_conv; @@ -63,18 +63,18 @@ class cbmc_solverst:public messaget delete prop_conv_ptr; } - //use this to get the prop_conv - prop_convt& prop_conv() const + // use this to get the prop_conv + prop_convt &prop_conv() const { assert(prop_conv_ptr!=NULL); return *prop_conv_ptr; } protected: - prop_convt* prop_conv_ptr; + prop_convt *prop_conv_ptr; }; - //returns a solvert object + // returns a solvert object virtual std::unique_ptr get_solver() { solvert *solver; @@ -107,19 +107,18 @@ class cbmc_solverst:public messaget // use gui format language_uit::uit ui; - solvert* get_default(); - solvert* get_dimacs(); - solvert* get_bv_refinement(); - solvert* get_smt1(smt1_dect::solvert solver); - solvert* get_smt2(smt2_dect::solvert solver); + solvert *get_default(); + solvert *get_dimacs(); + solvert *get_bv_refinement(); + solvert *get_smt1(smt1_dect::solvert solver); + solvert *get_smt2(smt2_dect::solvert solver); smt1_dect::solvert get_smt1_solver_type() const; smt2_dect::solvert get_smt2_solver_type() const; - //consistency checks during solver creation + // consistency checks during solver creation void no_beautification(); void no_incremental_check(); - }; #endif // CPROVER_CBMC_CBMC_SOLVERS_H diff --git a/src/cbmc/fault_localization.cpp b/src/cbmc/fault_localization.cpp index d1d711fe274..9fa6651c1c8 100644 --- a/src/cbmc/fault_localization.cpp +++ b/src/cbmc/fault_localization.cpp @@ -120,7 +120,7 @@ Function: fault_localizationt::check \*******************************************************************/ bool fault_localizationt::check(const lpointst &lpoints, - const lpoints_valuet& value) + const lpoints_valuet &value) { assert(value.size()==lpoints.size()); bvt assumptions; @@ -158,7 +158,7 @@ Function: fault_localizationt::update_scores \*******************************************************************/ void fault_localizationt::update_scores(lpointst &lpoints, - const lpoints_valuet& value) + const lpoints_valuet &value) { for(auto &l : lpoints) { @@ -195,9 +195,11 @@ void fault_localizationt::localize_linear(lpointst &lpoints) for(size_t i=0; i lpoints_valuet; - bool check(const lpointst &lpoints, const lpoints_valuet& value); + bool check(const lpointst &lpoints, const lpoints_valuet &value); void update_scores(lpointst &lpoints, - const lpoints_valuet& value); + const lpoints_valuet &value); // localization method: flip each point void localize_linear(lpointst &lpoints); // localization method: TBD - //void localize_TBD( + // void localize_TBD( // prop_convt &prop_conv); symex_target_equationt::SSA_stepst::const_iterator get_failed_property(); @@ -86,10 +87,10 @@ class fault_localizationt: void report(irep_idt goal_id); - //override bmc_all_propertiest + // override bmc_all_propertiest virtual void report(const cover_goalst &cover_goals); - //override bmc_all_propertiest + // override bmc_all_propertiest virtual void do_before_solving() { freeze_guards(); diff --git a/src/cbmc/show_vcc.cpp b/src/cbmc/show_vcc.cpp index 28e460774e5..46e7603662f 100644 --- a/src/cbmc/show_vcc.cpp +++ b/src/cbmc/show_vcc.cpp @@ -45,7 +45,8 @@ void bmct::show_vcc_plain(std::ostream &out) s_it!=equation.SSA_steps.end(); s_it++) { - if(!s_it->is_assert()) continue; + if(!s_it->is_assert()) + continue; if(s_it->source.pc->source_location.is_not_nil()) out << s_it->source.pc->source_location << "\n"; @@ -62,6 +63,7 @@ void bmct::show_vcc_plain(std::ostream &out) for(unsigned count=1; p_it!=last_it; p_it++) if(p_it->is_assume() || p_it->is_assignment() || p_it->is_constraint()) + { if(!p_it->ignore) { std::string string_value; @@ -76,6 +78,7 @@ void bmct::show_vcc_plain(std::ostream &out) count++; } + } out << "|--------------------------" << "\n"; @@ -114,7 +117,8 @@ void bmct::show_vcc_json(std::ostream &out) s_it!=equation.SSA_steps.end(); s_it++) { - if(!s_it->is_assert()) continue; + if(!s_it->is_assert()) + continue; // vcc object json_objectt &object=json_vccs.push_back(jsont()).make_object(); diff --git a/src/cbmc/symex_coverage.cpp b/src/cbmc/symex_coverage.cpp index b7f8e396473..8f64f9900a8 100644 --- a/src/cbmc/symex_coverage.cpp +++ b/src/cbmc/symex_coverage.cpp @@ -99,7 +99,7 @@ static std::string rate(std::size_t covered, std::size_t total) std::ostringstream oss; - oss << (float)covered/(float)total; + oss << static_cast(covered)/static_cast(total); #else std::ostringstream oss; oss << covered << " of " << total; @@ -219,7 +219,8 @@ void goto_program_coverage_recordt::compute_line_coverage( if(entry.second) { ++lines_total; - if(is_branch) ++branches_total; + if(is_branch) + ++branches_total; } // mark as branch if any instruction in this source code line is @@ -414,7 +415,8 @@ bool symex_coveraget::output_report( build_cobertura(goto_functions, xml_coverage); os << "\n"; - os << "\n"; + os << "\n"; os << xml_coverage; return !os.good(); diff --git a/src/cbmc/xml_interface.h b/src/cbmc/xml_interface.h index 1c2a926e33c..0cf038083db 100644 --- a/src/cbmc/xml_interface.h +++ b/src/cbmc/xml_interface.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com class xml_interfacet { public: - xml_interfacet(cmdlinet &_cmdline) + explicit xml_interfacet(cmdlinet &_cmdline) { get_xml_options(_cmdline); } diff --git a/src/cegis/cegis-util/instruction_iterator.h b/src/cegis/cegis-util/instruction_iterator.h index 40b289f88e9..0cbb042e93d 100644 --- a/src/cegis/cegis-util/instruction_iterator.h +++ b/src/cegis/cegis-util/instruction_iterator.h @@ -31,7 +31,7 @@ class instr_iteratort: public std::iteratorfalse * otherwise. */ - irep_pipet(bool auto_close); + explicit irep_pipet(bool auto_close); /** * @brief Optionally closing destructor. diff --git a/src/cegis/cegis-util/program_helper.cpp b/src/cegis/cegis-util/program_helper.cpp index 673510d8b04..80693d852c8 100644 --- a/src/cegis/cegis-util/program_helper.cpp +++ b/src/cegis/cegis-util/program_helper.cpp @@ -65,7 +65,7 @@ class id_searcht: public const_expr_visitort const irep_idt &id; bool found; public: - id_searcht(const irep_idt &id) : + explicit id_searcht(const irep_idt &id) : id(id), found(false) { } diff --git a/src/cegis/constant/literals_collector.cpp b/src/cegis/constant/literals_collector.cpp index 7400815ef89..4f779d331c1 100644 --- a/src/cegis/constant/literals_collector.cpp +++ b/src/cegis/constant/literals_collector.cpp @@ -21,7 +21,7 @@ class compare_constantt { const namespacet ns; public: - compare_constantt(const symbol_tablet &st) : + explicit compare_constantt(const symbol_tablet &st) : ns(st) { } diff --git a/src/cegis/control/simplify/remove_unused_elements.cpp b/src/cegis/control/simplify/remove_unused_elements.cpp index 3bc35dd88cf..140eeae9222 100644 --- a/src/cegis/control/simplify/remove_unused_elements.cpp +++ b/src/cegis/control/simplify/remove_unused_elements.cpp @@ -20,7 +20,7 @@ class symbol_visitort: public const_expr_visitort { std::set &vars; public: - symbol_visitort(std::set &vars) : + explicit symbol_visitort(std::set &vars) : vars(vars) { } diff --git a/src/cegis/control/verify/insert_solution.cpp b/src/cegis/control/verify/insert_solution.cpp index ca5decd1ac7..67743961feb 100644 --- a/src/cegis/control/verify/insert_solution.cpp +++ b/src/cegis/control/verify/insert_solution.cpp @@ -80,8 +80,7 @@ class is_assignment_tot { const std::string name; public: - is_assignment_tot(const std::string &name) : - name(name) + explicit is_assignment_tot(const std::string &name):name(name) { } diff --git a/src/cegis/control/verify/zero_solutions.h b/src/cegis/control/verify/zero_solutions.h index b1e47dfa3ff..3173b8ddb85 100644 --- a/src/cegis/control/verify/zero_solutions.h +++ b/src/cegis/control/verify/zero_solutions.h @@ -37,7 +37,7 @@ class zero_rational_solutiont * * @param st */ - zero_rational_solutiont(const symbol_tablet &st); + explicit zero_rational_solutiont(const symbol_tablet &st); /** * @brief @@ -65,7 +65,7 @@ class zero_vector_solutiont * * @param st */ - zero_vector_solutiont(const symbol_tablet &st); + explicit zero_vector_solutiont(const symbol_tablet &st); /** * @brief diff --git a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp b/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp index 899a86bcc34..6d05f817c7d 100644 --- a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp +++ b/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp @@ -55,7 +55,7 @@ class create_danger_meta_variables_for_loopt size_t loop_id; const bool use_ranking; public: - create_danger_meta_variables_for_loopt(danger_programt &prog) : + explicit create_danger_meta_variables_for_loopt(danger_programt &prog) : st(prog.st), gf(prog.gf), loop_id(0u), use_ranking(prog.use_ranking) { } diff --git a/src/cegis/danger/symex/learn/add_x0_placeholders.cpp b/src/cegis/danger/symex/learn/add_x0_placeholders.cpp index ebe7353d53c..2d69c1ad791 100644 --- a/src/cegis/danger/symex/learn/add_x0_placeholders.cpp +++ b/src/cegis/danger/symex/learn/add_x0_placeholders.cpp @@ -37,7 +37,7 @@ class add_x0_placeholdert symbol_tablet &st; goto_functionst &gf; public: - add_x0_placeholdert(danger_programt &prog) : + explicit add_x0_placeholdert(danger_programt &prog) : prog(prog), st(prog.st), gf(prog.gf) { } diff --git a/src/cegis/danger/symex/verify/insert_candidate.cpp b/src/cegis/danger/symex/verify/insert_candidate.cpp index 83bf1bbbc35..9fae8310f28 100644 --- a/src/cegis/danger/symex/verify/insert_candidate.cpp +++ b/src/cegis/danger/symex/verify/insert_candidate.cpp @@ -28,7 +28,7 @@ class assign_x0t goto_functionst &gf; goto_programt::targetst::const_iterator current_choice; public: - assign_x0t(danger_programt &prog) : + explicit assign_x0t(danger_programt &prog) : st(prog.st), gf(prog.gf), current_choice(prog.x0_choices.begin()) { } diff --git a/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp b/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp index 187b72551cd..01d127e6559 100644 --- a/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp +++ b/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp @@ -62,7 +62,7 @@ class danger_config_fullt typedef danger_verify_configt::counterexamplest counterexamplest; typedef danger_verify_configt::candidatet candidatet; - danger_config_fullt(danger_verify_configt &config) : + explicit danger_config_fullt(danger_verify_configt &config) : config(config) { } @@ -97,7 +97,7 @@ class danger_config_rankingt typedef danger_verify_configt::counterexamplest counterexamplest; typedef danger_verify_configt::candidatet candidatet; - danger_config_rankingt(danger_verify_configt &config) : + explicit danger_config_rankingt(danger_verify_configt &config) : config(config), gf(config.get_goto_functions()) { } @@ -132,7 +132,7 @@ class danger_config_assertiont typedef danger_verify_configt::counterexamplest counterexamplest; typedef danger_verify_configt::candidatet candidatet; - danger_config_assertiont(danger_verify_configt &config) : + explicit danger_config_assertiont(danger_verify_configt &config) : config(config), gf(config.get_goto_functions()) { } @@ -175,7 +175,7 @@ class ce_to_irept { irept &result; public: - ce_to_irept(irept &result) : + explicit ce_to_irept(irept &result) : result(result) { } @@ -197,7 +197,7 @@ class ces_to_irept { irept &result; public: - ces_to_irept(irept &result) : + explicit ces_to_irept(irept &result) : result(result) { } diff --git a/src/cegis/genetic/genetic_constant_strategy.cpp b/src/cegis/genetic/genetic_constant_strategy.cpp index 1e27f8faf00..5bc356e5dff 100644 --- a/src/cegis/genetic/genetic_constant_strategy.cpp +++ b/src/cegis/genetic/genetic_constant_strategy.cpp @@ -20,7 +20,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include -#include namespace { @@ -43,6 +42,7 @@ size_t genetic_constant_strategy(invariant_programt &prog, const size_t max_length) { symbol_tablet &st=prog.st; + const namespacet ns(st); goto_functionst &gf=prog.gf; goto_programt::targett pos=prog.invariant_range.begin; const std::vector literals(collect_literal_constants(prog)); @@ -55,7 +55,7 @@ size_t genetic_constant_strategy(invariant_programt &prog, if (!constants_printed) { std::cout << "" << const_index << "" << std::endl; - std::cout << "" << expr << "" << std::endl; + std::cout << "" << from_expr(ns, "", expr) << "\n"; } // XXX: Debug const std::string base_name(get_name(const_index++)); diff --git a/src/cegis/genetic/instruction_set_info_factory.h b/src/cegis/genetic/instruction_set_info_factory.h index c9c109cb1dc..69e158789f0 100644 --- a/src/cegis/genetic/instruction_set_info_factory.h +++ b/src/cegis/genetic/instruction_set_info_factory.h @@ -46,7 +46,8 @@ class instruction_set_info_factoryt * @tparam goto_program_providert */ template - instruction_set_info_factoryt(const goto_program_providert &provider); + explicit instruction_set_info_factoryt( + const goto_program_providert &provider); /** * @brief diff --git a/src/cegis/genetic/match_select.cpp b/src/cegis/genetic/match_select.cpp index 35e0cde1382..cf3e0f59b0f 100644 --- a/src/cegis/genetic/match_select.cpp +++ b/src/cegis/genetic/match_select.cpp @@ -56,7 +56,7 @@ class is_contestant_less_thant { const contestantt no_contestant; public: - is_contestant_less_thant(const contestantt &no_contestant) : + explicit is_contestant_less_thant(const contestantt &no_contestant) : no_contestant(no_contestant) { } diff --git a/src/cegis/genetic/symex_test_runner.h b/src/cegis/genetic/symex_test_runner.h index c96dd039684..c4aede09473 100644 --- a/src/cegis/genetic/symex_test_runner.h +++ b/src/cegis/genetic/symex_test_runner.h @@ -33,7 +33,7 @@ class symex_test_runnert individualt *individual; public: pid_t child_pid; - bool_pipet(individualt *individual); + explicit bool_pipet(individualt *individual); void run_test(const class optionst &options, configt &config, const counterexamplet &ce); void join(); diff --git a/src/cegis/genetic/tournament_select.cpp b/src/cegis/genetic/tournament_select.cpp index 392c3f81f80..855a2890e68 100644 --- a/src/cegis/genetic/tournament_select.cpp +++ b/src/cegis/genetic/tournament_select.cpp @@ -72,7 +72,7 @@ class arenat return father == c || mother == c || son == c || daughter == c; } public: - arenat(tournament_selectt::populationt &pop) : + explicit arenat(tournament_selectt::populationt &pop) : no_contestant(pop.end()), father(no_contestant), mother(no_contestant), son( no_contestant), daughter(no_contestant) { diff --git a/src/cegis/invariant/constant/literals_constant_strategy.cpp b/src/cegis/invariant/constant/literals_constant_strategy.cpp index 44d80d4d6f2..d1890f4135c 100644 --- a/src/cegis/invariant/constant/literals_constant_strategy.cpp +++ b/src/cegis/invariant/constant/literals_constant_strategy.cpp @@ -24,7 +24,7 @@ class compare_constantt { const namespacet ns; public: - compare_constantt(const invariant_programt &program) : + explicit compare_constantt(const invariant_programt &program) : ns(program.st) { } diff --git a/src/cegis/invariant/symex/verify/insert_program.cpp b/src/cegis/invariant/symex/verify/insert_program.cpp index 9509141932b..abed596b164 100644 --- a/src/cegis/invariant/symex/verify/insert_program.cpp +++ b/src/cegis/invariant/symex/verify/insert_program.cpp @@ -16,7 +16,7 @@ class replace_name_visitort: public expr_visitort { const replacementst &repl; public: - replace_name_visitort(const replacementst &repl) : + explicit replace_name_visitort(const replacementst &repl) : repl(repl) { } diff --git a/src/cegis/invariant/util/copy_instructions.cpp b/src/cegis/invariant/util/copy_instructions.cpp index b108a6dc389..6f1c4f62c25 100644 --- a/src/cegis/invariant/util/copy_instructions.cpp +++ b/src/cegis/invariant/util/copy_instructions.cpp @@ -104,7 +104,7 @@ class skip_removert typedef std::map skipst; skipst skips; public: - skip_removert(goto_programt::instructionst &instrs) : + explicit skip_removert(goto_programt::instructionst &instrs) : instrs(instrs) { } diff --git a/src/cegis/invariant/util/invariant_constraint_variables.cpp b/src/cegis/invariant/util/invariant_constraint_variables.cpp index 5c9a6fd69b7..a6a5bdca28d 100644 --- a/src/cegis/invariant/util/invariant_constraint_variables.cpp +++ b/src/cegis/invariant/util/invariant_constraint_variables.cpp @@ -49,7 +49,7 @@ class counterexample_variable_collectort { invariant_symbol_set &vars; public: - counterexample_variable_collectort(invariant_symbol_set &vars) : + explicit counterexample_variable_collectort(invariant_symbol_set &vars) : vars(vars) { } diff --git a/src/cegis/jsa/converters/replace_operators.cpp b/src/cegis/jsa/converters/replace_operators.cpp index 9d6d8e99d3d..098a82373f6 100644 --- a/src/cegis/jsa/converters/replace_operators.cpp +++ b/src/cegis/jsa/converters/replace_operators.cpp @@ -34,8 +34,8 @@ class replace_pred_ops_visitort: public expr_visitort { const __CPROVER_jsa_pred_instructiont &instr; public: - replace_pred_ops_visitort(const __CPROVER_jsa_pred_instructiont &instr) : - instr(instr) + explicit replace_pred_ops_visitort( + const __CPROVER_jsa_pred_instructiont &instr):instr(instr) { } diff --git a/src/cegis/jsa/genetic/jsa_source_provider.h b/src/cegis/jsa/genetic/jsa_source_provider.h index cf7be6f543a..5f892219b6b 100644 --- a/src/cegis/jsa/genetic/jsa_source_provider.h +++ b/src/cegis/jsa/genetic/jsa_source_provider.h @@ -29,7 +29,7 @@ class jsa_source_providert * * @param lcfg */ - jsa_source_providert(jsa_symex_learnt &lcfg); + explicit jsa_source_providert(jsa_symex_learnt &lcfg); /** * @brief diff --git a/src/cegis/jsa/learn/extract_candidate.cpp b/src/cegis/jsa/learn/extract_candidate.cpp index 1a1cf0768b1..40ed53af0b2 100644 --- a/src/cegis/jsa/learn/extract_candidate.cpp +++ b/src/cegis/jsa/learn/extract_candidate.cpp @@ -24,7 +24,7 @@ namespace typedef std::pair encoded_programt; typedef std::vector encoded_programst; -inline bool is_integer(const std::string & s) +inline bool is_integer(const std::string &s) { if (s.empty() || (!isdigit(s[0]) && s[0] != '-' && s[0] != '+')) return false; char *p; diff --git a/src/cegis/jsa/value/jsa_types.cpp b/src/cegis/jsa/value/jsa_types.cpp index 003d9361b04..e9234b4889b 100644 --- a/src/cegis/jsa/value/jsa_types.cpp +++ b/src/cegis/jsa/value/jsa_types.cpp @@ -44,7 +44,7 @@ symbol_typet jsa_invariant_instruction_type() return symbol_typet(INV_INSTR_TYPE); } -array_typet jsa_invariant_type(const exprt & size) +array_typet jsa_invariant_type(const exprt &size) { return array_typet(jsa_invariant_instruction_type(), size); } diff --git a/src/cegis/jsa/value/jsa_types.h b/src/cegis/jsa/value/jsa_types.h index a6f1aee52a5..739076e81bf 100644 --- a/src/cegis/jsa/value/jsa_types.h +++ b/src/cegis/jsa/value/jsa_types.h @@ -77,7 +77,7 @@ symbol_typet jsa_invariant_instruction_type(); * * @return */ -array_typet jsa_invariant_type(const exprt & size); +array_typet jsa_invariant_type(const exprt &size); /** * @brief @@ -97,7 +97,7 @@ symbol_typet jsa_query_instruction_type(); * * @return */ -array_typet jsa_query_type(const exprt & size); +array_typet jsa_query_type(const exprt &size); /** * @brief diff --git a/src/cegis/refactor/environment/instrument_state_vars.cpp b/src/cegis/refactor/environment/instrument_state_vars.cpp index 6dc9d60869a..89362222b23 100644 --- a/src/cegis/refactor/environment/instrument_state_vars.cpp +++ b/src/cegis/refactor/environment/instrument_state_vars.cpp @@ -15,7 +15,7 @@ class var_findert: public const_expr_visitort { std::set &vars; public: - var_findert(std::set &vars) : + explicit var_findert(std::set &vars) : vars(vars) { } diff --git a/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp b/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp index c9d233dad1e..e2597b2cc0e 100644 --- a/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp +++ b/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp @@ -46,7 +46,7 @@ class arithmetic_instructionst const typet &type; const instruction_descriptiont::typest sig; public: - arithmetic_instructionst(const typet &type) : + explicit arithmetic_instructionst(const typet &type) : type(type), sig( { type, type, type }) { } @@ -76,7 +76,7 @@ class assignt { const typet type; public: - assignt(const typet &type) : + explicit assignt(const typet &type) : type(type) { } diff --git a/src/cegis/refactor/options/refactor_program.h b/src/cegis/refactor/options/refactor_program.h index aa66f843bd3..558fb645b2e 100644 --- a/src/cegis/refactor/options/refactor_program.h +++ b/src/cegis/refactor/options/refactor_program.h @@ -102,7 +102,7 @@ class refactor_programt * * @details */ - explicit refactor_programt(); + refactor_programt(); /** * @brief diff --git a/src/cegis/safety/symex/verify/safety_verify_config.h b/src/cegis/safety/symex/verify/safety_verify_config.h index bf64a69be37..3bc7d5bab32 100644 --- a/src/cegis/safety/symex/verify/safety_verify_config.h +++ b/src/cegis/safety/symex/verify/safety_verify_config.h @@ -51,7 +51,7 @@ class safety_verify_configt * * @param program */ - safety_verify_configt(const safety_programt &program); + explicit safety_verify_configt(const safety_programt &program); /** * @brief diff --git a/src/cegis/seed/literals_seed.cpp b/src/cegis/seed/literals_seed.cpp index 6cd402d5467..1c1d4b43cda 100644 --- a/src/cegis/seed/literals_seed.cpp +++ b/src/cegis/seed/literals_seed.cpp @@ -32,7 +32,7 @@ class is_same_symbolt { const irep_idt &name; public: - is_same_symbolt(const irep_idt &name) : + explicit is_same_symbolt(const irep_idt &name) : name(name) { } @@ -51,7 +51,7 @@ class add_symbolt { keyst &keys; public: - add_symbolt(keyst &keys) : + explicit add_symbolt(keyst &keys) : keys(keys) { } @@ -67,7 +67,7 @@ class compare_literalt { const constant_exprt &literal; public: - compare_literalt(const constant_exprt &literal) : + explicit compare_literalt(const constant_exprt &literal) : literal(literal) { } @@ -82,7 +82,7 @@ class add_literalt { valuest &values; public: - add_literalt(valuest &values) : + explicit add_literalt(valuest &values) : values(values) { } @@ -178,7 +178,7 @@ class is_keyt { const exprt::operandst &ops; public: - is_keyt(const exprt::operandst &ops) : + explicit is_keyt(const exprt::operandst &ops) : ops(ops) { } @@ -212,7 +212,7 @@ class scrape_literalst: public const_expr_visitort std::deque keys; pool_storaget &pool; public: - scrape_literalst(pool_storaget &p) : + explicit scrape_literalst(pool_storaget &p) : pool(p) { std::transform(p.begin(), p.end(), std::back_inserter(keys), &get_first); diff --git a/src/cegis/wordsize/restrict_bv_size.cpp b/src/cegis/wordsize/restrict_bv_size.cpp index 8ca3a0791be..a30744f4f40 100644 --- a/src/cegis/wordsize/restrict_bv_size.cpp +++ b/src/cegis/wordsize/restrict_bv_size.cpp @@ -50,7 +50,7 @@ class restrict_bv_size_visitort: public expr_visitort { const size_t width_in_bits; public: - restrict_bv_size_visitort(const size_t width_in_bits) : + explicit restrict_bv_size_visitort(const size_t width_in_bits) : width_in_bits(width_in_bits) { } diff --git a/src/clobber/clobber_parse_options.cpp b/src/clobber/clobber_parse_options.cpp index e8d325db38b..4ac42666639 100644 --- a/src/clobber/clobber_parse_options.cpp +++ b/src/clobber/clobber_parse_options.cpp @@ -192,7 +192,8 @@ int clobber_parse_optionst::doit() dump_c(goto_functions, true, ns, out); - status() << "instrumentation complete; compile and execute simulator.c" << eom; + status() << "instrumentation complete; compile and execute simulator.c" + << eom; return 0; } @@ -287,7 +288,8 @@ bool clobber_parse_optionst::get_goto_program( if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end()) { - error() << "The goto binary has no entry point; please complete linking" << eom; + error() << "The goto binary has no entry point; please complete linking" + << eom; return true; } } @@ -317,7 +319,8 @@ bool clobber_parse_optionst::get_goto_program( if(language==NULL) { - error() << "failed to figure out type of file `" << filename << "'" << eom; + error() << "failed to figure out type of file `" << filename << "'" + << eom; return true; } @@ -336,10 +339,10 @@ bool clobber_parse_optionst::get_goto_program( } else { - - if(parse()) return true; - if(typecheck()) return true; - if(final()) return true; + if(parse() || + typecheck() || + final()) + return true; // we no longer need any parse trees or language files clear_parse(); @@ -667,6 +670,7 @@ void clobber_parse_optionst::help() #endif " --no-arch don't set up an architecture\n" " --no-library disable built-in abstract C library\n" + // NOLINTNEXTLINE(whitespace/line_length) " --round-to-nearest IEEE floating point rounding mode (default)\n" " --round-to-plus-inf IEEE floating point rounding mode\n" " --round-to-minus-inf IEEE floating point rounding mode\n" diff --git a/src/cpp/cpp_constructor.cpp b/src/cpp/cpp_constructor.cpp index 3de7a374e35..3c5b34762dd 100644 --- a/src/cpp/cpp_constructor.cpp +++ b/src/cpp/cpp_constructor.cpp @@ -93,7 +93,7 @@ codet cpp_typecheckt::cpp_constructor( /*if(cpp_is_pod(tmp_type)) { code_expressiont new_code; - exprt op_tc = operands.front(); + exprt op_tc=operands.front(); typecheck_expr(op_tc); // Override constantness object_tc.type().set("#constant", false); @@ -110,7 +110,7 @@ codet cpp_typecheckt::cpp_constructor( codet new_code(ID_block); // for each element of the array, call the default constructor - for(mp_integer i = 0; i < s; ++i) + for(mp_integer i=0; i < s; ++i) { exprt::operandst tmp_operands; @@ -209,14 +209,14 @@ codet cpp_typecheckt::cpp_constructor( codet block(ID_block); for(std::size_t i=0; i < struct_type.components().size(); i++) { - const irept &component = struct_type.components()[i]; - if(component.get(ID_base_name) != "@most_derived") + const irept &component=struct_type.components()[i]; + if(component.get(ID_base_name)!="@most_derived") continue; exprt member(ID_member, bool_typet()); member.set(ID_component_name, component.get(ID_name)); member.copy_to_operands(object_tc); - member.add_source_location() = source_location; + member.add_source_location()=source_location; member.set(ID_C_lvalue, object_tc.get_bool(ID_C_lvalue)); exprt val=false_exprt(); @@ -226,7 +226,7 @@ codet cpp_typecheckt::cpp_constructor( side_effect_exprt assign(ID_assign); assign.add_source_location()=source_location; - assign.move_to_operands(member,val); + assign.move_to_operands(member, val); typecheck_side_effect_assignment(assign); code_expressiont code_exp; code_exp.expression()=assign; @@ -279,23 +279,23 @@ codet cpp_typecheckt::cpp_constructor( function_call.op1().copy_to_operands(*it); typecheck_side_effect_function_call(function_call); - assert(function_call.get(ID_statement) == ID_temporary_object); + assert(function_call.get(ID_statement)==ID_temporary_object); exprt &initializer = static_cast(function_call.add(ID_initializer)); - assert(initializer.id()==ID_code - && initializer.get(ID_statement)==ID_expression); + assert(initializer.id()==ID_code && + initializer.get(ID_statement)==ID_expression); - side_effect_expr_function_callt& func_ini = + side_effect_expr_function_callt &func_ini= to_side_effect_expr_function_call(initializer.op0()); - exprt& tmp_this = func_ini.arguments().front(); - assert(tmp_this.id() == ID_address_of - && tmp_this.op0().id() == "new_object"); + exprt &tmp_this=func_ini.arguments().front(); + assert(tmp_this.id()==ID_address_of + && tmp_this.op0().id()=="new_object"); exprt address_of(ID_address_of, typet(ID_pointer)); - address_of.type().subtype() = object_tc.type(); + address_of.type().subtype()=object_tc.type(); address_of.copy_to_operands(object_tc); tmp_this.swap(address_of); @@ -339,9 +339,9 @@ void cpp_typecheckt::new_temporary( tmp_object_expr.add_source_location()= source_location; exprt new_object(ID_new_object); - new_object.add_source_location() = tmp_object_expr.source_location(); + new_object.add_source_location()=tmp_object_expr.source_location(); new_object.set(ID_C_lvalue, true); - new_object.type() = tmp_object_expr.type(); + new_object.type()=tmp_object_expr.type(); already_typechecked(new_object); diff --git a/src/cpp/cpp_convert_type.cpp b/src/cpp/cpp_convert_type.cpp index dbc9effe910..0f106b19575 100644 --- a/src/cpp/cpp_convert_type.cpp +++ b/src/cpp/cpp_convert_type.cpp @@ -34,7 +34,7 @@ class cpp_convert_typet std::list other; cpp_convert_typet() { } - cpp_convert_typet(const typet &type) { read(type); } + explicit cpp_convert_typet(const typet &type) { read(type); } protected: void read_rec(const typet &type); diff --git a/src/cpp/cpp_declaration.h b/src/cpp/cpp_declaration.h index 34ae1e796bc..271f7c5ee44 100644 --- a/src/cpp/cpp_declaration.h +++ b/src/cpp/cpp_declaration.h @@ -22,102 +22,104 @@ class cpp_declarationt:public exprt public: typedef std::vector declaratorst; - inline cpp_declarationt():exprt(ID_cpp_declaration) + cpp_declarationt():exprt(ID_cpp_declaration) { } - inline bool is_empty() const + bool is_empty() const { return type().is_nil() && !has_operands(); } - inline bool is_constructor() const + bool is_constructor() const { return type().id()==ID_constructor; } - inline bool is_static_assert() const + bool is_static_assert() const { return get_bool(ID_is_static_assert); } - inline bool is_destructor() const + bool is_destructor() const { return type().id()==ID_destructor; } - inline bool is_template() const + bool is_template() const { return get_bool(ID_is_template); } - inline bool is_class_template() const + bool is_class_template() const { return is_template() && type().id()==ID_struct && declarators().empty(); } - inline const declaratorst &declarators() const + const declaratorst &declarators() const { return (const declaratorst &)operands(); } - inline declaratorst &declarators() + declaratorst &declarators() { return (declaratorst &)operands(); } - inline const cpp_storage_spect &storage_spec() const + const cpp_storage_spect &storage_spec() const { return static_cast( find(ID_storage_spec)); } - inline cpp_storage_spect &storage_spec() + cpp_storage_spect &storage_spec() { return static_cast( add(ID_storage_spec)); } - inline const cpp_member_spect &member_spec() const + const cpp_member_spect &member_spec() const { return static_cast( find(ID_member_spec)); } - inline cpp_member_spect &member_spec() + cpp_member_spect &member_spec() { return static_cast( add(ID_member_spec)); } - inline template_typet &template_type() + template_typet &template_type() { return static_cast(add(ID_template_type)); } - inline const template_typet &template_type() const + const template_typet &template_type() const { return static_cast(find(ID_template_type)); } - inline cpp_template_args_non_tct &partial_specialization_args() + cpp_template_args_non_tct &partial_specialization_args() { - return static_cast(add("partial_specialization_args")); + return static_cast( + add("partial_specialization_args")); } - inline const cpp_template_args_non_tct &partial_specialization_args() const + const cpp_template_args_non_tct &partial_specialization_args() const { - return static_cast(find("partial_specialization_args")); + return static_cast( + find("partial_specialization_args")); } - inline void set_specialization_of(const irep_idt &id) + void set_specialization_of(const irep_idt &id) { set("specialization_of", id); } - inline irep_idt get_specialization_of() const + irep_idt get_specialization_of() const { return get("specialization_of"); } @@ -140,13 +142,13 @@ class cpp_declarationt:public exprt void name_anon_struct_union(typet &dest); }; -extern inline cpp_declarationt &to_cpp_declaration(irept &irep) +inline cpp_declarationt &to_cpp_declaration(irept &irep) { assert(irep.id()==ID_cpp_declaration); return static_cast(irep); } -extern inline const cpp_declarationt &to_cpp_declaration(const irept &irep) +inline const cpp_declarationt &to_cpp_declaration(const irept &irep) { assert(irep.id()==ID_cpp_declaration); return static_cast(irep); diff --git a/src/cpp/cpp_declarator.h b/src/cpp/cpp_declarator.h index 08ed4121fad..3a08f17180a 100644 --- a/src/cpp/cpp_declarator.h +++ b/src/cpp/cpp_declarator.h @@ -31,20 +31,32 @@ class cpp_declaratort:public exprt } cpp_namet &name() { return static_cast(add(ID_name)); } - const cpp_namet &name() const { return static_cast(find(ID_name)); } + const cpp_namet &name() const + { + return static_cast(find(ID_name)); + } exprt &value() { return static_cast(add(ID_value)); } - const exprt &value() const { return static_cast(find(ID_value)); } + const exprt &value() const + { + return static_cast(find(ID_value)); + } // initializers for function arguments exprt &init_args() { return static_cast(add("init_args")); } - const exprt &init_args() const { return static_cast(find("init_args")); } + const exprt &init_args() const + { + return static_cast(find("init_args")); + } irept &method_qualifier() { return add(ID_method_qualifier); } const irept &method_qualifier() const { return find(ID_method_qualifier); } irept &member_initializers() { return add(ID_member_initializers); } - const irept &member_initializers() const { return find(ID_member_initializers); } + const irept &member_initializers() const + { + return find(ID_member_initializers); + } irept &throw_decl() { return add("throw_decl"); } const irept &throw_decl() const { return find("throw_decl"); } diff --git a/src/cpp/cpp_declarator_converter.cpp b/src/cpp/cpp_declarator_converter.cpp index 29826d7b78e..83f5f1c1b38 100644 --- a/src/cpp/cpp_declarator_converter.cpp +++ b/src/cpp/cpp_declarator_converter.cpp @@ -134,7 +134,8 @@ symbolt &cpp_declarator_convertert::convert( if(c_it==cpp_typecheck.symbol_table.symbols.end()) { - cpp_typecheck.error().source_location=declarator.name().source_location(); + cpp_typecheck.error().source_location= + declarator.name().source_location(); cpp_typecheck.error() << "member `" << base_name << "' not found in scope `" << scope->identifier << "'" @@ -236,12 +237,13 @@ symbolt &cpp_declarator_convertert::convert( { cpp_scopet::id_sett id_set; - scope->lookup_identifier(symbol.name, cpp_idt::TEMPLATE_PARAMETER, id_set); + scope->lookup_identifier( + symbol.name, cpp_idt::TEMPLATE_PARAMETER, id_set); if(id_set.empty()) { cpp_idt &identifier= - cpp_typecheck.cpp_scopes.put_into_scope(symbol,*scope); + cpp_typecheck.cpp_scopes.put_into_scope(symbol, *scope); identifier.id_class=cpp_idt::TEMPLATE_PARAMETER; } } @@ -283,8 +285,10 @@ void cpp_declarator_convertert::combine_types( { for(unsigned i=0; i(cpp_name)); typecheck_side_effect_function_call(function_call); - assert(function_call.get(ID_statement) == ID_temporary_object); + assert(function_call.get(ID_statement)==ID_temporary_object); exprt &initializer = static_cast(function_call.add(ID_initializer)); @@ -143,15 +143,15 @@ codet cpp_typecheckt::cpp_destructor( assert(initializer.id()==ID_code && initializer.get(ID_statement)==ID_expression); - side_effect_expr_function_callt& func_ini = + side_effect_expr_function_callt &func_ini= to_side_effect_expr_function_call(initializer.op0()); - exprt& tmp_this = func_ini.arguments().front(); - assert(tmp_this.id() == ID_address_of - && tmp_this.op0().id() == "new_object"); + exprt &tmp_this=func_ini.arguments().front(); + assert(tmp_this.id()==ID_address_of + && tmp_this.op0().id()=="new_object"); exprt address_of(ID_address_of, typet(ID_pointer)); - address_of.type().subtype() = object.type(); + address_of.type().subtype()=object.type(); address_of.copy_to_operands(object); tmp_this.swap(address_of); diff --git a/src/cpp/cpp_enum_type.h b/src/cpp/cpp_enum_type.h index cb30d910e7b..23edd61900e 100644 --- a/src/cpp/cpp_enum_type.h +++ b/src/cpp/cpp_enum_type.h @@ -20,17 +20,17 @@ class cpp_enum_typet:public typet public: cpp_enum_typet(); - inline const cpp_namet &tag() const + const cpp_namet &tag() const { return static_cast(find(ID_tag)); } - inline bool has_tag() const + bool has_tag() const { return find(ID_tag).is_not_nil(); } - inline cpp_namet &tag() + cpp_namet &tag() { return static_cast(add(ID_tag)); } @@ -58,13 +58,13 @@ class cpp_enum_typet:public typet irep_idt generate_anon_tag() const; }; -extern inline const cpp_enum_typet &to_cpp_enum_type(const irept &irep) +inline const cpp_enum_typet &to_cpp_enum_type(const irept &irep) { assert(irep.id()==ID_c_enum); return static_cast(irep); } -extern inline cpp_enum_typet &to_cpp_enum_type(irept &irep) +inline cpp_enum_typet &to_cpp_enum_type(irept &irep) { assert(irep.id()==ID_c_enum); return static_cast(irep); diff --git a/src/cpp/cpp_exception_id.cpp b/src/cpp/cpp_exception_id.cpp index d661103de3b..e64fa67e0df 100644 --- a/src/cpp/cpp_exception_id.cpp +++ b/src/cpp/cpp_exception_id.cpp @@ -72,7 +72,6 @@ void cpp_exception_list_rec( dest.push_back(id2string(c_type)+suffix); return; } - } } diff --git a/src/cpp/cpp_id.cpp b/src/cpp/cpp_id.cpp index cacbcb0686d..1357c646fe6 100644 --- a/src/cpp/cpp_id.cpp +++ b/src/cpp/cpp_id.cpp @@ -115,10 +115,14 @@ void cpp_idt::print_fields(std::ostream &out, unsigned indent) const for(unsigned i=0; i #include -typedef std::multimap cpp_id_mapt; - class cpp_scopet; class cpp_idt @@ -40,22 +38,22 @@ class cpp_idt id_classt id_class; - inline bool is_class() const + bool is_class() const { return id_class==CLASS; } - inline bool is_enum() const + bool is_enum() const { return id_class==ENUM; } - inline bool is_namespace() const + bool is_namespace() const { return id_class==NAMESPACE; } - inline bool is_typedef() const + bool is_typedef() const { return id_class==TYPEDEF; } @@ -70,19 +68,19 @@ class cpp_idt std::string prefix, suffix; unsigned compound_counter; - inline cpp_idt &get_parent() const + cpp_idt &get_parent() const { assert(parent!=NULL); return *parent; } - inline void set_parent(cpp_idt &_parent) + void set_parent(cpp_idt &_parent) { assert(_parent.is_scope); parent=&_parent; } - inline void clear() + void clear() { *this=cpp_idt(); } @@ -90,9 +88,8 @@ class cpp_idt void print(std::ostream &out, unsigned indent=0) const; void print_fields(std::ostream &out, unsigned indent=0) const; - friend class cpp_scopet; - protected: + typedef std::multimap cpp_id_mapt; cpp_id_mapt sub; // These are used for base classes and 'using' clauses. diff --git a/src/cpp/cpp_instantiate_template.cpp b/src/cpp/cpp_instantiate_template.cpp index 0a3ad81463b..0a6b9d5c129 100644 --- a/src/cpp/cpp_instantiate_template.cpp +++ b/src/cpp/cpp_instantiate_template.cpp @@ -41,7 +41,10 @@ std::string cpp_typecheckt::template_suffix( it!=arguments.end(); it++) { - if(first) first=false; else result+=','; + if(first) + first=false; + else + result+=','; const exprt expr=*it; @@ -180,10 +183,12 @@ const symbolt &cpp_typecheckt::class_template_symbol( new_symbol.location=template_symbol.location; new_symbol.type=typet(ID_incomplete_struct); new_symbol.type.set(ID_tag, template_symbol.type.find(ID_tag)); - if(template_symbol.type.get_bool(ID_C_class)) new_symbol.type.set(ID_C_class, true); + if(template_symbol.type.get_bool(ID_C_class)) + new_symbol.type.set(ID_C_class, true); new_symbol.type.set(ID_template_class_instance, true); new_symbol.type.add_source_location()=template_symbol.location; - new_symbol.type.set("specialization_template_args", specialization_template_args); + new_symbol.type.set( + "specialization_template_args", specialization_template_args); new_symbol.type.set("full_template_args", full_template_args); new_symbol.type.set(ID_identifier, template_symbol.name); new_symbol.mode=template_symbol.mode; @@ -222,7 +227,8 @@ Function: cpp_typecheckt::elaborate_class_template void cpp_typecheckt::elaborate_class_template( const typet &type) { - if(type.id()!=ID_symbol) return; + if(type.id()!=ID_symbol) + return; const symbolt &symbol=lookup(type); @@ -235,8 +241,10 @@ void cpp_typecheckt::elaborate_class_template( instantiate_template( type.source_location(), lookup(t_type.get(ID_identifier)), - static_cast(t_type.find("specialization_template_args")), - static_cast(t_type.find("full_template_args"))); + static_cast( + t_type.find("specialization_template_args")), + static_cast( + t_type.find("full_template_args"))); } } @@ -295,7 +303,8 @@ const symbolt &cpp_typecheckt::instantiate_template( std::cout << "A: <"; forall_expr(it, specialization_template_args.arguments()) { - if(it!=specialization_template_args.arguments().begin()) std::cout << ", "; + if(it!=specialization_template_args.arguments().begin()) + std::cout << ", "; if(it->id()==ID_type) std::cout << to_string(it->type()); else diff --git a/src/cpp/cpp_internal_additions.cpp b/src/cpp/cpp_internal_additions.cpp index 1298f1c8e60..dfeabc2739e 100644 --- a/src/cpp/cpp_internal_additions.cpp +++ b/src/cpp/cpp_internal_additions.cpp @@ -71,8 +71,11 @@ void cpp_internal_additions(std::ostream &out) // auxiliaries for new/delete out << "extern \"C\" void *__new(__typeof__(sizeof(int)));" << '\n'; + // NOLINTNEXTLINE(whitespace/line_length) out << "extern \"C\" void *__new_array(__typeof__(sizeof(int)), __typeof__(sizeof(int)));" << '\n'; + // NOLINTNEXTLINE(whitespace/line_length) out << "extern \"C\" void *__placement_new(__typeof__(sizeof(int)), void *);" << '\n'; + // NOLINTNEXTLINE(whitespace/line_length) out << "extern \"C\" void *__placement_new_array(__typeof__(sizeof(int)), __typeof__(sizeof(int)), void *);" << '\n'; out << "extern \"C\" void __delete(void *);" << '\n'; out << "extern \"C\" void __delete_array(void *);" << '\n'; @@ -95,7 +98,7 @@ void cpp_internal_additions(std::ostream &out) "bool assertion, const char *description);" << '\n'; // CPROVER extensions - out << "extern \"C\" const unsigned __CPROVER::constant_infinity_uint;" << '\n'; + out << "extern \"C\" const unsigned __CPROVER::constant_infinity_uint;\n"; out << "extern \"C\" void __CPROVER_initialize();" << '\n'; out << "extern \"C\" void __CPROVER::input(const char *id, ...);" << '\n'; out << "extern \"C\" void __CPROVER::output(const char *id, ...);" << '\n'; @@ -104,9 +107,10 @@ void cpp_internal_additions(std::ostream &out) out << "extern \"C\" void __CPROVER::atomic_end();" << '\n'; // pointers - out << "extern \"C\" unsigned __CPROVER_POINTER_OBJECT(const void *p);" << '\n'; + out << "extern \"C\" unsigned __CPROVER_POINTER_OBJECT(const void *p);\n"; out << "extern \"C\" signed __CPROVER_POINTER_OFFSET(const void *p);" << '\n'; out << "extern \"C\" bool __CPROVER_DYNAMIC_OBJECT(const void *p);" << '\n'; + // NOLINTNEXTLINE(whitespace/line_length) out << "extern \"C\" extern unsigned char __CPROVER_memory[__CPROVER::constant_infinity_uint];" << '\n'; out << "extern \"C\" const void *__CPROVER_dead_object=0;" << '\n'; @@ -120,8 +124,9 @@ void cpp_internal_additions(std::ostream &out) out << "extern \"C\" int __CPROVER_rounding_mode;" << '\n'; // arrays + // NOLINTNEXTLINE(whitespace/line_length) out << "bool __CPROVER::array_equal(const void array1[], const void array2[]);" << '\n'; - out << "void __CPROVER::array_copy(const void dest[], const void src[]);" << '\n'; + out << "void __CPROVER::array_copy(const void dest[], const void src[]);\n"; out << "void __CPROVER::array_set(const void dest[], ...);" << '\n'; // GCC stuff, but also for ARM diff --git a/src/cpp/cpp_item.h b/src/cpp/cpp_item.h index b0255220f1f..f3f32674278 100644 --- a/src/cpp/cpp_item.h +++ b/src/cpp/cpp_item.h @@ -144,7 +144,6 @@ class cpp_itemt:public irept return static_cast( find(ID_C_source_location)); } - }; #endif // CPROVER_CPP_CPP_ITEM_H diff --git a/src/cpp/cpp_language.cpp b/src/cpp/cpp_language.cpp index cbabe644fa3..f1b4b97018d 100644 --- a/src/cpp/cpp_language.cpp +++ b/src/cpp/cpp_language.cpp @@ -177,11 +177,13 @@ bool cpp_languaget::typecheck( symbol_tablet &symbol_table, const std::string &module) { - if(module=="") return false; + if(module=="") + return false; symbol_tablet new_symbol_table; - if(cpp_typecheck(cpp_parse_tree, new_symbol_table, module, get_message_handler())) + if(cpp_typecheck( + cpp_parse_tree, new_symbol_table, module, get_message_handler())) return true; return linking(symbol_table, new_symbol_table, get_message_handler()); @@ -412,7 +414,7 @@ bool cpp_languaget::to_expr( else { // TODO - //expr.swap(cpp_parser.parse_tree.declarations.front()); + // expr.swap(cpp_parser.parse_tree.declarations.front()); // typecheck it result=cpp_typecheck(expr, get_message_handler(), ns); diff --git a/src/cpp/cpp_name.h b/src/cpp/cpp_name.h index d3d7da0fc15..9f1f635e26a 100644 --- a/src/cpp/cpp_name.h +++ b/src/cpp/cpp_name.h @@ -24,16 +24,16 @@ class cpp_namet:public irept class namet:public irept { public: - inline namet():irept(ID_name) + namet():irept(ID_name) { } - explicit inline namet(const irep_idt &base_name):irept(ID_name) + explicit namet(const irep_idt &base_name):irept(ID_name) { set(ID_identifier, base_name); } - inline namet( + namet( const irep_idt &_base_name, const source_locationt &_source_location):irept(ID_name) { @@ -41,49 +41,50 @@ class cpp_namet:public irept add_source_location()=_source_location; } - inline source_locationt &add_source_location() + source_locationt &add_source_location() { return static_cast(add(ID_C_source_location)); } - inline const source_locationt &source_location() const + const source_locationt &source_location() const { return static_cast(find(ID_C_source_location)); } }; - inline cpp_namet():irept(ID_cpp_name) + cpp_namet():irept(ID_cpp_name) { } - inline explicit cpp_namet(const irep_idt &base_name):irept(ID_cpp_name) + explicit cpp_namet(const irep_idt &base_name):irept(ID_cpp_name) { get_sub().push_back(namet(base_name)); } - inline cpp_namet( + cpp_namet( const irep_idt &_base_name, const source_locationt &_source_location):irept(ID_cpp_name) { get_sub().push_back(namet(_base_name, _source_location)); } - inline const source_locationt &source_location() const + const source_locationt &source_location() const { if(get_sub().empty()) return static_cast(get_nil_irep()); else - return static_cast(get_sub().front().find(ID_C_source_location)); + return static_cast( + get_sub().front().find(ID_C_source_location)); } - //void convert(std::string &identifier, std::string &base_name) const; + // void convert(std::string &identifier, std::string &base_name) const; irep_idt get_base_name() const; // one of three: // 'identifier' // 'operator X' // '~identifier' - inline bool is_simple_name() const + bool is_simple_name() const { const subt &sub=get_sub(); return (sub.size()==1 && sub.front().id()==ID_name) || @@ -93,7 +94,8 @@ class cpp_namet:public irept bool is_operator() const { - if(get_sub().empty()) return false; + if(get_sub().empty()) + return false; return get_sub().front().id()==ID_operator; } diff --git a/src/cpp/cpp_namespace_spec.h b/src/cpp/cpp_namespace_spec.h index f9635d557d0..84aa6314086 100644 --- a/src/cpp/cpp_namespace_spec.h +++ b/src/cpp/cpp_namespace_spec.h @@ -16,51 +16,51 @@ Author: Daniel Kroening, kroening@cs.cmu.edu class cpp_namespace_spect:public exprt { public: - inline cpp_namespace_spect():exprt(ID_cpp_namespace_spec) + cpp_namespace_spect():exprt(ID_cpp_namespace_spec) { add("alias").make_nil(); } typedef std::vector itemst; - inline const itemst &items() const + const itemst &items() const { return (const itemst &)operands(); } - inline itemst &items() + itemst &items() { return (itemst &)operands(); } - inline const irep_idt &get_namespace() const + const irep_idt &get_namespace() const { return get(ID_namespace); } - inline void set_namespace(const irep_idt &_namespace) + void set_namespace(const irep_idt &_namespace) { set(ID_namespace, _namespace); } - inline cpp_namet &alias() + cpp_namet &alias() { return static_cast(add("alias")); } - inline const cpp_namet &alias() const + const cpp_namet &alias() const { return static_cast(find("alias")); } void output(std::ostream &out) const; - inline void set_is_inline(bool value) + void set_is_inline(bool value) { set(ID_is_inline, value); } - inline bool get_is_inline() const + bool get_is_inline() const { return get_bool(ID_is_inline); } diff --git a/src/cpp/cpp_scope.cpp b/src/cpp/cpp_scope.cpp index ee5185ade6e..35b52479419 100644 --- a/src/cpp/cpp_scope.cpp +++ b/src/cpp/cpp_scope.cpp @@ -67,7 +67,8 @@ void cpp_scopet::lookup( if(this->base_name==base_name) id_set.insert(this); - if(kind==SCOPE_ONLY) return; // done + if(kind==SCOPE_ONLY) + return; // done // using scopes for(scope_listt::iterator @@ -82,7 +83,8 @@ void cpp_scopet::lookup( other_scope.lookup(base_name, QUALIFIED, id_set); } - if(!id_set.empty()) return; // done, upwards scopes are hidden + if(!id_set.empty()) + return; // done, upwards scopes are hidden // secondary scopes for(scope_listt::iterator @@ -97,8 +99,10 @@ void cpp_scopet::lookup( other_scope.lookup(base_name, QUALIFIED, id_set); } - if(kind==QUALIFIED) return; // done - if(!id_set.empty()) return; // done + if(kind==QUALIFIED) + return; // done + if(!id_set.empty()) + return; // done // ask parent, recursive call if(!is_root_scope()) @@ -154,7 +158,8 @@ void cpp_scopet::lookup( this->id_class == id_class) id_set.insert(this); - if(kind==SCOPE_ONLY) return; // done + if(kind==SCOPE_ONLY) + return; // done // using scopes for(scope_listt::iterator @@ -185,7 +190,8 @@ void cpp_scopet::lookup( other_scope.lookup(base_name, QUALIFIED, id_class, id_set); } - if(kind==QUALIFIED) return; // done + if(kind==QUALIFIED) + return; // done if(!id_set.empty() && id_class!=TEMPLATE) return; // done, upwards scopes are hidden @@ -227,7 +233,7 @@ void cpp_scopet::lookup_identifier( #if 0 for(unsigned i=0; i scope_sett; typedef std::set id_sett; - inline cpp_scopet ¤t_scope() + cpp_scopet ¤t_scope() { return *current_scope_ptr; } @@ -44,7 +44,7 @@ class cpp_scopest return n; } - inline cpp_scopet &new_namespace(const irep_idt &new_scope_name) + cpp_scopet &new_namespace(const irep_idt &new_scope_name) { return new_scope(new_scope_name, cpp_idt::NAMESPACE); } @@ -101,7 +101,7 @@ class cpp_scopest void go_to(cpp_idt &id) { assert(id.is_scope); - current_scope_ptr=(cpp_scopet *)&id; + current_scope_ptr=static_cast(&id); } // move up to next global scope @@ -125,7 +125,7 @@ class cpp_scopest class cpp_save_scopet { public: - cpp_save_scopet(cpp_scopest &_cpp_scopes): + explicit cpp_save_scopet(cpp_scopest &_cpp_scopes): cpp_scopes(_cpp_scopes), saved_scope(_cpp_scopes.current_scope_ptr) { diff --git a/src/cpp/cpp_storage_spec.h b/src/cpp/cpp_storage_spec.h index 410319fde7a..a2f438fe766 100644 --- a/src/cpp/cpp_storage_spec.h +++ b/src/cpp/cpp_storage_spec.h @@ -36,13 +36,13 @@ class cpp_storage_spect:public irept bool is_thread_local() const { return get_bool(ID_thread_local); } bool is_asm() const { return get_bool(ID_asm); } - void set_static () { set(ID_static, true); } - void set_extern () { set(ID_extern, true); } - void set_auto () { set(ID_auto, true); } - void set_register () { set(ID_register, true); } - void set_mutable () { set(ID_mutable, true); } + void set_static() { set(ID_static, true); } + void set_extern() { set(ID_extern, true); } + void set_auto() { set(ID_auto, true); } + void set_register() { set(ID_register, true); } + void set_mutable() { set(ID_mutable, true); } void set_thread_local() { set(ID_thread_local, true); } - void set_asm () { set(ID_asm, true); } + void set_asm() { set(ID_asm, true); } bool is_empty() const { diff --git a/src/cpp/cpp_template_args.h b/src/cpp/cpp_template_args.h index b30e17b7f4e..5fa708879a8 100644 --- a/src/cpp/cpp_template_args.h +++ b/src/cpp/cpp_template_args.h @@ -41,13 +41,15 @@ class cpp_template_args_non_tct:public cpp_template_args_baset { }; -extern inline cpp_template_args_non_tct &to_cpp_template_args_non_tc(irept &irep) +inline cpp_template_args_non_tct &to_cpp_template_args_non_tc( + irept &irep) { assert(irep.id()==ID_template_args); return static_cast(irep); } -extern inline const cpp_template_args_non_tct &to_cpp_template_args_non_tc(const irept &irep) +inline const cpp_template_args_non_tct &to_cpp_template_args_non_tc( + const irept &irep) { assert(irep.id()==ID_template_args); return static_cast(irep); @@ -73,13 +75,13 @@ class cpp_template_args_tct:public cpp_template_args_baset } }; -extern inline cpp_template_args_tct &to_cpp_template_args_tc(irept &irep) +inline cpp_template_args_tct &to_cpp_template_args_tc(irept &irep) { assert(irep.id()==ID_template_args); return static_cast(irep); } -extern inline const cpp_template_args_tct &to_cpp_template_args_tc(const irept &irep) +inline const cpp_template_args_tct &to_cpp_template_args_tc(const irept &irep) { assert(irep.id()==ID_template_args); return static_cast(irep); diff --git a/src/cpp/cpp_template_parameter.h b/src/cpp/cpp_template_parameter.h index 0a54a3a01a2..af5527a10c4 100644 --- a/src/cpp/cpp_template_parameter.h +++ b/src/cpp/cpp_template_parameter.h @@ -55,12 +55,12 @@ struct template_parametert:public exprt } #endif - inline exprt &default_argument() + exprt &default_argument() { return static_cast(add(ID_C_default_value)); } - inline const exprt &default_argument() const + const exprt &default_argument() const { return static_cast(find(ID_C_default_value)); } diff --git a/src/cpp/cpp_template_type.h b/src/cpp/cpp_template_type.h index 32eb23d1814..2ebb5ac34e0 100644 --- a/src/cpp/cpp_template_type.h +++ b/src/cpp/cpp_template_type.h @@ -17,18 +17,18 @@ Author: Daniel Kroening, kroening@cs.cmu.edu class template_typet:public typet { public: - inline template_typet():typet(ID_template) + template_typet():typet(ID_template) { } typedef std::vector template_parameterst; - inline template_parameterst &template_parameters() + template_parameterst &template_parameters() { return (template_parameterst &)add(ID_template_parameters).get_sub(); } - inline const template_parameterst &template_parameters() const + const template_parameterst &template_parameters() const { return (const template_parameterst &)find(ID_template_parameters).get_sub(); } diff --git a/src/cpp/cpp_token_buffer.cpp b/src/cpp/cpp_token_buffer.cpp index 1dbb0178684..9dcd75526e6 100644 --- a/src/cpp/cpp_token_buffer.cpp +++ b/src/cpp/cpp_token_buffer.cpp @@ -53,7 +53,8 @@ int cpp_token_buffert::get_token(cpp_tokent &token) { assert(current_pos<=token_vector.size()); - if(token_vector.size()==current_pos) read_token(); + if(token_vector.size()==current_pos) + read_token(); token=*token_vector[current_pos]; @@ -78,7 +79,8 @@ int cpp_token_buffert::get_token() { assert(current_pos<=token_vector.size()); - if(token_vector.size()==current_pos) read_token(); + if(token_vector.size()==current_pos) + read_token(); int kind=token_vector[current_pos]->kind; @@ -145,12 +147,12 @@ void cpp_token_buffert::read_token() tokens.back().filename=ansi_c_parser.get_file(); } - //std::cout << "TOKEN: " << kind << " " << tokens.back().text << std::endl; + // std::cout << "TOKEN: " << kind << " " << tokens.back().text << std::endl; tokens.back().kind=kind; - //std::cout << "II: " << token_vector.back()->kind << std::endl; - //std::cout << "I2: " << token_vector.size() << std::endl; + // std::cout << "II: " << token_vector.back()->kind << std::endl; + // std::cout << "I2: " << token_vector.size() << std::endl; } /*******************************************************************\ @@ -203,7 +205,8 @@ void cpp_token_buffert::Replace(const cpp_tokent &token) { assert(current_pos<=token_vector.size()); - if(token_vector.size()==current_pos) read_token(); + if(token_vector.size()==current_pos) + read_token(); *token_vector[current_pos]=token; } diff --git a/src/cpp/cpp_type2name.cpp b/src/cpp/cpp_type2name.cpp index ac745f89ffb..98842b8b41a 100644 --- a/src/cpp/cpp_type2name.cpp +++ b/src/cpp/cpp_type2name.cpp @@ -11,6 +11,8 @@ Author: Daniel Kroening, kroening@cs.cmu.edu #include #include +#include "cpp_type2name.h" + /*******************************************************************\ Function: do_prefix @@ -64,7 +66,10 @@ static void irep2name(const irept &irep, std::string &result) forall_named_irep(it, irep.get_named_sub()) { - if(first) first=false; else result+=','; + if(first) + first=false; + else + result+=','; result+=do_prefix(name2string(it->first)); @@ -79,7 +84,10 @@ static void irep2name(const irept &irep, std::string &result) it->first==ID_C_volatile || it->first==ID_C_restricted) { - if(first) first=false; else result+=','; + if(first) + first=false; + else + result+=','; result+=do_prefix(name2string(it->first)); result+='='; std::string tmp; @@ -89,7 +97,10 @@ static void irep2name(const irept &irep, std::string &result) forall_irep(it, irep.get_sub()) { - if(first) first=false; else result+=','; + if(first) + first=false; + else + result+=','; std::string tmp; irep2name(*it, tmp); result+=tmp; @@ -171,7 +182,8 @@ std::string cpp_type2name(const typet &type) arg_it!=parameters.end(); arg_it++) { - if(arg_it!=parameters.begin()) result+=','; + if(arg_it!=parameters.begin()) + result+=','; result+=cpp_type2name(arg_it->type()); } diff --git a/src/cpp/cpp_typecast.h b/src/cpp/cpp_typecast.h index 8f242c61e6b..34eaf8fd48a 100644 --- a/src/cpp/cpp_typecast.h +++ b/src/cpp/cpp_typecast.h @@ -16,7 +16,7 @@ class cpp_typecheckt; class cpp_typecastt:public c_typecastt { public: - cpp_typecastt(cpp_typecheckt &cpp_typecheck); + explicit cpp_typecastt(cpp_typecheckt &cpp_typecheck); virtual void implicit_typecast( exprt &expr, @@ -47,20 +47,20 @@ class cpp_typecastt:public c_typecastt bool subtype_typecast( const typet &from, const typet &to, - std::string& err); + std::string &err); bool integral_conversion( - const typet &src_type, - const typet &dest_type); + const typet &src_type, + const typet &dest_type); exprt subtype_offset( - const struct_typet &from, - const struct_typet &to); + const struct_typet &from, + const struct_typet &to); void make_ptr_typecast( - exprt &expr, - const typet & src_type, - const typet & dest_type); + exprt &expr, + const typet &src_type, + const typet &dest_type); cpp_typecheckt &cpp_typecheck; }; diff --git a/src/cpp/cpp_typecheck.cpp b/src/cpp/cpp_typecheck.cpp index 5d0387840fe..fe8a9f063d7 100644 --- a/src/cpp/cpp_typecheck.cpp +++ b/src/cpp/cpp_typecheck.cpp @@ -156,7 +156,8 @@ bool cpp_typecheck( const std::string &module, message_handlert &message_handler) { - cpp_typecheckt cpp_typecheck(cpp_parse_tree, symbol_table, module, message_handler); + cpp_typecheckt cpp_typecheck( + cpp_parse_tree, symbol_table, module, message_handler); return cpp_typecheck.typecheck_main(); } @@ -281,7 +282,7 @@ void cpp_typecheckt::static_and_dynamic_initialization() dynamic_initializations.clear(); - //block_sini.move_to_operands(block_dini); + // block_sini.move_to_operands(block_dini); // Create the dynamic initialization procedure symbolt init_symbol; diff --git a/src/cpp/cpp_typecheck.h b/src/cpp/cpp_typecheck.h index 2615996f52a..9c26ebbe16f 100644 --- a/src/cpp/cpp_typecheck.h +++ b/src/cpp/cpp_typecheck.h @@ -118,7 +118,7 @@ class cpp_typecheckt:public c_typecheck_baset void convert_initializer(symbolt &symbol); void convert_function(symbolt &symbol); - void convert_pmop(exprt& expr); + void convert_pmop(exprt &expr); void convert_anonymous_union( cpp_declarationt &declaration, @@ -253,15 +253,15 @@ class cpp_typecheckt:public c_typecheck_baset cpp_declarationt &ctor) const; void default_cpctor( - const symbolt&, cpp_declarationt& cpctor) const; + const symbolt&, cpp_declarationt &cpctor) const; void default_assignop( - const symbolt& symbol, cpp_declarationt& cpctor); + const symbolt &symbol, cpp_declarationt &cpctor); void default_assignop_value( - const symbolt& symbol, cpp_declaratort& declarator); + const symbolt &symbol, cpp_declaratort &declarator); - void default_dtor(const symbolt& symb, cpp_declarationt& dtor); + void default_dtor(const symbolt &symb, cpp_declarationt &dtor); codet dtor(const symbolt &symb); @@ -278,20 +278,20 @@ class cpp_typecheckt:public c_typecheck_baset const struct_union_typet &struct_union_type, irept &initializers); - bool find_cpctor(const symbolt& symbol)const; - bool find_assignop(const symbolt& symbol)const; - bool find_dtor(const symbolt& symbol)const; + bool find_cpctor(const symbolt &symbol)const; + bool find_assignop(const symbolt &symbol)const; + bool find_dtor(const symbolt &symbol)const; bool find_parent( - const symbolt& symb, + const symbolt &symb, const irep_idt &base_name, irep_idt &identifier); bool get_component( const source_locationt &source_location, - const exprt& object, - const irep_idt& component_name, - exprt& member); + const exprt &object, + const irep_idt &component_name, + exprt &member); void new_temporary(const source_locationt &source_location, const typet &, @@ -309,16 +309,16 @@ class cpp_typecheckt:public c_typecheck_baset void add_base_components( const struct_typet &from, - const irep_idt& access, + const irep_idt &access, struct_typet &to, - std::set& bases, - std::set& vbases, + std::set &bases, + std::set &vbases, bool is_virtual); bool cast_away_constness(const typet &t1, const typet &t2) const; - void do_virtual_table(const symbolt& symbol); + void do_virtual_table(const symbolt &symbol); // we need to be able to delay the typechecking // of method bodies to handle methods with @@ -384,7 +384,7 @@ class cpp_typecheckt:public c_typecheck_baset void put_compound_into_scope(const struct_union_typet::componentt &component); void typecheck_compound_body(symbolt &symbol); - void typecheck_compound_body(struct_union_typet &type) { assert(false); }; + void typecheck_compound_body(struct_union_typet &type) { assert(false); } void typecheck_enum_body(symbolt &symbol); void typecheck_method_bodies(method_bodiest &); void typecheck_compound_bases(struct_typet &type); @@ -568,7 +568,7 @@ class cpp_typecheckt:public c_typecheck_baset void make_ptr_typecast( exprt &expr, - const typet & dest_type); + const typet &dest_type); // the C++ typecasts diff --git a/src/cpp/cpp_typecheck_bases.cpp b/src/cpp/cpp_typecheck_bases.cpp index e8990a3bce7..5bcb06e55e3 100644 --- a/src/cpp/cpp_typecheck_bases.cpp +++ b/src/cpp/cpp_typecheck_bases.cpp @@ -116,7 +116,8 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type) most_derived.type()=bool_typet(); most_derived.set_access(ID_public); most_derived.set(ID_base_name, "@most_derived"); - most_derived.set_name(cpp_scopes.current_scope().prefix+"::"+"@most_derived"); + most_derived.set_name( + cpp_scopes.current_scope().prefix+"::"+"@most_derived"); most_derived.set(ID_pretty_name, "@most_derived"); most_derived.add_source_location()=type.source_location(); put_compound_into_scope(most_derived); @@ -232,6 +233,5 @@ void cpp_typecheckt::add_base_components( assert(false); // put into scope - } } diff --git a/src/cpp/cpp_typecheck_code.cpp b/src/cpp/cpp_typecheck_code.cpp index 0914df233d1..3d86c0f5f5d 100644 --- a/src/cpp/cpp_typecheck_code.cpp +++ b/src/cpp/cpp_typecheck_code.cpp @@ -327,16 +327,19 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code) if(symbol_expr.id() == ID_symbol && symbol_expr.type().id()!=ID_code) { - // maybe the name of the member collides with a parameter of the constructor + // maybe the name of the member collides with a parameter of the + // constructor symbol_expr.make_nil(); cpp_typecheck_fargst fargs; - exprt dereference(ID_dereference, cpp_scopes.current_scope().this_expr.type().subtype()); + exprt dereference( + ID_dereference, cpp_scopes.current_scope().this_expr.type().subtype()); dereference.copy_to_operands(cpp_scopes.current_scope().this_expr); fargs.add_object(dereference); { cpp_save_scopet cpp_saved_scope(cpp_scopes); - cpp_scopes.go_to(*(cpp_scopes.id_map[cpp_scopes.current_scope().class_identifier])); + cpp_scopes.go_to( + *(cpp_scopes.id_map[cpp_scopes.current_scope().class_identifier])); symbol_expr=resolve(member, cpp_typecheck_resolvet::VAR, fargs); } @@ -470,7 +473,8 @@ void cpp_typecheckt::typecheck_decl(codet &code) const symbolt &symbol= cpp_declarator_converter.convert(declaration, declarator); - if(is_typedef) continue; + if(is_typedef) + continue; codet decl_statement(ID_decl); decl_statement.reserve_operands(2); diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index f8057808f38..e1ece6d8be9 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -39,7 +39,8 @@ bool cpp_typecheckt::has_const(const typet &type) else if(type.id()==ID_merged_type) { forall_subtypes(it, type) - if(has_const(*it)) return true; + if(has_const(*it)) + return true; return false; } @@ -66,7 +67,8 @@ bool cpp_typecheckt::has_volatile(const typet &type) else if(type.id()==ID_merged_type) { forall_subtypes(it, type) - if(has_volatile(*it)) return true; + if(has_volatile(*it)) + return true; return false; } @@ -185,7 +187,8 @@ void cpp_typecheckt::typecheck_compound_type( cpp_save_scopet cpp_save_scope(cpp_scopes); cpp_typecheck_resolvet cpp_typecheck_resolve(*this); cpp_template_args_non_tct t_args; - dest_scope=&cpp_typecheck_resolve.resolve_scope(cpp_name, base_name, t_args); + dest_scope= + &cpp_typecheck_resolve.resolve_scope(cpp_name, base_name, t_args); } } @@ -249,7 +252,8 @@ void cpp_typecheckt::typecheck_compound_type( cpp_scopes.current_scope().prefix+ id2string(symbol.base_name)+ cpp_scopes.current_scope().suffix; - symbol.type.set(ID_tag, cpp_scopes.current_scope().prefix+id2string(symbol.base_name)); + symbol.type.set( + ID_tag, cpp_scopes.current_scope().prefix+id2string(symbol.base_name)); // move early, must be visible before doing body symbolt *new_symbol; @@ -257,8 +261,8 @@ void cpp_typecheckt::typecheck_compound_type( if(symbol_table.move(symbol, new_symbol)) { error().source_location=symbol.location; - error() << "cpp_typecheckt::typecheck_compound_type: symbol_table.move() failed" - << eom; + error() << "cpp_typecheckt::typecheck_compound_type: " + << "symbol_table.move() failed" << eom; throw 0; } @@ -433,7 +437,7 @@ void cpp_typecheckt::typecheck_compound_declarator( irep_idt identifier; // the below is a temporary hack - //if(is_method || is_static)d + // if(is_method || is_static)d if(id2string(cpp_scopes.current_scope().prefix).find("#anon")== std::string::npos || is_method || is_static) @@ -496,7 +500,8 @@ void cpp_typecheckt::typecheck_compound_declarator( std::string virtual_name= component.get_string(ID_base_name)+ id2string( - function_identifier(static_cast(component.find(ID_type)))); + function_identifier( + static_cast(component.find(ID_type)))); if(has_const(method_qualifier)) virtual_name+="$const"; @@ -517,10 +522,10 @@ void cpp_typecheckt::typecheck_compound_declarator( if(comp.get("virtual_name")==virtual_name) { is_virtual=true; - const code_typet& code_type=to_code_type(comp.type()); + const code_typet &code_type=to_code_type(comp.type()); assert(code_type.parameters().size()>0); - const typet& pointer_type = code_type.parameters()[0].type(); - assert(pointer_type.id() == ID_pointer); + const typet &pointer_type=code_type.parameters()[0].type(); + assert(pointer_type.id()==ID_pointer); virtual_bases.insert(pointer_type.subtype().get(ID_identifier)); } } @@ -542,12 +547,12 @@ void cpp_typecheckt::typecheck_compound_declarator( else // virtual { component.type().set(ID_C_is_virtual, true); - component.type().set("#virtual_name",virtual_name); + component.type().set("#virtual_name", virtual_name); // Check if it is a pure virtual method if(is_virtual) { - if(value.is_not_nil() && value.id() == ID_constant) + if(value.is_not_nil() && value.id()==ID_constant) { mp_integer i; to_integer(value, i); @@ -571,35 +576,37 @@ void cpp_typecheckt::typecheck_compound_declarator( value); // get the virtual-table symbol type - irep_idt vt_name = "virtual_table::"+id2string(symbol.name); + irep_idt vt_name="virtual_table::"+id2string(symbol.name); symbol_tablet::symbolst::iterator vtit = symbol_table.symbols.find(vt_name); - if(vtit == symbol_table.symbols.end()) + if(vtit==symbol_table.symbols.end()) { // first time: create a virtual-table symbol type symbolt vt_symb_type; vt_symb_type.name= vt_name; vt_symb_type.base_name="virtual_table::"+id2string(symbol.base_name); - vt_symb_type.pretty_name = vt_symb_type.base_name; + vt_symb_type.pretty_name=vt_symb_type.base_name; vt_symb_type.mode=ID_cpp; vt_symb_type.module=module; vt_symb_type.location=symbol.location; - vt_symb_type.type = struct_typet(); + vt_symb_type.type=struct_typet(); vt_symb_type.type.set(ID_name, vt_symb_type.name); - vt_symb_type.is_type = true; + vt_symb_type.is_type=true; - bool failed = symbol_table.move(vt_symb_type); + bool failed=symbol_table.move(vt_symb_type); assert(!failed); - vtit = symbol_table.symbols.find(vt_name); + vtit=symbol_table.symbols.find(vt_name); // add a virtual-table pointer struct_typet::componentt compo; - compo.type() = pointer_typet(symbol_typet(vt_name)); + compo.type()=pointer_typet(symbol_typet(vt_name)); compo.set_name(id2string(symbol.name) +"::@vtable_pointer"); compo.set(ID_base_name, "@vtable_pointer"); - compo.set(ID_pretty_name, id2string(symbol.base_name) +"@vtable_pointer"); + compo.set( + ID_pretty_name, + id2string(symbol.base_name) +"@vtable_pointer"); compo.set("is_vtptr", true); compo.set(ID_access, ID_public); components.push_back(compo); @@ -616,32 +623,33 @@ void cpp_typecheckt::typecheck_compound_declarator( // add an entry to the virtual table struct_typet::componentt vt_entry; - vt_entry.type() = pointer_typet(component.type()); + vt_entry.type()=pointer_typet(component.type()); vt_entry.set_name(id2string(vtit->first)+"::"+virtual_name); vt_entry.set(ID_base_name, virtual_name); vt_entry.set(ID_pretty_name, virtual_name); vt_entry.set(ID_access, ID_public); - vt_entry.add_source_location() = symbol.location; + vt_entry.add_source_location()=symbol.location; virtual_table.components().push_back(vt_entry); // take care of overloading while(!virtual_bases.empty()) { - irep_idt virtual_base = *virtual_bases.begin(); + irep_idt virtual_base=*virtual_bases.begin(); // a new function that does 'late casting' of the 'this' parameter symbolt func_symb; - func_symb.name=id2string(component.get_name()) + "::" +id2string(virtual_base); + func_symb.name= + id2string(component.get_name())+"::"+id2string(virtual_base); func_symb.base_name=component.get(ID_base_name); - func_symb.pretty_name = component.get(ID_base_name); + func_symb.pretty_name=component.get(ID_base_name); func_symb.mode=ID_cpp; func_symb.module=module; func_symb.location=component.source_location(); func_symb.type=component.type(); // change the type of the 'this' pointer - code_typet& code_type = to_code_type(func_symb.type); - code_typet::parametert& arg= code_type.parameters().front(); + code_typet &code_type=to_code_type(func_symb.type); + code_typet::parametert &arg= code_type.parameters().front(); arg.type().subtype().set(ID_identifier, virtual_base); // create symbols for the parameters @@ -649,28 +657,29 @@ void cpp_typecheckt::typecheck_compound_declarator( unsigned i=0; for(auto &arg : args) { - irep_idt base_name = arg.get_base_name(); + irep_idt base_name=arg.get_base_name(); if(base_name==irep_idt()) base_name="arg"+std::to_string(i++); symbolt arg_symb; - arg_symb.name = id2string(func_symb.name) + "::"+ id2string(base_name); - arg_symb.base_name = base_name; - arg_symb.pretty_name = base_name; + arg_symb.name=id2string(func_symb.name) + "::"+ id2string(base_name); + arg_symb.base_name=base_name; + arg_symb.pretty_name=base_name; arg_symb.mode=ID_cpp; arg_symb.location=func_symb.location; - arg_symb.type = arg.type(); + arg_symb.type=arg.type(); arg.set(ID_C_identifier, arg_symb.name); // add the parameter to the symbol table - bool failed = symbol_table.move(arg_symb); + bool failed=symbol_table.move(arg_symb); assert(!failed); } // do the body of the function - typecast_exprt late_cast(to_code_type(component.type()).parameters()[0].type()); + typecast_exprt late_cast( + to_code_type(component.type()).parameters()[0].type()); late_cast.op0()= namespacet(symbol_table).lookup( @@ -680,15 +689,17 @@ void cpp_typecheckt::typecheck_compound_declarator( code_type.return_type().id()!=ID_destructor) { side_effect_expr_function_callt expr_call; - expr_call.function() = symbol_exprt(component.get_name(),component.type()); - expr_call.type() = to_code_type(component.type()).return_type(); + expr_call.function()= + symbol_exprt(component.get_name(), component.type()); + expr_call.type()=to_code_type(component.type()).return_type(); expr_call.arguments().reserve(args.size()); expr_call.arguments().push_back(late_cast); for(unsigned i=1; i < args.size(); i++) { expr_call.arguments().push_back( - namespacet(symbol_table).lookup(args[i].get(ID_C_identifier)).symbol_expr()); + namespacet(symbol_table).lookup( + args[i].get(ID_C_identifier)).symbol_expr()); } func_symb.value=code_returnt(expr_call); @@ -696,7 +707,8 @@ void cpp_typecheckt::typecheck_compound_declarator( else { code_function_callt code_func; - code_func.function() = symbol_exprt(component.get_name(),component.type()); + code_func.function()= + symbol_exprt(component.get_name(), component.type()); code_func.arguments().reserve(args.size()); code_func.arguments().push_back(late_cast); @@ -707,19 +719,19 @@ void cpp_typecheckt::typecheck_compound_declarator( args[i].get(ID_C_identifier)).symbol_expr()); } - func_symb.value = code_func; + func_symb.value=code_func; } // add this new function to the list of components - struct_typet::componentt new_compo = component; - new_compo.type() = func_symb.type; + struct_typet::componentt new_compo=component; + new_compo.type()=func_symb.type; new_compo.set_name(func_symb.name); components.push_back(new_compo); // add the function to the symbol table { - bool failed = symbol_table.move(func_symb); + bool failed=symbol_table.move(func_symb); assert(!failed); } @@ -847,10 +859,10 @@ void cpp_typecheckt::put_compound_into_scope( id.id_class=compound.get_bool("is_type")?cpp_idt::TYPEDEF:cpp_idt::SYMBOL; id.identifier=name; id.class_identifier=cpp_scopes.current_scope().identifier; - id.is_member = true; + id.is_member=true; id.is_constructor = - compound.find(ID_type).get(ID_return_type) == ID_constructor; - id.is_method = true; + compound.find(ID_type).get(ID_return_type)==ID_constructor; + id.is_method=true; id.is_static_member=compound.get_bool(ID_is_static); // create function block-scope in the scope @@ -873,7 +885,8 @@ void cpp_typecheckt::put_compound_into_scope( // check if it's already there cpp_scopest::id_sett id_set; - cpp_scopes.current_scope().lookup(base_name, cpp_scopet::SCOPE_ONLY, id_set); + cpp_scopes.current_scope().lookup( + base_name, cpp_scopet::SCOPE_ONLY, id_set); for(const auto &id_it : id_set) { @@ -963,7 +976,7 @@ void cpp_typecheckt::typecheck_friend_declaration( for(auto &sub_it : declaration.declarators()) { - bool has_value = sub_it.value().is_not_nil(); + bool has_value=sub_it.value().is_not_nil(); if(!has_value) { @@ -973,24 +986,24 @@ void cpp_typecheckt::typecheck_friend_declaration( cpp_save_scopet saved_scope(cpp_scopes); cpp_scopes.go_to_global_scope(); cpp_declarator_convertert cpp_declarator_converter(*this); - const symbolt &conv_symb = cpp_declarator_converter.convert( + const symbolt &conv_symb=cpp_declarator_converter.convert( declaration.type(), declaration.storage_spec(), declaration.member_spec(), sub_it); - exprt symb_expr = cpp_symbol_expr(conv_symb); + exprt symb_expr=cpp_symbol_expr(conv_symb); symbol.type.add("#friends").move_to_sub(symb_expr); } else { cpp_declarator_convertert cpp_declarator_converter(*this); - cpp_declarator_converter.is_friend = true; + cpp_declarator_converter.is_friend=true; declaration.member_spec().set_inline(true); - const symbolt &conv_symb = cpp_declarator_converter.convert( + const symbolt &conv_symb=cpp_declarator_converter.convert( declaration.type(), declaration.storage_spec(), declaration.member_spec(), sub_it); - exprt symb_expr = cpp_symbol_expr(conv_symb); + exprt symb_expr=cpp_symbol_expr(conv_symb); symbol.type.add("#friends").move_to_sub(symb_expr); } @@ -1213,20 +1226,19 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol) check_member_initializers( type.add(ID_bases), type.components(), - declarator.member_initializers() - ); + declarator.member_initializers()); full_member_initialization( type, - declarator.member_initializers() - ); + declarator.member_initializers()); } // Finally, we typecheck the constructor with the // full member-initialization list - bool is_static=declaration.storage_spec().is_static(); // Shall be false - bool is_mutable=declaration.storage_spec().is_mutable(); // Shall be false - bool is_typedef=declaration.is_typedef(); // Shall be false + // Shall all be false + bool is_static=declaration.storage_spec().is_static(); + bool is_mutable=declaration.storage_spec().is_mutable(); + bool is_typedef=declaration.is_typedef(); typecheck_compound_declarator( symbol, @@ -1259,7 +1271,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol) exprt value("cpp_not_typechecked"); value.copy_to_operands(cpctor.declarators()[0].value()); - cpctor.declarators()[0].value() = value; + cpctor.declarators()[0].value()=value; typecheck_compound_declarator( symbol, @@ -1279,7 +1291,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol) // is actually used cpp_declaratort declarator; assignop.declarators().push_back(declarator); - assignop.declarators()[0].value() = exprt("cpp_not_typechecked"); + assignop.declarators()[0].value()=exprt("cpp_not_typechecked"); typecheck_compound_declarator( symbol, @@ -1672,7 +1684,7 @@ bool cpp_typecheckt::get_component( !component.get_bool("is_mutable")) member.type().set(ID_C_constant, true); - member.add_source_location() = source_location; + member.add_source_location()=source_location; return true; // component found } @@ -1706,7 +1718,7 @@ bool cpp_typecheckt::get_component( !component.get_bool("is_mutable")) member.type().set(ID_C_constant, true); - member.add_source_location() = source_location; + member.add_source_location()=source_location; return true; // component found } } @@ -1737,21 +1749,21 @@ bool cpp_typecheckt::check_component_access( if(access=="noaccess") return true; // not ok - if(access == ID_public) + if(access==ID_public) return false; // ok - assert(access == ID_private || - access == ID_protected); + assert(access==ID_private || + access==ID_protected); const irep_idt &struct_identifier= struct_union_type.get(ID_name); - cpp_scopet *pscope = &(cpp_scopes.current_scope()); + cpp_scopet *pscope=&(cpp_scopes.current_scope()); while(!(pscope->is_root_scope())) { if(pscope->is_class()) { - if(pscope->identifier == struct_identifier) + if(pscope->identifier==struct_identifier) return false; // ok const struct_typet &scope_struct= @@ -1763,7 +1775,7 @@ bool cpp_typecheckt::check_component_access( else break; } - pscope = &(pscope->get_parent()); + pscope=&(pscope->get_parent()); } // check friendship @@ -1772,26 +1784,26 @@ bool cpp_typecheckt::check_component_access( forall_irep(f_it, friends) { - const irept &friend_symb = *f_it; + const irept &friend_symb=*f_it; const cpp_scopet &friend_scope = cpp_scopes.get_scope(friend_symb.get(ID_identifier)); - cpp_scopet *pscope = &(cpp_scopes.current_scope()); + cpp_scopet *pscope=&(cpp_scopes.current_scope()); while(!(pscope->is_root_scope())) { - if(friend_scope.identifier == pscope->identifier) + if(friend_scope.identifier==pscope->identifier) return false; // ok if(pscope->is_class()) break; - pscope = &(pscope->get_parent()); + pscope=&(pscope->get_parent()); } } - return true; //not ok + return true; // not ok } /*******************************************************************\ @@ -1815,13 +1827,13 @@ void cpp_typecheckt::get_bases( forall_irep(it, bases) { assert(it->id()==ID_base); - assert(it->get(ID_type) == ID_symbol); + assert(it->get(ID_type)==ID_symbol); const struct_typet &base= to_struct_type(lookup(it->find(ID_type).get(ID_identifier)).type); set_bases.insert(base.get(ID_name)); - get_bases(base,set_bases); + get_bases(base, set_bases); } } @@ -1838,10 +1850,10 @@ Function: cpp_typecheckt::get_virtual_bases \*******************************************************************/ void cpp_typecheckt::get_virtual_bases( - const struct_typet& type, + const struct_typet &type, std::list &vbases) const { - if(std::find(vbases.begin(), vbases.end(), type.get(ID_name)) != vbases.end()) + if(std::find(vbases.begin(), vbases.end(), type.get(ID_name))!=vbases.end()) return; const irept::subt &bases=type.find(ID_bases).get_sub(); @@ -1849,7 +1861,7 @@ void cpp_typecheckt::get_virtual_bases( forall_irep(it, bases) { assert(it->id()==ID_base); - assert(it->get(ID_type) == ID_symbol); + assert(it->get(ID_type)==ID_symbol); const struct_typet &base= to_struct_type(lookup(it->find(ID_type).get(ID_identifier)).type); @@ -1857,7 +1869,7 @@ void cpp_typecheckt::get_virtual_bases( if(it->get_bool(ID_virtual)) vbases.push_back(base.get(ID_name)); - get_virtual_bases(base,vbases); + get_virtual_bases(base, vbases); } } @@ -1884,7 +1896,7 @@ bool cpp_typecheckt::subtype_typecast( get_bases(from, bases); - return bases.find(to.get(ID_name)) != bases.end(); + return bases.find(to.get(ID_name))!=bases.end(); } /*******************************************************************\ @@ -1901,9 +1913,9 @@ Function: cpp_typecheckt::make_ptr_subtypecast void cpp_typecheckt::make_ptr_typecast( exprt &expr, - const typet & dest_type) + const typet &dest_type) { - typet src_type = expr.type(); + typet src_type=expr.type(); assert(src_type.id()== ID_pointer); assert(dest_type.id()== ID_pointer); diff --git a/src/cpp/cpp_typecheck_constructor.cpp b/src/cpp/cpp_typecheck_constructor.cpp index 65e97dfd263..01cc9ca7123 100644 --- a/src/cpp/cpp_typecheck_constructor.cpp +++ b/src/cpp/cpp_typecheck_constructor.cpp @@ -49,10 +49,10 @@ static void copy_parent( op0.operands().push_back(exprt("cpp-this")); op0.type().id(ID_pointer); op0.type().subtype()=cpp_namet(parent_base_name, source_location).as_type(); - op0.add_source_location() = source_location; + op0.add_source_location()=source_location; code.operands().push_back(exprt("explicit-typecast")); - exprt &op1 = code.op1(); + exprt &op1=code.op1(); op1.type().id(ID_pointer); op1.type().set(ID_C_reference, true); @@ -63,7 +63,7 @@ static void copy_parent( op1.op0().get_sub().push_back(irept(ID_name)); op1.op0().get_sub().back().set(ID_identifier, arg_name); op1.op0().get_sub().back().set(ID_C_source_location, source_location); - op1.add_source_location() = source_location; + op1.add_source_location()=source_location; } /*******************************************************************\ @@ -93,10 +93,10 @@ static void copy_member( code.operands().push_back(exprt(ID_side_effect)); code.op0().set(ID_statement, ID_assign); code.op0().operands().push_back(exprt(ID_cpp_name)); - code.add_source_location() = source_location; + code.add_source_location()=source_location; - exprt &op0 = code.op0().op0(); - op0.add_source_location() = source_location; + exprt &op0=code.op0().op0(); + op0.add_source_location()=source_location; op0.get_sub().push_back(irept(ID_name)); op0.get_sub().back().set(ID_identifier, member_base_name); @@ -104,18 +104,20 @@ static void copy_member( code.op0().operands().push_back(exprt(ID_member)); - exprt &op1 = code.op0().op1(); + exprt &op1=code.op0().op1(); op1.add(ID_component_cpp_name).id(ID_cpp_name); op1.add(ID_component_cpp_name).get_sub().push_back(irept(ID_name)); - op1.add(ID_component_cpp_name).get_sub().back().set(ID_identifier, member_base_name); - op1.add(ID_component_cpp_name).get_sub().back().set(ID_C_source_location, source_location); + op1.add(ID_component_cpp_name).get_sub().back().set( + ID_identifier, member_base_name); + op1.add(ID_component_cpp_name).get_sub().back().set( + ID_C_source_location, source_location); op1.operands().push_back(exprt(ID_cpp_name)); op1.op0().get_sub().push_back(irept(ID_name)); op1.op0().get_sub().back().set(ID_identifier, arg_name); op1.op0().get_sub().back().set(ID_C_source_location, source_location); - op1.add_source_location() = source_location; + op1.add_source_location()=source_location; } /*******************************************************************\ @@ -143,17 +145,17 @@ static void copy_array( exprt constant=from_integer(i, index_type()); block.operands().push_back(exprt(ID_code)); - exprt& code = block.operands().back(); - code.add_source_location() = source_location; + exprt &code=block.operands().back(); + code.add_source_location()=source_location; code.set(ID_statement, ID_expression); code.add(ID_type)=typet(ID_code); code.operands().push_back(exprt(ID_side_effect)); code.op0().set(ID_statement, ID_assign); code.op0().operands().push_back(exprt(ID_index)); - exprt& op0 = code.op0().op0(); + exprt &op0=code.op0().op0(); op0.operands().push_back(exprt(ID_cpp_name)); - op0.add_source_location() = source_location; + op0.add_source_location()=source_location; op0.op0().get_sub().push_back(irept(ID_name)); op0.op0().get_sub().back().set(ID_identifier, member_base_name); @@ -162,12 +164,14 @@ static void copy_array( code.op0().operands().push_back(exprt(ID_index)); - exprt& op1 = code.op0().op1(); + exprt &op1=code.op0().op1(); op1.operands().push_back(exprt(ID_member)); op1.op0().add(ID_component_cpp_name).id(ID_cpp_name); op1.op0().add(ID_component_cpp_name).get_sub().push_back(irept(ID_name)); - op1.op0().add(ID_component_cpp_name).get_sub().back().set(ID_identifier, member_base_name); - op1.op0().add(ID_component_cpp_name).get_sub().back().set(ID_C_source_location, source_location); + op1.op0().add(ID_component_cpp_name).get_sub().back().set( + ID_identifier, member_base_name); + op1.op0().add(ID_component_cpp_name).get_sub().back().set( + ID_C_source_location, source_location); op1.op0().operands().push_back(exprt(ID_cpp_name)); op1.op0().op0().get_sub().push_back(irept(ID_name)); @@ -175,7 +179,7 @@ static void copy_array( op1.op0().op0().get_sub().back().set(ID_C_source_location, source_location); op1.copy_to_operands(constant); - op1.add_source_location() = source_location; + op1.add_source_location()=source_location; } /*******************************************************************\ @@ -197,14 +201,14 @@ void cpp_typecheckt::default_ctor( { exprt name(ID_name); name.set(ID_identifier, base_name); - name.add_source_location() = source_location; + name.add_source_location()=source_location; cpp_declaratort decl; decl.name().id(ID_cpp_name); decl.name().move_to_sub(name); decl.type()=typet(ID_function_type); decl.type().subtype().make_nil(); - decl.add_source_location() = source_location; + decl.add_source_location()=source_location; decl.value().id(ID_code); decl.value().type()=typet(ID_code); @@ -215,7 +219,7 @@ void cpp_typecheckt::default_ctor( ctor.type().id(ID_constructor); ctor.add(ID_storage_spec).id(ID_cpp_storage_spec); ctor.move_to_operands(decl); - ctor.add_source_location() = source_location; + ctor.add_source_location()=source_location; } /*******************************************************************\ @@ -234,7 +238,7 @@ void cpp_typecheckt::default_cpctor( const symbolt &symbol, cpp_declarationt &cpctor) const { - source_locationt source_location = symbol.type.source_location(); + source_locationt source_location=symbol.type.source_location(); source_location.set_function( id2string(symbol.base_name)+ @@ -243,7 +247,7 @@ void cpp_typecheckt::default_cpctor( // Produce default constructor first default_ctor(source_location, symbol.base_name, cpctor); - cpp_declaratort &decl0 = cpctor.declarators()[0]; + cpp_declaratort &decl0=cpctor.declarators()[0]; std::string param_identifier("ref"); @@ -269,34 +273,35 @@ void cpp_typecheckt::default_cpctor( parameter_tor.set(ID_name, cpp_parameter); parameter_tor.type()=reference_typet(); parameter_tor.type().subtype().make_nil(); - parameter_tor.add_source_location() = source_location; + parameter_tor.add_source_location()=source_location; // Parameter declaration cpp_declarationt parameter_decl; parameter_decl.set(ID_type, ID_merged_type); - typet::subtypest &sub = parameter_decl.type().subtypes(); - sub.push_back(static_cast(static_cast(cppcomp))); + typet::subtypest &sub=parameter_decl.type().subtypes(); + sub.push_back( + static_cast(static_cast(cppcomp))); irept constnd(ID_const); sub.push_back(static_cast(constnd)); parameter_decl.move_to_operands(parameter_tor); - parameter_decl.add_source_location() = source_location; + parameter_decl.add_source_location()=source_location; // Add parameter to function type decl0.add(ID_type).add(ID_parameters).get_sub().push_back(parameter_decl); - decl0.add_source_location() = source_location; + decl0.add_source_location()=source_location; - irept &initializers = decl0.add(ID_member_initializers); + irept &initializers=decl0.add(ID_member_initializers); initializers.id(ID_member_initializers); - cpp_declaratort &declarator = static_cast(cpctor.op0()); - exprt &block = declarator.value(); + cpp_declaratort &declarator=static_cast(cpctor.op0()); + exprt &block=declarator.value(); // First, we need to call the parent copy constructors - const irept &bases = symbol.type.find(ID_bases); + const irept &bases=symbol.type.find(ID_bases); forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->id() == ID_base); - assert(parent_it->get(ID_type) == ID_symbol); + assert(parent_it->id()==ID_base); + assert(parent_it->get(ID_type)==ID_symbol); const symbolt &parsymb= lookup(parent_it->find(ID_type).get(ID_identifier)); @@ -305,49 +310,53 @@ void cpp_typecheckt::default_cpctor( copy_parent(source_location, parsymb.base_name, param_identifier, block); else { - irep_idt ctor_name = parsymb.base_name; + irep_idt ctor_name=parsymb.base_name; // Call the parent default copy constructor exprt name(ID_name); name.set(ID_identifier, ctor_name); - name.add_source_location() = source_location; + name.add_source_location()=source_location; cpp_namet cppname; cppname.move_to_sub(name); codet mem_init(ID_member_initializer); - mem_init.add_source_location() = source_location; + mem_init.add_source_location()=source_location; mem_init.set(ID_member, cppname); - mem_init.copy_to_operands(static_cast(static_cast(cpp_parameter))); + mem_init.copy_to_operands( + static_cast(static_cast(cpp_parameter))); initializers.move_to_sub(mem_init); } } // Then, we add the member initializers - const struct_typet::componentst& components = to_struct_type(symbol.type).components(); - for(struct_typet::componentst::const_iterator mem_it = components.begin(); - mem_it != components.end(); mem_it++) + const struct_typet::componentst &components= + to_struct_type(symbol.type).components(); + for(struct_typet::componentst::const_iterator mem_it=components.begin(); + mem_it!=components.end(); mem_it++) { // Take care of virtual tables if(mem_it->get_bool("is_vtptr")) { exprt name(ID_name); - name.set(ID_identifier,mem_it->get(ID_base_name)); + name.set(ID_identifier, mem_it->get(ID_base_name)); name.add_source_location()=source_location; cpp_namet cppname; cppname.move_to_sub(name); const symbolt &virtual_table_symbol_type = - namespacet(symbol_table).lookup(mem_it->type().subtype().get(ID_identifier)); + namespacet(symbol_table).lookup( + mem_it->type().subtype().get(ID_identifier)); const symbolt &virtual_table_symbol_var = - namespacet(symbol_table).lookup(id2string(virtual_table_symbol_type.name) + "@" + + namespacet(symbol_table).lookup( + id2string(virtual_table_symbol_type.name) + "@" + id2string(symbol.name)); - exprt var = virtual_table_symbol_var.symbol_expr(); + exprt var=virtual_table_symbol_var.symbol_expr(); address_of_exprt address(var); - assert(address.type() == mem_it->type()); + assert(address.type()==mem_it->type()); already_typechecked(address); @@ -363,26 +372,27 @@ void cpp_typecheckt::default_cpctor( if( mem_it->get_bool("from_base") || mem_it->get_bool(ID_is_type) || mem_it->get_bool(ID_is_static) - || mem_it->type().id() == ID_code) + || mem_it->type().id()==ID_code) continue; - irep_idt mem_name = mem_it->get(ID_base_name); + irep_idt mem_name=mem_it->get(ID_base_name); exprt name(ID_name); name.set(ID_identifier, mem_name); - name.add_source_location() = source_location; + name.add_source_location()=source_location; cpp_namet cppname; cppname.move_to_sub(name); codet mem_init(ID_member_initializer); mem_init.set(ID_member, cppname); - mem_init.add_source_location() = source_location; + mem_init.add_source_location()=source_location; exprt memberexpr(ID_member); memberexpr.set(ID_component_cpp_name, cppname); - memberexpr.copy_to_operands(static_cast(static_cast(cpp_parameter))); - memberexpr.add_source_location() = source_location; + memberexpr.copy_to_operands( + static_cast(static_cast(cpp_parameter))); + memberexpr.add_source_location()=source_location; if(mem_it->type().id()==ID_array) memberexpr.set("#array_ini", true); @@ -406,10 +416,10 @@ Function: cpp_typecheckt::default_assignop \*******************************************************************/ void cpp_typecheckt::default_assignop( - const symbolt& symbol, - cpp_declarationt& cpctor) + const symbolt &symbol, + cpp_declarationt &cpctor) { - source_locationt source_location = symbol.type.source_location(); + source_locationt source_location=symbol.type.source_location(); source_location.set_function( id2string(symbol.base_name) @@ -423,15 +433,15 @@ void cpp_typecheckt::default_assignop( cpctor.type().id(ID_symbol); cpctor.type().add(ID_identifier).id(symbol.name); cpctor.operands().push_back(exprt(ID_cpp_declarator)); - cpctor.add_source_location() = source_location; + cpctor.add_source_location()=source_location; - cpp_declaratort &declarator = (cpp_declaratort&) cpctor.op0(); - declarator.add_source_location() = source_location; + cpp_declaratort &declarator=(cpp_declaratort&) cpctor.op0(); + declarator.add_source_location()=source_location; - cpp_namet &declarator_name = declarator.name(); - typet &declarator_type = declarator.type(); + cpp_namet &declarator_name=declarator.name(); + typet &declarator_type=declarator.type(); - declarator_type.add_source_location() = source_location; + declarator_type.add_source_location()=source_location; declarator_name.id(ID_cpp_name); declarator_name.get_sub().push_back(irept(ID_operator)); @@ -442,32 +452,35 @@ void cpp_typecheckt::default_assignop( declarator_type.subtype().add("#qualifier").make_nil(); declarator_type.subtype().subtype().make_nil(); - exprt& args = (exprt&) declarator.type().add(ID_parameters); - args.add_source_location() = source_location; + exprt &args=static_cast(declarator.type().add(ID_parameters)); + args.add_source_location()=source_location; args.get_sub().push_back(irept(ID_cpp_declaration)); - cpp_declarationt& args_decl = (cpp_declarationt&) args.get_sub().back(); + cpp_declarationt &args_decl= + static_cast(args.get_sub().back()); - typet::subtypest & args_decl_type_sub = args_decl.type().subtypes(); + typet::subtypest &args_decl_type_sub=args_decl.type().subtypes(); args_decl.type().id(ID_merged_type); args_decl_type_sub.push_back(typet(ID_cpp_name)); args_decl_type_sub.back().get_sub().push_back(irept(ID_name)); - args_decl_type_sub.back().get_sub().back().set(ID_identifier, symbol.base_name); - args_decl_type_sub.back().get_sub().back().set(ID_C_source_location, source_location); + args_decl_type_sub.back().get_sub().back().set( + ID_identifier, symbol.base_name); + args_decl_type_sub.back().get_sub().back().set( + ID_C_source_location, source_location); args_decl_type_sub.push_back(typet(ID_const)); args_decl.operands().push_back(exprt(ID_cpp_declarator)); - args_decl.add_source_location() = source_location; + args_decl.add_source_location()=source_location; cpp_declaratort &args_decl_declor= - (cpp_declaratort&) args_decl.operands().back(); + static_cast(args_decl.operands().back()); args_decl_declor.name().id(ID_cpp_name); args_decl_declor.name().get_sub().push_back(irept(ID_name)); args_decl_declor.name().get_sub().back().add(ID_identifier).id(arg_name); - args_decl_declor.add_source_location() = source_location; + args_decl_declor.add_source_location()=source_location; args_decl_declor.type().id(ID_pointer); args_decl_declor.type().set(ID_C_reference, true); @@ -505,12 +518,12 @@ void cpp_typecheckt::default_assignop_value( std::string arg_name("ref"); // First, we copy the parents - const irept &bases = symbol.type.find(ID_bases); + const irept &bases=symbol.type.find(ID_bases); forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->id() == ID_base); - assert(parent_it->get(ID_type) == ID_symbol); + assert(parent_it->id()==ID_base); + assert(parent_it->get(ID_type)==ID_symbol); const symbolt &symb= lookup(parent_it->find(ID_type).get(ID_identifier)); @@ -546,13 +559,13 @@ void cpp_typecheckt::default_assignop_value( } mp_integer size; - bool to_int = to_integer(size_expr, size); + bool to_int=to_integer(size_expr, size); assert(!to_int); assert(size>=0); exprt::operandst empty_operands; - for(mp_integer i = 0; i < size; ++i) - copy_array(source_location, mem_name,i,arg_name,block); + for(mp_integer i=0; i < size; ++i) + copy_array(source_location, mem_name, i, arg_name, block); } else copy_member(source_location, mem_name, arg_name, block); @@ -560,7 +573,7 @@ void cpp_typecheckt::default_assignop_value( // Finally we add the return statement block.operands().push_back(exprt(ID_code)); - exprt &ret_code = declarator.value().operands().back(); + exprt &ret_code=declarator.value().operands().back(); ret_code.operands().push_back(exprt(ID_dereference)); ret_code.op0().operands().push_back(exprt("cpp-this")); ret_code.set(ID_statement, ID_return); @@ -590,36 +603,36 @@ void cpp_typecheckt::check_member_initializers( const struct_typet::componentst &components, const irept &initializers) { - assert(initializers.id() == ID_member_initializers); + assert(initializers.id()==ID_member_initializers); forall_irep(init_it, initializers.get_sub()) { - const irept &initializer = *init_it; + const irept &initializer=*init_it; assert(initializer.is_not_nil()); - assert(initializer.get(ID_member) == ID_cpp_name); + assert(initializer.get(ID_member)==ID_cpp_name); const cpp_namet &member_name= to_cpp_name(initializer.find(ID_member)); - bool has_template_args = member_name.has_template_args(); + bool has_template_args=member_name.has_template_args(); if(has_template_args) { // it has to be a parent constructor - typet member_type = (typet&) initializer.find(ID_member); + typet member_type=(typet&) initializer.find(ID_member); typecheck_type(member_type); // check for a direct parent - bool ok = false; + bool ok=false; forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->get(ID_type) == ID_symbol); + assert(parent_it->get(ID_type)==ID_symbol); if(member_type.get(ID_identifier) - == parent_it->find(ID_type).get(ID_identifier)) + ==parent_it->find(ID_type).get(ID_identifier)) { - ok = true; + ok=true; break; } } @@ -635,42 +648,43 @@ void cpp_typecheckt::check_member_initializers( } irep_idt base_name=member_name.get_base_name(); - bool ok = false; + bool ok=false; for(struct_typet::componentst::const_iterator c_it=components.begin(); c_it!=components.end(); c_it++) { - if(c_it->get(ID_base_name)!=base_name ) continue; + if(c_it->get(ID_base_name)!=base_name) + continue; // Data member if(!c_it->get_bool(ID_from_base) && !c_it->get_bool(ID_is_static) && - c_it->get(ID_type) != ID_code) + c_it->get(ID_type)!=ID_code) { - ok = true; + ok=true; break; } // Maybe it is a parent constructor? if(c_it->get_bool("is_type")) { - typet type = static_cast(c_it->find(ID_type)); - if(type.id() != ID_symbol) + typet type=static_cast(c_it->find(ID_type)); + if(type.id()!=ID_symbol) continue; - const symbolt& symb = lookup(type.get(ID_identifier)); - if(symb.type.id() != ID_struct) + const symbolt &symb=lookup(type.get(ID_identifier)); + if(symb.type.id()!=ID_struct) break; // check for a direct parent forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->get(ID_type) == ID_symbol ); - if(symb.name == parent_it->find(ID_type).get(ID_identifier)) + assert(parent_it->get(ID_type)==ID_symbol); + if(symb.name==parent_it->find(ID_type).get(ID_identifier)) { - ok = true; + ok=true; break; } } @@ -678,24 +692,24 @@ void cpp_typecheckt::check_member_initializers( } // Parent constructor - if( c_it->get_bool(ID_from_base) - && !c_it->get_bool(ID_is_type) - && !c_it->get_bool(ID_is_static) - && c_it->get(ID_type) == ID_code - && c_it->find(ID_type).get(ID_return_type) == ID_constructor) + if(c_it->get_bool(ID_from_base) && + !c_it->get_bool(ID_is_type) && + !c_it->get_bool(ID_is_static) && + c_it->get(ID_type)==ID_code && + c_it->find(ID_type).get(ID_return_type)==ID_constructor) { - typet member_type = (typet&) initializer.find(ID_member); + typet member_type=(typet&) initializer.find(ID_member); typecheck_type(member_type); // check for a direct parent forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->get(ID_type) == ID_symbol ); + assert(parent_it->get(ID_type)==ID_symbol); - if(member_type.get(ID_identifier) - == parent_it->find(ID_type).get(ID_identifier)) + if(member_type.get(ID_identifier)== + parent_it->find(ID_type).get(ID_identifier)) { - ok = true; + ok=true; break; } } @@ -736,7 +750,7 @@ void cpp_typecheckt::full_member_initialization( const struct_union_typet::componentst &components= struct_union_type.components(); - assert(initializers.id() == ID_member_initializers); + assert(initializers.id()==ID_member_initializers); irept final_initializers(ID_member_initializers); @@ -765,7 +779,7 @@ void cpp_typecheckt::full_member_initialization( while(!vbases.empty()) { - const symbolt& symb = lookup(vbases.front()); + const symbolt &symb=lookup(vbases.front()); if(!cpp_is_pod(symb.type)) { // default initializer @@ -790,8 +804,8 @@ void cpp_typecheckt::full_member_initialization( // Subsequenlty, we need to call the non-POD parent constructors forall_irep(parent_it, bases.get_sub()) { - assert(parent_it->id() == ID_base); - assert(parent_it->get(ID_type) == ID_symbol); + assert(parent_it->id()==ID_base); + assert(parent_it->get(ID_type)==ID_symbol); const symbolt &ctorsymb= lookup(parent_it->find(ID_type).get(ID_identifier)); @@ -803,34 +817,34 @@ void cpp_typecheckt::full_member_initialization( // Check if the initialization list of the constructor // explicitly calls the parent constructor. - bool found = false; + bool found=false; forall_irep(m_it, initializers.get_sub()) { - irept initializer = *m_it; + irept initializer=*m_it; - assert(initializer.get(ID_member) == ID_cpp_name); + assert(initializer.get(ID_member)==ID_cpp_name); const cpp_namet &member_name= to_cpp_name(initializer.find(ID_member)); - bool has_template_args = member_name.has_template_args(); + bool has_template_args=member_name.has_template_args(); if(!has_template_args) { irep_idt base_name=member_name.get_base_name(); // check if the initializer is a data - bool is_data = false; + bool is_data=false; for(struct_typet::componentst::const_iterator c_it = - components.begin(); c_it != components.end(); c_it++) + components.begin(); c_it!=components.end(); c_it++) { if(c_it->get(ID_base_name)==base_name && c_it->get(ID_type)!=ID_code && !c_it->get_bool(ID_is_type)) { - is_data = true; + is_data=true; break; } } @@ -851,7 +865,7 @@ void cpp_typecheckt::full_member_initialization( member_type.get(ID_identifier)) { final_initializers.move_to_sub(initializer); - found = true; + found=true; break; } } @@ -896,28 +910,28 @@ void cpp_typecheckt::full_member_initialization( // Then, we add the member initializers for(struct_typet::componentst::const_iterator mem_it = - components.begin(); mem_it != components.end(); mem_it++) + components.begin(); mem_it!=components.end(); mem_it++) { // Take care of virtual tables if(mem_it->get_bool("is_vtptr")) { exprt name(ID_name); - name.set(ID_identifier,mem_it->get(ID_base_name)); - name.add_source_location() = mem_it->source_location(); + name.set(ID_identifier, mem_it->get(ID_base_name)); + name.add_source_location()=mem_it->source_location(); cpp_namet cppname; cppname.move_to_sub(name); - const symbolt& virtual_table_symbol_type = + const symbolt &virtual_table_symbol_type = lookup(mem_it->type().subtype().get(ID_identifier)); - const symbolt& virtual_table_symbol_var = + const symbolt &virtual_table_symbol_var = lookup(id2string(virtual_table_symbol_type.name) + "@" + id2string(struct_union_type.get(ID_name))); - exprt var = virtual_table_symbol_var.symbol_expr(); + exprt var=virtual_table_symbol_var.symbol_expr(); address_of_exprt address(var); - assert(address.type() == mem_it->type()); + assert(address.type()==mem_it->type()); already_typechecked(address); @@ -931,21 +945,22 @@ void cpp_typecheckt::full_member_initialization( } if( mem_it->get_bool(ID_from_base) - || mem_it->type().id() == ID_code + || mem_it->type().id()==ID_code || mem_it->get_bool(ID_is_type) || mem_it->get_bool(ID_is_static)) continue; - irep_idt mem_name = mem_it->get(ID_base_name); + irep_idt mem_name=mem_it->get(ID_base_name); // Check if the initialization list of the constructor // explicitly initializes the data member - bool found = false; + bool found=false; Forall_irep(m_it, initializers.get_sub()) { - irept &initializer = *m_it; + irept &initializer=*m_it; - if(initializer.get(ID_member)!=ID_cpp_name) continue; + if(initializer.get(ID_member)!=ID_cpp_name) + continue; cpp_namet &member_name=(cpp_namet&) initializer.add(ID_member); if(member_name.has_template_args()) @@ -956,7 +971,7 @@ void cpp_typecheckt::full_member_initialization( if(mem_name==base_name) { final_initializers.move_to_sub(initializer); - found = true; + found=true; break; } } @@ -1010,8 +1025,8 @@ Function: find_cpctor bool cpp_typecheckt::find_cpctor(const symbolt &symbol) const { - const struct_typet &struct_type = to_struct_type(symbol.type); - const struct_typet::componentst &components = struct_type.components(); + const struct_typet &struct_type=to_struct_type(symbol.type); + const struct_typet::componentst &components=struct_type.components(); for(struct_typet::componentst::const_iterator cit=components.begin(); @@ -1019,17 +1034,17 @@ bool cpp_typecheckt::find_cpctor(const symbolt &symbol) const cit++) { // Skip non-ctor - const struct_typet::componentt& component = *cit; + const struct_typet::componentt &component=*cit; - if(component.type().id() != ID_code - || to_code_type(component.type()).return_type().id() !=ID_constructor) + if(component.type().id()!=ID_code || + to_code_type(component.type()).return_type().id() !=ID_constructor) continue; // Skip inherited constructor if(component.get_bool(ID_from_base)) continue; - const code_typet& code_type = to_code_type(component.type()); + const code_typet &code_type=to_code_type(component.type()); const code_typet::parameterst ¶meters=code_type.parameters(); @@ -1038,7 +1053,7 @@ bool cpp_typecheckt::find_cpctor(const symbolt &symbol) const if(parameters.size() < 2) continue; - const code_typet::parametert ¶meter1 = parameters[1]; + const code_typet::parametert ¶meter1=parameters[1]; const typet ¶meter1_type=parameter1.type(); @@ -1048,7 +1063,7 @@ bool cpp_typecheckt::find_cpctor(const symbolt &symbol) const if(parameter1_type.subtype().get(ID_identifier)!=symbol.name) continue; - bool defargs = true; + bool defargs=true; for(std::size_t i=2; i= config.ansi_c.int_width) return false; - new_expr = expr; + new_expr=expr; new_expr.make_typecast(int_type); return true; } @@ -265,7 +265,7 @@ bool cpp_typecheckt::standard_conversion_integral_promotion( std::size_t width=to_unsignedbv_type(expr.type()).get_width(); if(width >= config.ansi_c.int_width) return false; - new_expr = expr; + new_expr=expr; if(width==config.ansi_c.int_width) int_type.id(ID_unsignedbv); new_expr.make_typecast(int_type); @@ -382,7 +382,7 @@ bool cpp_typecheckt::standard_conversion_integral_conversion( c_qualifierst qual_from; qual_from.read(expr.type()); - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); qual_from.write(new_expr.type()); @@ -445,7 +445,7 @@ bool cpp_typecheckt::standard_conversion_floating_integral_conversion( c_qualifierst qual_from; qual_from.read(expr.type()); - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); qual_from.write(new_expr.type()); @@ -497,7 +497,7 @@ bool cpp_typecheckt::standard_conversion_floating_point_conversion( c_qualifierst qual_from; qual_from.read(expr.type()); - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); qual_from.write(new_expr.type()); @@ -561,9 +561,9 @@ bool cpp_typecheckt::standard_conversion_pointer( if(simplify_expr(expr, *this).is_zero() && expr.type().id()!=ID_pointer) { - new_expr = expr; + new_expr=expr; new_expr.set(ID_value, ID_NULL); - new_expr.type() = type; + new_expr.type()=type; return true; } @@ -574,8 +574,8 @@ bool cpp_typecheckt::standard_conversion_pointer( expr.type().find("to-member").is_not_nil()) return false; - typet sub_from = follow(expr.type().subtype()); - typet sub_to = follow(type.subtype()); + typet sub_from=follow(expr.type().subtype()); + typet sub_to=follow(type.subtype()); // std::nullptr_t to _any_ pointer type if(sub_from.id()==ID_nullptr) @@ -586,7 +586,7 @@ bool cpp_typecheckt::standard_conversion_pointer( { c_qualifierst qual_from; qual_from.read(expr.type().subtype()); - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); qual_from.write(new_expr.type().subtype()); return true; @@ -595,13 +595,13 @@ bool cpp_typecheckt::standard_conversion_pointer( // struct * to struct * if(sub_from.id()==ID_struct && sub_to.id()==ID_struct) { - const struct_typet& from_struct = to_struct_type(sub_from); - const struct_typet& to_struct = to_struct_type(sub_to); + const struct_typet &from_struct=to_struct_type(sub_from); + const struct_typet &to_struct=to_struct_type(sub_to); if(subtype_typecast(from_struct, to_struct)) { c_qualifierst qual_from; qual_from.read(expr.type().subtype()); - new_expr = expr; + new_expr=expr; make_ptr_typecast(new_expr, type); qual_from.write(new_expr.type().subtype()); return true; @@ -671,15 +671,15 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member( if(type.subtype().id()==ID_code && expr.type().subtype().id()==ID_code) { - code_typet code1 = to_code_type(expr.type().subtype()); + code_typet code1=to_code_type(expr.type().subtype()); assert(code1.parameters().size()>0); - code_typet::parametert this1 = code1.parameters()[0]; + code_typet::parametert this1=code1.parameters()[0]; assert(this1.get(ID_C_base_name)==ID_this); code1.parameters().erase(code1.parameters().begin()); - code_typet code2 = to_code_type(type.subtype()); + code_typet code2=to_code_type(type.subtype()); assert(code2.parameters().size()>0); - code_typet::parametert this2 = code2.parameters()[0]; + code_typet::parametert this2=code2.parameters()[0]; assert(this2.get(ID_C_base_name)==ID_this); code2.parameters().erase(code2.parameters().begin()); @@ -701,7 +701,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member( if(expr.id()==ID_constant && expr.get(ID_value)==ID_NULL) { - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); return true; } @@ -716,7 +716,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member( if(subtype_typecast(to_struct, from_struct)) { - new_expr = expr; + new_expr=expr; new_expr.make_typecast(type); return true; } @@ -868,7 +868,8 @@ bool cpp_typecheckt::standard_conversion_sequence( { if(!standard_conversion_integral_conversion(curr_expr, type, new_expr)) { - if(!standard_conversion_floating_integral_conversion(curr_expr, type, new_expr)) + if(!standard_conversion_floating_integral_conversion( + curr_expr, type, new_expr)) return false; } @@ -882,8 +883,10 @@ bool cpp_typecheckt::standard_conversion_sequence( if(!standard_conversion_floating_point_promotion(curr_expr, new_expr) || new_expr.type() != type) { - if(!standard_conversion_floating_point_conversion(curr_expr, type, new_expr) && - !standard_conversion_floating_integral_conversion(curr_expr, type, new_expr)) + if(!standard_conversion_floating_point_conversion( + curr_expr, type, new_expr) && + !standard_conversion_floating_integral_conversion( + curr_expr, type, new_expr)) return false; rank += 3; @@ -908,7 +911,7 @@ bool cpp_typecheckt::standard_conversion_sequence( } else if(type.id()==ID_bool) { - if(!standard_conversion_boolean(curr_expr,new_expr)) + if(!standard_conversion_boolean(curr_expr, new_expr)) return false; rank += 3; @@ -917,7 +920,7 @@ bool cpp_typecheckt::standard_conversion_sequence( return false; } else - new_expr = curr_expr; + new_expr=curr_expr; curr_expr.swap(new_expr); @@ -928,9 +931,9 @@ bool cpp_typecheckt::standard_conversion_sequence( do { - typet tmp_from = sub_from.subtype(); + typet tmp_from=sub_from.subtype(); sub_from.swap(tmp_from); - typet tmp_to = sub_to.subtype(); + typet tmp_to=sub_to.subtype(); sub_to.swap(tmp_to); c_qualifierst qual_from; @@ -944,7 +947,6 @@ bool cpp_typecheckt::standard_conversion_sequence( rank+=1; break; } - } while(sub_from.id()==ID_pointer); @@ -953,8 +955,8 @@ bool cpp_typecheckt::standard_conversion_sequence( } else { - new_expr = curr_expr; - new_expr.type() = type; + new_expr=curr_expr; + new_expr.type()=type; } return true; @@ -983,8 +985,8 @@ bool cpp_typecheckt::user_defined_conversion_sequence( assert(!is_reference(expr.type())); assert(!is_reference(type)); - const typet &from = follow(expr.type()); - const typet &to = follow(type); + const typet &from=follow(expr.type()); + const typet &to=follow(type); new_expr.make_nil(); @@ -1015,14 +1017,14 @@ bool cpp_typecheckt::user_defined_conversion_sequence( { exprt address(ID_address_of, pointer_typet()); address.copy_to_operands(expr); - address.type().subtype() = expr.type(); + address.type().subtype()=expr.type(); // simplify address if(expr.id()==ID_dereference) address=expr.op0(); pointer_typet ptr_sub; - ptr_sub.subtype() = type; + ptr_sub.subtype()=type; c_qualifierst qual_from; qual_from.read(expr.type()); qual_from.write(ptr_sub.subtype()); @@ -1030,7 +1032,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence( exprt deref(ID_dereference); deref.copy_to_operands(address); - deref.type() = address.type().subtype(); + deref.type()=address.type().subtype(); // create temporary object exprt tmp_object_expr=exprt(ID_side_effect, type); @@ -1054,14 +1056,14 @@ bool cpp_typecheckt::user_defined_conversion_sequence( struct_typet to_struct=to_struct_type(to); - bool found = false; + bool found=false; for(struct_typet::componentst::const_iterator - it = to_struct.components().begin(); + it=to_struct.components().begin(); it != to_struct.components().end(); it++) { - const irept& component = *it; + const irept &component=*it; if(component.get_bool(ID_from_base)) continue; @@ -1069,7 +1071,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence( if(component.get_bool("is_explicit")) continue; - const typet& comp_type = + const typet &comp_type = static_cast(component.find(ID_type)); if(comp_type.id() !=ID_code) @@ -1080,13 +1082,13 @@ bool cpp_typecheckt::user_defined_conversion_sequence( // TODO: ellipsis - const irept ¶meters = comp_type.find(ID_parameters); + const irept ¶meters=comp_type.find(ID_parameters); if(parameters.get_sub().size() != 2) continue; - exprt curr_arg1 = static_cast (parameters.get_sub()[1]); - typet arg1_type = curr_arg1.type(); + exprt curr_arg1=static_cast (parameters.get_sub()[1]); + typet arg1_type=curr_arg1.type(); if(is_reference(arg1_type)) { @@ -1097,29 +1099,30 @@ bool cpp_typecheckt::user_defined_conversion_sequence( struct_typet arg1_struct; arg1_struct.make_nil(); { - typet tmp = follow(arg1_type); + typet tmp=follow(arg1_type); if(tmp.id()==ID_struct) - arg1_struct = to_struct_type(tmp); + arg1_struct=to_struct_type(tmp); } - unsigned tmp_rank = 0; + unsigned tmp_rank=0; if(arg1_struct.is_nil()) { exprt tmp_expr; - if(standard_conversion_sequence(expr, arg1_type, tmp_expr, tmp_rank)) + if(standard_conversion_sequence( + expr, arg1_type, tmp_expr, tmp_rank)) { // check if it's ambiguous if(found) return false; - found = true; + found=true; if(expr.get_bool(ID_C_lvalue)) tmp_expr.set(ID_C_lvalue, true); - tmp_expr.add_source_location() = expr.source_location(); + tmp_expr.add_source_location()=expr.source_location(); - exprt func_symb = cpp_symbol_expr(lookup(component.get(ID_name))); - func_symb.type() = comp_type; + exprt func_symb=cpp_symbol_expr(lookup(component.get(ID_name))); + func_symb.type()=comp_type; { exprt tmp("already_typechecked"); tmp.copy_to_operands(func_symb); @@ -1128,7 +1131,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence( // create temporary object side_effect_expr_function_callt ctor_expr; - ctor_expr.add_source_location() = expr.source_location(); + ctor_expr.add_source_location()=expr.source_location(); ctor_expr.function().swap(func_symb); ctor_expr.arguments().push_back(tmp_expr); typecheck_side_effect_function_call(ctor_expr); @@ -1146,35 +1149,37 @@ bool cpp_typecheckt::user_defined_conversion_sequence( { // try derived-to-base conversion exprt expr_pfrom(ID_address_of, pointer_typet()); - expr_pfrom.type().subtype() = expr.type(); + expr_pfrom.type().subtype()=expr.type(); expr_pfrom.copy_to_operands(expr); pointer_typet pto; - pto.subtype() = arg1_type; + pto.subtype()=arg1_type; exprt expr_ptmp; - tmp_rank = 0; - if(standard_conversion_sequence(expr_pfrom, pto, expr_ptmp, tmp_rank)) + tmp_rank=0; + if(standard_conversion_sequence( + expr_pfrom, pto, expr_ptmp, tmp_rank)) { // check if it's ambiguous if(found) return false; - found = true; + found=true; rank+=tmp_rank; // create temporary object - exprt expr_deref = exprt(ID_dereference, expr_ptmp.type().subtype()); + exprt expr_deref= + exprt(ID_dereference, expr_ptmp.type().subtype()); expr_deref.set(ID_C_lvalue, true); expr_deref.copy_to_operands(expr_ptmp); - expr_deref.add_source_location() = expr.source_location(); + expr_deref.add_source_location()=expr.source_location(); exprt new_object("new_object", type); new_object.set(ID_C_lvalue, true); new_object.type().set(ID_C_constant, false); - exprt func_symb = cpp_symbol_expr(lookup(component.get(ID_name))); - func_symb.type() = comp_type; + exprt func_symb=cpp_symbol_expr(lookup(component.get(ID_name))); + func_symb.type()=comp_type; { exprt tmp("already_typechecked"); tmp.copy_to_operands(func_symb); @@ -1182,7 +1187,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence( } side_effect_expr_function_callt ctor_expr; - ctor_expr.add_source_location() = expr.source_location(); + ctor_expr.add_source_location()=expr.source_location(); ctor_expr.function().swap(func_symb); ctor_expr.arguments().push_back(expr_deref); typecheck_side_effect_function_call(ctor_expr); @@ -1204,15 +1209,15 @@ bool cpp_typecheckt::user_defined_conversion_sequence( // conversion operators if(from.id()==ID_struct) { - struct_typet from_struct = to_struct_type(from); + struct_typet from_struct=to_struct_type(from); - bool found = false; + bool found=false; for(struct_typet::componentst::const_iterator - it = from_struct.components().begin(); + it=from_struct.components().begin(); it != from_struct.components().end(); it++) { - const irept& component = *it; - const typet comp_type = static_cast(component.find(ID_type)); + const irept &component=*it; + const typet comp_type=static_cast(component.find(ID_type)); if(component.get_bool(ID_from_base)) continue; @@ -1233,7 +1238,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence( exprt this_expr(expr); this_type.set(ID_C_this, true); - unsigned tmp_rank = 0; + unsigned tmp_rank=0; exprt tmp_expr; if(implicit_conversion_sequence( @@ -1247,23 +1252,23 @@ bool cpp_typecheckt::user_defined_conversion_sequence( cpp_func_name.get_sub().push_back(func_name); exprt member_func(ID_member); - member_func.add(ID_component_cpp_name) = cpp_func_name; + member_func.add(ID_component_cpp_name)=cpp_func_name; exprt ac("already_typechecked"); ac.copy_to_operands(expr); member_func.copy_to_operands(ac); side_effect_expr_function_callt func_expr; - func_expr.add_source_location() = expr.source_location(); + func_expr.add_source_location()=expr.source_location(); func_expr.function().swap(member_func); typecheck_side_effect_function_call(func_expr); exprt tmp_expr; - if(standard_conversion_sequence(func_expr,type, tmp_expr, tmp_rank)) + if(standard_conversion_sequence(func_expr, type, tmp_expr, tmp_rank)) { // check if it's ambiguous if(found) return false; - found = true; + found=true; rank+=tmp_rank; new_expr.swap(tmp_expr); @@ -1298,8 +1303,8 @@ bool cpp_typecheckt::reference_related( assert(is_reference(type)); assert(!is_reference(expr.type())); - typet from = follow(expr.type()); - typet to = follow(type.subtype()); + typet from=follow(expr.type()); + typet to=follow(type.subtype()); // need to check #c_type if(from.get(ID_C_c_type)!=to.get(ID_C_c_type)) @@ -1420,7 +1425,7 @@ bool cpp_typecheckt::reference_binding( assert(is_reference(type)); assert(!is_reference(expr.type())); - unsigned backup_rank = rank; + unsigned backup_rank=rank; if(type.get_bool(ID_C_this) && !expr.get_bool(ID_C_lvalue)) @@ -1434,7 +1439,7 @@ bool cpp_typecheckt::reference_binding( { expr.remove("#temporary_avoided"); exprt temporary; - new_temporary(expr.source_location(),expr.type(), expr, temporary); + new_temporary(expr.source_location(), expr.type(), expr, temporary); expr.swap(temporary); expr.set(ID_C_lvalue, true); } @@ -1467,20 +1472,20 @@ bool cpp_typecheckt::reference_binding( return true; } - rank = backup_rank; + rank=backup_rank; } // conversion operators - typet from_type = follow(expr.type()); + typet from_type=follow(expr.type()); if(from_type.id()==ID_struct) { - struct_typet from_struct = to_struct_type(from_type); + struct_typet from_struct=to_struct_type(from_type); for(struct_typet::componentst::const_iterator - it = from_struct.components().begin(); + it=from_struct.components().begin(); it != from_struct.components().end(); it++) { - const irept& component = *it; + const irept &component=*it; if(component.get_bool(ID_from_base)) continue; @@ -1488,7 +1493,7 @@ bool cpp_typecheckt::reference_binding( if(!component.get_bool("is_cast_operator")) continue; - const code_typet& component_type = + const code_typet &component_type = to_code_type(static_cast(component.find(ID_type))); // otherwise it cannot bind directly (not an lvalue) @@ -1505,7 +1510,7 @@ bool cpp_typecheckt::reference_binding( this_type.set(ID_C_this, true); - unsigned tmp_rank = 0; + unsigned tmp_rank=0; exprt tmp_expr; if(implicit_conversion_sequence( @@ -1519,34 +1524,34 @@ bool cpp_typecheckt::reference_binding( cpp_func_name.get_sub().push_back(func_name); exprt member_func(ID_member); - member_func.add(ID_component_cpp_name) = cpp_func_name; + member_func.add(ID_component_cpp_name)=cpp_func_name; exprt ac("already_typechecked"); ac.copy_to_operands(expr); member_func.copy_to_operands(ac); side_effect_expr_function_callt func_expr; - func_expr.add_source_location() = expr.source_location(); + func_expr.add_source_location()=expr.source_location(); func_expr.function().swap(member_func); typecheck_side_effect_function_call(func_expr); // let's check if the returned value binds directly - exprt returned_value = func_expr; + exprt returned_value=func_expr; add_implicit_dereference(returned_value); if(returned_value.get_bool(ID_C_lvalue) && - reference_compatible(returned_value,type, rank)) + reference_compatible(returned_value, type, rank)) { // returned values are lvalues in case of references only assert(returned_value.id()==ID_dereference && is_reference(returned_value.op0().type())); - new_expr = returned_value.op0(); + new_expr=returned_value.op0(); if(returned_value.type() != type.subtype()) { c_qualifierst qual_from; qual_from.read(returned_value.type()); - make_ptr_typecast(new_expr,type); + make_ptr_typecast(new_expr, type); qual_from.write(new_expr.type().subtype()); } rank+=4+tmp_rank; @@ -1569,7 +1574,7 @@ bool cpp_typecheckt::reference_binding( !expr.get_bool(ID_C_lvalue)) return false; - exprt arg_expr = expr; + exprt arg_expr=expr; if(follow(arg_expr.type()).id()==ID_struct) { @@ -1577,7 +1582,7 @@ bool cpp_typecheckt::reference_binding( arg_expr.set(ID_C_lvalue, true); } - if(user_defined_conversion_sequence(arg_expr,type.subtype(), new_expr, rank)) + if(user_defined_conversion_sequence(arg_expr, type.subtype(), new_expr, rank)) { address_of_exprt tmp; tmp.type()=pointer_typet(); @@ -1589,15 +1594,15 @@ bool cpp_typecheckt::reference_binding( return true; } - rank = backup_rank; - if(standard_conversion_sequence(expr,type.subtype(),new_expr,rank)) + rank=backup_rank; + if(standard_conversion_sequence(expr, type.subtype(), new_expr, rank)) { { // create temporary object exprt tmp=exprt(ID_side_effect, type.subtype()); tmp.set(ID_statement, ID_temporary_object); tmp.add_source_location()=expr.source_location(); - //tmp.set(ID_C_lvalue, true); + // tmp.set(ID_C_lvalue, true); tmp.move_to_operands(new_expr); new_expr.swap(tmp); } @@ -1635,7 +1640,7 @@ bool cpp_typecheckt::implicit_conversion_sequence( exprt &new_expr, unsigned &rank) { - unsigned backup_rank = rank; + unsigned backup_rank=rank; exprt e=expr; add_implicit_dereference(e); @@ -1653,7 +1658,7 @@ bool cpp_typecheckt::implicit_conversion_sequence( } else if(!standard_conversion_sequence(e, type, new_expr, rank)) { - rank = backup_rank; + rank=backup_rank; if(!user_defined_conversion_sequence(e, type, new_expr, rank)) return false; @@ -1685,7 +1690,7 @@ bool cpp_typecheckt::implicit_conversion_sequence( const typet &type, exprt &new_expr) { - unsigned rank = 0; + unsigned rank=0; return implicit_conversion_sequence(expr, type, new_expr, rank); } @@ -1728,7 +1733,7 @@ Function: cpp_typecheck_baset::implicit_typecast void cpp_typecheckt::implicit_typecast(exprt &expr, const typet &type) { - exprt e = expr; + exprt e=expr; if(!implicit_conversion_sequence(e, type, expr)) { @@ -1809,7 +1814,7 @@ void cpp_typecheckt::reference_initializer( unsigned rank=0; exprt new_expr; - if(reference_binding(expr,type,new_expr,rank)) + if(reference_binding(expr, type, new_expr, rank)) { expr.swap(new_expr); return; @@ -1838,8 +1843,8 @@ bool cpp_typecheckt::cast_away_constness( const typet &t2) const { assert(t1.id()==ID_pointer && t2.id()==ID_pointer); - typet nt1 = t1; - typet nt2 = t2; + typet nt1=t1; + typet nt2=t2; if(is_reference(nt1)) nt1.remove(ID_C_reference); @@ -1862,7 +1867,7 @@ bool cpp_typecheckt::cast_away_constness( bool_typet newnt1; q1.write(newnt1); - snt1.back() = newnt1; + snt1.back()=newnt1; std::vector snt2; snt2.push_back(nt2); @@ -1877,16 +1882,16 @@ bool cpp_typecheckt::cast_away_constness( bool_typet newnt2; q2.write(newnt2); - snt2.back() = newnt2; + snt2.back()=newnt2; - const std::size_t k = snt1.size() < snt2.size() ? snt1.size() : snt2.size(); + const std::size_t k=snt1.size() < snt2.size() ? snt1.size() : snt2.size(); - for(std::size_t i = k; i > 1; i--) + for(std::size_t i=k; i > 1; i--) { - snt1[snt1.size()-2].subtype() = snt1[snt1.size()-1]; + snt1[snt1.size()-2].subtype()=snt1[snt1.size()-1]; snt1.pop_back(); - snt2[snt2.size()-2].subtype() = snt2[snt2.size()-1]; + snt2[snt2.size()-2].subtype()=snt2[snt2.size()-1]; snt2.pop_back(); } @@ -1915,7 +1920,7 @@ bool cpp_typecheckt::const_typecast( { assert(is_reference(expr.type())==false); - exprt curr_expr = expr; + exprt curr_expr=expr; if(curr_expr.type().id()==ID_array) { @@ -1937,7 +1942,7 @@ bool cpp_typecheckt::const_typecast( return false; } else - new_expr = curr_expr; + new_expr=curr_expr; if(is_reference(type)) { @@ -1989,7 +1994,7 @@ bool cpp_typecheckt::dynamic_typecast( if(type.id()==ID_pointer) { if(e.id()==ID_dereference && e.get_bool(ID_C_implicit)) - e = expr.op0(); + e=expr.op0(); if(e.type().id()==ID_pointer && cast_away_constness(e.type(), type)) @@ -2020,7 +2025,7 @@ bool cpp_typecheckt::dynamic_typecast( { exprt tmp(e); - if(!standard_conversion_lvalue_to_rvalue(tmp,e)) + if(!standard_conversion_lvalue_to_rvalue(tmp, e)) return false; } } @@ -2028,7 +2033,7 @@ bool cpp_typecheckt::dynamic_typecast( } else return false; - return static_typecast(e,type, new_expr); + return static_typecast(e, type, new_expr); } /*******************************************************************\ @@ -2054,7 +2059,7 @@ bool cpp_typecheckt::reinterpret_typecast( if(check_constantness && type.id()==ID_pointer) { if(e.id()==ID_dereference && e.get_bool(ID_C_implicit)) - e = expr.op0(); + e=expr.op0(); if(e.type().id()==ID_pointer && cast_away_constness(e.type(), type)) @@ -2103,21 +2108,21 @@ bool cpp_typecheckt::reinterpret_typecast( if((e.type().id()==ID_unsignedbv || e.type().id()==ID_signedbv || - e.type().id()==ID_bool) - && type.id()==ID_pointer - && !is_reference(type)) + e.type().id()==ID_bool) && + type.id()==ID_pointer && + !is_reference(type)) { // integer to pointer if(simplify_expr(e, *this).is_zero()) { // NULL - new_expr = e; + new_expr=e; new_expr.set(ID_value, ID_NULL); - new_expr.type() = type; + new_expr.type()=type; } else { - new_expr = e; + new_expr=e; new_expr.make_typecast(type); } return true; @@ -2137,7 +2142,7 @@ bool cpp_typecheckt::reinterpret_typecast( if(is_reference(type) && e.get_bool(ID_C_lvalue)) { exprt tmp(ID_address_of, pointer_typet()); - tmp.type().subtype() = e.type(); + tmp.type().subtype()=e.type(); tmp.copy_to_operands(e); tmp.make_typecast(type); new_expr.swap(tmp); @@ -2170,7 +2175,7 @@ bool cpp_typecheckt::static_typecast( if(check_constantness && type.id()==ID_pointer) { if(e.id()==ID_dereference && e.get_bool(ID_C_implicit)) - e = expr.op0(); + e=expr.op0(); if(e.type().id()==ID_pointer && cast_away_constness(e.type(), type)) @@ -2182,11 +2187,11 @@ bool cpp_typecheckt::static_typecast( if(type.get_bool(ID_C_reference)) { unsigned rank=0; - if(reference_binding(e,type,new_expr,rank)) + if(reference_binding(e, type, new_expr, rank)) return true; - typet subto = follow(type.subtype()); - typet from = follow(e.type()); + typet subto=follow(type.subtype()); + typet from=follow(e.type()); if(subto.id()==ID_struct && from.id()==ID_struct) { @@ -2202,14 +2207,14 @@ bool cpp_typecheckt::static_typecast( if(!qual_to.is_subset_of(qual_from)) return false; - struct_typet from_struct = to_struct_type(from); - struct_typet subto_struct = to_struct_type(subto); + struct_typet from_struct=to_struct_type(from); + struct_typet subto_struct=to_struct_type(subto); if(subtype_typecast(subto_struct, from_struct)) { if(e.id()==ID_dereference) { - make_ptr_typecast(e.op0(),type); + make_ptr_typecast(e.op0(), type); new_expr.swap(e.op0()); return true; } @@ -2217,7 +2222,7 @@ bool cpp_typecheckt::static_typecast( exprt address_of(ID_address_of, pointer_typet()); address_of.type().subtype()=e.type(); address_of.copy_to_operands(e); - make_ptr_typecast(address_of ,type); + make_ptr_typecast(address_of , type); new_expr.swap(address_of); return true; } @@ -2227,16 +2232,16 @@ bool cpp_typecheckt::static_typecast( if(type.id()==ID_empty) { - new_expr = e; + new_expr=e; new_expr.make_typecast(type); return true; } // int/enum to enum - if(type.id()==ID_c_enum_tag && ( - e.type().id()==ID_signedbv - || e.type().id()==ID_unsignedbv - || e.type().id()==ID_c_enum_tag)) + if(type.id()==ID_c_enum_tag && + (e.type().id()==ID_signedbv || + e.type().id()==ID_unsignedbv || + e.type().id()==ID_c_enum_tag)) { new_expr=e; new_expr.make_typecast(type); @@ -2270,8 +2275,8 @@ bool cpp_typecheckt::static_typecast( if(type.find("to-member").is_nil() && e.type().find("to-member").is_nil()) { - typet to = follow(type.subtype()); - typet from = follow(e.type().subtype()); + typet to=follow(type.subtype()); + typet from=follow(e.type().subtype()); if(from.id()==ID_empty) { @@ -2282,19 +2287,18 @@ bool cpp_typecheckt::static_typecast( if(to.id()==ID_struct && from.id()==ID_struct) { - if(e.get_bool(ID_C_lvalue)) { exprt tmp(e); - if(!standard_conversion_lvalue_to_rvalue(tmp,e)) + if(!standard_conversion_lvalue_to_rvalue(tmp, e)) return false; } - struct_typet from_struct = to_struct_type(from); - struct_typet to_struct = to_struct_type(to); + struct_typet from_struct=to_struct_type(from); + struct_typet to_struct=to_struct_type(to); if(subtype_typecast(to_struct, from_struct)) { - make_ptr_typecast(e,type); + make_ptr_typecast(e, type); new_expr.swap(e); return true; } @@ -2302,21 +2306,23 @@ bool cpp_typecheckt::static_typecast( return false; } - else if (type.find("to-member").is_not_nil() - && e.type().find("to-member").is_not_nil()) + else if(type.find("to-member").is_not_nil() && + e.type().find("to-member").is_not_nil()) { - if(type.subtype() != e.type().subtype()) + if(type.subtype()!=e.type().subtype()) return false; - struct_typet from_struct = - to_struct_type(follow(static_cast(e.type().find("to-member")))); + struct_typet from_struct= + to_struct_type( + follow(static_cast(e.type().find("to-member")))); - struct_typet to_struct = - to_struct_type(follow(static_cast(type.find("to-member")))); + struct_typet to_struct= + to_struct_type( + follow(static_cast(type.find("to-member")))); if(subtype_typecast(from_struct, to_struct)) { - new_expr = e; + new_expr=e; new_expr.make_typecast(type); return true; } diff --git a/src/cpp/cpp_typecheck_declaration.cpp b/src/cpp/cpp_typecheck_declaration.cpp index bef63d1eda1..fd846d90c0d 100644 --- a/src/cpp/cpp_typecheck_declaration.cpp +++ b/src/cpp/cpp_typecheck_declaration.cpp @@ -24,7 +24,8 @@ Function: cpp_typecheckt::convert void cpp_typecheckt::convert(cpp_declarationt &declaration) { // see if the declaration is empty - if(declaration.is_empty()) return; + if(declaration.is_empty()) + return; // Record the function bodies so we can check them later. // This function is used recursively, so we save them. @@ -81,9 +82,9 @@ void cpp_typecheckt::convert_anonymous_union( if(!cpp_is_pod(declaration.type())) { - error().source_location=follow(declaration.type()).source_location(); - error() << "anonymous union is not POD" << eom; - throw 0; + error().source_location=follow(declaration.type()).source_location(); + error() << "anonymous union is not POD" << eom; + throw 0; } codet decl_statement(ID_decl); @@ -197,7 +198,9 @@ void cpp_typecheckt::convert_non_template_declaration( if(declaration.find(ID_C_template).is_not_nil()) { symbol.type.set(ID_C_template, declaration.find(ID_C_template)); - symbol.type.set(ID_C_template_arguments, declaration.find(ID_C_template_arguments)); + symbol.type.set( + ID_C_template_arguments, + declaration.find(ID_C_template_arguments)); } // replace declarator by symbol expression diff --git a/src/cpp/cpp_typecheck_destructor.cpp b/src/cpp/cpp_typecheck_destructor.cpp index 39fabd3cf5e..4b1be9ceeb4 100644 --- a/src/cpp/cpp_typecheck_destructor.cpp +++ b/src/cpp/cpp_typecheck_destructor.cpp @@ -20,7 +20,7 @@ Function: cpp_typecheckt::find_dtor \*******************************************************************/ -bool cpp_typecheckt::find_dtor(const symbolt& symbol) const +bool cpp_typecheckt::find_dtor(const symbolt &symbol) const { const irept &components= symbol.type.find(ID_components); @@ -127,7 +127,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol) const symbolt &virtual_table_symbol_var = namespacet(symbol_table).lookup( - id2string(virtual_table_symbol_type.name) + "@" + id2string(symbol.name)); + id2string(virtual_table_symbol_type.name)+"@"+id2string(symbol.name)); exprt var=virtual_table_symbol_var.symbol_expr(); address_of_exprt address(var); @@ -190,7 +190,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol) { assert(bit->id()==ID_base); assert(bit->find(ID_type).id()==ID_symbol); - const symbolt& psymb = lookup(bit->find(ID_type).get(ID_identifier)); + const symbolt &psymb = lookup(bit->find(ID_type).get(ID_identifier)); exprt object(ID_dereference); object.operands().push_back(exprt("cpp-this")); diff --git a/src/cpp/cpp_typecheck_enum_type.cpp b/src/cpp/cpp_typecheck_enum_type.cpp index 1813ee060d0..2e1bcf67172 100644 --- a/src/cpp/cpp_typecheck_enum_type.cpp +++ b/src/cpp/cpp_typecheck_enum_type.cpp @@ -63,7 +63,8 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol) symbol.name=id2string(enum_symbol.name)+"::"+id2string(name); symbol.base_name=name; symbol.value=value_expr; - symbol.location=static_cast(it->find(ID_C_source_location)); + symbol.location= + static_cast(it->find(ID_C_source_location)); symbol.mode=ID_cpp; symbol.module=module; symbol.type=enum_tag_type; @@ -74,8 +75,8 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol) if(symbol_table.move(symbol, new_symbol)) { error().source_location=symbol.location; - error() << "cpp_typecheckt::typecheck_enum_body: symbol_table.move() failed" - << eom; + error() << "cpp_typecheckt::typecheck_enum_body: " + << "symbol_table.move() failed" << eom; throw 0; } @@ -202,8 +203,8 @@ void cpp_typecheckt::typecheck_enum_type(typet &type) if(symbol_table.move(symbol, new_symbol)) { error().source_location=symbol.location; - error() << "cpp_typecheckt::typecheck_enum_type: symbol_table.move() failed" - << eom; + error() << "cpp_typecheckt::typecheck_enum_type: " + << "symbol_table.move() failed" << eom; throw 0; } diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index 935d174a23e..51b43cde996 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -40,7 +40,7 @@ Function: cpp_typecheckt::find_parent \*******************************************************************/ bool cpp_typecheckt::find_parent( - const symbolt& symb, + const symbolt &symb, const irep_idt &base_name, irep_idt &identifier) { @@ -48,7 +48,7 @@ bool cpp_typecheckt::find_parent( { if(lookup(bit->find(ID_type).get(ID_identifier)).base_name == base_name) { - identifier = bit->find(ID_type).get(ID_identifier); + identifier=bit->find(ID_type).get(ID_identifier); return true; } } @@ -268,21 +268,21 @@ void cpp_typecheckt::typecheck_expr_trinary(if_exprt &expr) qual2.read(expr.op2().type()); if(qual1.is_subset_of(qual2)) - expr.type() = expr.op1().type(); + expr.type()=expr.op1().type(); else - expr.type() = expr.op2().type(); + expr.type()=expr.op2().type(); } else { - exprt e1 = expr.op1(); - exprt e2 = expr.op2(); + exprt e1=expr.op1(); + exprt e2=expr.op2(); if(implicit_conversion_sequence(expr.op1(), expr.op2().type(), e1)) { expr.type()=e1.type(); expr.op1().swap(e1); } - else if(implicit_conversion_sequence(expr.op2(),expr.op1().type(), e2)) + else if(implicit_conversion_sequence(expr.op2(), expr.op1().type(), e2)) { expr.type()=e2.type(); expr.op2().swap(e2); @@ -294,21 +294,21 @@ void cpp_typecheckt::typecheck_expr_trinary(if_exprt &expr) // array-to-pointer conversion index_exprt index1; - index1.array() = expr.op1(); - index1.index() = from_integer(0, index_type()); - index1.type() = expr.op1().type().subtype(); + index1.array()=expr.op1(); + index1.index()=from_integer(0, index_type()); + index1.type()=expr.op1().type().subtype(); index_exprt index2; - index2.array() = expr.op2(); - index2.index() = from_integer(0, index_type()); - index2.type() = expr.op2().type().subtype(); + index2.array()=expr.op2(); + index2.index()=from_integer(0, index_type()); + index2.type()=expr.op2().type().subtype(); address_of_exprt addr1(index1); address_of_exprt addr2(index2); - expr.op1() = addr1; - expr.op2() = addr2; - expr.type() = addr1.type(); + expr.op1()=addr1; + expr.op2()=addr2; + expr.type()=addr1.type(); return; } else @@ -474,7 +474,8 @@ void cpp_typecheckt::typecheck_function_expr( cpp_namet cpp_name; cpp_name.get_sub().push_back(irept(ID_name)); cpp_name.get_sub().back().set(ID_identifier, op_name); - cpp_name.get_sub().back().add(ID_C_source_location)=expr.source_location(); + cpp_name.get_sub().back().add(ID_C_source_location)= + expr.source_location(); function_call.function()= static_cast( @@ -608,7 +609,7 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) cpp_name.get_sub().back().add(ID_C_source_location)=expr.source_location(); // See if the struct decalares the cast operator as a member - bool found_in_struct = false; + bool found_in_struct=false; assert(!expr.operands().empty()); typet t0(follow(expr.op0().type())); @@ -628,7 +629,7 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) if(!it->get_bool(ID_from_base) && it->get(ID_base_name) == op_name) { - found_in_struct = true; + found_in_struct=true; break; } } @@ -687,7 +688,8 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) cpp_namet cpp_name; cpp_name.get_sub().push_back(irept(ID_name)); cpp_name.get_sub().back().set(ID_identifier, op_name); - cpp_name.get_sub().back().add(ID_C_source_location)=expr.source_location(); + cpp_name.get_sub().back().add(ID_C_source_location)= + expr.source_location(); // turn this into a function call side_effect_expr_function_callt function_call; @@ -795,7 +797,6 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) return true; } } - } return false; @@ -835,7 +836,7 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr) { // we take the address of the method. assert(expr.op0().id()==ID_member); - exprt symb = cpp_symbol_expr(lookup(expr.op0().get(ID_component_name))); + exprt symb=cpp_symbol_expr(lookup(expr.op0().get(ID_component_name))); exprt address(ID_address_of, typet(ID_pointer)); address.copy_to_operands(symb); address.type().subtype()=symb.type(); @@ -847,15 +848,15 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr) expr.op0().get_bool(ID_C_implicit)) { // must be the address of a function - code_typet& code_type = to_code_type(op.type().subtype()); + code_typet &code_type=to_code_type(op.type().subtype()); - code_typet::parameterst& args = code_type.parameters(); + code_typet::parameterst &args=code_type.parameters(); if(args.size() > 0 && args[0].get(ID_C_base_name)==ID_this) { // it's a pointer to member function typet symbol(ID_symbol); symbol.set(ID_identifier, code_type.get(ID_C_member_name)); - expr.op0().type().add("to-member") = symbol; + expr.op0().type().add("to-member")=symbol; if(code_type.get_bool(ID_C_is_virtual)) { @@ -1769,7 +1770,8 @@ void cpp_typecheckt::typecheck_expr_cpp_name( result.set_identifier(identifier); code_typet t; t.parameters().push_back(code_typet::parametert(ptr_arg.type())); - t.parameters().push_back(code_typet::parametert(ptr_arg.type().subtype())); + t.parameters().push_back( + code_typet::parametert(ptr_arg.type().subtype())); t.parameters().push_back(code_typet::parametert(signed_int_type())); t.return_type()=empty_typet(); result.type()=t; @@ -1785,7 +1787,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name( if(fargs.operands.size()!=3) { error().source_location=source_location; - error () << identifier << " expects three arguments" << eom; + error() << identifier << " expects three arguments" << eom; throw 0; } @@ -1804,7 +1806,8 @@ void cpp_typecheckt::typecheck_expr_cpp_name( result.set_identifier(identifier); code_typet t; t.parameters().push_back(code_typet::parametert(ptr_arg.type())); - t.parameters().push_back(code_typet::parametert(ptr_arg.type().subtype())); + t.parameters().push_back( + code_typet::parametert(ptr_arg.type().subtype())); t.parameters().push_back(code_typet::parametert(signed_int_type())); t.return_type()=ptr_arg.type().subtype(); result.type()=t; @@ -1907,8 +1910,10 @@ void cpp_typecheckt::typecheck_expr_cpp_name( else if(identifier=="__atomic_compare_exchange_n" || identifier=="__atomic_compare_exchange") { - // bool __atomic_compare_exchange_n(type *ptr, type *expected, type desired, bool weak, int success_memorder, int failure_memorder) - // bool __atomic_compare_exchange(type *ptr, type *expected, type *desired, bool weak, int success_memorder, int failure_memorder) + // bool __atomic_compare_exchange_n(type *ptr, type *expected, type + // desired, bool weak, int success_memorder, int failure_memorder) + // bool __atomic_compare_exchange(type *ptr, type *expected, type + // *desired, bool weak, int success_memorder, int failure_memorder) if(fargs.operands.size()!=6) { @@ -1954,7 +1959,8 @@ void cpp_typecheckt::typecheck_expr_cpp_name( if(identifier=="__atomic_compare_exchange") t.parameters().push_back(code_typet::parametert(ptr_arg.type())); else - t.parameters().push_back(code_typet::parametert(ptr_arg.type().subtype())); + t.parameters().push_back( + code_typet::parametert(ptr_arg.type().subtype())); t.parameters().push_back(code_typet::parametert(c_bool_type())); t.parameters().push_back(code_typet::parametert(signed_int_type())); @@ -2122,7 +2128,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name( ptrmem.operands().push_back( cpp_scopes.current_scope().this_expr); - ptrmem.add(ID_component_cpp_name) = expr; + ptrmem.add(ID_component_cpp_name)=expr; ptrmem.add_source_location()=source_location; typecheck_expr_ptrmember(ptrmem, fargs); @@ -2185,7 +2191,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call( // For virtual functions, it is important to check whether // the function name is qualified. If it is qualified, then // the call is not virtual. - bool is_qualified = false; + bool is_qualified=false; if(expr.function().id()==ID_member || expr.function().id()==ID_ptrmember) @@ -2233,7 +2239,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call( { exprt typecast("explicit-typecast"); typecast.type()=pod; - typecast.add_source_location() = expr.source_location(); + typecast.add_source_location()=expr.source_location(); typecast.copy_to_operands(expr.arguments().front()); typecheck_expr_explicit_typecast(typecast); expr.swap(typecast); @@ -2332,8 +2338,10 @@ void cpp_typecheckt::typecheck_side_effect_function_call( } // get the virtual table - typet this_type = to_code_type(expr.function().type()).parameters().front().type(); - irep_idt vtable_name = this_type.subtype().get_string(ID_identifier) +"::@vtable_pointer"; + typet this_type= + to_code_type(expr.function().type()).parameters().front().type(); + irep_idt vtable_name= + this_type.subtype().get_string(ID_identifier) +"::@vtable_pointer"; const struct_typet &vt_struct= to_struct_type(follow(this_type.subtype())); @@ -2346,12 +2354,13 @@ void cpp_typecheckt::typecheck_side_effect_function_call( vtptr_member.set(ID_component_name, vtable_name); // look for the right entry - irep_idt vtentry_component_name = vt_compo.type().subtype().get_string(ID_identifier) - + "::" + expr.function().type().get_string("#virtual_name"); + irep_idt vtentry_component_name= + vt_compo.type().subtype().get_string(ID_identifier)+"::"+ + expr.function().type().get_string("#virtual_name"); exprt vtentry_member(ID_ptrmember); vtentry_member.copy_to_operands(vtptr_member); - vtentry_member.set(ID_component_name, vtentry_component_name ); + vtentry_member.set(ID_component_name, vtentry_component_name); typecheck_expr(vtentry_member); assert(vtentry_member.type().id()==ID_pointer); @@ -2389,7 +2398,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call( cppname.get_sub().push_back(name); exprt member(ID_member); - member.add(ID_component_cpp_name) = cppname; + member.add(ID_component_cpp_name)=cppname; member.move_to_operands(op0); @@ -2422,7 +2431,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call( const typet &this_type=parameters[0].type(); // change type from 'constructor' to object type - expr.type() = this_type.subtype(); + expr.type()=this_type.subtype(); // create temporary object exprt tmp_object_expr(ID_side_effect, this_type.subtype()); @@ -2486,7 +2495,7 @@ void cpp_typecheckt::typecheck_side_effect_function_call( codet new_code(ID_expression); new_code.copy_to_operands(expr); - tmp_object_expr.add(ID_initializer) = new_code; + tmp_object_expr.add(ID_initializer)=new_code; expr.swap(tmp_object_expr); return; } @@ -2618,7 +2627,7 @@ Function: cpp_typecheckt::typecheck_expr_side_effect \*******************************************************************/ void cpp_typecheckt::typecheck_expr_side_effect( - side_effect_exprt &expr) + side_effect_exprt &expr) { const irep_idt &statement=expr.get(ID_statement); @@ -2708,7 +2717,7 @@ void cpp_typecheckt::typecheck_method_application( } else { - exprt this_arg = member_expr.op0(); + exprt this_arg=member_expr.op0(); implicit_typecast(this_arg, this_type); assert(is_reference(this_arg.type())); this_arg.type().remove(ID_C_reference); @@ -2859,8 +2868,8 @@ void cpp_typecheckt::typecheck_side_effect_inc_dec( // Turn into an operator call - std::string str_op = "operator"; - bool post = false; + std::string str_op="operator"; + bool post=false; if(expr.get(ID_statement)==ID_preincrement) str_op += "++"; @@ -2869,12 +2878,12 @@ void cpp_typecheckt::typecheck_side_effect_inc_dec( else if(expr.get(ID_statement)==ID_postincrement) { str_op += "++"; - post = true; + post=true; } else if(expr.get(ID_statement)==ID_postdecrement) { str_op += "--"; - post = true; + post=true; } else { @@ -2958,7 +2967,7 @@ Function: cpp_typecheckt::convert_pmop \*******************************************************************/ -void cpp_typecheckt::convert_pmop(exprt& expr) +void cpp_typecheckt::convert_pmop(exprt &expr) { assert(expr.id()=="pointer-to-member"); assert(expr.operands().size() == 2); @@ -2971,13 +2980,13 @@ void cpp_typecheckt::convert_pmop(exprt& expr) throw 0; } - typet t0 = expr.op0().type().id()==ID_pointer ? + typet t0=expr.op0().type().id()==ID_pointer ? expr.op0().type().subtype(): expr.op0().type(); typet t1((const typet&)expr.op1().type().find("to-member")); - t0 = follow(t0); - t1 = follow(t1); + t0=follow(t0); + t1=follow(t1); if(t0.id()!=ID_struct) { @@ -2986,8 +2995,8 @@ void cpp_typecheckt::convert_pmop(exprt& expr) throw 0; } - const struct_typet &from_struct = to_struct_type(t0); - const struct_typet &to_struct = to_struct_type(t1); + const struct_typet &from_struct=to_struct_type(t0); + const struct_typet &to_struct=to_struct_type(t1); if(!subtype_typecast(from_struct, to_struct)) { @@ -3009,7 +3018,7 @@ void cpp_typecheckt::convert_pmop(exprt& expr) { if(expr.op0().id()==ID_dereference) { - exprt tmp = expr.op0().op0(); + exprt tmp=expr.op0().op0(); expr.op0().swap(tmp); } else @@ -3017,7 +3026,7 @@ void cpp_typecheckt::convert_pmop(exprt& expr) assert(expr.op0().get_bool(ID_C_lvalue)); exprt address_of(ID_address_of, typet(ID_pointer)); address_of.copy_to_operands(expr.op0()); - address_of.type().subtype() = address_of.op0().type(); + address_of.type().subtype()=address_of.op0().type(); expr.op0().swap(address_of); } } @@ -3050,7 +3059,7 @@ void cpp_typecheckt::typecheck_expr_function_identifier(exprt &expr) assert(it != symbol_table.symbols.end()); - symbolt &func_symb = it->second; + symbolt &func_symb=it->second; if(func_symb.value.id()=="cpp_not_typechecked") func_symb.value.set("is_used", true); @@ -3158,7 +3167,6 @@ void cpp_typecheckt::explicit_typecast_ambiguity(exprt &expr) expr.swap(new_binary_expr); } } - } /*******************************************************************\ diff --git a/src/cpp/cpp_typecheck_fargs.cpp b/src/cpp/cpp_typecheck_fargs.cpp index b0beff42864..592c538fc2c 100644 --- a/src/cpp/cpp_typecheck_fargs.cpp +++ b/src/cpp/cpp_typecheck_fargs.cpp @@ -113,9 +113,11 @@ bool cpp_typecheck_fargst::match( for(const auto ¶meter : parameters) { // read - // http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/com.ibm.xlcpp8a.doc/language/ref/implicit_conversion_sequences.htm + // http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/ + // com.ibm.xlcpp8a.doc/language/ref/implicit_conversion_sequences.htm // - // The following are the three categories of conversion sequences in order from best to worst: + // The following are the three categories of conversion sequences + // in order from best to worst: // * Standard conversion sequences // * User-defined conversion sequences // * Ellipsis conversion sequences @@ -145,7 +147,8 @@ bool cpp_typecheck_fargst::match( #if 0 std::cout << "C: " << cpp_typecheck.to_string(operand.type()) - << " -> " << cpp_typecheck.to_string(parameter.type()) << std::endl; + << " -> " << cpp_typecheck.to_string(parameter.type()) + << std::endl; #endif // can we do the standard conversion sequence? diff --git a/src/cpp/cpp_typecheck_fargs.h b/src/cpp/cpp_typecheck_fargs.h index 61efa7979b3..370cc10ed65 100644 --- a/src/cpp/cpp_typecheck_fargs.h +++ b/src/cpp/cpp_typecheck_fargs.h @@ -44,7 +44,7 @@ class cpp_typecheck_fargst // for function overloading void add_object(const exprt &expr) { - //if(!in_use) return; + // if(!in_use) return; has_object=true; operands.insert(operands.begin(), expr); } diff --git a/src/cpp/cpp_typecheck_function.cpp b/src/cpp/cpp_typecheck_function.cpp index ccbd2dd58b2..a55bbf41d6b 100644 --- a/src/cpp/cpp_typecheck_function.cpp +++ b/src/cpp/cpp_typecheck_function.cpp @@ -145,7 +145,8 @@ void cpp_typecheckt::convert_function(symbolt &symbol) assert(parameters.size()>=1); code_typet::parametert &this_parameter_expr=parameters.front(); function_scope.this_expr=exprt(ID_symbol, this_parameter_expr.type()); - function_scope.this_expr.set(ID_identifier, this_parameter_expr.get(ID_C_identifier)); + function_scope.this_expr.set( + ID_identifier, this_parameter_expr.get(ID_C_identifier)); } else function_scope.this_expr.make_nil(); @@ -208,8 +209,10 @@ irep_idt cpp_typecheckt::function_identifier(const typet &type) { const typet &pointer=it->type(); const typet &symbol =pointer.subtype(); - if(symbol.get_bool(ID_C_constant)) result+="const$"; - if(symbol.get_bool(ID_C_volatile)) result+="volatile$"; + if(symbol.get_bool(ID_C_constant)) + result+="const$"; + if(symbol.get_bool(ID_C_volatile)) + result+="volatile$"; result+="this"; first=false; it++; @@ -219,7 +222,10 @@ irep_idt cpp_typecheckt::function_identifier(const typet &type) for(; it!=parameters.end(); it++) { - if(first) first=false; else result+=','; + if(first) + first=false; + else + result+=','; typet tmp_type=it->type(); result+=cpp_type2name(it->type()); } diff --git a/src/cpp/cpp_typecheck_initializer.cpp b/src/cpp/cpp_typecheck_initializer.cpp index 225f6d5aa5c..ef19cba6050 100644 --- a/src/cpp/cpp_typecheck_initializer.cpp +++ b/src/cpp/cpp_typecheck_initializer.cpp @@ -34,7 +34,8 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol) if(symbol.is_type) { - if(symbol.value.is_nil()) return; + if(symbol.value.is_nil()) + return; if(symbol.value.id()!=ID_type) { @@ -321,7 +322,8 @@ void cpp_typecheckt::zero_initializer( else { exprt value= - ::zero_initializer(final_type, source_location, *this, get_message_handler()); + ::zero_initializer( + final_type, source_location, *this, get_message_handler()); code_assignt assign; assign.lhs()=object; diff --git a/src/cpp/cpp_typecheck_resolve.cpp b/src/cpp/cpp_typecheck_resolve.cpp index 6655eb258f6..47628c9f3f7 100644 --- a/src/cpp/cpp_typecheck_resolve.cpp +++ b/src/cpp/cpp_typecheck_resolve.cpp @@ -347,7 +347,8 @@ exprt cpp_typecheck_resolvet::convert_identifier( #if 0 std::cout << "I: " << identifier.class_identifier << " " - << cpp_typecheck.cpp_scopes.current_scope().this_class_identifier << std::endl; + << cpp_typecheck.cpp_scopes.current_scope(). + this_class_identifier << std::endl; #endif const exprt &this_expr= @@ -391,16 +392,16 @@ exprt cpp_typecheck_resolvet::convert_identifier( // we got an object e.move_to_operands(object); - bool old_value = cpp_typecheck.disable_access_control; - cpp_typecheck.disable_access_control = true; + bool old_value=cpp_typecheck.disable_access_control; + cpp_typecheck.disable_access_control=true; cpp_typecheck.typecheck_expr_member(e); - cpp_typecheck.disable_access_control = old_value; + cpp_typecheck.disable_access_control=old_value; } else { // this has to be a method if(identifier.is_method) - e = cpp_symbol_expr(cpp_typecheck.lookup(identifier.identifier)); + e=cpp_symbol_expr(cpp_typecheck.lookup(identifier.identifier)); else e.make_nil(); } @@ -530,7 +531,8 @@ void cpp_typecheck_resolvet::exact_match_functions( resolve_identifierst &identifiers, const cpp_typecheck_fargst &fargs) { - if(!fargs.in_use) return; + if(!fargs.in_use) + return; resolve_identifierst old_identifiers; old_identifiers.swap(identifiers); @@ -590,6 +592,7 @@ void cpp_typecheck_resolvet::disambiguate_functions( // we give strong preference to functions that have // fewer template arguments std::size_t total_distance= + // NOLINTNEXTLINE(whitespace/operators) 1000*template_distance+args_distance; distance_map.insert( @@ -620,7 +623,8 @@ void cpp_typecheck_resolvet::disambiguate_functions( it1!=identifiers.end(); it1++) { - if(it1->type().id()!=ID_code) continue; + if(it1->type().id()!=ID_code) + continue; const code_typet &f1= to_code_type(it1->type()); @@ -651,10 +655,12 @@ void cpp_typecheck_resolvet::disambiguate_functions( bool f1_better=true; bool f2_better=true; - for(std::size_t i=0; i < f1.parameters().size() && (f1_better || f2_better); i++) + for(std::size_t i=0; + iid() == ID_merged_type) { // it's a cast operator - irept next_ir = *next; + irept next_ir=*next; typet op_name; op_name.swap(next_ir); cpp_typecheck.typecheck_type(op_name); final_base_name+="("+cpp_type2name(op_name)+")"; pos++; } - } else final_base_name+=pos->id_string(); @@ -1192,9 +1199,11 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes( { const irep_idt id=(*it)->identifier; const symbolt &s=cpp_typecheck.lookup(id); - if(!s.type.get_bool(ID_is_template)) continue; + if(!s.type.get_bool(ID_is_template)) + continue; const cpp_declarationt &cpp_declaration=to_cpp_declaration(s.type); - if(!cpp_declaration.is_class_template()) continue; + if(!cpp_declaration.is_class_template()) + continue; irep_idt specialization_of=cpp_declaration.get_specialization_of(); if(specialization_of!="") primary_templates.insert(specialization_of); @@ -1254,7 +1263,8 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes( const symbolt &s=cpp_typecheck.lookup(id); irep_idt specialization_of=s.type.get("specialization_of"); - if(specialization_of=="") continue; + if(specialization_of=="") + continue; const cpp_declarationt &cpp_declaration= to_cpp_declaration(s.type); @@ -1531,7 +1541,8 @@ void cpp_typecheck_resolvet::show_identifiers( if(code_type.has_ellipsis()) { - if(!parameters.empty()) out << ", "; + if(!parameters.empty()) + out << ", "; out << "..."; } @@ -1547,7 +1558,8 @@ void cpp_typecheck_resolvet::show_identifiers( } else if(id_expr.id()==ID_template_function_instance) { - const symbolt &symbol=cpp_typecheck.lookup(id_expr.type().get(ID_C_template)); + const symbolt &symbol= + cpp_typecheck.lookup(id_expr.type().get(ID_C_template)); out << " (" << symbol.location << ")"; } } @@ -1614,9 +1626,11 @@ exprt cpp_typecheck_resolvet::resolve( qualified?cpp_scopet::QUALIFIED:cpp_scopet::RECURSIVE; if(template_args.is_nil()) - cpp_typecheck.cpp_scopes.current_scope().lookup(base_name, lookup_kind, id_set); + cpp_typecheck.cpp_scopes.current_scope().lookup( + base_name, lookup_kind, id_set); else - cpp_typecheck.cpp_scopes.current_scope().lookup(base_name, lookup_kind, cpp_idt::TEMPLATE, id_set); + cpp_typecheck.cpp_scopes.current_scope().lookup( + base_name, lookup_kind, cpp_idt::TEMPLATE, id_set); // Argument-dependent name lookup #if 0 @@ -1627,7 +1641,8 @@ exprt cpp_typecheck_resolvet::resolve( if(id_set.empty()) { - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); cpp_typecheck.show_instantiation_stack(cpp_typecheck.error()); cpp_typecheck.error().source_location=source_location; @@ -1653,8 +1668,8 @@ exprt cpp_typecheck_resolvet::resolve( } cpp_typecheck.error() << messaget::eom; - //cpp_typecheck.cpp_scopes.get_root_scope().print(std::cout); - //cpp_typecheck.cpp_scopes.current_scope().print(std::cout); + // cpp_typecheck.cpp_scopes.get_root_scope().print(std::cout); + // cpp_typecheck.cpp_scopes.current_scope().print(std::cout); throw 0; } @@ -1682,7 +1697,8 @@ exprt cpp_typecheck_resolvet::resolve( if(want==BOTH && have_classes && have_methods) { - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); cpp_typecheck.show_instantiation_stack(cpp_typecheck.error()); cpp_typecheck.error().source_location=source_location; @@ -1785,7 +1801,8 @@ exprt cpp_typecheck_resolvet::resolve( else { // nothing or too many - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); if(new_identifiers.empty()) { @@ -1807,9 +1824,13 @@ exprt cpp_typecheck_resolvet::resolve( exprt e1=*new_identifiers.begin(); exprt e2=*(++new_identifiers.begin()); cpp_typecheck.str << "e1==e2: " << (e1==e2) << std::endl; - cpp_typecheck.str << "e1.type==e2.type: " << (e1.type()==e2.type()) << std::endl; - cpp_typecheck.str << "e1.id()==e2.id(): " << (e1.id()==e2.id()) << std::endl; - cpp_typecheck.str << "e1.iden==e2.iden: " << (e1.get(ID_identifier)==e2.get(ID_identifier)) << std::endl; + cpp_typecheck.str << "e1.type==e2.type: " << (e1.type()==e2.type()) + << std::endl; + cpp_typecheck.str << "e1.id()==e2.id(): " << (e1.id()==e2.id()) + << std::endl; + cpp_typecheck.str << "e1.iden==e2.iden: " + << (e1.get(ID_identifier)==e2.get(ID_identifier)) + << std::endl; cpp_typecheck.str << "e1.iden:: " << e1.get(ID_identifier) << std::endl; cpp_typecheck.str << "e2.iden:: " << e2.get(ID_identifier) << std::endl; #endif @@ -1843,7 +1864,8 @@ exprt cpp_typecheck_resolvet::resolve( if(result.get_bool("#not_accessible")) { #if 0 - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); cpp_typecheck.error().source_location=result.source_location()); cpp_typecheck.str @@ -1858,7 +1880,8 @@ exprt cpp_typecheck_resolvet::resolve( case VAR: if(result.id()==ID_type && !cpp_typecheck.cpp_is_pod(result.type())) { - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); cpp_typecheck.error().source_location=source_location; @@ -1874,7 +1897,8 @@ exprt cpp_typecheck_resolvet::resolve( case TYPE: if(result.id()!=ID_type) { - if(!fail_with_exception) return nil_exprt(); + if(!fail_with_exception) + return nil_exprt(); cpp_typecheck.error().source_location=source_location; @@ -1886,7 +1910,9 @@ exprt cpp_typecheck_resolvet::resolve( } break; - default:; + default: + { + } } return result; @@ -1966,7 +1992,8 @@ void cpp_typecheck_resolvet::guess_template_args( const typet &desired_type) { // look at - // http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/com.ibm.xlcpp8a.doc/language/ref/template_argument_deduction.htm + // http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/topic/ + // com.ibm.xlcpp8a.doc/language/ref/template_argument_deduction.htm // T // const T @@ -2078,7 +2105,8 @@ void cpp_typecheck_resolvet::guess_template_args( cpp_typecheck.follow(desired_type); if(desired_type_followed.id()==ID_pointer) - guess_template_args(template_type.subtype(), desired_type_followed.subtype()); + guess_template_args( + template_type.subtype(), desired_type_followed.subtype()); } else if(template_type.id()==ID_array) { @@ -2193,7 +2221,7 @@ exprt cpp_typecheck_resolvet::guess_function_template_args( function_declarator.type().find(ID_parameters).get_sub(); exprt::operandst::const_iterator it=fargs.operands.begin(); - for(const auto & parameter : parameters) + for(const auto ¶meter : parameters) { if(it==fargs.operands.end()) break; @@ -2343,8 +2371,9 @@ void cpp_typecheck_resolvet::apply_template_args( // do we have an object? if(fargs.has_object) { - const symbolt &type_symb = - cpp_typecheck.lookup(fargs.operands.begin()->type().get(ID_identifier)); + const symbolt &type_symb= + cpp_typecheck.lookup( + fargs.operands.begin()->type().get(ID_identifier)); assert(type_symb.type.id()==ID_struct); @@ -2359,7 +2388,6 @@ void cpp_typecheck_resolvet::apply_template_args( expr.swap(member); return; } - } expr=cpp_symbol_expr(new_symbol); @@ -2399,14 +2427,14 @@ bool cpp_typecheck_resolvet::disambiguate_functions( if(!fargs.has_object) { const code_typet::parameterst ¶meters=type.parameters(); - const code_typet::parametert ¶meter = parameters.front(); + const code_typet::parametert ¶meter=parameters.front(); assert(parameter.get(ID_C_base_name)==ID_this); if(type.return_type().id() == ID_constructor) { // it's a constructor - const typet &object_type = parameter.type().subtype(); + const typet &object_type=parameter.type().subtype(); exprt object(ID_symbol, object_type); object.set(ID_C_lvalue, true); @@ -2481,8 +2509,9 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( if(id.is_member) { - struct_typet struct_type = - static_cast(cpp_typecheck.lookup(id.class_identifier).type); + struct_typet struct_type= + static_cast( + cpp_typecheck.lookup(id.class_identifier).type); const exprt pcomp=struct_type.get_component(identifier); assert(pcomp.is_not_nil()); assert(pcomp.get_bool(ID_is_type)); @@ -2518,7 +2547,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( } else if(id.id_class==cpp_scopet::TEMPLATE) { - //std::cout << "X3\n"; + // std::cout << "X3\n"; #if 0 const symbolt &symbol= cpp_typecheck.lookup(id.identifier); @@ -2541,8 +2570,11 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( #if 0 cpp_typecheck.template_map.print(std::cout); - std::cout << "S: " << cpp_typecheck.cpp_scopes.current_scope().identifier << std::endl; - std::cout << "P: " << cpp_typecheck.cpp_scopes.current_scope().get_parent() << std::endl; + std::cout << "S: " << cpp_typecheck.cpp_scopes.current_scope().identifier + << std::endl; + std::cout << "P: " + << cpp_typecheck.cpp_scopes.current_scope().get_parent() + << std::endl; std::cout << "I: " << id.identifier << std::endl; std::cout << "E: " << e.pretty() << std::endl; #endif @@ -2637,7 +2669,7 @@ void cpp_typecheck_resolvet::resolve_with_arguments( const cpp_typecheck_fargst &fargs) { // not clear what this is good for - for(const auto & arg : fargs.operands) + for(const auto &arg : fargs.operands) { const typet &final_type=cpp_typecheck.follow(arg.type()); @@ -2645,7 +2677,8 @@ void cpp_typecheck_resolvet::resolve_with_arguments( continue; cpp_scopest::id_sett tmp_set; - cpp_scopet &scope=cpp_typecheck.cpp_scopes.get_scope(final_type.get(ID_name)); + cpp_scopet &scope= + cpp_typecheck.cpp_scopes.get_scope(final_type.get(ID_name)); scope.lookup(base_name, cpp_scopet::SCOPE_ONLY, tmp_set); id_set.insert(tmp_set.begin(), tmp_set.end()); } diff --git a/src/cpp/cpp_typecheck_resolve.h b/src/cpp/cpp_typecheck_resolve.h index 108bb8c1db6..07e3511e0b3 100644 --- a/src/cpp/cpp_typecheck_resolve.h +++ b/src/cpp/cpp_typecheck_resolve.h @@ -133,26 +133,26 @@ class cpp_typecheck_resolvet struct matcht { - unsigned cost; + std::size_t cost; cpp_template_args_tct specialization_args; cpp_template_args_tct full_args; irep_idt id; - matcht(cpp_template_args_tct _s_args, - cpp_template_args_tct _f_args, - irep_idt _id): - cost((unsigned)_s_args.arguments().size()), - specialization_args(_s_args), - full_args(_f_args), - id(_id) + matcht( + cpp_template_args_tct _s_args, + cpp_template_args_tct _f_args, + irep_idt _id): + cost(_s_args.arguments().size()), + specialization_args(_s_args), + full_args(_f_args), + id(_id) { } - }; - - inline friend bool operator < (const matcht &m1, const matcht &m2) - { - return m1.cost(instantiated_with.get_sub()[i]); + static_cast( + instantiated_with.get_sub()[i]); cpp_declarationt decl_tmp=declaration; @@ -520,7 +525,8 @@ std::string cpp_typecheckt::class_template_identifier( it!=template_type.template_parameters().end(); it++) { - if(counter!=0) identifier+=','; + if(counter!=0) + identifier+=','; if(it->id()==ID_type) identifier+="Type"+std::to_string(counter); @@ -542,7 +548,8 @@ std::string cpp_typecheckt::class_template_identifier( it!=partial_specialization_args.arguments().end(); it++, counter++) { - if(counter!=0) identifier+=','; + if(counter!=0) + identifier+=','; // These are not yet typechecked, as they may depend // on unassigned template parameters. @@ -709,7 +716,7 @@ void cpp_typecheckt::convert_class_template_specialization( template_args_tc, type); } - else + else // NOLINT(readability/braces) #endif { @@ -1198,7 +1205,9 @@ void cpp_typecheckt::convert_template_declaration( typecheck_class_template(declaration); return; } - else // maybe function template, maybe class template member, maye template variable + // maybe function template, maybe class template member, maye + // template variable + else { // there should be declarators in either case if(declaration.declarators().empty()) diff --git a/src/cpp/cpp_typecheck_using.cpp b/src/cpp/cpp_typecheck_using.cpp index d7f02b1ebe7..4908539a2d4 100644 --- a/src/cpp/cpp_typecheck_using.cpp +++ b/src/cpp/cpp_typecheck_using.cpp @@ -64,7 +64,8 @@ void cpp_typecheckt::convert(cpp_usingt &cpp_using) if(using_directive) { if((*it)->id_class==cpp_idt::NAMESPACE) - cpp_scopes.current_scope().add_using_scope(static_cast(**it)); + cpp_scopes.current_scope().add_using_scope( + static_cast(**it)); else { // we should likely complain about this diff --git a/src/cpp/cpp_typecheck_virtual_table.cpp b/src/cpp/cpp_typecheck_virtual_table.cpp index 1d8cca10b84..ec52b1270ae 100644 --- a/src/cpp/cpp_typecheck_virtual_table.cpp +++ b/src/cpp/cpp_typecheck_virtual_table.cpp @@ -15,11 +15,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu Function: cpp_typecheckt::do_virtual_table -Inputs: - -Outputs: - -Purpose: +Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ @@ -28,80 +24,84 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol) assert(symbol.type.id()==ID_struct); // builds virtual-table value maps: (class x virtual_name x value) - std::map > vt_value_maps; + std::map > vt_value_maps; - const struct_typet &struct_type = to_struct_type(symbol.type); + const struct_typet &struct_type=to_struct_type(symbol.type); - for(unsigned i = 0; i < struct_type.components().size(); i++) + for(unsigned i=0; i < struct_type.components().size(); i++) { - const struct_typet::componentt& compo = struct_type.components()[i]; + const struct_typet::componentt &compo=struct_type.components()[i]; if(!compo.get_bool("is_virtual")) continue; - const code_typet& code_type = to_code_type(compo.type()); + const code_typet &code_type=to_code_type(compo.type()); assert(code_type.parameters().size() > 0); - const pointer_typet& pointer_type = + const pointer_typet &pointer_type = static_cast(code_type.parameters()[0].type()); - irep_idt class_id = pointer_type.subtype().get("identifier"); + irep_idt class_id=pointer_type.subtype().get("identifier"); - std::map& value_map = + std::map &value_map = vt_value_maps[class_id]; - exprt e = symbol_exprt(compo.get_name(),code_type); + exprt e=symbol_exprt(compo.get_name(), code_type); if(compo.get_bool("is_pure_virtual")) { pointer_typet pointer_type(code_type); e=null_pointer_exprt(pointer_type); - value_map[compo.get("virtual_name")] = e; + value_map[compo.get("virtual_name")]=e; } else { address_of_exprt address(e); - value_map[compo.get("virtual_name")] = address; + value_map[compo.get("virtual_name")]=address; } } // create virtual-table symbol variables - for(std::map >::const_iterator cit = - vt_value_maps.begin(); cit != vt_value_maps.end(); cit++) + for(std::map >::const_iterator cit = + vt_value_maps.begin(); cit!=vt_value_maps.end(); cit++) { - const std::map& value_map = cit->second; + const std::map &value_map=cit->second; - const symbolt& late_cast_symb = namespacet(symbol_table).lookup(cit->first); - const symbolt& vt_symb_type = namespacet(symbol_table).lookup("virtual_table::"+id2string(late_cast_symb.name)); + const symbolt &late_cast_symb=namespacet(symbol_table).lookup(cit->first); + const symbolt &vt_symb_type= + namespacet(symbol_table).lookup( + "virtual_table::"+id2string(late_cast_symb.name)); symbolt vt_symb_var; - vt_symb_var.name= id2string(vt_symb_type.name) + "@"+ id2string(symbol.name); - vt_symb_var.base_name= id2string(vt_symb_type.base_name) + "@" + id2string(symbol.base_name); + vt_symb_var.name= + id2string(vt_symb_type.name) + "@"+ id2string(symbol.name); + vt_symb_var.base_name= + id2string(vt_symb_type.base_name) + "@" + id2string(symbol.base_name); vt_symb_var.mode=ID_cpp; vt_symb_var.module=module; vt_symb_var.location=vt_symb_type.location; - vt_symb_var.type = symbol_typet(vt_symb_type.name); - vt_symb_var.is_lvalue = true; - vt_symb_var.is_static_lifetime = true; + vt_symb_var.type=symbol_typet(vt_symb_type.name); + vt_symb_var.is_lvalue=true; + vt_symb_var.is_static_lifetime=true; // do the values - const struct_typet &vt_type = to_struct_type(vt_symb_type.type); + const struct_typet &vt_type=to_struct_type(vt_symb_type.type); exprt values(ID_struct, symbol_typet(vt_symb_type.name)); for(unsigned i=0; i < vt_type.components().size(); i++) { - const struct_typet::componentt& compo = vt_type.components()[i]; - std::map::const_iterator cit2 = - value_map.find( compo.get("base_name")); - assert(cit2 != value_map.end()); - const exprt& value = cit2->second; - assert(value.type() == compo.type()); + const struct_typet::componentt &compo=vt_type.components()[i]; + std::map::const_iterator cit2 = + value_map.find(compo.get("base_name")); + assert(cit2!=value_map.end()); + const exprt &value=cit2->second; + assert(value.type()==compo.type()); values.operands().push_back(value); } - vt_symb_var.value = values; + vt_symb_var.value=values; - bool failed = symbol_table.move(vt_symb_var); + bool failed=symbol_table.move(vt_symb_var); assert(!failed); } } diff --git a/src/cpp/cpp_util.h b/src/cpp/cpp_util.h index 8bb50c9dc83..17351354c1d 100644 --- a/src/cpp/cpp_util.h +++ b/src/cpp/cpp_util.h @@ -38,7 +38,7 @@ Function: already_typechecked \*******************************************************************/ -extern inline void already_typechecked(irept &irep) +inline void already_typechecked(irept &irep) { exprt tmp("already_typechecked"); tmp.copy_to_operands(static_cast(irep)); diff --git a/src/cpp/expr2cpp.cpp b/src/cpp/expr2cpp.cpp index d01ff791599..052483a06f0 100644 --- a/src/cpp/expr2cpp.cpp +++ b/src/cpp/expr2cpp.cpp @@ -24,7 +24,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu class expr2cppt:public expr2ct { public: - expr2cppt(const namespacet &_ns):expr2ct(_ns) { } + explicit expr2cppt(const namespacet &_ns):expr2ct(_ns) { } std::string convert(const exprt &src) override { @@ -45,6 +45,7 @@ class expr2cppt:public expr2ct std::string convert_code_cpp_delete(const exprt &src, unsigned precedence); std::string convert_struct(const exprt &src, unsigned &precedence) override; std::string convert_code(const codet &src, unsigned indent) override; + // NOLINTNEXTLINE(whitespace/line_length) std::string convert_constant(const constant_exprt &src, unsigned &precedence) override; std::string convert_rec( @@ -310,7 +311,8 @@ std::string expr2cppt::convert_rec( forall_irep(it, arguments) { - if(it!=arguments.begin()) dest+=", "; + if(it!=arguments.begin()) + dest+=", "; const exprt &argument=(const exprt &)*it; @@ -343,26 +345,27 @@ std::string expr2cppt::convert_rec( typet member; member.swap(tmp.add("to-member")); - std::string dest = "(" + convert_rec(member, c_qualifierst(), "") + ":: *)"; + std::string dest="("+convert_rec(member, c_qualifierst(), "")+":: *)"; if(src.subtype().id()==ID_code) { - const code_typet& code_type = to_code_type(src.subtype()); - const typet& return_type = code_type.return_type(); - dest = convert_rec(return_type, c_qualifierst(), "") +" " + dest; + const code_typet &code_type = to_code_type(src.subtype()); + const typet &return_type = code_type.return_type(); + dest=convert_rec(return_type, c_qualifierst(), "")+" "+dest; const code_typet::parameterst &args = code_type.parameters(); - dest += "("; + dest+="("; for(code_typet::parameterst::const_iterator it=args.begin(); it!=args.end(); ++it) { - if(it!=args.begin()) dest+=", "; + if(it!=args.begin()) + dest+=", "; dest+=convert_rec(it->type(), c_qualifierst(), ""); } - dest += ")"; + dest+=")"; dest+=d; } else @@ -406,7 +409,8 @@ std::string expr2cppt::convert_rec( if(code_type.has_ellipsis()) { - if(!parameters.empty()) dest+=", "; + if(!parameters.empty()) + dest+=", "; dest+="..."; } @@ -542,10 +546,10 @@ std::string expr2cppt::convert( else if(src.id()==ID_side_effect && src.get(ID_statement)==ID_throw) return convert_function(src, "throw", precedence=16); - else if(src.is_constant() && src.type().id() == ID_verilog_signedbv) - return "'" + id2string(src.get(ID_value)) + "'"; - else if(src.is_constant() && src.type().id() == ID_verilog_unsignedbv) - return "'" + id2string(src.get(ID_value)) + "'"; + else if(src.is_constant() && src.type().id()==ID_verilog_signedbv) + return "'"+id2string(src.get(ID_value))+"'"; + else if(src.is_constant() && src.type().id()==ID_verilog_unsignedbv) + return "'"+id2string(src.get(ID_value))+"'"; else if(src.is_constant() && to_constant_expr(src).get_value()==ID_nullptr) return "nullptr"; else if(src.id()==ID_unassigned) @@ -580,7 +584,7 @@ std::string expr2cppt::convert_code( if(statement==ID_cpp_new || statement==ID_cpp_new_array) - return convert_cpp_new(src,indent); + return convert_cpp_new(src, indent); return expr2ct::convert_code(src, indent); } @@ -601,8 +605,8 @@ std::string expr2cppt::convert_extractbit( const exprt &src, unsigned precedence) { - assert(src.operands().size() == 2); - return convert(src.op0()) + "[" + convert(src.op1()) + "]"; + assert(src.operands().size()==2); + return convert(src.op0())+"["+convert(src.op1())+"]"; } /*******************************************************************\ @@ -621,9 +625,10 @@ std::string expr2cppt::convert_extractbits( const exprt &src, unsigned precedence) { - assert(src.operands().size() == 3); - return convert(src.op0()) + ".range(" + convert(src.op1()) + "," - + convert(src.op2()) + ")"; + assert(src.operands().size()==3); + return + convert(src.op0())+".range("+convert(src.op1())+ ","+ + convert(src.op2())+")"; } /*******************************************************************\ diff --git a/src/cpp/parse.cpp b/src/cpp/parse.cpp index e07b21c55bf..5a7d2095a58 100644 --- a/src/cpp/parse.cpp +++ b/src/cpp/parse.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: C++ Language Parsing + +Author: Daniel Kroening, kroening@cs.cmu.edu + +\*******************************************************************/ + #include #include @@ -13,14 +21,14 @@ #include "cpp_member_spec.h" #include "cpp_enum_type.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include static unsigned __indent; -struct indenter +struct indenter // NOLINT(readability/identifiers) { indenter() { __indent+=2; } ~indenter() { __indent-=2; } @@ -129,7 +137,7 @@ class new_scopet class save_scopet { public: - inline save_scopet(new_scopet *&_scope): + explicit save_scopet(new_scopet *&_scope): scope_ptr(_scope), old_scope(_scope) { } @@ -171,7 +179,7 @@ void new_scopet::print_rec(std::ostream &out, unsigned indent) const } } -class Parser +class Parser // NOLINT(readability/identifiers) { public: explicit Parser(cpp_parsert &_cpp_parser): @@ -224,9 +232,22 @@ class Parser bool rExternTemplateDecl(irept &); bool rDeclaration(cpp_declarationt &); - bool rIntegralDeclaration(cpp_declarationt &, cpp_storage_spect &, cpp_member_spect &, typet &, typet &); - bool rConstDeclaration(cpp_declarationt &, cpp_storage_spect &, cpp_member_spect &, typet &); - bool rOtherDeclaration(cpp_declarationt &, cpp_storage_spect &, cpp_member_spect &, typet &); + bool rIntegralDeclaration( + cpp_declarationt &, + cpp_storage_spect &, + cpp_member_spect &, + typet &, + typet &); + bool rConstDeclaration( + cpp_declarationt &, + cpp_storage_spect &, + cpp_member_spect &, + typet &); + bool rOtherDeclaration( + cpp_declarationt &, + cpp_storage_spect &, + cpp_member_spect &, + typet &); bool rCondition(exprt &); bool rSimpleDeclaration(cpp_declarationt &); @@ -239,7 +260,10 @@ class Parser bool rAttribute(); bool optAttribute(cpp_declarationt &); bool optIntegralTypeOrClassSpec(typet &); - bool rConstructorDecl(cpp_declaratort &, typet &, typet &trailing_return_type); + bool rConstructorDecl( + cpp_declaratort &, + typet &, + typet &trailing_return_type); bool optThrowDecl(irept &); bool rDeclarators(cpp_declarationt::declaratorst &, bool, bool=false); @@ -493,7 +517,8 @@ Function: Parser::merge_types void Parser::merge_types(const typet &src, typet &dest) { - if(src.is_nil()) return; + if(src.is_nil()) + return; if(dest.is_nil()) dest=src; @@ -542,7 +567,8 @@ bool Parser::SyntaxError() for(unsigned i=0; i(lex.LookAhead(0)) << "\n"; #endif if(!optCvQualify(cv_q)) @@ -1826,7 +1864,8 @@ bool Parser::rIntegralDeclaration( { case ';': #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 4\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 4\n"; #endif lex.get_token(tk); @@ -1834,7 +1873,8 @@ bool Parser::rIntegralDeclaration( case ':': // bit field #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 5\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 5\n"; #endif lex.get_token(tk); @@ -1854,7 +1894,8 @@ bool Parser::rIntegralDeclaration( default: #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 6 " + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 6 " << lex.LookAhead(0) << "\n"; #endif @@ -1862,13 +1903,15 @@ bool Parser::rIntegralDeclaration( return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 7\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 7\n"; #endif if(lex.LookAhead(0)==';') { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 8 " + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 8 " << declaration << "\n"; #endif @@ -1878,7 +1921,8 @@ bool Parser::rIntegralDeclaration( else { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 9\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 9\n"; #endif if(declaration.declarators().size()!=1) @@ -1888,7 +1932,8 @@ bool Parser::rIntegralDeclaration( return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rIntegralDeclaration 10\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rIntegralDeclaration 10\n"; #endif return true; @@ -2014,7 +2059,8 @@ bool Parser::rOtherDeclaration( cpp_declaratort conv_operator_declarator; typet trailing_return_type; - if(!rConstructorDecl(conv_operator_declarator, type_name, trailing_return_type)) + if(!rConstructorDecl( + conv_operator_declarator, type_name, trailing_return_type)) return false; type_name=typet("cpp-cast-operator"); @@ -2031,11 +2077,16 @@ bool Parser::rOtherDeclaration( bool is_destructor=false; forall_irep(it, type_name.get_sub()) - if(it->id()=="~") { is_destructor=true; break; } + if(it->id()=="~") + { + is_destructor=true; + break; + } cpp_declaratort constructor_declarator; typet trailing_return_type; - if(!rConstructorDecl(constructor_declarator, type_name, trailing_return_type)) + if(!rConstructorDecl( + constructor_declarator, type_name, trailing_return_type)) return false; #ifdef DEBUG @@ -2057,15 +2108,15 @@ bool Parser::rOtherDeclaration( #endif // FRIEND name ';' - //if(Ptree::Length(member_spec)==1 && member_spec->Car()->What()==FRIEND) + // if(Ptree::Length(member_spec)==1 && member_spec->Car()->What()==FRIEND) { cpp_tokent tk; lex.get_token(tk); - //statement=new PtreeDeclaration(head, Ptree::List(type_name, + // statement=new PtreeDeclaration(head, Ptree::List(type_name, // new Leaf(tk))); return true; } - //else + // else // return false; } else @@ -2139,8 +2190,8 @@ bool Parser::isConstructorDecl() { #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::isConstructorDecl "<< lex.LookAhead(0) - << " "<< lex.LookAhead(1) << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::isConstructorDecl " + << lex.LookAhead(0) << " "<< lex.LookAhead(1) << "\n"; #endif if(lex.LookAhead(0)!='(') @@ -2291,7 +2342,8 @@ bool Parser::optMemberSpec(cpp_member_spect &member_spec) \*******************************************************************/ /* - storage.spec : STATIC | EXTERN | AUTO | REGISTER | MUTABLE | ASM | THREAD_LOCAL + storage.spec : STATIC | EXTERN | AUTO | REGISTER | MUTABLE | ASM | + THREAD_LOCAL */ bool Parser::optStorageSpec(cpp_storage_spect &storage_spec) { @@ -2445,11 +2497,13 @@ bool Parser::optAlignas(typet &cv) lex.get_token(op); if(rTypeName(tname)) + { if(lex.get_token(cp)==')') { // TODO return true; } + } lex.Restore(pos); @@ -2484,7 +2538,8 @@ bool Parser::rAttribute() { case '(': rAttribute(); - if(lex.LookAhead(0)!=')') return false; + if(lex.LookAhead(0)!=')') + return false; lex.get_token(tk); break; @@ -2569,7 +2624,8 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) { #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 0\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 0\n"; #endif // DEBUG // This makes no sense, but is used in Visual Studio header files. @@ -2589,7 +2645,8 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) t=lex.LookAhead(0); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 1\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 1\n"; #endif // DEBUG irep_idt type_id; @@ -2637,14 +2694,16 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) } #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 2\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 2\n"; #endif // DEBUG if(is_integral) return true; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 3\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 3\n"; #endif // DEBUG if(t==TOK_CLASS || t==TOK_STRUCT || t==TOK_UNION || t==TOK_INTERFACE) @@ -2654,21 +2713,24 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) else if(t==TOK_TYPEOF) { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 4\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 4\n"; #endif // DEBUG cpp_tokent typeof_tk; lex.get_token(typeof_tk); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 5\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 5\n"; #endif // DEBUG p=typet(ID_typeof); set_location(p, typeof_tk); cpp_tokent tk; - if(lex.get_token(tk)!='(') return false; + if(lex.get_token(tk)!='(') + return false; // the argument can be a type or an expression @@ -2677,30 +2739,37 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) cpp_token_buffert::post pos=lex.Save(); if(rTypeName(tname)) + { if(lex.get_token(tk)==')') { p.add(ID_type_arg).swap(tname); return true; } + } lex.Restore(pos); } #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 6\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 6\n"; #endif // DEBUG exprt expr; - if(!rCommaExpression(expr)) return false; + if(!rCommaExpression(expr)) + return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 7\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 7\n"; #endif // DEBUG - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!=')') + return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optIntegralTypeOrClassSpec 8\n"; + std::cout << std::string(__indent, ' ') + << "Parser::optIntegralTypeOrClassSpec 8\n"; #endif // DEBUG p.add(ID_expr_arg).swap(expr); @@ -2716,14 +2785,17 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) set_location(p, decltype_tk); cpp_tokent tk; - if(lex.get_token(tk)!='(') return false; + if(lex.get_token(tk)!='(') + return false; // the argument is always an expression exprt expr; - if(!rCommaExpression(expr)) return false; + if(!rCommaExpression(expr)) + return false; - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!=')') + return false; p.add(ID_expr_arg).swap(expr); @@ -2740,7 +2812,8 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) set_location(p, underlying_type_tk); cpp_tokent tk; - if(lex.get_token(tk)!='(') return false; + if(lex.get_token(tk)!='(') + return false; // the argument is always a type @@ -2749,7 +2822,8 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p) if(!rTypeName(tname)) return false; - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!=')') + return false; p.add(ID_type_arg).swap(tname); @@ -2885,7 +2959,6 @@ bool Parser::rConstructorDecl( default: return false; } - } else constructor.add(ID_value).make_nil(); @@ -2919,12 +2992,12 @@ bool Parser::optThrowDecl(irept &throw_decl) if(lex.LookAhead(0)==TOK_THROW) { lex.get_token(tk); - //p=Ptree::Snoc(p, new LeafReserved(tk)); + // p=Ptree::Snoc(p, new LeafReserved(tk)); if(lex.get_token(tk)!='(') return false; - //p=Ptree::Snoc(p, new Leaf(tk)); + // p=Ptree::Snoc(p, new Leaf(tk)); for(;;) { @@ -2948,7 +3021,7 @@ bool Parser::optThrowDecl(irept &throw_decl) if(lex.LookAhead(0)==',') { lex.get_token(tk); - //p=Ptree::Snoc(p, new Leaf(tk)); + // p=Ptree::Snoc(p, new Leaf(tk)); } else break; @@ -2957,7 +3030,7 @@ bool Parser::optThrowDecl(irept &throw_decl) if(lex.get_token(tk)!=')') return false; - //p=Ptree::Snoc(p, new Leaf(tk)); + // p=Ptree::Snoc(p, new Leaf(tk)); } else if(lex.LookAhead(0)==TOK_NOEXCEPT) { @@ -3051,7 +3124,7 @@ bool Parser::rDeclaratorWithInit( bit_field_type.subtype().make_nil(); set_location(bit_field_type, tk); - //merge_types(bit_field_type, declarator.type()); + // merge_types(bit_field_type, declarator.type()); return true; } @@ -3071,9 +3144,12 @@ bool Parser::rDeclaratorWithInit( cpp_tokent tk; lex.get_token(tk); // TOK_GCC_ASM - if(lex.get_token(tk)!='(') return false; - if(!rString(tk)) return false; - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!='(') + return false; + if(!rString(tk)) + return false; + if(lex.get_token(tk)!=')') + return false; } int t=lex.LookAhead(0); @@ -3259,12 +3335,14 @@ bool Parser::rDeclarator( return false; if(!should_be_declarator) + { if((kind==kDeclarator || kind==kCastDeclarator) && d_outer.is_nil()) { t=lex.LookAhead(0); if(t!='[' && t!='(') return false; } + } #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rDeclarator2 5\n"; @@ -3290,7 +3368,8 @@ bool Parser::rDeclarator( #endif exprt init_args(static_cast(get_nil_irep())); - typet method_qualifier(static_cast(get_nil_irep())); // const... + // const... + typet method_qualifier(static_cast(get_nil_irep())); for(;;) { @@ -3465,7 +3544,8 @@ bool Parser::optPtrOperator(typet &ptrs) int t=lex.LookAhead(0); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::optPtrOperator 2 " << t << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::optPtrOperator 2 " + << t << "\n"; #endif if(t=='*') @@ -3758,7 +3838,8 @@ bool Parser::rName(irept &name) cpp_tokent tk; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rName 2 " << lex.LookAhead(0) << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::rName 2 " + << lex.LookAhead(0) << "\n"; #endif switch(lex.LookAhead(0)) @@ -3769,7 +3850,8 @@ bool Parser::rName(irept &name) #endif lex.get_token(tk); // Skip template token, next will be identifier - if(lex.LookAhead(0)!=TOK_IDENTIFIER) return false; + if(lex.LookAhead(0)!=TOK_IDENTIFIER) + return false; break; case '<': @@ -3785,7 +3867,8 @@ bool Parser::rName(irept &name) components.back().add(ID_arguments).swap(args); // done unless scope is next - if(lex.LookAhead(0)!=TOK_SCOPE) return true; + if(lex.LookAhead(0)!=TOK_SCOPE) + return true; } break; @@ -3801,7 +3884,8 @@ bool Parser::rName(irept &name) { int t=lex.LookAhead(0); // done unless scope or template args is next - if(t!=TOK_SCOPE && t!='<') return true; + if(t!=TOK_SCOPE && t!='<') + return true; } break; @@ -3844,7 +3928,8 @@ bool Parser::rName(irept &name) } // done unless template args are next - if(lex.LookAhead(0)!='<') return true; + if(lex.LookAhead(0)!='<') + return true; break; default: @@ -3901,7 +3986,7 @@ bool Parser::rOperatorName(irept &name) case '<': case '>': case ',': - operator_id=irep_idt(std::string(char(t), 1)); + operator_id=irep_idt(std::string(static_cast(t), 1)); break; case TOK_MULTASSIGN: operator_id="*="; break; @@ -3948,7 +4033,6 @@ bool Parser::rOperatorName(irept &name) if(lex.get_token(tk)!=']') return false; } - } return true; @@ -4015,7 +4099,7 @@ bool Parser::rCastOperatorName(irept &name) return false; } - merge_types(cv1,type_name); + merge_types(cv1, type_name); if(!optCvQualify(cv2)) return false; @@ -4074,7 +4158,8 @@ bool Parser::rPtrToMember(irept &ptr_to_mem) case TOK_TEMPLATE: lex.get_token(tk); // Skip template token, next will be identifier - if(lex.LookAhead(0)!=TOK_IDENTIFIER) return false; + if(lex.LookAhead(0)!=TOK_IDENTIFIER) + return false; break; case '<': @@ -4086,7 +4171,8 @@ bool Parser::rPtrToMember(irept &ptr_to_mem) components.push_back(irept(ID_template_args)); components.back().add(ID_arguments).swap(args); - if(lex.LookAhead(0)!=TOK_SCOPE) return false; + if(lex.LookAhead(0)!=TOK_SCOPE) + return false; } break; @@ -4098,7 +4184,8 @@ bool Parser::rPtrToMember(irept &ptr_to_mem) { int t=lex.LookAhead(0); - if(t!=TOK_SCOPE && t!='<') return false; + if(t!=TOK_SCOPE && t!='<') + return false; } break; @@ -4326,7 +4413,7 @@ bool Parser::rArgDeclListOrInit( if(lex.LookAhead(0)==')') { is_args=false; - //encode.Clear(); + // encode.Clear(); return true; } @@ -4340,7 +4427,7 @@ bool Parser::rArgDeclListOrInit( else { lex.Restore(pos); - //encode.Clear(); + // encode.Clear(); return rFunctionArguments(arglist); } } @@ -4511,13 +4598,20 @@ bool Parser::rInitializeExpr(exprt &expr) cpp_tokent tk; exprt name; lex.get_token(tk); - if(lex.get_token(tk)!='(') return false; - if(!rVarName(name)) return false; - if(lex.get_token(tk)!=')') return false; - if(lex.get_token(tk)!='{') return false; - if(!rInitializeExpr(name)) return false; - if(lex.LookAhead(0)==',') lex.get_token(tk); - if(lex.get_token(tk)!='}') return false; + if(lex.get_token(tk)!='(') + return false; + if(!rVarName(name)) + return false; + if(lex.get_token(tk)!=')') + return false; + if(lex.get_token(tk)!='{') + return false; + if(!rInitializeExpr(name)) + return false; + if(lex.LookAhead(0)==',') + lex.get_token(tk); + if(lex.get_token(tk)!='}') + return false; } if(!rInitializeExpr(tmp)) @@ -4637,7 +4731,7 @@ bool Parser::rEnumSpec(typet &spec) #endif cpp_tokent tk; - //bool is_enum_class=false; + // bool is_enum_class=false; if(lex.get_token(tk)!=TOK_ENUM) return false; @@ -4651,7 +4745,7 @@ bool Parser::rEnumSpec(typet &spec) if(lex.LookAhead(0)==TOK_CLASS) { lex.get_token(tk); - //is_enum_class=true; + // is_enum_class=true; } if(lex.LookAhead(0)!='{' && @@ -4675,7 +4769,8 @@ bool Parser::rEnumSpec(typet &spec) if(lex.LookAhead(0)==':') { lex.get_token(tk); // read the colon - if(!rTypeName(spec.subtype())) return false; + if(!rTypeName(spec.subtype())) + return false; } #ifdef DEBUG @@ -5020,15 +5115,17 @@ bool Parser::rClassBody(exprt &body) SkipTo('}'); lex.get_token(tk); - //body=Ptree::List(ob, nil, new Leaf(tk)); + // body=Ptree::List(ob, nil, new Leaf(tk)); return true; // error recovery } #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rClassBody " << member << std::endl; + std::cout << std::string(__indent, ' ') << "Parser::rClassBody " << member + << std::endl; #endif - members.move_to_operands(static_cast(static_cast(member))); + members.move_to_operands( + static_cast(static_cast(member))); } lex.get_token(tk); @@ -5072,7 +5169,8 @@ bool Parser::rClassMember(cpp_itemt &member) #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::rClassMember 0 " << t << std::endl; + std::cout << std::string(__indent, ' ') << "Parser::rClassMember 0 " << t + << std::endl; #endif // DEBUG if(t==TOK_PUBLIC || t==TOK_PROTECTED || t==TOK_PRIVATE) @@ -5154,7 +5252,7 @@ bool Parser::rAccessDecl(irept &mem) if(lex.get_token(tk)!=';') return false; - //mem=new PtreeAccessDecl(new PtreeName(name, encode), + // mem=new PtreeAccessDecl(new PtreeName(name, encode), // Ptree::List(new Leaf(tk))); return true; } @@ -6114,7 +6212,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) { #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 0\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 0\n"; #endif cpp_token_buffert::post pos=lex.Save(); @@ -6122,7 +6221,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) if(rTypeName(tname) && lex.LookAhead(0)!='(') { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 1\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 1\n"; #endif if(!optPtrOperator(tname)) @@ -6134,7 +6234,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) lex.Restore(pos); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 2\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 2\n"; #endif code_typet type; @@ -6143,7 +6244,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 3\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 3\n"; #endif if(lex.LookAhead(0)!='(') @@ -6157,14 +6259,16 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) } #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 4\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 4\n"; #endif cpp_tokent op; lex.get_token(op); // TODO -- cruel hack for Clang's type_traits: - // struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false> + // struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), + // true, false> if(lex.LookAhead(0)==TOK_IDENTIFIER && lex.LookAhead(1)==TOK_SCOPE && lex.LookAhead(2)=='*' && @@ -6203,7 +6307,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) // function type parameters #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 5\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 5\n"; #endif int t=lex.LookAhead(0); @@ -6245,7 +6350,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) } #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 6\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 6\n"; #endif cpp_tokent cp; @@ -6256,7 +6362,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 7\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 7\n"; #endif // not sure where this one belongs @@ -6266,7 +6373,8 @@ bool Parser::rTypeNameOrFunctionType(typet &tname) tname.swap(type); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rTypeNameOrFunctionType 8\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rTypeNameOrFunctionType 8\n"; #endif return true; @@ -6485,9 +6593,10 @@ bool Parser::rTypeidExpr(exprt &exp) cpp_token_buffert::post pos=lex.Save(); lex.get_token(op); if(rTypeName(tname)) + { if(lex.get_token(cp)==')') { - //exp=new PtreeTypeidExpr(new Leaf(tk), + // exp=new PtreeTypeidExpr(new Leaf(tk), // Ptree::List(new Leaf(op), tname, // new Leaf(cp))); @@ -6495,22 +6604,26 @@ bool Parser::rTypeidExpr(exprt &exp) set_location(exp, tk); return true; } + } lex.Restore(pos); lex.get_token(op); if(rExpression(subexp, false)) + { if(lex.get_token(cp)==')') { - // exp=new PtreeTypeidExpr(new Leaf(tk), - // Ptree::List( - // Ptree::List(new Leaf(op), subexp, new Leaf(cp)) - // )); + // exp=new PtreeTypeidExpr( + // new Leaf(tk), + // Ptree::List( + // Ptree::List(new Leaf(op), subexp, new Leaf(cp)) + // )); exp=exprt("typeid"); set_location(exp, tk); return true; } + } lex.Restore(pos); } @@ -6558,6 +6671,7 @@ bool Parser::rSizeofExpr(exprt &exp) lex.get_token(op); if(rTypeName(tname)) + { if(lex.get_token(cp)==')') { exp=exprt(ID_sizeof); @@ -6565,6 +6679,7 @@ bool Parser::rSizeofExpr(exprt &exp) set_location(exp, tk); return true; } + } lex.Restore(pos); } @@ -6578,6 +6693,7 @@ bool Parser::rSizeofExpr(exprt &exp) lex.get_token(op); if(rTypeName(tname)) + { if(lex.get_token(cp)==')') { exp=exprt(ID_sizeof); @@ -6585,6 +6701,7 @@ bool Parser::rSizeofExpr(exprt &exp) set_location(exp, tk); return true; } + } return false; } @@ -6677,6 +6794,7 @@ bool Parser::rNoexceptExpr(exprt &exp) lex.get_token(op); if(rExpression(subexp, false)) + { if(lex.get_token(cp)==')') { // TODO @@ -6685,6 +6803,7 @@ bool Parser::rNoexceptExpr(exprt &exp) set_location(exp, tk); return true; } + } } else return true; @@ -6731,7 +6850,7 @@ bool Parser::rAllocateExpr(exprt &exp) if(t==TOK_SCOPE) { lex.get_token(tk); - // TODO, one can put 'new'/'delete' into a namespace! + // TODO one can put 'new'/'delete' into a namespace! } #ifdef DEBUG @@ -7397,18 +7516,26 @@ bool Parser::rTypePredicate(exprt &expr) switch(tk.kind) { case TOK_UNARY_TYPE_PREDICATE: - if(lex.get_token(tk)!='(') return false; - if(!rTypeName(tname1)) return false; - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!='(') + return false; + if(!rTypeName(tname1)) + return false; + if(lex.get_token(tk)!=')') + return false; expr.add(ID_type_arg).swap(tname1); break; case TOK_BINARY_TYPE_PREDICATE: - if(lex.get_token(tk)!='(') return false; - if(!rTypeName(tname1)) return false; - if(lex.get_token(tk)!=',') return false; - if(!rTypeName(tname2)) return false; - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!='(') + return false; + if(!rTypeName(tname1)) + return false; + if(lex.get_token(tk)!=',') + return false; + if(!rTypeName(tname2)) + return false; + if(lex.get_token(tk)!=')') + return false; expr.add("type_arg1").swap(tname1); expr.add("type_arg2").swap(tname2); break; @@ -7455,7 +7582,8 @@ bool Parser::rPrimaryExpr(exprt &exp) #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 0 " << lex.LookAhead(0) << " " << lex.current_token().text <<"\n"; + std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 0 " + << lex.LookAhead(0) << " " << lex.current_token().text <<"\n"; #endif switch(lex.LookAhead(0)) @@ -7657,7 +7785,7 @@ bool Parser::rPrimaryExpr(exprt &exp) { lex.get_token(tk); - //exp=new PtreeStaticUserStatementExpr(exp, + // exp=new PtreeStaticUserStatementExpr(exp, // Ptree::Cons(new Leaf(tk), exp2)); // TODO } @@ -7750,7 +7878,8 @@ bool Parser::rVarNameCore(exprt &name) cpp_tokent tk; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rVarNameCore 1.1 " << lex.LookAhead(0) + std::cout << std::string(__indent, ' ') << "Parser::rVarNameCore 1.1 " + << lex.LookAhead(0) << std::endl; #endif @@ -7763,7 +7892,8 @@ bool Parser::rVarNameCore(exprt &name) #endif lex.get_token(tk); // Skip template token, next will be identifier - if(lex.LookAhead(0)!=TOK_IDENTIFIER) return false; + if(lex.LookAhead(0)!=TOK_IDENTIFIER) + return false; break; case TOK_IDENTIFIER: @@ -7796,7 +7926,8 @@ bool Parser::rVarNameCore(exprt &name) components.back().add(ID_arguments).swap(args); } - if(!moreVarName()) return true; + if(!moreVarName()) + return true; break; case TOK_SCOPE: @@ -7918,13 +8049,15 @@ bool Parser::maybeTemplateArgs() while(n>0) { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::maybeTemplateArgs 1\n"; + std::cout << std::string(__indent, ' ') + << "Parser::maybeTemplateArgs 1\n"; #endif int u=lex.LookAhead(i++); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::maybeTemplateArgs 2\n"; + std::cout << std::string(__indent, ' ') + << "Parser::maybeTemplateArgs 2\n"; #endif if(u=='<') @@ -7939,7 +8072,8 @@ bool Parser::maybeTemplateArgs() int v=lex.LookAhead(i++); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::maybeTemplateArgs 3\n"; + std::cout << std::string(__indent, ' ') + << "Parser::maybeTemplateArgs 3\n"; #endif if(v=='(') @@ -7956,7 +8090,8 @@ bool Parser::maybeTemplateArgs() n-=2; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::maybeTemplateArgs 4\n"; + std::cout << std::string(__indent, ' ') + << "Parser::maybeTemplateArgs 4\n"; #endif } @@ -8015,7 +8150,8 @@ bool Parser::rFunctionBody(cpp_declaratort &declarator) lex.get_token(tk); // TODO: add to body - if(lex.get_token(cb)!='}') return false; + if(lex.get_token(cb)!='}') + return false; declarator.value()=body; return true; @@ -8139,7 +8275,8 @@ bool Parser::rStatement(codet &statement) #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::rStatement 0 " << lex.LookAhead(0) << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::rStatement 0 " + << lex.LookAhead(0) << "\n"; #endif switch(k=lex.LookAhead(0)) @@ -8203,14 +8340,16 @@ bool Parser::rStatement(codet &statement) if(lex.LookAhead(0)==';') { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rStatement RETURN 1\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rStatement RETURN 1\n"; #endif lex.get_token(tk2); } else { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rStatement RETURN 2\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rStatement RETURN 2\n"; #endif exprt exp; @@ -8219,7 +8358,8 @@ bool Parser::rStatement(codet &statement) return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rStatement RETURN 3\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rStatement RETURN 3\n"; #endif if(lex.get_token(tk2)!=';') @@ -8884,7 +9024,8 @@ bool Parser::rGCCAsmStatement(codet &statement) // asm [volatile] ("stuff" [ : ["=S" [(__res)], ... ]]) ; - if(lex.get_token(tk)!=TOK_GCC_ASM) return false; + if(lex.get_token(tk)!=TOK_GCC_ASM) + return false; statement=codet(ID_asm); statement.set(ID_flavor, ID_gcc); @@ -8898,8 +9039,10 @@ bool Parser::rGCCAsmStatement(codet &statement) std::cout << std::string(__indent, ' ') << "Parser::rGCCAsmStatement 3\n"; #endif // DEBUG - if(lex.get_token(tk)!='(') return false; - if(!rString(tk)) return false; + if(lex.get_token(tk)!='(') + return false; + if(!rString(tk)) + return false; statement.op0()=tk.data; @@ -8914,11 +9057,13 @@ bool Parser::rGCCAsmStatement(codet &statement) #endif // DEBUG // get ':' - if(lex.get_token(tk)!=':') return false; + if(lex.get_token(tk)!=':') + return false; for(;;) { - if(lex.LookAhead(0)!=TOK_STRING) break; + if(lex.LookAhead(0)!=TOK_STRING) + break; // get String rString(tk); @@ -8929,21 +9074,26 @@ bool Parser::rGCCAsmStatement(codet &statement) lex.get_token(tk); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rGCCAsmStatement 5\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rGCCAsmStatement 5\n"; #endif // DEBUG exprt expr; - if(!rCommaExpression(expr)) return false; + if(!rCommaExpression(expr)) + return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rGCCAsmStatement 6\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rGCCAsmStatement 6\n"; #endif // DEBUG - if(lex.get_token(tk)!=')') return false; + if(lex.get_token(tk)!=')') + return false; } // more? - if(lex.LookAhead(0)!=',') break; + if(lex.LookAhead(0)!=',') + break; lex.get_token(tk); } } @@ -8952,8 +9102,10 @@ bool Parser::rGCCAsmStatement(codet &statement) std::cout << std::string(__indent, ' ') << "Parser::rGCCAsmStatement 7\n"; #endif // DEBUG - if(lex.get_token(tk)!=')') return false; - if(lex.get_token(tk)!=';') return false; + if(lex.get_token(tk)!=')') + return false; + if(lex.get_token(tk)!=';') + return false; #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rGCCAsmStatement 8\n"; @@ -8986,7 +9138,8 @@ bool Parser::rMSCAsmStatement(codet &statement) // asm "STUFF" // asm { "STUFF" } - if(lex.get_token(tk)!=TOK_MSC_ASM) return false; + if(lex.get_token(tk)!=TOK_MSC_ASM) + return false; statement=codet(ID_asm); statement.set(ID_flavor, ID_msc); @@ -9010,7 +9163,8 @@ bool Parser::rMSCAsmStatement(codet &statement) lex.get_token(tk); statement.move_to_operands(tk.data); - if(lex.get_token(tk)!='}') return false; + if(lex.get_token(tk)!='}') + return false; #ifdef DEBUG std::cout << std::string(__indent, ' ') << "Parser::rMSCAsmStatement 4\n"; @@ -9091,7 +9245,8 @@ bool Parser::rExprStatement(codet &statement) if(rDeclarationStatement(statement)) { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "rDe: " << statement << std::endl; + std::cout << std::string(__indent, ' ') << "rDe: " << statement + << std::endl; #endif return true; } @@ -9113,7 +9268,8 @@ bool Parser::rExprStatement(codet &statement) #endif #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rExprStatement 5 " << lex.LookAhead(0) << "\n"; + std::cout << std::string(__indent, ' ') << "Parser::rExprStatement 5 " + << lex.LookAhead(0) << "\n"; #endif if(lex.get_token(tk)!=';') @@ -9202,7 +9358,8 @@ bool Parser::rDeclarationStatement(codet &statement) #ifdef DEBUG indenter _i; - std::cout << std::string(__indent, ' ') << "Parser::rDeclarationStatement 1\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rDeclarationStatement 1\n"; #endif if(!optStorageSpec(storage_spec)) @@ -9224,7 +9381,8 @@ bool Parser::rDeclarationStatement(codet &statement) return false; #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rDeclarationStatement 2\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rDeclarationStatement 2\n"; #endif if(integral.is_not_nil()) @@ -9234,14 +9392,16 @@ bool Parser::rDeclarationStatement(codet &statement) int t=lex.LookAhead(0); #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rDeclarationStatement 3 " << t << "\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rDeclarationStatement 3 " << t << "\n"; #endif if((cv_q.is_not_nil() || storage_spec.is_auto()) && ((t==TOK_IDENTIFIER && lex.LookAhead(1)=='=') || t=='*')) { #ifdef DEBUG - std::cout << std::string(__indent, ' ') << "Parser::rDeclarationStatement 4\n"; + std::cout << std::string(__indent, ' ') + << "Parser::rDeclarationStatement 4\n"; #endif statement=codet(ID_decl); @@ -9432,10 +9592,6 @@ Function: Parser::operator() \*******************************************************************/ -#if 0 -#include -#endif - bool Parser::operator()() { number_of_errors=0; diff --git a/src/cpp/recursion_counter.h b/src/cpp/recursion_counter.h index 9be4c188ae7..fab87c254f7 100644 --- a/src/cpp/recursion_counter.h +++ b/src/cpp/recursion_counter.h @@ -12,7 +12,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu class recursion_countert { public: - recursion_countert(unsigned &_cnt):cnt(_cnt) + explicit recursion_countert(unsigned &_cnt):cnt(_cnt) { cnt++; } diff --git a/src/cpp/template_map.h b/src/cpp/template_map.h index dcdee42e849..c1347eca059 100644 --- a/src/cpp/template_map.h +++ b/src/cpp/template_map.h @@ -65,7 +65,7 @@ class template_mapt class cpp_saved_template_mapt { public: - cpp_saved_template_mapt(template_mapt &map): + explicit cpp_saved_template_mapt(template_mapt &map): old_map(map), map(map) { } diff --git a/src/goto-analyzer/goto_analyzer_parse_options.cpp b/src/goto-analyzer/goto_analyzer_parse_options.cpp index 9e9c4a180bb..68e28755041 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.cpp +++ b/src/goto-analyzer/goto_analyzer_parse_options.cpp @@ -60,7 +60,9 @@ Function: goto_analyzer_parse_optionst::goto_analyzer_parse_optionst \*******************************************************************/ -goto_analyzer_parse_optionst::goto_analyzer_parse_optionst(int argc, const char **argv): +goto_analyzer_parse_optionst::goto_analyzer_parse_optionst( + int argc, + const char **argv): parse_options_baset(GOTO_ANALYSER_OPTIONS, argc, argv), language_uit(cmdline, ui_message_handler), ui_message_handler(cmdline, "GOTO-ANALYZER " CBMC_VERSION) @@ -107,7 +109,8 @@ void goto_analyzer_parse_optionst::eval_verbosity() if(cmdline.isset("verbosity")) { v=unsafe_string2unsigned(cmdline.get_value("verbosity")); - if(v>10) v=10; + if(v>10) + v=10; } ui_message_handler.set_verbosity(v); @@ -231,7 +234,8 @@ int goto_analyzer_parse_optionst::doit() { std::string json_file=cmdline.get_value("json"); bool result= - taint_analysis(goto_model, taint_file, get_message_handler(), false, json_file); + taint_analysis( + goto_model, taint_file, get_message_handler(), false, json_file); return result?10:0; } } @@ -481,12 +485,14 @@ void goto_analyzer_parse_optionst::help() "\n" "Analyses:\n" "\n" + // NOLINTNEXTLINE(whitespace/line_length) " --taint file_name perform taint analysis using rules in given file\n" " --unreachable-instructions list dead code\n" " --intervals interval analysis\n" " --non-null non-null analysis\n" "\n" "Analysis options:\n" + // NOLINTNEXTLINE(whitespace/line_length) " --json file_name output results in JSON format to given file\n" " --xml file_name output results in XML format to given file\n" "\n" @@ -503,14 +509,18 @@ void goto_analyzer_parse_optionst::help() configt::ansi_ct::default_c_standard()== configt::ansi_ct::c_standardt::C99?"c99": configt::ansi_ct::default_c_standard()== - configt::ansi_ct::c_standardt::C11?"c11":"") << ")\n" + configt::ansi_ct::c_standardt::C11? + "c11":"") << ")\n" " --cpp98/03/11 set C++ language standard (default: " << (configt::cppt::default_cpp_standard()== - configt::cppt::cpp_standardt::CPP98?"cpp98": + configt::cppt::cpp_standardt::CPP98? + "cpp98": configt::cppt::default_cpp_standard()== - configt::cppt::cpp_standardt::CPP03?"cpp03": + configt::cppt::cpp_standardt::CPP03? + "cpp03": configt::cppt::default_cpp_standard()== - configt::cppt::cpp_standardt::CPP11?"cpp11":"") << ")\n" + configt::cppt::cpp_standardt::CPP11? + "cpp11":"") << ")\n" #ifdef _WIN32 " --gcc use GCC as preprocessor\n" #endif @@ -524,6 +534,7 @@ void goto_analyzer_parse_optionst::help() " --show-parse-tree show parse tree\n" " --show-symbol-table show symbol table\n" HELP_SHOW_GOTO_FUNCTIONS + // NOLINTNEXTLINE(whitespace/line_length) " --show-properties show the properties, but don't run analysis\n" "\n" "Other options:\n" diff --git a/src/goto-analyzer/static_analyzer.cpp b/src/goto-analyzer/static_analyzer.cpp index f4f6c5cff33..1168cff1a73 100644 --- a/src/goto-analyzer/static_analyzer.cpp +++ b/src/goto-analyzer/static_analyzer.cpp @@ -91,7 +91,8 @@ tvt static_analyzert::eval(goto_programt::const_targett t) exprt guard=t->guard; interval_domaint d=interval_analysis[t]; d.assume(not_exprt(guard), ns); - if(d.is_bottom()) return tvt(true); + if(d.is_bottom()) + return tvt(true); return tvt::unknown(); } @@ -113,7 +114,8 @@ void static_analyzert::plain_text_report() forall_goto_functions(f_it, goto_functions) { - if(!f_it->second.body.has_assertion()) continue; + if(!f_it->second.body.has_assertion()) + continue; if(f_it->first=="__actual_thread_spawn") continue; @@ -122,7 +124,8 @@ void static_analyzert::plain_text_report() forall_goto_program_instructions(i_it, f_it->second.body) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; tvt r=eval(i_it); @@ -174,14 +177,16 @@ void static_analyzert::json_report(const std::string &file_name) forall_goto_functions(f_it, goto_functions) { - if(!f_it->second.body.has_assertion()) continue; + if(!f_it->second.body.has_assertion()) + continue; if(f_it->first=="__actual_thread_spawn") continue; forall_goto_program_instructions(i_it, f_it->second.body) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; tvt r=eval(i_it); @@ -231,14 +236,16 @@ void static_analyzert::xml_report(const std::string &file_name) forall_goto_functions(f_it, goto_functions) { - if(!f_it->second.body.has_assertion()) continue; + if(!f_it->second.body.has_assertion()) + continue; if(f_it->first=="__actual_thread_spawn") continue; forall_goto_program_instructions(i_it, f_it->second.body) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; tvt r=eval(i_it); @@ -253,7 +260,8 @@ void static_analyzert::xml_report(const std::string &file_name) x.set_attribute("file", id2string(i_it->source_location.get_file())); x.set_attribute("line", id2string(i_it->source_location.get_line())); - x.set_attribute("description", id2string(i_it->source_location.get_comment())); + x.set_attribute( + "description", id2string(i_it->source_location.get_comment())); } } diff --git a/src/goto-analyzer/taint_analysis.cpp b/src/goto-analyzer/taint_analysis.cpp index f1f2342013a..f1f62f2e2d7 100644 --- a/src/goto-analyzer/taint_analysis.cpp +++ b/src/goto-analyzer/taint_analysis.cpp @@ -117,12 +117,12 @@ void taint_analysist::instrument( irep_idt class_id=function.get(ID_C_class); if(class_id.empty()) { - } else { std::string suffix= - std::string(id2string(identifier), class_id.size(), std::string::npos); + std::string( + id2string(identifier), class_id.size(), std::string::npos); class_hierarchyt::idst parents= class_hierarchy.get_parents_trans(class_id); @@ -135,7 +135,9 @@ void taint_analysist::instrument( bool match=false; for(const auto &i : identifiers) if(i==rule.function_identifier || - has_prefix(id2string(i), "java::"+id2string(rule.function_identifier)+":")) + has_prefix( + id2string(i), + "java::"+id2string(rule.function_identifier)+":")) { match=true; break; @@ -165,7 +167,8 @@ void taint_analysist::instrument( case taint_parse_treet::rulet::PARAMETER: { - unsigned nr=have_this?rule.parameter_number:rule.parameter_number-1; + unsigned nr= + have_this?rule.parameter_number:rule.parameter_number-1; if(function_call.arguments().size()>nr) where=function_call.arguments()[nr]; } @@ -187,7 +190,8 @@ void taint_analysist::instrument( codet code_set_may("set_may"); code_set_may.operands().resize(2); code_set_may.op0()=where; - code_set_may.op1()=address_of_exprt(string_constantt(rule.taint)); + code_set_may.op1()= + address_of_exprt(string_constantt(rule.taint)); goto_programt::targett t=tmp.add_instruction(); t->make_other(code_set_may); t->source_location=instruction.source_location; @@ -202,7 +206,8 @@ void taint_analysist::instrument( get_may.op1()=address_of_exprt(string_constantt(rule.taint)); t->make_assertion(not_exprt(get_may)); t->source_location=instruction.source_location; - t->source_location.set_property_class("taint rule "+id2string(rule.id)); + t->source_location.set_property_class( + "taint rule "+id2string(rule.id)); t->source_location.set_comment(rule.message); } break; @@ -212,21 +217,23 @@ void taint_analysist::instrument( codet code_clear_may("clear_may"); code_clear_may.operands().resize(2); code_clear_may.op0()=where; - code_clear_may.op1()=address_of_exprt(string_constantt(rule.taint)); + code_clear_may.op1()= + address_of_exprt(string_constantt(rule.taint)); goto_programt::targett t=tmp.add_instruction(); t->make_other(code_clear_may); t->source_location=instruction.source_location; } break; } - } } } } break; - default:; + default: + { + } } if(!tmp.empty()) @@ -297,7 +304,8 @@ bool taint_analysist::operator()( else { status() << "No entry point found; " - "we will consider the heads of all functions as reachable" << eom; + << "we will consider the heads of all functions as reachable" + << eom; goto_programt end, gotos, calls; @@ -341,7 +349,8 @@ bool taint_analysist::operator()( forall_goto_functions(f_it, goto_functions) { - if(!f_it->second.body.has_assertion()) continue; + if(!f_it->second.body.has_assertion()) + continue; const symbolt &symbol=ns.lookup(f_it->first); @@ -352,31 +361,37 @@ bool taint_analysist::operator()( forall_goto_program_instructions(i_it, f_it->second.body) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; if(!custom_bitvector_domaint::has_get_must_or_may(i_it->guard)) continue; - if(custom_bitvector_analysis[i_it].has_values.is_false()) continue; + if(custom_bitvector_analysis[i_it].has_values.is_false()) + continue; exprt result=custom_bitvector_analysis.eval(i_it->guard, i_it); exprt result2=simplify_expr(result, ns); - if(result2.is_true()) continue; + if(result2.is_true()) + continue; if(first) { first=false; if(!use_json) std::cout << "\n" - "******** Function " << symbol.display_name() << '\n'; + << "******** Function " << symbol.display_name() << '\n'; } if(use_json) { json_objectt json; - json["bug_class"]=json_stringt(id2string(i_it->source_location.get_property_class())); - json["file"]=json_stringt(id2string(i_it->source_location.get_file())); - json["line"]=json_numbert(id2string(i_it->source_location.get_line())); + json["bug_class"]= + json_stringt(id2string(i_it->source_location.get_property_class())); + json["file"]= + json_stringt(id2string(i_it->source_location.get_file())); + json["line"]= + json_numbert(id2string(i_it->source_location.get_line())); json_result.array.push_back(json); } else @@ -386,7 +401,8 @@ bool taint_analysist::operator()( std::cout << ": " << i_it->source_location.get_comment(); if(!i_it->source_location.get_property_class().empty()) - std::cout << " (" << i_it->source_location.get_property_class() << ")"; + std::cout << " (" + << i_it->source_location.get_property_class() << ")"; std::cout << '\n'; } @@ -450,5 +466,9 @@ bool taint_analysis( taint_analysist taint_analysis; taint_analysis.set_message_handler(message_handler); return taint_analysis( - taint_file_name, goto_model.symbol_table, goto_model.goto_functions, show_full, json_file_name); + taint_file_name, + goto_model.symbol_table, + goto_model.goto_functions, + show_full, + json_file_name); } diff --git a/src/goto-analyzer/taint_parser.cpp b/src/goto-analyzer/taint_parser.cpp index c815e2d158a..e60fb2ded54 100644 --- a/src/goto-analyzer/taint_parser.cpp +++ b/src/goto-analyzer/taint_parser.cpp @@ -57,7 +57,8 @@ bool taint_parser( if(!it->is_object()) { messaget message(message_handler); - message.error() << "expecting an array of objects in the taint file, but got " + message.error() << "expecting an array of objects " + << "in the taint file, but got " << *it << messaget::eom; return true; } @@ -114,7 +115,8 @@ bool taint_parser( { messaget message(message_handler); message.error() << "taint rule must have \"where\"" - << " which is \"return_value\" or \"this\" or \"parameter1\"..." + << " which is \"return_value\" or \"this\" " + << "or \"parameter1\"..." << messaget::eom; return true; } @@ -143,7 +145,8 @@ Function: taint_parse_treet::rulet::output void taint_parse_treet::rulet::output(std::ostream &out) const { - if(!id.empty()) out << id << ": "; + if(!id.empty()) + out << id << ": "; switch(kind) { @@ -157,7 +160,8 @@ void taint_parse_treet::rulet::output(std::ostream &out) const switch(where) { case THIS: out << "this in " << function_identifier; break; - case PARAMETER: out << "parameter " << parameter_number << " of " << function_identifier; break; + case PARAMETER: out << "parameter " << parameter_number << " of " + << function_identifier; break; case RETURN_VALUE: out << "return value of " << function_identifier; break; } diff --git a/src/goto-analyzer/taint_parser.h b/src/goto-analyzer/taint_parser.h index 783fa922de5..bc02e66c1ce 100644 --- a/src/goto-analyzer/taint_parser.h +++ b/src/goto-analyzer/taint_parser.h @@ -25,17 +25,17 @@ class taint_parse_treet enum { SOURCE, SINK, SANITIZER } kind; enum { THIS, PARAMETER, RETURN_VALUE } where; - inline bool is_source() const + bool is_source() const { return kind==SOURCE; } - inline bool is_sink() const + bool is_sink() const { return kind==SINK; } - inline bool is_sanitizer() const + bool is_sanitizer() const { return kind==SANITIZER; } @@ -48,7 +48,7 @@ class taint_parse_treet void output(std::ostream &) const; - inline rulet():parameter_number(0) + rulet():parameter_number(0) { } }; diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index 9af2aec210c..7b71752f6b6 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -191,7 +191,8 @@ void unreachable_instructions( forall_goto_functions(f_it, goto_model.goto_functions) { - if(!f_it->second.body_available()) continue; + if(!f_it->second.body_available()) + continue; const goto_programt &goto_program=f_it->second.body; dead_mapt dead_map; diff --git a/src/goto-cc/armcc_mode.cpp b/src/goto-cc/armcc_mode.cpp index f4a57655582..9eb677f631d 100644 --- a/src/goto-cc/armcc_mode.cpp +++ b/src/goto-cc/armcc_mode.cpp @@ -187,8 +187,10 @@ int armcc_modet::doit() std::cout << " " << (*it) << std::endl; } - std::cout << "Output file (object): " << compiler.output_file_object << std::endl; - std::cout << "Output file (executable): " << compiler.output_file_executable << std::endl; + std::cout << "Output file (object): " + << compiler.output_file_object << std::endl; + std::cout << "Output file (executable): " + << compiler.output_file_executable << std::endl; } // Parse input program, convert to goto program, write output @@ -209,5 +211,6 @@ Function: armcc_modet::help_mode void armcc_modet::help_mode() { - std::cout << "goto-armcc understands the options of armcc plus the following.\n\n"; + std::cout << "goto-armcc understands the options " + << "of armcc plus the following.\n\n"; } diff --git a/src/goto-cc/compile.cpp b/src/goto-cc/compile.cpp index 7ab9c5eae3d..f900b9824a7 100644 --- a/src/goto-cc/compile.cpp +++ b/src/goto-cc/compile.cpp @@ -122,13 +122,15 @@ bool compilet::doit() } if(source_files.size()>0) - if(compile()) return true; + if(compile()) + return true; if(mode==LINK_LIBRARY || mode==COMPILE_LINK || mode==COMPILE_LINK_EXECUTABLE) { - if(link()) return true; + if(link()) + return true; } return false; @@ -223,9 +225,9 @@ bool compilet::add_input_file(const std::string &file_name) // add the files from "ar t" #ifdef _WIN32 - if(file_name[0]!='/' && file_name[1]!=':') + if(file_name[0]!='/' && file_name[1]!=':') // NOLINT(readability/braces) #else - if(file_name[0]!='/') + if(file_name[0]!='/') // NOLINT(readability/braces) #endif { cmd << "ar t " << @@ -250,7 +252,7 @@ bool compilet::add_input_file(const std::string &file_name) { if(ch!='\n') { - line+=(char)ch; + line+=static_cast(ch); } else { @@ -414,7 +416,8 @@ bool compilet::link() convert_symbols(compiled_functions); } - if(write_object_file(output_file_executable, symbol_table, compiled_functions)) + if(write_object_file( + output_file_executable, symbol_table, compiled_functions)) return true; return false; @@ -500,7 +503,8 @@ Function: compilet::parse bool compilet::parse(const std::string &file_name) { - if(file_name=="-") return parse_stdin(); + if(file_name=="-") + return parse_stdin(); #ifdef _MSC_VER std::ifstream infile(widen(file_name)); diff --git a/src/goto-cc/compile.h b/src/goto-cc/compile.h index 6c752036f6e..936f4cd21d5 100644 --- a/src/goto-cc/compile.h +++ b/src/goto-cc/compile.h @@ -45,7 +45,7 @@ class compilet:public language_uit std::string object_file_extension; std::string output_file_object, output_file_executable; - compilet(cmdlinet &_cmdline); + explicit compilet(cmdlinet &_cmdline); ~compilet(); @@ -61,10 +61,14 @@ class compilet:public language_uit bool parse_source(const std::string &); - bool write_object_file( const std::string &, const symbol_tablet &, - goto_functionst &); - bool write_bin_object_file( const std::string&, const symbol_tablet &, - goto_functionst& ); + bool write_object_file( + const std::string &, + const symbol_tablet &, + goto_functionst &); + bool write_bin_object_file( + const std::string &, + const symbol_tablet &, + goto_functionst &); protected: cmdlinet &cmdline; diff --git a/src/goto-cc/cw_mode.cpp b/src/goto-cc/cw_mode.cpp index 510f7c9c0aa..18f1bf60494 100644 --- a/src/goto-cc/cw_mode.cpp +++ b/src/goto-cc/cw_mode.cpp @@ -176,8 +176,10 @@ int cw_modet::doit() std::cout << " " << (*it) << std::endl; } - std::cout << "Output file (object): " << compiler.output_file_object << std::endl; - std::cout << "Output file (executable): " << compiler.output_file_executable << std::endl; + std::cout << "Output file (object): " + << compiler.output_file_object << std::endl; + std::cout << "Output file (executable): " + << compiler.output_file_executable << std::endl; } // Parse input program, convert to goto program, write output @@ -198,5 +200,6 @@ Function: cw_modet::help_mode void cw_modet::help_mode() { - std::cout << "goto-cw understands the options of gcc (mwcc mode) plus the following.\n\n"; + std::cout << "goto-cw understands the options of " + << "gcc (mwcc mode) plus the following.\n\n"; } diff --git a/src/goto-cc/gcc_cmdline.cpp b/src/goto-cc/gcc_cmdline.cpp index b131d25f1a5..f9bd0d1ead4 100644 --- a/src/goto-cc/gcc_cmdline.cpp +++ b/src/goto-cc/gcc_cmdline.cpp @@ -382,7 +382,8 @@ bool gcc_cmdlinet::parse_arguments( else set(argv_i, ""); } - else if(has_prefix(argv_i, std::string(*o)+"=")) // concatenated with "=" + // concatenated with "=" + else if(has_prefix(argv_i, std::string(*o)+"=")) { found=true; set(*o, argv_i.substr(strlen(*o)+1)); diff --git a/src/goto-cc/gcc_mode.cpp b/src/goto-cc/gcc_mode.cpp index d56b2c3c351..19444ef1fc5 100644 --- a/src/goto-cc/gcc_mode.cpp +++ b/src/goto-cc/gcc_mode.cpp @@ -193,7 +193,8 @@ int gcc_modet::doit() // Compilation continues, don't exit! if(act_as_ld) - std::cout << "GNU ld version 2.16.91 20050610 (goto-cc " CBMC_VERSION ")\n"; + std::cout << "GNU ld version 2.16.91 20050610 (goto-cc " CBMC_VERSION + << ")\n"; else if(act_as_bcc) std::cout << "bcc: version 0.16.17 (goto-cc " CBMC_VERSION ")\n"; else @@ -324,12 +325,18 @@ int gcc_modet::doit() switch(compiler.mode) { - case compilet::LINK_LIBRARY: debug() << "Linking a library only" << eom; break; - case compilet::COMPILE_ONLY: debug() << "Compiling only" << eom; break; - case compilet::ASSEMBLE_ONLY: debug() << "Assembling only" << eom; break; - case compilet::PREPROCESS_ONLY: debug() << "Preprocessing only" << eom; break; - case compilet::COMPILE_LINK: debug() << "Compiling and linking a library" << eom; break; - case compilet::COMPILE_LINK_EXECUTABLE: debug() << "Compiling and linking an executable" << eom; break; + case compilet::LINK_LIBRARY: + debug() << "Linking a library only" << eom; break; + case compilet::COMPILE_ONLY: + debug() << "Compiling only" << eom; break; + case compilet::ASSEMBLE_ONLY: + debug() << "Assembling only" << eom; break; + case compilet::PREPROCESS_ONLY: + debug() << "Preprocessing only" << eom; break; + case compilet::COMPILE_LINK: + debug() << "Compiling and linking a library" << eom; break; + case compilet::COMPILE_LINK_EXECUTABLE: + debug() << "Compiling and linking an executable" << eom; break; default: assert(false); } @@ -481,13 +488,15 @@ int gcc_modet::doit() if(arg_it!=cmdline.parsed_argv.end()) { language=arg_it->arg; - if(language=="none") language=""; + if(language=="none") + language=""; } } else if(has_prefix(arg_it->arg, "-x")) { language=std::string(arg_it->arg, 2, std::string::npos); - if(language=="none") language=""; + if(language=="none") + language=""; } } } @@ -903,7 +912,9 @@ Function: gcc_modet::help_mode void gcc_modet::help_mode() { if(act_as_ld) - std::cout << "goto-ld understands the options of ld plus the following.\n\n"; + std::cout << "goto-ld understands the options of " + << "ld plus the following.\n\n"; else - std::cout << "goto-cc understands the options of gcc plus the following.\n\n"; + std::cout << "goto-cc understands the options of " + << "gcc plus the following.\n\n"; } diff --git a/src/goto-cc/goto_cc_cmdline.h b/src/goto-cc/goto_cc_cmdline.h index c59adc699dc..d3608400f30 100644 --- a/src/goto-cc/goto_cc_cmdline.h +++ b/src/goto-cc/goto_cc_cmdline.h @@ -63,7 +63,8 @@ class goto_cc_cmdlinet:public cmdlinet { for(parsed_argvt::const_iterator it=parsed_argv.begin(); it!=parsed_argv.end(); it++) - if(it->is_infile_name) return true; + if(it->is_infile_name) + return true; return false; } diff --git a/src/goto-cc/goto_cc_mode.cpp b/src/goto-cc/goto_cc_mode.cpp index 225a703e838..a0e363ad112 100644 --- a/src/goto-cc/goto_cc_mode.cpp +++ b/src/goto-cc/goto_cc_mode.cpp @@ -76,6 +76,7 @@ void goto_cc_modet::help() { std::cout << "\n" + // NOLINTNEXTLINE(whitespace/line_length) "* * goto-cc " CBMC_VERSION " - Copyright (C) 2006-2014 * *\n" "* * Daniel Kroening, Christoph Wintersteiger * *\n" "* * kroening@kroening.com * *\n" diff --git a/src/goto-cc/ld_cmdline.cpp b/src/goto-cc/ld_cmdline.cpp index 29a05d66d30..242c1245941 100644 --- a/src/goto-cc/ld_cmdline.cpp +++ b/src/goto-cc/ld_cmdline.cpp @@ -353,7 +353,8 @@ bool ld_cmdlinet::parse(int argc, const char **argv) found=true; set(os, argv[i]+os.size()+1); } - else if(os.size()>2 && has_prefix("-"+argv_i, os+"=")) // concatenated, long as short + // concatenated, long as short + else if(os.size()>2 && has_prefix("-"+argv_i, os+"=")) { found=true; set(os, argv[i]+os.size()+1-1); @@ -363,7 +364,8 @@ bool ld_cmdlinet::parse(int argc, const char **argv) if(!found) { // unrecognized option - std::cerr << "Warning: uninterpreted ld option '" << argv_i << "'" << std::endl; + std::cerr << "Warning: uninterpreted ld option '" << argv_i + << "'" << std::endl; } } diff --git a/src/goto-cc/ms_cl_cmdline.cpp b/src/goto-cc/ms_cl_cmdline.cpp index 29669514bfa..fb9c8b4e23c 100644 --- a/src/goto-cc/ms_cl_cmdline.cpp +++ b/src/goto-cc/ms_cl_cmdline.cpp @@ -64,11 +64,13 @@ bool ms_cl_cmdlinet::parse(const std::vector &options) if(options[i]=="--verbosity" || options[i]=="--function") + { if(i=2 && - line[0]==char(0xff) && - line[1]==char(0xfe)) + line[0]==static_cast(0xff) && + line[1]==static_cast(0xfe)) { // Unicode, UTF-16 little endian @@ -255,9 +258,9 @@ void ms_cl_cmdlinet::process_response_file(const std::string &file) #endif } else if(line.size()>=3 && - line[0]==char(0xef) && - line[1]==char(0xbb) && - line[2]==char(0xbf)) + line[0]==static_cast(0xef) && + line[1]==static_cast(0xbb) && + line[2]==static_cast(0xbf)) { // This is the UTF-8 BOM. We can proceed as usual, since // we use UTF-8 internally. @@ -294,8 +297,10 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line) // on one line (cannot span multiple lines). Response files can have // comments that begin with the # symbol. - if(line.empty()) return; - if(line[0]=='#') return; // comment + if(line.empty()) + return; + if(line[0]=='#') + return; // comment std::vector options; std::string option; @@ -306,7 +311,8 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line) if(ch==' ' && !in_quotes) { - if(!option.empty()) options.push_back(option); + if(!option.empty()) + options.push_back(option); option.clear(); } else if(ch=='"') @@ -317,7 +323,8 @@ void ms_cl_cmdlinet::process_response_file_line(const std::string &line) option+=ch; } - if(!option.empty()) options.push_back(option); + if(!option.empty()) + options.push_back(option); parse(options); } @@ -486,7 +493,8 @@ const char *ms_cl_prefixes[]= void ms_cl_cmdlinet::process_cl_option(const std::string &s) { - if(s=="") return; + if(s=="") + return; if(s[0]!='/' && s[0]!='-') { diff --git a/src/goto-cc/ms_cl_mode.cpp b/src/goto-cc/ms_cl_mode.cpp index 86aaf3f0a3d..25dc0e039e2 100644 --- a/src/goto-cc/ms_cl_mode.cpp +++ b/src/goto-cc/ms_cl_mode.cpp @@ -41,7 +41,8 @@ Function: ms_cl_modet::doit static bool is_directory(const std::string &s) { - if(s.size()<1) return false; + if(s.empty()) + return false; char last_char=s[s.size()-1]; // Visual CL recognizes both return last_char=='\\' || last_char=='/'; @@ -168,8 +169,10 @@ int ms_cl_modet::doit() std::cout << " " << (*it) << std::endl; } - std::cout << "Output file (object): " << compiler.output_file_object << std::endl; - std::cout << "Output file (executable): " << compiler.output_file_executable << std::endl; + std::cout << "Output file (object): " + << compiler.output_file_object << std::endl; + std::cout << "Output file (executable): " + << compiler.output_file_executable << std::endl; } // Parse input program, convert to goto program, write output diff --git a/src/goto-cc/xml_binaries/read_goto_object.cpp b/src/goto-cc/xml_binaries/read_goto_object.cpp index 83e59545ff6..01fffa8d4b5 100644 --- a/src/goto-cc/xml_binaries/read_goto_object.cpp +++ b/src/goto-cc/xml_binaries/read_goto_object.cpp @@ -49,12 +49,12 @@ bool read_goto_object( xml_parser.in = ∈ xml_parser.set_message_handler(message_handler); - if (xml_parser.parse()) + if(xml_parser.parse()) return true; xmlt &top = xml_parser.parse_tree.element; - if (top.get_attribute("version")!=XML_VERSION) + if(top.get_attribute("version")!=XML_VERSION) { message.error() << "The input was compiled with a different version of " @@ -75,7 +75,7 @@ bool read_goto_object( sec_it++) { xmlt sec = *sec_it; - if (sec.name=="irep_hash_map") + if(sec.name=="irep_hash_map") { for(xmlt::elementst::const_iterator irep_it = sec.elements.begin(); @@ -87,7 +87,7 @@ bool read_goto_object( irepconverter.insert(irep_it->get_attribute("id"), i); } } - else if (sec.name=="symbols") + else if(sec.name=="symbols") { for(xmlt::elementst::const_iterator sym_it = sec.elements.begin(); @@ -109,7 +109,7 @@ bool read_goto_object( symbol_table.add(symbol); } } - else if (sec.name=="functions") + else if(sec.name=="functions") { for(xmlt::elementst::const_iterator fun_it = sec.elements.begin(); @@ -117,7 +117,7 @@ bool read_goto_object( fun_it++) { std::string fname = fun_it->get_attribute("name"); - //std::cout << "Adding function body: " << fname << std::endl; + // std::cout << "Adding function body: " << fname << std::endl; goto_functionst::goto_functiont &f = functions.function_map[fname]; gfconverter.convert(*fun_it, f); } @@ -128,7 +128,6 @@ bool read_goto_object( << "' in object file." << messaget::eom; return true; } - } } else diff --git a/src/goto-cc/xml_binaries/xml_goto_function.cpp b/src/goto-cc/xml_binaries/xml_goto_function.cpp index a50006eb8a1..27021511fa8 100644 --- a/src/goto-cc/xml_binaries/xml_goto_function.cpp +++ b/src/goto-cc/xml_binaries/xml_goto_function.cpp @@ -25,9 +25,9 @@ Function: convert \*******************************************************************/ -void convert( const goto_functionst::goto_functiont& function, xmlt& xml) +void convert(const goto_functionst::goto_functiont &function, xmlt &xml) { - if (function.body_available) + if(function.body_available) convert(function.body, xml); } @@ -44,7 +44,7 @@ Function: convert \*******************************************************************/ -void convert( const xmlt& xml, goto_functionst::goto_functiont& function) +void convert(const xmlt &xml, goto_functionst::goto_functiont &function) { function.body.clear(); convert(xml, function.body); diff --git a/src/goto-cc/xml_binaries/xml_goto_function.h b/src/goto-cc/xml_binaries/xml_goto_function.h index 09ddd0cb41a..8f9db9982c6 100644 --- a/src/goto-cc/xml_binaries/xml_goto_function.h +++ b/src/goto-cc/xml_binaries/xml_goto_function.h @@ -14,7 +14,7 @@ Date: June 2006 #include #include -void convert( const xmlt&, goto_functionst::goto_functiont& ); -void convert( const goto_functionst::goto_functiont&, xmlt& ); +void convert(const xmlt&, goto_functionst::goto_functiont&); +void convert(const goto_functionst::goto_functiont&, xmlt&); #endif // CPROVER_GOTO_CC_XML_BINARIES_XML_GOTO_FUNCTION_H diff --git a/src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp b/src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp index 1fbb85c76ec..f5ba898e55d 100644 --- a/src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp +++ b/src/goto-cc/xml_binaries/xml_goto_function_hashing.cpp @@ -24,11 +24,12 @@ Function: xml_goto_function_convertt::convert \*******************************************************************/ -void -xml_goto_function_convertt::convert( const goto_functionst::goto_functiont& function, xmlt& xml) +void xml_goto_function_convertt::convert( + const goto_functionst::goto_functiont &function, + xmlt &xml) { xml_goto_program_convertt gpconverter(ireps_container); - if (function.body_available) + if(function.body_available) gpconverter.convert(function.body, xml); } @@ -45,8 +46,9 @@ Function: xml_goto_function_convertt::convert \*******************************************************************/ -void -xml_goto_function_convertt::convert( const xmlt& xml, goto_functionst::goto_functiont& function) +void xml_goto_function_convertt::convert( + const xmlt &xml, + goto_functionst::goto_functiont &function) { xml_goto_program_convertt gpconverter(ireps_container); function.body.clear(); diff --git a/src/goto-cc/xml_binaries/xml_goto_function_hashing.h b/src/goto-cc/xml_binaries/xml_goto_function_hashing.h index f826bdeed65..a0b86b72376 100644 --- a/src/goto-cc/xml_binaries/xml_goto_function_hashing.h +++ b/src/goto-cc/xml_binaries/xml_goto_function_hashing.h @@ -17,15 +17,19 @@ Date: July 2006 #include "xml_irep_hashing.h" -class xml_goto_function_convertt { - private: - xml_irep_convertt::ireps_containert &ireps_container; - public: - xml_goto_function_convertt(xml_irep_convertt::ireps_containert &ic) : - ireps_container(ic) {}; - - void convert( const xmlt&, goto_functionst::goto_functiont& ); - void convert( const goto_functionst::goto_functiont&, xmlt& ); +class xml_goto_function_convertt +{ +private: + xml_irep_convertt::ireps_containert &ireps_container; + +public: + explicit xml_goto_function_convertt(xml_irep_convertt::ireps_containert &ic): + ireps_container(ic) + { + } + + void convert(const xmlt&, goto_functionst::goto_functiont&); + void convert(const goto_functionst::goto_functiont&, xmlt&); }; #endif // CPROVER_GOTO_CC_XML_BINARIES_XML_GOTO_FUNCTION_HASHING_H diff --git a/src/goto-cc/xml_binaries/xml_goto_program.cpp b/src/goto-cc/xml_binaries/xml_goto_program.cpp index b8ab9a1c8b4..ee6a53960c0 100644 --- a/src/goto-cc/xml_binaries/xml_goto_program.cpp +++ b/src/goto-cc/xml_binaries/xml_goto_program.cpp @@ -34,25 +34,21 @@ void convert(const goto_programt &goto_program, std::stringstream tmp; // std::cout << "TNO: " << goto_program.target_numbers.size() << std::endl; - const goto_programt::instructionst &instructions = - goto_program.instructions; - goto_programt::instructionst::const_iterator ins_it = - instructions.begin(); - for (;ins_it!=instructions.end();ins_it++) + for(const auto &inst : goto_program.instructions) { - xmlt &ins = xml.new_element("instruction"); + xmlt &ins=xml.new_element("instruction"); - if (!ins_it->location.is_nil()) + if(!inst.location.is_nil()) { - convert(ins_it->location, ins.new_element("location")); + convert(inst.location, ins.new_element("location")); } - if(!ins_it->labels.empty()) + if(!inst.labels.empty()) { - xmlt &lbl = ins.new_element("labels"); + xmlt &lbl=ins.new_element("labels"); for(goto_programt::instructiont::labelst::const_iterator - l_it=ins_it->labels.begin(); - l_it!=ins_it->labels.end(); + l_it=inst.labels.begin(); + l_it!=inst.labels.end(); l_it++) { lbl.new_element("label").set_attribute("name", id2string(*l_it)); @@ -60,44 +56,44 @@ void convert(const goto_programt &goto_program, } - if(ins_it->target_number!=0) + if(inst.target_number!=0) { // std::cout << "Targetlabel found!" << std::endl; tmp.str(""); - tmp << ins_it->target_number; - ins.set_attribute("targetlabel",tmp.str()); + tmp << inst.target_number; + ins.set_attribute("targetlabel", tmp.str()); } - switch(ins_it->type) + switch(inst.type) { case GOTO: { - ins.name = "goto"; - if (!ins_it->guard.is_true()) + ins.name="goto"; + if(!inst.guard.is_true()) { - xmlt &g = ins.new_element("guard"); - convert(ins_it->guard, g); + xmlt &g=ins.new_element("guard"); + convert(inst.guard, g); } - xmlt &tgt = ins.new_element("targets"); + xmlt &tgt=ins.new_element("targets"); for(goto_programt::instructiont::targetst::const_iterator - gt_it=ins_it->targets.begin(); - gt_it!=ins_it->targets.end(); + gt_it=inst.targets.begin(); + gt_it!=inst.targets.end(); gt_it++) { tmp.str(""); tmp << (*gt_it)->target_number; - tgt.new_element("target").data = tmp.str(); + tgt.new_element("target").data=tmp.str(); } break; } case ASSUME: { - ins.name = "assume"; - xmlt &g = ins.new_element("guard"); - convert(ins_it->guard, g); + ins.name="assume"; + xmlt &g=ins.new_element("guard"); + convert(inst.guard, g); - const irep_idt &comment=ins_it->location.get("comment"); + const irep_idt &comment=inst.location.get("comment"); if(comment!="") ins.new_element("comment").data=id2string(comment); @@ -107,10 +103,10 @@ void convert(const goto_programt &goto_program, case ASSERT: { - ins.name = "assert"; - xmlt &g = ins.new_element("guard"); - convert(ins_it->guard, g); - const irep_idt &comment=ins_it->location.get("comment"); + ins.name="assert"; + xmlt &g=ins.new_element("guard"); + convert(inst.guard, g); + const irep_idt &comment=inst.location.get("comment"); if(comment!="") ins.new_element("comment").data=id2string(comment); @@ -119,87 +115,87 @@ void convert(const goto_programt &goto_program, } case SKIP: - ins.name = "skip"; + ins.name="skip"; break; case END_FUNCTION: - ins.name = "end_function"; + ins.name="end_function"; break; case LOCATION: - ins.name = "location"; + ins.name="location"; break; case DEAD: - ins.name = "dead"; + ins.name="dead"; break; case ATOMIC_BEGIN: - ins.name = "atomic_begin"; + ins.name="atomic_begin"; break; case ATOMIC_END: - ins.name = "atomic_end"; + ins.name="atomic_end"; break; case RETURN: { - ins.name = "return"; - xmlt &c = ins.new_element("code"); - convert(ins_it->code, c); + ins.name="return"; + xmlt &c=ins.new_element("code"); + convert(inst.code, c); break; } case OTHER: { - ins.name = "instruction"; - xmlt &c = ins.new_element("code"); - convert(ins_it->code, c); + ins.name="instruction"; + xmlt &c=ins.new_element("code"); + convert(inst.code, c); break; } case ASSIGN: { - ins.name = "assign"; - xmlt &c = ins.new_element("code"); - convert(ins_it->code, c); + ins.name="assign"; + xmlt &c=ins.new_element("code"); + convert(inst.code, c); break; } case FUNCTION_CALL: { - ins.name = "functioncall"; - xmlt &c = ins.new_element("code"); - convert(ins_it->code, c); + ins.name="functioncall"; + xmlt &c=ins.new_element("code"); + convert(inst.code, c); break; } case START_THREAD: { - ins.name = "thread_start"; - xmlt &tgt = ins.new_element("targets"); - if(ins_it->targets.size()==1) + ins.name="thread_start"; + xmlt &tgt=ins.new_element("targets"); + if(inst.targets.size()==1) { tmp.str(""); - tmp << ins_it->targets.front()->target_number; - tgt.new_element("target").data = tmp.str(); + tmp << inst.targets.front()->target_number; + tgt.new_element("target").data=tmp.str(); } break; } case END_THREAD: - ins.name = "thread_end"; + ins.name="thread_end"; break; default: - ins.name = "unknown"; + ins.name="unknown"; break; } - if (ins_it->function!="") + if(inst.function!="") { - xmlt &fnc = ins.new_element("function"); - fnc.data = id2string(ins_it->function); + xmlt &fnc=ins.new_element("function"); + fnc.data=id2string(inst.function); } } } @@ -217,77 +213,77 @@ Function: convert and the namespace into the given goto program object. \*******************************************************************/ -void convert( const xmlt& xml, - goto_programt& goto_program) + +void convert(const xmlt &xml, goto_programt &goto_program) { goto_program.clear(); goto_programt::instructionst &instructions = goto_program.instructions; xmlt::elementst::const_iterator it = xml.elements.begin(); - for (; it != xml.elements.end(); it++) + for(; it != xml.elements.end(); it++) { goto_programt::targett inst = goto_program.add_instruction(); inst->targets.clear(); - if (it->name=="goto") + if(it->name=="goto") { inst->type = GOTO; } - else if (it->name=="assume") + else if(it->name=="assume") { inst->type = ASSUME; } - else if (it->name=="assert") + else if(it->name=="assert") { inst->type = ASSERT; } - else if (it->name=="skip") + else if(it->name=="skip") { inst->type = SKIP; } - else if (it->name=="end_function") + else if(it->name=="end_function") { inst->type = END_FUNCTION; } - else if (it->name=="location") + else if(it->name=="location") { inst->type = LOCATION; } - else if (it->name=="dead") + else if(it->name=="dead") { inst->type = DEAD; } - else if (it->name=="atomic_begin") + else if(it->name=="atomic_begin") { inst->type = ATOMIC_BEGIN; } - else if (it->name=="atomic_end") + else if(it->name=="atomic_end") { inst->type = ATOMIC_END; } - else if (it->name=="return") + else if(it->name=="return") { inst->make_return(); } - else if (it->name=="instruction") // OTHER + else if(it->name=="instruction") // OTHER { inst->make_other(); } - else if (it->name=="assign") + else if(it->name=="assign") { inst->make_other(); inst->type=ASSIGN; } - else if (it->name=="functioncall") + else if(it->name=="functioncall") { inst->make_other(); inst->type=FUNCTION_CALL; } - else if (it->name=="thread_start") + else if(it->name=="thread_start") { inst->type = START_THREAD; } - else if (it->name=="thread_end") + else if(it->name=="thread_end") { inst->type = END_THREAD; } @@ -299,21 +295,21 @@ void convert( const xmlt& xml, } xmlt::elementst::const_iterator eit = it->elements.begin(); - for (; eit != it->elements.end(); eit++) + for(; eit != it->elements.end(); eit++) { - if (eit->name=="location") + if(eit->name=="location") { convert(*eit, inst->location); } - else if (eit->name=="variables") + else if(eit->name=="variables") { } - else if (eit->name=="labels") + else if(eit->name=="labels") { xmlt::elementst::const_iterator lit = eit->elements.begin(); - for (; lit != eit->elements.end(); lit++) + for(; lit != eit->elements.end(); lit++) { - if (lit->name=="label") + if(lit->name=="label") { std::string ls = lit->get_attribute("name"); inst->labels.push_back(ls); @@ -325,24 +321,24 @@ void convert( const xmlt& xml, } } } - else if (eit->name=="guard") + else if(eit->name=="guard") { inst->guard.remove("value"); convert(*eit, inst->guard); } - else if (eit->name=="code") + else if(eit->name=="code") { convert(*eit, inst->code); } - else if (eit->name=="targets") + else if(eit->name=="targets") { // Don't do anything here, we'll need a second run for that } - else if (eit->name=="comment") + else if(eit->name=="comment") { inst->location.set("comment", eit->data); } - else if (eit->name=="function") + else if(eit->name=="function") { inst->function = eit->data; } @@ -355,21 +351,21 @@ void convert( const xmlt& xml, // second run, for targets goto_programt::targett ins_it = instructions.begin(); it = xml.elements.begin(); - for (; it != xml.elements.end() && ins_it!=instructions.end(); it++) + for(; it != xml.elements.end() && ins_it!=instructions.end(); it++) { xmlt::elementst::const_iterator eit = it->elements.begin(); - for (; eit != it->elements.end(); eit++) + for(; eit != it->elements.end(); eit++) { - if (eit->name=="targets") + if(eit->name=="targets") { xmlt::elementst::const_iterator tit = eit->elements.begin(); - for (; tit != eit->elements.end(); tit++) + for(; tit != eit->elements.end(); tit++) { - if (tit->name=="target") + if(tit->name=="target") { goto_programt::targett tins = find_instruction(xml, instructions, tit->data); - if (tins != instructions.end()) + if(tins != instructions.end()) { // Here we insert the iterators that somehow seem // to be strange afterwards (see line 87) @@ -395,7 +391,7 @@ void convert( const xmlt& xml, // resolve links goto_program.update(); - //std::cout << "TNI: " << goto_program.target_numbers.size() << std::endl; + // std::cout << "TNI: " << goto_program.target_numbers.size() << std::endl; } /*******************************************************************\ @@ -420,9 +416,9 @@ find_instruction( goto_programt::targett ins_it=instructions.begin(); xmlt::elementst::const_iterator it=xml.elements.begin(); - for (; it != xml.elements.end() && ins_it!=instructions.end(); it++) + for(; it != xml.elements.end() && ins_it!=instructions.end(); it++) { - if (label==it->get_attribute("targetlabel")) + if(label==it->get_attribute("targetlabel")) return ins_it; ins_it++; diff --git a/src/goto-cc/xml_binaries/xml_goto_program_hashing.cpp b/src/goto-cc/xml_binaries/xml_goto_program_hashing.cpp index 3f624306c3b..fa1ac0c2b00 100644 --- a/src/goto-cc/xml_binaries/xml_goto_program_hashing.cpp +++ b/src/goto-cc/xml_binaries/xml_goto_program_hashing.cpp @@ -28,30 +28,28 @@ Function: xml_goto_program_convertt::convert \*******************************************************************/ -void xml_goto_program_convertt::convert(const goto_programt &goto_program, - xmlt &xml) +void xml_goto_program_convertt::convert( + const goto_programt &goto_program, + xmlt &xml) { std::stringstream tmp; // std::cout << "TNO: " << goto_program.target_numbers.size() << std::endl; - const goto_programt::instructionst &instructions = - goto_program.instructions; - goto_programt::instructionst::const_iterator ins_it = - instructions.begin(); - for (;ins_it!=instructions.end();ins_it++) + for(const auto &inst : goto_program.instructions) { - xmlt &ins = xml.new_element("instruction"); - if (!ins_it->location.is_nil()) + xmlt &ins=xml.new_element("instruction"); + if(!inst.location.is_nil()) { - irepconverter.reference_convert(ins_it->location, ins.new_element("location")); + irepconverter.reference_convert( + inst.location, ins.new_element("location")); } - if(!ins_it->labels.empty()) + if(!inst.labels.empty()) { - xmlt &lbl = ins.new_element("labels"); + xmlt &lbl=ins.new_element("labels"); for(goto_programt::instructiont::labelst::const_iterator - l_it=ins_it->labels.begin(); - l_it!=ins_it->labels.end(); + l_it=inst.labels.begin(); + l_it!=inst.labels.end(); l_it++) { lbl.new_element("label").set_attribute("name", id2string(*l_it)); @@ -59,43 +57,43 @@ void xml_goto_program_convertt::convert(const goto_programt &goto_program, } - if(ins_it->target_number!=0) + if(inst.target_number!=0) { // std::cout << "Targetlabel found!" << std::endl; tmp.str(""); - tmp << ins_it->target_number; - ins.set_attribute("targetlabel",tmp.str()); + tmp << inst.target_number; + ins.set_attribute("targetlabel", tmp.str()); } - switch(ins_it->type) + switch(inst.type) { case GOTO: { - ins.name = "goto"; - if (!ins_it->guard.is_true()) + ins.name="goto"; + if(!inst.guard.is_true()) { - xmlt &g = ins.new_element("guard"); - irepconverter.reference_convert(ins_it->guard, g); + xmlt &g=ins.new_element("guard"); + irepconverter.reference_convert(inst.guard, g); } - xmlt &tgt = ins.new_element("targets"); + xmlt &tgt=ins.new_element("targets"); for(goto_programt::instructiont::targetst::const_iterator - gt_it=ins_it->targets.begin(); - gt_it!=ins_it->targets.end(); + gt_it=inst.targets.begin(); + gt_it!=inst.targets.end(); gt_it++) { tmp.str(""); tmp << (*gt_it)->target_number; - tgt.new_element("target").data = tmp.str(); + tgt.new_element("target").data=tmp.str(); } break; } case ASSUME: { - ins.name = "assume"; - xmlt &g = ins.new_element("guard"); - irepconverter.reference_convert(ins_it->guard, g); - const irep_idt &comment=ins_it->location.get("comment"); + ins.name="assume"; + xmlt &g=ins.new_element("guard"); + irepconverter.reference_convert(inst.guard, g); + const irep_idt &comment=inst.location.get("comment"); if(comment!="") ins.new_element("comment").data=id2string(comment); break; @@ -103,97 +101,97 @@ void xml_goto_program_convertt::convert(const goto_programt &goto_program, case ASSERT: { - ins.name = "assert"; - xmlt &g = ins.new_element("guard"); - irepconverter.reference_convert(ins_it->guard, g); - const irep_idt &comment=ins_it->location.get("comment"); + ins.name="assert"; + xmlt &g=ins.new_element("guard"); + irepconverter.reference_convert(inst.guard, g); + const irep_idt &comment=inst.location.get("comment"); if(comment!="") ins.new_element("comment").data=id2string(comment); break; } case SKIP: - ins.name = "skip"; + ins.name="skip"; break; case END_FUNCTION: - ins.name = "end_function"; + ins.name="end_function"; break; case LOCATION: - ins.name = "location"; + ins.name="location"; break; case DEAD: - ins.name = "dead"; + ins.name="dead"; break; case ATOMIC_BEGIN: - ins.name = "atomic_begin"; + ins.name="atomic_begin"; break; case ATOMIC_END: - ins.name = "atomic_end"; + ins.name="atomic_end"; break; case RETURN: { - ins.name = "return"; - xmlt &c = ins.new_element("code"); - irepconverter.reference_convert(ins_it->code, c); + ins.name="return"; + xmlt &c=ins.new_element("code"); + irepconverter.reference_convert(inst.code, c); break; } case OTHER: { - ins.name = "instruction"; - xmlt &c = ins.new_element("code"); - irepconverter.reference_convert(ins_it->code, c); + ins.name="instruction"; + xmlt &c=ins.new_element("code"); + irepconverter.reference_convert(inst.code, c); break; } case ASSIGN: { - ins.name = "assign"; - xmlt &c = ins.new_element("code"); - irepconverter.reference_convert(ins_it->code, c); + ins.name="assign"; + xmlt &c=ins.new_element("code"); + irepconverter.reference_convert(inst.code, c); break; } case FUNCTION_CALL: { - ins.name = "functioncall"; - xmlt &c = ins.new_element("code"); - irepconverter.reference_convert(ins_it->code, c); + ins.name="functioncall"; + xmlt &c=ins.new_element("code"); + irepconverter.reference_convert(inst.code, c); break; } case START_THREAD: { - ins.name = "thread_start"; - xmlt &tgt = ins.new_element("targets"); - if(ins_it->targets.size()==1) + ins.name="thread_start"; + xmlt &tgt=ins.new_element("targets"); + if(inst.targets.size()==1) { tmp.str(""); - tmp << ins_it->targets.front()->target_number; - tgt.new_element("target").data = tmp.str(); + tmp << inst.targets.front()->target_number; + tgt.new_element("target").data=tmp.str(); } break; } case END_THREAD: - ins.name = "thread_end"; + ins.name="thread_end"; break; default: - ins.name = "unknown"; + ins.name="unknown"; break; } - if(ins_it->function!="") + if(inst.function!="") { xmlt &fnc=ins.new_element("function"); - fnc.data=id2string(ins_it->function); + fnc.data=id2string(inst.function); } } } @@ -210,106 +208,107 @@ Function: xml_goto_program_convertt::convert and the namespace into the given goto program object. \*******************************************************************/ -void xml_goto_program_convertt::convert( const xmlt& xml, - goto_programt& goto_program) +void xml_goto_program_convertt::convert( + const xmlt &xml, + goto_programt &goto_program) { goto_program.clear(); - goto_programt::instructionst &instructions = goto_program.instructions; + goto_programt::instructionst &instructions=goto_program.instructions; - xmlt::elementst::const_iterator it = xml.elements.begin(); - for (; it != xml.elements.end(); it++) + for(const auto &element : xml.elements) { - goto_programt::targett inst = goto_program.add_instruction(); + goto_programt::targett inst=goto_program.add_instruction(); inst->targets.clear(); - if (it->name=="goto") + if(element.name=="goto") { - inst->type = GOTO; + inst->type=GOTO; } - else if (it->name=="assume") + else if(element.name=="assume") { - inst->type = ASSUME; + inst->type=ASSUME; } - else if (it->name=="assert") + else if(element.name=="assert") { - inst->type = ASSERT; + inst->type=ASSERT; } - else if (it->name=="skip") + else if(element.name=="skip") { - inst->type = SKIP; + inst->type=SKIP; } - else if (it->name=="end_function") + else if(element.name=="end_function") { - inst->type = END_FUNCTION; + inst->type=END_FUNCTION; } - else if (it->name=="location") + else if(element.name=="location") { - inst->type = LOCATION; + inst->type=LOCATION; } - else if (it->name=="dead") + else if(element.name=="dead") { - inst->type = DEAD; + inst->type=DEAD; } - else if (it->name=="atomic_begin") + else if(element.name=="atomic_begin") { - inst->type = ATOMIC_BEGIN; + inst->type=ATOMIC_BEGIN; } - else if (it->name=="atomic_end") + else if(element.name=="atomic_end") { - inst->type = ATOMIC_END; + inst->type=ATOMIC_END; } - else if (it->name=="return") + else if(element.name=="return") { inst->make_return(); } - else if (it->name=="instruction") // OTHER + else if(element.name=="instruction") // OTHER { inst->make_other(); } - else if (it->name=="assign") // OTHER + else if(element.name=="assign") // OTHER { inst->make_other(); - inst->type = ASSIGN; + inst->type=ASSIGN; } - else if (it->name=="functioncall") // OTHER + else if(element.name=="functioncall") // OTHER { inst->make_other(); - inst->type = FUNCTION_CALL; + inst->type=FUNCTION_CALL; } - else if (it->name=="thread_start") + else if(element.name=="thread_start") { - inst->type = START_THREAD; + inst->type=START_THREAD; } - else if (it->name=="thread_end") + else if(element.name=="thread_end") { - inst->type = END_THREAD; + inst->type=END_THREAD; } else { - std::cout << "Unknown instruction type encountered (" << it->name << ")"; + std::cout << "Unknown instruction type encountered (" + << element.name << ")"; std::cout << std::endl; return; } - xmlt::elementst::const_iterator eit = it->elements.begin(); - for (; eit != it->elements.end(); eit++) + xmlt::elementst::const_iterator eit=element.elements.begin(); + for(const auto &sub : element.elements) { - if (eit->name=="location") + if(sub.name=="location") { irepconverter.convert(*eit, inst->location); irepconverter.resolve_references(inst->location); } - else if (eit->name=="variables") + else if(sub.name=="variables") { } - else if (eit->name=="labels") + else if(sub.name=="labels") { - xmlt::elementst::const_iterator lit = eit->elements.begin(); - for (; lit != eit->elements.end(); lit++) + xmlt::elementst::const_iterator lit=sub.elements.begin(); + for(; lit != sub.elements.end(); lit++) { - if (lit->name=="label") + if(lit->name=="label") { - std::string ls = lit->get_attribute("name"); + std::string ls=lit->get_attribute("name"); inst->labels.push_back(ls); } else @@ -319,28 +318,28 @@ void xml_goto_program_convertt::convert( const xmlt& xml, } } } - else if (eit->name=="guard") + else if(sub.name=="guard") { inst->guard.remove("value"); irepconverter.convert(*eit, inst->guard); irepconverter.resolve_references(inst->guard); } - else if (eit->name=="code") + else if(sub.name=="code") { irepconverter.convert(*eit, inst->code); irepconverter.resolve_references(inst->code); } - else if (eit->name=="targets") + else if(sub.name=="targets") { // Don't do anything here, we'll need a second run for that } - else if (eit->name=="comment") + else if(sub.name=="comment") { - inst->location.set("comment", eit->data); + inst->location.set("comment", sub.data); } - else if (eit->name=="function") + else if(sub.name=="function") { - inst->function=eit->data; + inst->function=sub.data; } } } @@ -349,23 +348,23 @@ void xml_goto_program_convertt::convert( const xmlt& xml, goto_program.compute_location_numbers(); // second run, for targets - goto_programt::targett ins_it = instructions.begin(); - it = xml.elements.begin(); - for (; it != xml.elements.end() && ins_it!=instructions.end(); it++) + goto_programt::targett ins_it=instructions.begin(); + for(const auto &element : xml.elements) { - xmlt::elementst::const_iterator eit = it->elements.begin(); - for (; eit != it->elements.end(); eit++) + if(ins_it==instructions.end()) + break; + + for(const auto &sub : element.elements) { - if (eit->name=="targets") + if(sub.name=="targets") { - xmlt::elementst::const_iterator tit = eit->elements.begin(); - for (; tit != eit->elements.end(); tit++) + for(const auto &t : sub.elements) { - if (tit->name=="target") + if(t.name=="target") { goto_programt::targett tins = - find_instruction(xml, instructions, tit->data); - if (tins != instructions.end()) + find_instruction(xml, instructions, t.data); + if(tins!=instructions.end()) { // Here we insert the iterators that somehow seem // to be strange afterwards (see line 87) @@ -391,7 +390,7 @@ void xml_goto_program_convertt::convert( const xmlt& xml, // resolve links goto_program.update(); - //std::cout << "TNI: " << goto_program.target_numbers.size() << std::endl; + // std::cout << "TNI: " << goto_program.target_numbers.size() << std::endl; } /*******************************************************************\ @@ -406,16 +405,18 @@ Function: xml_goto_program_convertt::find_instruction target label in the given xml-program \*******************************************************************/ -goto_programt::targett -xml_goto_program_convertt::find_instruction( const xmlt &xml, - goto_programt::instructionst &instructions, - const std::string &label) +goto_programt::targett xml_goto_program_convertt::find_instruction( + const xmlt &xml, + goto_programt::instructionst &instructions, + const std::string &label) { - goto_programt::targett ins_it = instructions.begin(); - xmlt::elementst::const_iterator it = xml.elements.begin(); - for (; it != xml.elements.end() && ins_it!=instructions.end(); it++) + goto_programt::targett ins_it=instructions.begin(); + for(const auto &element : xml.elements) { - if (label==it->get_attribute("targetlabel")) + if(ins_it==instructions.end()) + break; + + if(label==element.get_attribute("targetlabel")) return ins_it; ins_it++; } diff --git a/src/goto-cc/xml_binaries/xml_goto_program_hashing.h b/src/goto-cc/xml_binaries/xml_goto_program_hashing.h index 52f0e796db9..a3af286f1a7 100644 --- a/src/goto-cc/xml_binaries/xml_goto_program_hashing.h +++ b/src/goto-cc/xml_binaries/xml_goto_program_hashing.h @@ -17,23 +17,24 @@ Date: July 2006 #include "xml_irep_hashing.h" -class xml_goto_program_convertt { - private: - xml_irep_convertt irepconverter; - public: - xml_goto_program_convertt(xml_irep_convertt::ireps_containert &ic) : - irepconverter(ic) {}; +class xml_goto_program_convertt +{ +private: + xml_irep_convertt irepconverter; + +public: + explicit xml_goto_program_convertt(xml_irep_convertt::ireps_containert &ic): + irepconverter(ic) + { + } void convert(const goto_programt&, xmlt&); void convert(const xmlt&, goto_programt&); - goto_programt::targett - find_instruction( const xmlt &, - goto_programt::instructionst &, - const std::string &); + goto_programt::targett find_instruction( + const xmlt &, + goto_programt::instructionst &, + const std::string &); }; - - - #endif // CPROVER_GOTO_CC_XML_BINARIES_XML_GOTO_PROGRAM_HASHING_H diff --git a/src/goto-cc/xml_binaries/xml_irep_hashing.cpp b/src/goto-cc/xml_binaries/xml_irep_hashing.cpp index 80c71ab6939..54aa9c06bf8 100644 --- a/src/goto-cc/xml_binaries/xml_irep_hashing.cpp +++ b/src/goto-cc/xml_binaries/xml_irep_hashing.cpp @@ -48,7 +48,7 @@ void xml_irep_convertt::convert( forall_named_irep(it, irep.get_comments()) { - xmlt &x_com = xml.new_element("c"); + xmlt &x_com=xml.new_element("c"); x_com.set_attribute("n", name2string(it->first)); reference_convert(it->second, x_com); } @@ -71,35 +71,36 @@ void xml_irep_convertt::convert( irept &irep) { irep.id("nil"); - xmlt::elementst::const_iterator it = xml.elements.begin(); - for (; it != xml.elements.end(); it++) + xmlt::elementst::const_iterator it=xml.elements.begin(); + for(; it != xml.elements.end(); it++) { - if (it->name=="R") { + if(it->name=="R") + { irep.id("__REFERENCE__"); irep.set("REF", it->data); } - else if (it->name=="id") + else if(it->name=="id") { irep.id(it->data); } - else if (it->name=="ns") + else if(it->name=="ns") { irept r; convert(*it, r); - std::string named_name = it->get_attribute("n"); + std::string named_name=it->get_attribute("n"); irep.move_to_named_sub(named_name, r); } - else if (it->name=="s") + else if(it->name=="s") { irept r; convert(*it, r); irep.move_to_sub(r); } - else if (it->name=="c") + else if(it->name=="c") { irept r; convert(*it, r); - std::string named_name = it->get_attribute("n"); + std::string named_name=it->get_attribute("n"); irep.move_to_named_sub(named_name, r); } else @@ -127,17 +128,19 @@ void xml_irep_convertt::reference_convert( const irept &irep, xmlt &xml) { - xmlt &ir = xml.new_element("R"); + xmlt &ir=xml.new_element("R"); - ireps_containert::content_containert::const_iterator fi = + ireps_containert::content_containert::const_iterator fi= find_irep_by_content(irep); - if (fi==ireps_container.content_container.end()) + if(fi==ireps_container.content_container.end()) + { + unsigned id=ireps_container.id_replace_map[add_with_childs(irep)]; + ir.data=long_to_string(id); + } + else { - unsigned id = ireps_container.id_replace_map[add_with_childs(irep)]; - ir.data = long_to_string(id); - } else { - ir.data = long_to_string( - ireps_container.id_replace_map[fi->second]); + ir.data= + long_to_string(ireps_container.id_replace_map[fi->second]); } } @@ -154,32 +157,33 @@ Function: xml_irep_convertt::add_with_childs \*******************************************************************/ unsigned long xml_irep_convertt::add_with_childs(const irept &iwi) { - unsigned long id = insert((unsigned long)&iwi, iwi); - if (id!=(unsigned long)&iwi) return id; + unsigned long id=insert((unsigned long)&iwi, iwi); + if(id!=(unsigned long)&iwi) + return id; forall_irep(it, iwi.get_sub()) { - ireps_containert::content_containert::const_iterator fi = + ireps_containert::content_containert::const_iterator fi= find_irep_by_content(*it); - if (fi==ireps_container.content_container.end()) + if(fi==ireps_container.content_container.end()) { add_with_childs(*it); } } forall_named_irep(it, iwi.get_named_sub()) { - ireps_containert::content_containert::const_iterator fi = + ireps_containert::content_containert::const_iterator fi= find_irep_by_content(it->second); - if (fi==ireps_container.content_container.end()) + if(fi==ireps_container.content_container.end()) { add_with_childs(it->second); } } forall_named_irep(it, iwi.get_comments()) { - ireps_containert::content_containert::const_iterator fi = + ireps_containert::content_containert::const_iterator fi= find_irep_by_content(it->second); - if (fi==ireps_container.content_container.end()) + if(fi==ireps_container.content_container.end()) { add_with_childs(it->second); } @@ -200,21 +204,21 @@ Function: xml_irep_convertt::resolve_references \*******************************************************************/ -void xml_irep_convertt::resolve_references( const irept &cur ) +void xml_irep_convertt::resolve_references(const irept &cur) { - if (cur.id() == "__REFERENCE__") + if(cur.id() == "__REFERENCE__") { - unsigned long id = string_to_long(cur.get_string("REF")); - ireps_containert::id_containert::const_iterator itr = find_irep_by_id(id); - if (itr==ireps_container.id_container.end()) + unsigned long id=string_to_long(cur.get_string("REF")); + ireps_containert::id_containert::const_iterator itr=find_irep_by_id(id); + if(itr==ireps_container.id_container.end()) { std::cout << "Warning: can't resolve irep reference (sub " - << cur.get("REF") << ")" << std::endl; + << cur.get("REF") << ")" << std::endl; } else { - irept &curX = const_cast(cur); - curX = itr->second; + irept &curX=const_cast(cur); + curX=itr->second; } } @@ -226,7 +230,6 @@ void xml_irep_convertt::resolve_references( const irept &cur ) forall_named_irep(iti, cur.get_comments()) resolve_references(iti->second); - } /*******************************************************************\ @@ -240,7 +243,9 @@ Function: xml_irep_convertt::long_to_string Purpose: converts the hash value to a readable string \*******************************************************************/ -std::string xml_irep_convertt::long_to_string(const unsigned long l) { + +std::string xml_irep_convertt::long_to_string(const unsigned long l) +{ std::stringstream s; s << std::hex << l; return s.str(); @@ -258,7 +263,9 @@ Function: xml_irep_convertt::string_to_long a pointer to an irep in an old compilation \*******************************************************************/ -unsigned long xml_irep_convertt::string_to_long(const std::string &s) { + +unsigned long xml_irep_convertt::string_to_long(const std::string &s) +{ std::stringstream ss(s); unsigned long res=0; ss >> std::hex >> res; @@ -276,8 +283,10 @@ Function: xml_irep_convertt::find_irep_by_id Purpose: finds an irep in the ireps hash set by its id \*******************************************************************/ + xml_irep_convertt::ireps_containert::id_containert::const_iterator -xml_irep_convertt::find_irep_by_id(const unsigned int id) { + xml_irep_convertt::find_irep_by_id(const unsigned int id) +{ return ireps_container.id_container.find(id); } @@ -292,8 +301,10 @@ Function: xml_irep_convertt::find_irep_by_content Purpose: finds an irep in the ireps hash set by checking contents \*******************************************************************/ -xml_irep_convertt::ireps_containert::content_containert::const_iterator -xml_irep_convertt::find_irep_by_content(const irept &irep) { + + xml_irep_convertt::ireps_containert::content_containert::const_iterator + xml_irep_convertt::find_irep_by_content(const irept &irep) +{ return ireps_container.content_container.find(irep); } @@ -308,25 +319,29 @@ Function: xml_irep_convertt::insert Purpose: inserts an irep into the hashtable \*******************************************************************/ + unsigned long xml_irep_convertt::insert( unsigned long id, - const irept& i) + const irept &i) { ireps_containert::content_containert::const_iterator sit; - sit = find_irep_by_content(i); - if (sit==ireps_container.content_container.end()) { + sit=find_irep_by_content(i); + if(sit==ireps_container.content_container.end()) + { ireps_container.content_container.insert( std::pair(i, id)); - if( ireps_container.id_container.insert( - std::pair(id, i) - ).second ) { + if(ireps_container.id_container.insert( + std::pair(id, i)).second) + { ireps_container.id_replace_map[id] = ireps_container.id_container.size(); } return id; - } else { + } + else + { return sit->second; } } @@ -342,9 +357,10 @@ Function: xml_irep_convertt::insert Purpose: inserts an irep into the hashtable \*******************************************************************/ + unsigned long xml_irep_convertt::insert( const std::string &id, - const irept& i) + const irept &i) { return insert(string_to_long(id), i); } @@ -361,13 +377,17 @@ Function: xml_irep_convertt::convert_map structure \*******************************************************************/ -void xml_irep_convertt::convert_map(xmlt &xml) { - ireps_containert::id_containert::iterator hit = + +void xml_irep_convertt::convert_map(xmlt &xml) +{ + ireps_containert::id_containert::iterator hit= ireps_container.id_container.begin(); - for (; hit!=ireps_container.id_container.end(); hit++) { - xmlt &xmlhe = xml.new_element("irep"); - xmlhe.set_attribute("id", long_to_string( - ireps_container.id_replace_map[hit->first])); + for(; hit!=ireps_container.id_container.end(); hit++) + { + xmlt &xmlhe=xml.new_element("irep"); + xmlhe.set_attribute( + "id", + long_to_string(ireps_container.id_replace_map[hit->first])); convert(hit->second, xmlhe); } } @@ -384,13 +404,17 @@ Function: xml_irep_convertt::output_map outputs them to the stream \*******************************************************************/ -void xml_irep_convertt::output_map(std::ostream &out, unsigned indent) { - ireps_containert::id_containert::iterator hit = + +void xml_irep_convertt::output_map(std::ostream &out, unsigned indent) +{ + ireps_containert::id_containert::iterator hit= ireps_container.id_container.begin(); - for (; hit!=ireps_container.id_container.end(); hit++) { + for(; hit!=ireps_container.id_container.end(); hit++) + { xmlt xmlhe("irep"); - xmlhe.set_attribute("id", long_to_string( - ireps_container.id_replace_map[hit->first])); + xmlhe.set_attribute( + "id", + long_to_string(ireps_container.id_replace_map[hit->first])); convert(hit->second, xmlhe); xmlhe.output(out, indent); } diff --git a/src/goto-cc/xml_binaries/xml_irep_hashing.h b/src/goto-cc/xml_binaries/xml_irep_hashing.h index 5fe4df7bb20..6fc074c9941 100644 --- a/src/goto-cc/xml_binaries/xml_irep_hashing.h +++ b/src/goto-cc/xml_binaries/xml_irep_hashing.h @@ -14,81 +14,100 @@ Date: July 2006 #include #include -class xml_irep_convertt { - private: - - struct ul_hash +class xml_irep_convertt +{ +private: + // NOLINTNEXTLINE(readability/identifiers) + struct ul_hash + { + unsigned short operator()(const unsigned long l) const { - unsigned short operator()(const unsigned long l) const - { - return (l & 0xFFFF); - } - }; - struct ul_eq + return (l &0xFFFF); + } + }; + + // NOLINTNEXTLINE(readability/identifiers) + struct ul_eq + { + bool operator()(const unsigned long l, const unsigned long r) const { - bool operator()(const unsigned long l, const unsigned long r) const - { - return (l==r); - } - }; - struct irep_full_hash + return (l==r); + } + }; + + // NOLINTNEXTLINE(readability/identifiers) + struct irep_full_hash + { + size_t operator()(const irept &i) const { - size_t operator()(const irept &i) const - { - return i.full_hash(); - } - }; - struct irep_content_eq + return i.full_hash(); + } + }; + + // NOLINTNEXTLINE(readability/identifiers) + struct irep_content_eq + { + bool operator()(const irept &l, const irept &r) const { - bool operator()(const irept &l, const irept &r) const + return l.full_eq(l, r); + } + }; + +public: + struct ireps_containert + { + typedef std::unordered_map + id_containert; + id_containert id_container; + + typedef std::unordered_map + content_containert; + content_containert content_container; + + typedef std::map id_replace_mapt; + id_replace_mapt id_replace_map; + + void clear() { - return full_eq(l,r); + id_container.clear(); + content_container.clear(); + id_replace_map.clear(); } - }; - - public: - class ireps_containert { - public: - typedef std::unordered_map id_containert; - id_containert id_container; - typedef std::unordered_map content_containert; - content_containert content_container; - typedef std::map id_replace_mapt; - id_replace_mapt id_replace_map; - - void clear( void ) { - id_container.clear(); - content_container.clear(); - id_replace_map.clear(); - } - }; - - xml_irep_convertt(ireps_containert& ic) : ireps_container(ic) {}; - - unsigned long insert(unsigned long, const irept&); - unsigned long insert(const std::string&, const irept&); - - void convert(const irept &irep, xmlt &xml); - void convert(const xmlt &xml, irept &irep); - void reference_convert(const irept &irep, xmlt &xml); - void resolve_references( const irept &cur ); - - void convert_map(xmlt &xml); - void output_map(std::ostream &out, unsigned indent); - - void clear( void ) { ireps_container.clear(); } - private: - ireps_containert& ireps_container; - - ireps_containert::id_containert::const_iterator - find_irep_by_id(const unsigned int); - ireps_containert::content_containert::const_iterator - find_irep_by_content(const irept &irep); - - std::string long_to_string(const unsigned long); - unsigned long string_to_long(const std::string &); - - unsigned long add_with_childs(const irept&); + }; + + explicit xml_irep_convertt(ireps_containert &ic):ireps_container(ic) + { + }; + + unsigned long insert(unsigned long, const irept&); + unsigned long insert(const std::string&, const irept&); + + void convert(const irept &irep, xmlt &xml); + void convert(const xmlt &xml, irept &irep); + void reference_convert(const irept &irep, xmlt &xml); + void resolve_references(const irept &cur); + + void convert_map(xmlt &xml); + void output_map(std::ostream &out, unsigned indent); + + void clear() + { + ireps_container.clear(); + } + +private: + ireps_containert &ireps_container; + + ireps_containert::id_containert::const_iterator + find_irep_by_id(const unsigned int); + ireps_containert::content_containert::const_iterator + find_irep_by_content(const irept &irep); + + std::string long_to_string(const unsigned long); + unsigned long string_to_long(const std::string &); + + unsigned long add_with_childs(const irept&); }; #endif // CPROVER_GOTO_CC_XML_BINARIES_XML_IREP_HASHING_H diff --git a/src/goto-cc/xml_binaries/xml_symbol.cpp b/src/goto-cc/xml_binaries/xml_symbol.cpp index de15befac84..051d6b38d4f 100644 --- a/src/goto-cc/xml_binaries/xml_symbol.cpp +++ b/src/goto-cc/xml_binaries/xml_symbol.cpp @@ -23,7 +23,7 @@ Function: convert \*******************************************************************/ -void convert(const symbolt& sym, xmlt &root) +void convert(const symbolt &sym, xmlt &root) { xmlt &xmlsym = root.new_element("symbol"); xmlsym.set_attribute("name", id2string(sym.name)); @@ -49,9 +49,9 @@ void convert(const symbolt& sym, xmlt &root) flags.set_attribute_bool("input", sym.is_input); flags.set_attribute_bool("output", sym.is_output); flags.set_attribute_bool("macro", sym.is_macro); - //flags.set_attribute_bool("actual", sym.is_actual); - //flags.set_attribute_bool("binding", sym.binding); - //flags.set_attribute_bool("free_var", sym.free_var); + // flags.set_attribute_bool("actual", sym.is_actual); + // flags.set_attribute_bool("binding", sym.binding); + // flags.set_attribute_bool("free_var", sym.free_var); flags.set_attribute_bool("statevar", sym.is_state_var); xmlt &mode = flags.new_element("mode"); @@ -60,7 +60,7 @@ void convert(const symbolt& sym, xmlt &root) flags.new_element("base_name").data=id2string(sym.base_name); flags.new_element("module").data=id2string(sym.module); - if (sym.pretty_name.size()>0) + if(sym.pretty_name.size()>0) flags.new_element("pretty_name").data=id2string(sym.pretty_name); xmlt &xmlloc = xmlsym.new_element("location"); @@ -80,7 +80,7 @@ Function: convert \*******************************************************************/ -void convert(const xmlt &xmlsym, symbolt& symbol) +void convert(const xmlt &xmlsym, symbolt &symbol) { symbol.name=xmlsym.get_attribute("name"); @@ -89,13 +89,13 @@ void convert(const xmlt &xmlsym, symbolt& symbol) it!=xmlsym.elements.end(); it++) { - if (it->name=="type") + if(it->name=="type") { convert(*it, symbol.type); } - else if (it->name=="value") + else if(it->name=="value") { - if (it->data=="compiled") + if(it->data=="compiled") { symbol.value.id("code"); } @@ -104,7 +104,7 @@ void convert(const xmlt &xmlsym, symbolt& symbol) convert(*it, symbol.value); } } - else if (it->name=="flags") + else if(it->name=="flags") { symbol.is_lvalue = it->get_attribute_bool("lvalue"); symbol.is_static_lifetime = it->get_attribute_bool("static_lifetime"); @@ -116,9 +116,9 @@ void convert(const xmlt &xmlsym, symbolt& symbol) symbol.is_input = it->get_attribute_bool("input"); symbol.is_output = it->get_attribute_bool("output"); symbol.is_macro = it->get_attribute_bool("macro"); - //symbol.is_actual = it->get_attribute_bool("actual"); - //symbol.binding = it->get_attribute_bool("binding"); - //symbol.free_var = it->get_attribute_bool("free_var"); + // symbol.is_actual = it->get_attribute_bool("actual"); + // symbol.binding = it->get_attribute_bool("binding"); + // symbol.free_var = it->get_attribute_bool("free_var"); symbol.is_state_var = it->get_attribute_bool("statevar"); for(xmlt::elementst::const_iterator diff --git a/src/goto-cc/xml_binaries/xml_symbol_hashing.cpp b/src/goto-cc/xml_binaries/xml_symbol_hashing.cpp index 49051cac072..ab6c17ab412 100644 --- a/src/goto-cc/xml_binaries/xml_symbol_hashing.cpp +++ b/src/goto-cc/xml_binaries/xml_symbol_hashing.cpp @@ -23,7 +23,7 @@ Function: xml_symbol_convertt::convert \*******************************************************************/ -void xml_symbol_convertt::convert(const symbolt& sym, xmlt &root) +void xml_symbol_convertt::convert(const symbolt &sym, xmlt &root) { xmlt &xmlsym = root.new_element("symbol"); irepcache.push_back(irept()); @@ -43,7 +43,7 @@ Function: xml_symbol_convertt::convert \*******************************************************************/ -void xml_symbol_convertt::convert(const xmlt &xmlsym, symbolt& symbol) +void xml_symbol_convertt::convert(const xmlt &xmlsym, symbolt &symbol) { irept t; diff --git a/src/goto-cc/xml_binaries/xml_symbol_hashing.h b/src/goto-cc/xml_binaries/xml_symbol_hashing.h index e09b4389121..0ade830430e 100644 --- a/src/goto-cc/xml_binaries/xml_symbol_hashing.h +++ b/src/goto-cc/xml_binaries/xml_symbol_hashing.h @@ -16,14 +16,17 @@ Date: July 2006 #include "xml_irep_hashing.h" -class xml_symbol_convertt { - private: - xml_irep_convertt irepconverter; - std::list irepcache; - - public: - xml_symbol_convertt(xml_irep_convertt::ireps_containert &ic) : - irepconverter(ic) {}; +class xml_symbol_convertt +{ +private: + xml_irep_convertt irepconverter; + std::list irepcache; + +public: + explicit xml_symbol_convertt(xml_irep_convertt::ireps_containert &ic): + irepconverter(ic) + { + } void convert(const symbolt &, xmlt &); void convert(const xmlt &, symbolt &); diff --git a/src/goto-diff/change_impact.cpp b/src/goto-diff/change_impact.cpp index a8ab174ee68..0644cef2220 100644 --- a/src/goto-diff/change_impact.cpp +++ b/src/goto-diff/change_impact.cpp @@ -127,7 +127,8 @@ void full_slicert::operator()( req_it!=cfg[e].required_by.end(); ++req_it) { - if(req_it!=cfg[e].required_by.begin()) c+=","; + if(req_it!=cfg[e].required_by.begin()) + c+=","; c+=std::to_string(*req_it); } i_it->source_location.set_column(c); // for show-goto-functions @@ -286,12 +287,16 @@ class change_impactt goto_program_change_impactt &old_impact, goto_program_change_impactt &new_impact); - void propogate_dep_back(const dependence_grapht::nodet &d_node, - const dependence_grapht &dep_graph, - goto_functions_change_impactt &change_impact, bool del); - void propogate_dep_forward(const dependence_grapht::nodet &d_node, - const dependence_grapht &dep_graph, - goto_functions_change_impactt &change_impact, bool del); + void propogate_dep_back( + const dependence_grapht::nodet &d_node, + const dependence_grapht &dep_graph, + goto_functions_change_impactt &change_impact, + bool del); + void propogate_dep_forward( + const dependence_grapht::nodet &d_node, + const dependence_grapht &dep_graph, + goto_functions_change_impactt &change_impact, + bool del); void output_change_impact( const irep_idt &function, @@ -311,7 +316,7 @@ class change_impactt const goto_programt &goto_program, const namespacet &ns, const irep_idt &function, - goto_programt::const_targett& target) const; + goto_programt::const_targett &target) const; }; /*******************************************************************\ @@ -440,10 +445,18 @@ void change_impactt::change_impact( const dependence_grapht::nodet &d_node= old_dep_graph[old_dep_graph[o_it].get_node_id()]; - if(impact_mode == BACKWARD || impact_mode == BOTH) - propogate_dep_back(d_node, old_dep_graph, old_change_impact, true); - if(impact_mode == FORWARD || impact_mode == BOTH) - propogate_dep_forward(d_node, old_dep_graph, old_change_impact, true); + if(impact_mode==BACKWARD || impact_mode==BOTH) + propogate_dep_back( + d_node, + old_dep_graph, + old_change_impact, + true); + if(impact_mode==FORWARD || impact_mode==BOTH) + propogate_dep_forward( + d_node, + old_dep_graph, + old_change_impact, + true); } old_impact[o_it]|=DELETED; ++o_it; @@ -455,10 +468,18 @@ void change_impactt::change_impact( const dependence_grapht::nodet &d_node= new_dep_graph[new_dep_graph[n_it].get_node_id()]; - if(impact_mode == BACKWARD || impact_mode == BOTH) - propogate_dep_back(d_node, new_dep_graph, new_change_impact, false); - if(impact_mode == FORWARD || impact_mode == BOTH) - propogate_dep_forward(d_node, new_dep_graph, new_change_impact, false); + if(impact_mode==BACKWARD || impact_mode==BOTH) + propogate_dep_back( + d_node, + new_dep_graph, + new_change_impact, + false); + if(impact_mode==FORWARD || impact_mode==BOTH) + propogate_dep_forward( + d_node, + new_dep_graph, + new_change_impact, + false); } new_impact[n_it]|=NEW; ++n_it; @@ -480,9 +501,12 @@ Function: change_impactt::propogate_dep_forward \*******************************************************************/ -void change_impactt::propogate_dep_forward(const dependence_grapht::nodet &d_node, - const dependence_grapht &dep_graph, - goto_functions_change_impactt &change_impact, bool del) { +void change_impactt::propogate_dep_forward( + const dependence_grapht::nodet &d_node, + const dependence_grapht &dep_graph, + goto_functions_change_impactt &change_impact, + bool del) +{ for(dependence_grapht::edgest::const_iterator it = d_node.out.begin(); it != d_node.out.end(); ++it) { @@ -491,8 +515,8 @@ void change_impactt::propogate_dep_forward(const dependence_grapht::nodet &d_nod mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP; mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP; - if((change_impact[src->function][src] & data_flag) - || (change_impact[src->function][src] & ctrl_flag)) + if((change_impact[src->function][src] &data_flag) + || (change_impact[src->function][src] &ctrl_flag)) continue; if(it->second.get() == dep_edget::DATA || it->second.get() == dep_edget::BOTH) @@ -516,9 +540,12 @@ Function: change_impactt::propogate_dep_back \*******************************************************************/ -void change_impactt::propogate_dep_back(const dependence_grapht::nodet &d_node, - const dependence_grapht &dep_graph, - goto_functions_change_impactt &change_impact, bool del) { +void change_impactt::propogate_dep_back( + const dependence_grapht::nodet &d_node, + const dependence_grapht &dep_graph, + goto_functions_change_impactt &change_impact, + bool del) +{ for(dependence_grapht::edgest::const_iterator it = d_node.in.begin(); it != d_node.in.end(); ++it) { @@ -527,8 +554,8 @@ void change_impactt::propogate_dep_back(const dependence_grapht::nodet &d_node, mod_flagt data_flag = del ? DEL_DATA_DEP : NEW_DATA_DEP; mod_flagt ctrl_flag = del ? DEL_CTRL_DEP : NEW_CTRL_DEP; - if((change_impact[src->function][src] & data_flag) - || (change_impact[src->function][src] & ctrl_flag)) + if((change_impact[src->function][src] &data_flag) + || (change_impact[src->function][src] &ctrl_flag)) { continue; } @@ -826,7 +853,7 @@ void change_impactt::output_instruction(char prefix, const goto_programt &goto_program, const namespacet &ns, const irep_idt &function, - goto_programt::const_targett& target) const + goto_programt::const_targett &target) const { if(compact_output) { @@ -834,10 +861,11 @@ void change_impactt::output_instruction(char prefix, return; const irep_idt &file=target->source_location.get_file(); const irep_idt &line=target->source_location.get_line(); - if (!file.empty() && !line.empty()) + if(!file.empty() && !line.empty()) std::cout << prefix << " " << id2string(file) - << " " << id2string(line) << std::endl; - } else + << " " << id2string(line) << std::endl; + } + else { std::cout << prefix; goto_program.output_instruction(ns, function, std::cout, target); diff --git a/src/goto-diff/goto_diff.h b/src/goto-diff/goto_diff.h index 65d9324364d..94155664129 100644 --- a/src/goto-diff/goto_diff.h +++ b/src/goto-diff/goto_diff.h @@ -16,7 +16,7 @@ Author: Peter Schrammel #include -class goto_difft : public messaget +class goto_difft:public messaget { public: explicit goto_difft( @@ -34,14 +34,14 @@ class goto_difft : public messaget virtual bool operator()()=0; - void set_ui(language_uit::uit _ui) { ui=_ui; } + void set_ui(language_uit::uit _ui) { ui=_ui; } virtual std::ostream &output_functions(std::ostream &out) const; protected: const goto_modelt &goto_model1; const goto_modelt &goto_model2; - language_uit::uit ui; + language_uit::uit ui; unsigned total_functions_count; typedef std::set irep_id_sett; @@ -53,7 +53,6 @@ class goto_difft : public messaget void convert_function( json_objectt &result, const irep_idt &function_name) const; - }; #endif // CPROVER_GOTO_DIFF_GOTO_DIFF_H diff --git a/src/goto-diff/goto_diff_languages.h b/src/goto-diff/goto_diff_languages.h index 251c3ce1a91..b0489e85544 100644 --- a/src/goto-diff/goto_diff_languages.h +++ b/src/goto-diff/goto_diff_languages.h @@ -12,12 +12,11 @@ Author: Peter Schrammel #include #include -class goto_diff_languagest : - public language_uit +class goto_diff_languagest:public language_uit { public: explicit goto_diff_languagest( - const cmdlinet& cmdline, + const cmdlinet &cmdline, ui_message_handlert &ui_message_handler) : language_uit(cmdline, ui_message_handler) { @@ -26,7 +25,6 @@ class goto_diff_languagest : protected: virtual void register_languages(); - }; #endif // CPROVER_GOTO_DIFF_GOTO_DIFF_LANGUAGES_H diff --git a/src/goto-diff/goto_diff_parse_options.cpp b/src/goto-diff/goto_diff_parse_options.cpp index b2a6ae5fd14..a405178652f 100644 --- a/src/goto-diff/goto_diff_parse_options.cpp +++ b/src/goto-diff/goto_diff_parse_options.cpp @@ -31,7 +31,6 @@ Author: Peter Schrammel #include #include #include -#include #include @@ -108,7 +107,8 @@ void goto_diff_parse_optionst::eval_verbosity() if(cmdline.isset("verbosity")) { v=unsafe_string2unsigned(cmdline.get_value("verbosity")); - if(v>10) v=10; + if(v>10) + v=10; } ui_message_handler.set_verbosity(v); @@ -264,17 +264,18 @@ void goto_diff_parse_optionst::get_command_line_options(optionst &options) if(cmdline.isset("cover")) options.set_option("unwinding-assertions", false); else - options.set_option("unwinding-assertions", + options.set_option( + "unwinding-assertions", cmdline.isset("unwinding-assertions")); // generate unwinding assumptions otherwise - options.set_option("partial-loops", - cmdline.isset("partial-loops")); + options.set_option("partial-loops", cmdline.isset("partial-loops")); if(options.get_bool_option("partial-loops") && options.get_bool_option("unwinding-assertions")) { - error() << "--partial-loops and --unwinding-assertions must not be given together" << eom; + error() << "--partial-loops and --unwinding-assertions" + << " must not be given together" << eom; exit(1); } } @@ -340,18 +341,23 @@ int goto_diff_parse_optionst::doit() } if(cmdline.isset("change-impact") || - cmdline.isset("forward-impact")|| - cmdline.isset("backward-impact")) + cmdline.isset("forward-impact") || + cmdline.isset("backward-impact")) { - //Workaround to avoid deps not propagating between return and end_func + // Workaround to avoid deps not propagating between return and end_func remove_returns(goto_model1); remove_returns(goto_model2); - impact_modet impact_mode = - cmdline.isset("forward-impact") ? - FORWARD : (cmdline.isset("backward-impact") ? BACKWARD : BOTH); - change_impact(goto_model1, goto_model2, impact_mode, - cmdline.isset("compact-output")); + impact_modet impact_mode= + cmdline.isset("forward-impact") ? + FORWARD : + (cmdline.isset("backward-impact") ? BACKWARD : BOTH); + change_impact( + goto_model1, + goto_model2, + impact_mode, + cmdline.isset("compact-output")); + return 0; } @@ -367,7 +373,7 @@ int goto_diff_parse_optionst::doit() std::unique_ptr goto_diff; goto_diff = std::unique_ptr( - new syntactic_difft(goto_model1, goto_model2,get_message_handler())); + new syntactic_difft(goto_model1, goto_model2, get_message_handler())); goto_diff->set_ui(get_ui()); (*goto_diff)(); @@ -398,9 +404,11 @@ int goto_diff_parse_optionst::get_goto_program( if(is_goto_binary(cmdline.args[0])) { - if(read_goto_binary(cmdline.args[0], - goto_model.symbol_table, goto_model.goto_functions, - languages.get_message_handler())) + if(read_goto_binary( + cmdline.args[0], + goto_model.symbol_table, + goto_model.goto_functions, + languages.get_message_handler())) return 6; config.set(cmdline); @@ -420,9 +428,10 @@ int goto_diff_parse_optionst::get_goto_program( cmdline.args.erase(--cmdline.args.end()); } - if(languages.parse()) return 6; - if(languages.typecheck()) return 6; - if(languages.final()) return 6; + if(languages.parse() || + languages.typecheck() || + languages.final()) + return 6; // we no longer need any parse trees or language files languages.clear_parse(); @@ -430,8 +439,10 @@ int goto_diff_parse_optionst::get_goto_program( status() << "Generating GOTO Program" << eom; goto_model.symbol_table=languages.symbol_table; - goto_convert(goto_model.symbol_table, goto_model.goto_functions, - ui_message_handler); + goto_convert( + goto_model.symbol_table, + goto_model.goto_functions, + ui_message_handler); // if we had a second argument then we will handle it next if(arg2!="") @@ -475,7 +486,9 @@ bool goto_diff_parse_optionst::process_goto_program( // remove function pointers status() << "Function Pointer Removal" << eom; - remove_function_pointers(symbol_table, goto_functions, + remove_function_pointers( + symbol_table, + goto_functions, cmdline.isset("pointer-check")); // do partial inlining @@ -554,6 +567,7 @@ void goto_diff_parse_optionst::help() { std::cout << "\n" + // NOLINTNEXTLINE(whitespace/line_length) "* * GOTO_DIFF " CBMC_VERSION " - Copyright (C) 2016 * *\n" "* * Daniel Kroening, Peter Schrammel * *\n" "* * kroening@kroening.com * *\n" @@ -569,6 +583,7 @@ void goto_diff_parse_optionst::help() " -u | --unified output unified diff\n" " --change-impact | \n" " --forward-impact |\n" + // NOLINTNEXTLINE(whitespace/line_length) " --backward-impact output unified diff with forward&backward/forward/backward dependencies\n" " --compact-output output dependencies in compact mode\n" "\n" diff --git a/src/goto-diff/syntactic_diff.cpp b/src/goto-diff/syntactic_diff.cpp index af1e910fd66..4c0e831dfdc 100644 --- a/src/goto-diff/syntactic_diff.cpp +++ b/src/goto-diff/syntactic_diff.cpp @@ -61,7 +61,6 @@ bool syntactic_difft::operator()() break; } } - } forall_goto_functions(it, goto_model2.goto_functions) { diff --git a/src/goto-diff/syntactic_diff.h b/src/goto-diff/syntactic_diff.h index 3ffc28fd722..dd10374dc4b 100644 --- a/src/goto-diff/syntactic_diff.h +++ b/src/goto-diff/syntactic_diff.h @@ -11,20 +11,18 @@ Author: Peter Schrammel #include "goto_diff.h" -class syntactic_difft : public goto_difft +class syntactic_difft:public goto_difft { public: explicit syntactic_difft( const goto_modelt &_goto_model1, const goto_modelt &_goto_model2, - message_handlert &_message_handler - ) - : + message_handlert &_message_handler): goto_difft(_goto_model1, _goto_model2, _message_handler) - {} + { + } virtual bool operator()(); - }; #endif // CPROVER_GOTO_DIFF_SYNTACTIC_DIFF_H diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index e8a5c3d4e25..8cf1f8f27b3 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -313,7 +313,8 @@ void unified_difft::lcss( for(j=0; j<=new_count; ++j) { std::cerr << " "; - if(lcss_matrix[i][j]<10) std::cerr << " "; + if(lcss_matrix[i][j]<10) + std::cerr << " "; std::cerr << lcss_matrix[i][j]; } std::cerr << std::endl; diff --git a/src/goto-instrument/accelerate/accelerate.cpp b/src/goto-instrument/accelerate/accelerate.cpp index 3047a4f9198..93d0ca0dfd7 100644 --- a/src/goto-instrument/accelerate/accelerate.cpp +++ b/src/goto-instrument/accelerate/accelerate.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include @@ -18,50 +26,57 @@ #include "disjunctive_polynomial_acceleration.h" #include "overflow_instrumenter.h" #include "util.h" -//#include "symbolic_accelerator.h" #define DEBUG goto_programt::targett acceleratet::find_back_jump( - goto_programt::targett loop_header) { - natural_loops_mutablet::natural_loopt &loop = + goto_programt::targett loop_header) +{ + natural_loops_mutablet::natural_loopt &loop= natural_loops.loop_map[loop_header]; - goto_programt::targett back_jump = loop_header; + goto_programt::targett back_jump=loop_header; - for (natural_loops_mutablet::natural_loopt::iterator it = loop.begin(); - it != loop.end(); - ++it) { - goto_programt::targett t = *it; - if (t->is_goto() && + for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { + goto_programt::targett t=*it; + if(t->is_goto() && t->guard.is_true() && - t->targets.size() == 1 && - t->targets.front() == loop_header && - t->location_number > back_jump->location_number) { - back_jump = t; + t->targets.size()==1 && + t->targets.front()==loop_header && + t->location_number > back_jump->location_number) + { + back_jump=t; } } return back_jump; } -bool acceleratet::contains_nested_loops(goto_programt::targett &loop_header) { - natural_loops_mutablet::natural_loopt &loop = +bool acceleratet::contains_nested_loops(goto_programt::targett &loop_header) +{ + natural_loops_mutablet::natural_loopt &loop= natural_loops.loop_map[loop_header]; - for (natural_loops_mutablet::natural_loopt::iterator it = loop.begin(); - it != loop.end(); - ++it) { - const goto_programt::targett &t = *it; + for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { + const goto_programt::targett &t=*it; - if (t->is_backwards_goto()) { - if (t->targets.size() != 1 || - t->get_target() != loop_header) { + if(t->is_backwards_goto()) + { + if(t->targets.size()!=1 || + t->get_target()!=loop_header) + { return true; } } - if (t != loop_header && - natural_loops.loop_map.find(t) != natural_loops.loop_map.end()) { + if(t!=loop_header && + natural_loops.loop_map.find(t)!=natural_loops.loop_map.end()) + { return true; } } @@ -69,15 +84,17 @@ bool acceleratet::contains_nested_loops(goto_programt::targett &loop_header) { return false; } -int acceleratet::accelerate_loop(goto_programt::targett &loop_header) { +int acceleratet::accelerate_loop(goto_programt::targett &loop_header) +{ pathst loop_paths, exit_paths; - goto_programt::targett back_jump = find_back_jump(loop_header); - int num_accelerated = 0; + goto_programt::targett back_jump=find_back_jump(loop_header); + int num_accelerated=0; std::list accelerators; natural_loops_mutablet::natural_loopt &loop = natural_loops.loop_map[loop_header]; - if (contains_nested_loops(loop_header)) { + if(contains_nested_loops(loop_header)) + { // For now, only accelerate innermost loops. #ifdef DEBUG std::cout << "Not accelerating an outer loop" << std::endl; @@ -90,24 +107,33 @@ int acceleratet::accelerate_loop(goto_programt::targett &loop_header) { program.update(); #if 1 - enumerating_loop_accelerationt acceleration(symbol_table, goto_functions, - program, loop, loop_header, accelerate_limit); + enumerating_loop_accelerationt + acceleration( + symbol_table, + goto_functions, + program, + loop, + loop_header, + accelerate_limit); #else - disjunctive_polynomial_accelerationt acceleration(symbol_table, goto_functions, - program, loop, loop_header); + disjunctive_polynomial_accelerationt + acceleration(symbol_table, goto_functions, program, loop, loop_header); #endif path_acceleratort accelerator; - while (acceleration.accelerate(accelerator) && - (accelerate_limit < 0 || - num_accelerated < accelerate_limit)) { - //set_dirty_vars(accelerator); + while(acceleration.accelerate(accelerator) && + (accelerate_limit < 0 || + num_accelerated < accelerate_limit)) + { + // set_dirty_vars(accelerator); - if (is_underapproximate(accelerator)) { + if(is_underapproximate(accelerator)) + { // We have some underapproximated variables -- just punt for now. #ifdef DEBUG - std::cout << "Not inserting accelerator because of underapproximation" << std::endl; + std::cout << "Not inserting accelerator because of underapproximation" + << std::endl; #endif continue; @@ -120,15 +146,16 @@ int acceleratet::accelerate_loop(goto_programt::targett &loop_header) { std::cout << "Accelerated path:" << std::endl; output_path(accelerator.path, program, ns, std::cout); - std::cout << "Accelerator has " << accelerator.pure_accelerator.instructions.size() - << " instructions" << std::endl; + std::cout << "Accelerator has " + << accelerator.pure_accelerator.instructions.size() + << " instructions" << std::endl; #endif } goto_programt::instructiont skip(SKIP); program.insert_before_swap(loop_header, skip); - goto_programt::targett new_inst = loop_header; + goto_programt::targett new_inst=loop_header; ++new_inst; loop.insert(new_inst); @@ -137,9 +164,10 @@ int acceleratet::accelerate_loop(goto_programt::targett &loop_header) { std::cout << "Overflow loc is " << overflow_loc->location_number << std::endl; std::cout << "Back jump is " << back_jump->location_number << std::endl; - for (std::list::iterator it = accelerators.begin(); - it != accelerators.end(); - ++it) { + for(std::list::iterator it=accelerators.begin(); + it!=accelerators.end(); + ++it) + { subsumed_patht inserted(it->path); insert_accelerator(loop_header, back_jump, *it, inserted); @@ -150,16 +178,19 @@ int acceleratet::accelerate_loop(goto_programt::targett &loop_header) { return num_accelerated; } -void acceleratet::insert_accelerator(goto_programt::targett &loop_header, - goto_programt::targett &back_jump, - path_acceleratort &accelerator, - subsumed_patht &subsumed) { - insert_looping_path(loop_header, back_jump, accelerator.pure_accelerator, - subsumed.accelerator); +void acceleratet::insert_accelerator( + goto_programt::targett &loop_header, + goto_programt::targett &back_jump, + path_acceleratort &accelerator, + subsumed_patht &subsumed) +{ + insert_looping_path( + loop_header, back_jump, accelerator.pure_accelerator, subsumed.accelerator); - if (!accelerator.overflow_path.instructions.empty()) { - insert_looping_path(loop_header, back_jump, accelerator.overflow_path, - subsumed.residue); + if(!accelerator.overflow_path.instructions.empty()) + { + insert_looping_path( + loop_header, back_jump, accelerator.overflow_path, subsumed.residue); } } @@ -170,88 +201,96 @@ void acceleratet::insert_accelerator(goto_programt::targett &loop_header, * * THIS DESTROYS looping_path!! */ -void acceleratet::insert_looping_path(goto_programt::targett &loop_header, - goto_programt::targett &back_jump, - goto_programt &looping_path, - patht &inserted_path) { - goto_programt::targett loop_body = loop_header; +void acceleratet::insert_looping_path( + goto_programt::targett &loop_header, + goto_programt::targett &back_jump, + goto_programt &looping_path, + patht &inserted_path) +{ + goto_programt::targett loop_body=loop_header; ++loop_body; - goto_programt::targett jump = program.insert_before(loop_body); + goto_programt::targett jump=program.insert_before(loop_body); jump->make_goto(); - jump->guard = side_effect_expr_nondett(bool_typet()); + jump->guard=side_effect_expr_nondett(bool_typet()); jump->targets.push_back(loop_body); program.destructive_insert(loop_body, looping_path); - jump = program.insert_before(loop_body); + jump=program.insert_before(loop_body); jump->make_goto(); - jump->guard = true_exprt(); + jump->guard=true_exprt(); jump->targets.push_back(back_jump); - for (goto_programt::targett t = loop_header; - t != loop_body; - ++t) { + for(goto_programt::targett t=loop_header; + t!=loop_body; + ++t) + { inserted_path.push_back(path_nodet(t)); } inserted_path.push_back(path_nodet(back_jump)); } -void acceleratet::make_overflow_loc(goto_programt::targett loop_header, - goto_programt::targett &loop_end, - goto_programt::targett &overflow_loc) { - symbolt overflow_sym = utils.fresh_symbol("accelerate::overflow", bool_typet()); - const exprt &overflow_var = overflow_sym.symbol_expr(); +void acceleratet::make_overflow_loc( + goto_programt::targett loop_header, + goto_programt::targett &loop_end, + goto_programt::targett &overflow_loc) +{ + symbolt overflow_sym=utils.fresh_symbol("accelerate::overflow", bool_typet()); + const exprt &overflow_var=overflow_sym.symbol_expr(); natural_loops_mutablet::natural_loopt &loop = natural_loops.loop_map[loop_header]; overflow_instrumentert instrumenter(program, overflow_var, symbol_table); - for (natural_loops_mutablet::natural_loopt::iterator it = loop.begin(); - it != loop.end(); - ++it) { - overflow_locs[*it] = goto_programt::targetst(); - goto_programt::targetst &added = overflow_locs[*it]; + for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { + overflow_locs[*it]=goto_programt::targetst(); + goto_programt::targetst &added=overflow_locs[*it]; instrumenter.add_overflow_checks(*it, added); loop.insert(added.begin(), added.end()); } - - goto_programt::targett t = program.insert_after(loop_header); + goto_programt::targett t=program.insert_after(loop_header); t->make_assignment(); - t->code = code_assignt(overflow_var, false_exprt()); + t->code=code_assignt(overflow_var, false_exprt()); t->swap(*loop_header); loop.insert(t); overflow_locs[loop_header].push_back(t); goto_programt::instructiont s(SKIP); - overflow_loc = program.insert_after(loop_end); - *overflow_loc = s; + overflow_loc=program.insert_after(loop_end); + *overflow_loc=s; overflow_loc->swap(*loop_end); loop.insert(overflow_loc); goto_programt::instructiont g(GOTO); - g.guard = not_exprt(overflow_var); + g.guard=not_exprt(overflow_var); g.targets.push_back(overflow_loc); - goto_programt::targett t2 = program.insert_after(loop_end); - *t2 = g; + goto_programt::targett t2=program.insert_after(loop_end); + *t2=g; t2->swap(*loop_end); overflow_locs[overflow_loc].push_back(t2); loop.insert(t2); - goto_programt::targett tmp = overflow_loc; - overflow_loc = loop_end; - loop_end = tmp; + goto_programt::targett tmp=overflow_loc; + overflow_loc=loop_end; + loop_end=tmp; } -void acceleratet::restrict_traces() { +void acceleratet::restrict_traces() +{ trace_automatont automaton(program); - for (subsumed_pathst::iterator it = subsumed.begin(); - it != subsumed.end(); - ++it) { - if (!it->subsumed.empty()) { + for(subsumed_pathst::iterator it=subsumed.begin(); + it!=subsumed.end(); + ++it) + { + if(!it->subsumed.empty()) + { #ifdef DEBUG namespacet ns(symbol_table); std::cout << "Restricting path:" << std::endl; @@ -262,9 +301,11 @@ void acceleratet::restrict_traces() { } patht double_accelerator; - patht::iterator jt = double_accelerator.begin(); - double_accelerator.insert(jt, it->accelerator.begin(), it->accelerator.end()); - double_accelerator.insert(jt, it->accelerator.begin(), it->accelerator.end()); + patht::iterator jt=double_accelerator.begin(); + double_accelerator.insert( + jt, it->accelerator.begin(), it->accelerator.end()); + double_accelerator.insert( + jt, it->accelerator.begin(), it->accelerator.end()); #ifdef DEBUG namespacet ns(symbol_table); @@ -280,20 +321,25 @@ void acceleratet::restrict_traces() { insert_automaton(automaton); } -void acceleratet::set_dirty_vars(path_acceleratort &accelerator) { - for (std::set::iterator it = accelerator.dirty_vars.begin(); - it != accelerator.dirty_vars.end(); - ++it) { - expr_mapt::iterator jt = dirty_vars_map.find(*it); +void acceleratet::set_dirty_vars(path_acceleratort &accelerator) +{ + for(std::set::iterator it=accelerator.dirty_vars.begin(); + it!=accelerator.dirty_vars.end(); + ++it) + { + expr_mapt::iterator jt=dirty_vars_map.find(*it); exprt dirty_var; - if (jt == dirty_vars_map.end()) { + if(jt==dirty_vars_map.end()) + { scratch_programt scratch(symbol_table); - symbolt new_sym = utils.fresh_symbol("accelerate::dirty", bool_typet()); - dirty_var = new_sym.symbol_expr(); - dirty_vars_map[*it] = dirty_var; - } else { - dirty_var = jt->second; + symbolt new_sym=utils.fresh_symbol("accelerate::dirty", bool_typet()); + dirty_var=new_sym.symbol_expr(); + dirty_vars_map[*it]=dirty_var; + } + else + { + dirty_var=jt->second; } #ifdef DEBUG @@ -306,33 +352,38 @@ void acceleratet::set_dirty_vars(path_acceleratort &accelerator) { } } -void acceleratet::add_dirty_checks() { - for (expr_mapt::iterator it = dirty_vars_map.begin(); - it != dirty_vars_map.end(); - ++it) { +void acceleratet::add_dirty_checks() +{ + for(expr_mapt::iterator it=dirty_vars_map.begin(); + it!=dirty_vars_map.end(); + ++it) + { goto_programt::instructiont assign(ASSIGN); - assign.code = code_assignt(it->second, false_exprt()); + assign.code=code_assignt(it->second, false_exprt()); program.insert_before_swap(program.instructions.begin(), assign); } goto_programt::targett next; - for (goto_programt::targett it = program.instructions.begin(); - it != program.instructions.end(); - it = next) { - next = it; + for(goto_programt::targett it=program.instructions.begin(); + it!=program.instructions.end(); + it=next) + { + next=it; ++next; // If this is an assign to a tracked variable, clear the dirty flag. // Note: this order of insertions means that we assume each of the read // variables is clean _before_ clearing any dirty flags. - if (it->is_assign()) { - exprt &lhs = it->code.op0(); - expr_mapt::iterator dirty_var = dirty_vars_map.find(lhs); + if(it->is_assign()) + { + exprt &lhs=it->code.op0(); + expr_mapt::iterator dirty_var=dirty_vars_map.find(lhs); - if (dirty_var != dirty_vars_map.end()) { + if(dirty_var!=dirty_vars_map.end()) + { goto_programt::instructiont clear_flag(ASSIGN); - clear_flag.code = code_assignt(dirty_var->second, false_exprt()); + clear_flag.code=code_assignt(dirty_var->second, false_exprt()); program.insert_before_swap(it, clear_flag); } } @@ -343,36 +394,43 @@ void acceleratet::add_dirty_checks() { find_symbols(it->guard, read); - if (it->is_assign()) { + if(it->is_assign()) + { find_symbols(it->code.op1(), read); } - for (find_symbols_sett::iterator jt = read.begin(); - jt != read.end(); - ++jt) { - const exprt &var = ns.lookup(*jt).symbol_expr(); - expr_mapt::iterator dirty_var = dirty_vars_map.find(var); + for(find_symbols_sett::iterator jt=read.begin(); + jt!=read.end(); + ++jt) + { + const exprt &var=ns.lookup(*jt).symbol_expr(); + expr_mapt::iterator dirty_var=dirty_vars_map.find(var); - if (dirty_var == dirty_vars_map.end()) { + if(dirty_var==dirty_vars_map.end()) + { continue; } goto_programt::instructiont not_dirty(ASSUME); - not_dirty.guard = not_exprt(dirty_var->second); + not_dirty.guard=not_exprt(dirty_var->second); program.insert_before_swap(it, not_dirty); } } } -bool acceleratet::is_underapproximate(path_acceleratort &accelerator) { - for (std::set::iterator it = accelerator.dirty_vars.begin(); - it != accelerator.dirty_vars.end(); - ++it) { - if (it->id() == ID_symbol && it->type() == bool_typet()) { - const irep_idt &id = to_symbol_expr(*it).get_identifier(); - const symbolt &sym = symbol_table.lookup(id); +bool acceleratet::is_underapproximate(path_acceleratort &accelerator) +{ + for(std::set::iterator it=accelerator.dirty_vars.begin(); + it!=accelerator.dirty_vars.end(); + ++it) + { + if(it->id()==ID_symbol && it->type() == bool_typet()) + { + const irep_idt &id=to_symbol_expr(*it).get_identifier(); + const symbolt &sym=symbol_table.lookup(id); - if (sym.module == "scratch") { + if(sym.module=="scratch") + { continue; } } @@ -386,46 +444,50 @@ bool acceleratet::is_underapproximate(path_acceleratort &accelerator) { return false; } -symbolt acceleratet::make_symbol(std::string name, typet type) { +symbolt acceleratet::make_symbol(std::string name, typet type) +{ symbolt ret; - ret.module = "accelerate"; - ret.name = name; - ret.base_name = name; - ret.pretty_name = name; - ret.type = type; + ret.module="accelerate"; + ret.name=name; + ret.base_name=name; + ret.pretty_name=name; + ret.type=type; symbol_table.add(ret); return ret; } -void acceleratet::decl(symbol_exprt &sym, goto_programt::targett t) { +void acceleratet::decl(symbol_exprt &sym, goto_programt::targett t) +{ return; - goto_programt::targett decl = program.insert_before(t); + goto_programt::targett decl=program.insert_before(t); code_declt code(sym); decl->make_decl(); - decl->code = code; + decl->code=code; } -void acceleratet::decl(symbol_exprt &sym, goto_programt::targett t, exprt init) { +void acceleratet::decl(symbol_exprt &sym, goto_programt::targett t, exprt init) +{ decl(sym, t); - goto_programt::targett assign = program.insert_before(t); + goto_programt::targett assign=program.insert_before(t); code_assignt code(sym, init); assign->make_assignment(); - assign->code = code; + assign->code=code; } -void acceleratet::insert_automaton(trace_automatont &automaton) { - symbolt state_sym = make_symbol("trace_automaton::state", +void acceleratet::insert_automaton(trace_automatont &automaton) +{ + symbolt state_sym=make_symbol("trace_automaton::state", unsigned_poly_type()); - symbolt next_state_sym = make_symbol("trace_automaton::next_state", + symbolt next_state_sym=make_symbol("trace_automaton::next_state", unsigned_poly_type()); - symbol_exprt state = state_sym.symbol_expr(); - symbol_exprt next_state = next_state_sym.symbol_expr(); + symbol_exprt state=state_sym.symbol_expr(); + symbol_exprt next_state=next_state_sym.symbol_expr(); trace_automatont::sym_mapt transitions; state_sett accept_states; @@ -440,7 +502,7 @@ void acceleratet::insert_automaton(trace_automatont &automaton) { << transitions.size() << " transitions" << std::endl; // Declare the variables we'll use to encode the state machine. - goto_programt::targett t = program.instructions.begin(); + goto_programt::targett t=program.instructions.begin(); decl(state, t, from_integer(automaton.init_state(), state.type())); decl(next_state, t); @@ -459,45 +521,56 @@ void acceleratet::insert_automaton(trace_automatont &automaton) { } } -void acceleratet::build_state_machine(trace_automatont::sym_mapt::iterator begin, - trace_automatont::sym_mapt::iterator end, - state_sett &accept_states, - symbol_exprt state, - symbol_exprt next_state, - scratch_programt &state_machine) { +void acceleratet::build_state_machine( + trace_automatont::sym_mapt::iterator begin, + trace_automatont::sym_mapt::iterator end, + state_sett &accept_states, + symbol_exprt state, + symbol_exprt next_state, + scratch_programt &state_machine) +{ std::map successor_counts; - unsigned int max_count = 0; - unsigned int likely_next = 0; + unsigned int max_count=0; + unsigned int likely_next=0; // Optimisation: find the most common successor state and initialise // next_state to that value. This reduces the size of the state machine // driver substantially. - for (trace_automatont::sym_mapt::iterator p = begin; p != end; ++p) { - trace_automatont::state_pairt state_pair = p->second; - unsigned int to = state_pair.second; - unsigned int count = 0; - - if (successor_counts.find(to) == successor_counts.end()) { - count = 1; - } else { - count = successor_counts[to] + 1; + for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p) + { + trace_automatont::state_pairt state_pair=p->second; + unsigned int to=state_pair.second; + unsigned int count=0; + + if(successor_counts.find(to)==successor_counts.end()) + { + count=1; + } + else + { + count=successor_counts[to] + 1; } - successor_counts[to] = count; + successor_counts[to]=count; - if (count > max_count) { - max_count = count; - likely_next = to; + if(count > max_count) + { + max_count=count; + likely_next=to; } } // Optimisation: if there is only one possible successor state, just // jump straight to it instead of driving the whole machine. - if (successor_counts.size() == 1) { - if (accept_states.find(likely_next) != accept_states.end()) { + if(successor_counts.size()==1) + { + if(accept_states.find(likely_next)!=accept_states.end()) + { // It's an accept state. Just assume(false). state_machine.assume(false_exprt()); - } else { + } + else + { state_machine.assign(state, from_integer(likely_next, next_state.type())); } @@ -508,12 +581,14 @@ void acceleratet::build_state_machine(trace_automatont::sym_mapt::iterator begin state_machine.assign(next_state, from_integer(likely_next, next_state.type())); - for (trace_automatont::sym_mapt::iterator p = begin; p != end; ++p) { - trace_automatont::state_pairt state_pair = p->second; - unsigned int from = state_pair.first; - unsigned int to = state_pair.second; + for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p) + { + trace_automatont::state_pairt state_pair=p->second; + unsigned int from=state_pair.first; + unsigned int to=state_pair.second; - if (to == likely_next) { + if(to==likely_next) + { continue; } @@ -523,7 +598,7 @@ void acceleratet::build_state_machine(trace_automatont::sym_mapt::iterator begin // // which we encode by inserting: // - // next_state = (state == from) ? to : next_state; + // next_state=(state==from) ? to : next_state; // // just before loc. equal_exprt guard(state, from_integer(from, state.type())); @@ -534,34 +609,36 @@ void acceleratet::build_state_machine(trace_automatont::sym_mapt::iterator begin // Update the state and assume(false) if we've hit an accept state. state_machine.assign(state, next_state); - for (state_sett::iterator it = accept_states.begin(); - it != accept_states.end(); - ++it) { - state_machine.assume(not_exprt(equal_exprt(state, - from_integer(*it, state.type()) - ))); + for(state_sett::iterator it=accept_states.begin(); + it!=accept_states.end(); + ++it) + { + state_machine.assume( + not_exprt(equal_exprt(state, from_integer(*it, state.type())))); } } int acceleratet::accelerate_loops() { - int num_accelerated = 0; + int num_accelerated=0; - for (natural_loops_mutablet::loop_mapt::iterator it = - natural_loops.loop_map.begin(); - it != natural_loops.loop_map.end(); - ++it) { - goto_programt::targett t = it->first; + for(natural_loops_mutablet::loop_mapt::iterator it = + natural_loops.loop_map.begin(); + it!=natural_loops.loop_map.end(); + ++it) + { + goto_programt::targett t=it->first; num_accelerated += accelerate_loop(t); } program.update(); - if (num_accelerated > 0) { + if(num_accelerated > 0) + { std::cout << "Engaging crush mode..." << std::endl; restrict_traces(); - //add_dirty_checks(); + // add_dirty_checks(); program.update(); std::cout << "Crush mode engaged." << std::endl; @@ -576,15 +653,17 @@ void accelerate_functions( symbol_tablet &symbol_table, bool use_z3) { - Forall_goto_functions (it, functions) + Forall_goto_functions(it, functions) { std::cout << "Accelerating function " << it->first << std::endl; acceleratet accelerate(it->second.body, functions, symbol_table, use_z3); - int num_accelerated = accelerate.accelerate_loops(); + int num_accelerated=accelerate.accelerate_loops(); - if (num_accelerated > 0) { - std::cout << "Added " << num_accelerated << " accelerator(s)" << std::endl; + if(num_accelerated > 0) + { + std::cout << "Added " << num_accelerated + << " accelerator(s)" << std::endl; } } } diff --git a/src/goto-instrument/accelerate/accelerate.h b/src/goto-instrument/accelerate/accelerate.h index e4ed3700e87..03c61a3fa39 100644 --- a/src/goto-instrument/accelerate/accelerate.h +++ b/src/goto-instrument/accelerate/accelerate.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATE_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATE_H @@ -15,7 +23,8 @@ #include "scratch_program.h" #include "acceleration_utils.h" -class acceleratet { +class acceleratet +{ public: acceleratet(goto_programt &_program, goto_functionst &_goto_functions, @@ -95,7 +104,8 @@ class acceleratet { subsumed_pathst subsumed; acceleration_utilst utils; - typedef std::map overflow_mapt; + typedef std::map + overflow_mapt; overflow_mapt overflow_locs; expr_mapt dirty_vars_map; diff --git a/src/goto-instrument/accelerate/acceleration_utils.cpp b/src/goto-instrument/accelerate/acceleration_utils.cpp index 8c39059fe66..d90357d2246 100644 --- a/src/goto-instrument/accelerate/acceleration_utils.cpp +++ b/src/goto-instrument/accelerate/acceleration_utils.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include @@ -36,15 +44,21 @@ #define DEBUG -void acceleration_utilst::gather_rvalues(const exprt &expr, - expr_sett &rvalues) { - if (expr.id() == ID_symbol || - expr.id() == ID_index || - expr.id() == ID_member || - expr.id() == ID_dereference) { +void acceleration_utilst::gather_rvalues( + const exprt &expr, + expr_sett &rvalues) +{ + if(expr.id()==ID_symbol || + expr.id()==ID_index || + expr.id()==ID_member || + expr.id()==ID_dereference) + { rvalues.insert(expr); - } else { - forall_operands(it, expr) { + } + else + { + forall_operands(it, expr) + { gather_rvalues(*it, rvalues); } } @@ -89,8 +103,9 @@ void acceleration_utilst::find_modified( goto_programt::const_targett t, expr_sett &modified) { - if (t->is_assign()) { - code_assignt assignment = to_code_assign(t->code); + if(t->is_assign()) + { + code_assignt assignment=to_code_assign(t->code); modified.insert(assignment.lhs()); } } @@ -98,17 +113,18 @@ void acceleration_utilst::find_modified( bool acceleration_utilst::check_inductive( std::map polynomials, - patht &path) { + patht &path) +{ // Checking that our polynomial is inductive with respect to the loop body is // equivalent to checking safety of the following program: // - // assume (target1 == polynomial1); - // assume (target2 == polynomial2) + // assume (target1==polynomial1); + // assume (target2==polynomial2) // ... // loop_body; // loop_counter++; - // assert (target1 == polynomial1); - // assert (target2 == polynomial2); + // assert (target1==polynomial1); + // assert (target2==polynomial2); // ... scratch_programt program(symbol_table); std::vector polynomials_hold; @@ -116,27 +132,31 @@ bool acceleration_utilst::check_inductive( stash_polynomials(program, polynomials, substitution, path); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { - exprt holds = equal_exprt(it->first, it->second.to_expr()); - program.add_instruction(ASSUME)->guard = holds; + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { + exprt holds=equal_exprt(it->first, it->second.to_expr()); + program.add_instruction(ASSUME)->guard=holds; polynomials_hold.push_back(holds); } program.append_path(path); - codet inc_loop_counter = code_assignt(loop_counter, - plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); - program.add_instruction(ASSIGN)->code = inc_loop_counter; + codet inc_loop_counter= + code_assignt( + loop_counter, + plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); + program.add_instruction(ASSIGN)->code=inc_loop_counter; ensure_no_overflows(program); - for (std::vector::iterator it = polynomials_hold.begin(); - it != polynomials_hold.end(); - ++it) { - program.add_instruction(ASSERT)->guard = *it; + for(std::vector::iterator it=polynomials_hold.begin(); + it!=polynomials_hold.end(); + ++it) + { + program.add_instruction(ASSERT)->guard=*it; } #ifdef DEBUG @@ -144,62 +164,76 @@ bool acceleration_utilst::check_inductive( program.output(ns, "", std::cout); #endif - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { // We found a counterexample to inductiveness... :-( #ifdef DEBUG std::cout << "Not inductive!" << std::endl; #endif return false; - } else { + } + else + { return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in inductiveness SAT check: " << s << std::endl; return false; - } catch (const char *s) { + } + catch (const char *s) + { std::cout << "Error in inductiveness SAT check: " << s << std::endl; return false; } } void acceleration_utilst::stash_polynomials( - scratch_programt &program, - std::map &polynomials, - substitutiont &substitution, - patht &path) { + scratch_programt &program, + std::map &polynomials, + substitutiont &substitution, + patht &path) +{ expr_sett modified; find_modified(path, modified); stash_variables(program, modified, substitution); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { it->second.substitute(substitution); } } -void acceleration_utilst::stash_variables(scratch_programt &program, - expr_sett modified, - substitutiont &substitution) { +void acceleration_utilst::stash_variables( + scratch_programt &program, + expr_sett modified, + substitutiont &substitution) +{ find_symbols_sett vars; - for (expr_sett::iterator it = modified.begin(); - it != modified.end(); - ++it) { + for(expr_sett::iterator it=modified.begin(); + it!=modified.end(); + ++it) + { find_symbols(*it, vars); } - irep_idt loop_counter_name = to_symbol_expr(loop_counter).get_identifier(); + irep_idt loop_counter_name=to_symbol_expr(loop_counter).get_identifier(); vars.erase(loop_counter_name); - for (find_symbols_sett::iterator it = vars.begin(); - it != vars.end(); - ++it) { - symbolt orig = symbol_table.lookup(*it); - symbolt stashed_sym = fresh_symbol("polynomial::stash", orig.type); - substitution[orig.symbol_expr()] = stashed_sym.symbol_expr(); + for(find_symbols_sett::iterator it=vars.begin(); + it!=vars.end(); + ++it) + { + symbolt orig=symbol_table.lookup(*it); + symbolt stashed_sym=fresh_symbol("polynomial::stash", orig.type); + substitution[orig.symbol_expr()]=stashed_sym.symbol_expr(); program.assign(stashed_sym.symbol_expr(), orig.symbol_expr()); } } @@ -212,118 +246,144 @@ void acceleration_utilst::stash_variables(scratch_programt &program, * to aliasing. */ -exprt acceleration_utilst::precondition(patht &path) { - exprt ret = false_exprt(); +exprt acceleration_utilst::precondition(patht &path) +{ + exprt ret=false_exprt(); - for (patht::reverse_iterator r_it = path.rbegin(); - r_it != path.rend(); - ++r_it) { - goto_programt::const_targett t = r_it->loc; + for(patht::reverse_iterator r_it=path.rbegin(); + r_it!=path.rend(); + ++r_it) + { + goto_programt::const_targett t=r_it->loc; - if (t->is_assign()) { + if(t->is_assign()) + { // XXX Need to check for aliasing... - const code_assignt &assignment = to_code_assign(t->code); - const exprt &lhs = assignment.lhs(); - const exprt &rhs = assignment.rhs(); - - if (lhs.id() == ID_symbol || - lhs.id() == ID_index || - lhs.id() == ID_dereference) { + const code_assignt &assignment=to_code_assign(t->code); + const exprt &lhs=assignment.lhs(); + const exprt &rhs=assignment.rhs(); + + if(lhs.id()==ID_symbol || + lhs.id()==ID_index || + lhs.id()==ID_dereference) + { replace_expr(lhs, rhs, ret); - } else { - throw "Couldn't take WP of " + expr2c(lhs, ns) + " = " + expr2c(rhs, ns); } - } else if (t->is_assume() || t->is_assert()) { - ret = implies_exprt(t->guard, ret); - } else { + else + { + throw "couldn't take WP of " + expr2c(lhs, ns) + "=" + expr2c(rhs, ns); + } + } + else if(t->is_assume() || t->is_assert()) + { + ret=implies_exprt(t->guard, ret); + } + else + { // Ignore. } - if (!r_it->guard.is_true() && !r_it->guard.is_nil()) { + if(!r_it->guard.is_true() && !r_it->guard.is_nil()) + { // The guard isn't constant true, so we need to accumulate that too. - ret = implies_exprt(r_it->guard, ret); + ret=implies_exprt(r_it->guard, ret); } } // Hack: replace array accesses with nondet. expr_mapt array_abstractions; - //abstract_arrays(ret, array_abstractions); + // abstract_arrays(ret, array_abstractions); simplify(ret, ns); return ret; } -void acceleration_utilst::abstract_arrays(exprt &expr, expr_mapt &abstractions) { - if (expr.id() == ID_index || - expr.id() == ID_dereference) { - expr_mapt::iterator it = abstractions.find(expr); - - if (it == abstractions.end()) { - symbolt sym = fresh_symbol("accelerate::array_abstraction", expr.type()); - abstractions[expr] = sym.symbol_expr(); - expr = sym.symbol_expr(); - } else { - expr = it->second; +void acceleration_utilst::abstract_arrays( + exprt &expr, + expr_mapt &abstractions) +{ + if(expr.id()==ID_index || + expr.id()==ID_dereference) + { + expr_mapt::iterator it=abstractions.find(expr); + + if(it==abstractions.end()) + { + symbolt sym=fresh_symbol("accelerate::array_abstraction", expr.type()); + abstractions[expr]=sym.symbol_expr(); + expr=sym.symbol_expr(); } - } else { - Forall_operands(it, expr) { + else + { + expr=it->second; + } + } + else + { + Forall_operands(it, expr) + { abstract_arrays(*it, abstractions); } } } -void acceleration_utilst::push_nondet(exprt &expr) { - Forall_operands(it, expr) { +void acceleration_utilst::push_nondet(exprt &expr) +{ + Forall_operands(it, expr) + { push_nondet(*it); } - if (expr.id() == ID_not && - expr.op0().id() == ID_nondet) { - expr = side_effect_expr_nondett(expr.type()); - } else if (expr.id() == ID_equal || - expr.id() == ID_lt || - expr.id() == ID_gt || - expr.id() == ID_le || - expr.id() == ID_ge) { - if (expr.op0().id() == ID_nondet || - expr.op1().id() == ID_nondet) { - expr = side_effect_expr_nondett(expr.type()); + if(expr.id()==ID_not && + expr.op0().id()==ID_nondet) + { + expr=side_effect_expr_nondett(expr.type()); + } + else if(expr.id()==ID_equal || + expr.id()==ID_lt || + expr.id()==ID_gt || + expr.id()==ID_le || + expr.id()==ID_ge) + { + if(expr.op0().id()==ID_nondet || + expr.op1().id()==ID_nondet) + { + expr=side_effect_expr_nondett(expr.type()); } } } - - bool acceleration_utilst::do_assumptions( std::map polynomials, patht &path, - exprt &guard) { + exprt &guard) +{ // We want to check that if an assumption fails, the next iteration can't be // feasible again. To do this we check the following program for safety: // - // loop_counter = 1; - // assume(target1 == polynomial1); - // assume(target2 == polynomial2); + // loop_counter=1; + // assume(target1==polynomial1); + // assume(target2==polynomial2); // ... // assume(precondition); // - // loop_counter = *; - // target1 = polynomial1); - // target2 = polynomial2); + // loop_counter=*; + // target1=polynomial1); + // target2=polynomial2); // ... // assume(!precondition); // // loop_counter++; // - // target1 = polynomial1; - // target2 = polynomial2; + // target1=polynomial1; + // target2=polynomial2; // ... // // assume(no overflows in above program) // assert(!precondition); - exprt condition = precondition(path); + exprt condition=precondition(path); scratch_programt program(symbol_table); substitutiont substitution; @@ -331,20 +391,22 @@ bool acceleration_utilst::do_assumptions( std::vector polynomials_hold; - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { - exprt lhs = it->first; - exprt rhs = it->second.to_expr(); + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { + exprt lhs=it->first; + exprt rhs=it->second.to_expr(); polynomials_hold.push_back(equal_exprt(lhs, rhs)); } program.assign(loop_counter, from_integer(0, loop_counter.type())); - for (std::vector::iterator it = polynomials_hold.begin(); - it != polynomials_hold.end(); - ++it) { + for(std::vector::iterator it=polynomials_hold.begin(); + it!=polynomials_hold.end(); + ++it) + { program.assume(*it); } @@ -352,27 +414,30 @@ bool acceleration_utilst::do_assumptions( program.assign(loop_counter, side_effect_expr_nondett(loop_counter.type())); - for (std::map::iterator p_it = polynomials.begin(); - p_it != polynomials.end(); - ++p_it) { + for(std::map::iterator p_it=polynomials.begin(); + p_it!=polynomials.end(); + ++p_it) + { program.assign(p_it->first, p_it->second.to_expr()); } program.assume(condition); - program.assign(loop_counter, - plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); + program.assign( + loop_counter, + plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); - for (std::map::iterator p_it = polynomials.begin(); - p_it != polynomials.end(); - ++p_it) { + for(std::map::iterator p_it=polynomials.begin(); + p_it!=polynomials.end(); + ++p_it) + { program.assign(p_it->first, p_it->second.to_expr()); } ensure_no_overflows(program); - program.add_instruction(ASSERT)->guard = condition; + program.add_instruction(ASSERT)->guard=condition; - guard = not_exprt(condition); + guard=not_exprt(condition); simplify(guard, ns); #ifdef DEBUG @@ -380,18 +445,24 @@ bool acceleration_utilst::do_assumptions( program.output(ns, "", std::cout); #endif - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { #ifdef DEBUG std::cout << "Path is not monotone" << std::endl; #endif return false; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in monotonicity SAT check: " << s << std::endl; return false; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in monotonicity SAT check: " << s << std::endl; return false; } @@ -403,9 +474,10 @@ bool acceleration_utilst::do_assumptions( return true; } -void acceleration_utilst::ensure_no_overflows(scratch_programt &program) { - symbolt overflow_sym = fresh_symbol("polynomial::overflow", bool_typet()); - const exprt &overflow_var = overflow_sym.symbol_expr(); +void acceleration_utilst::ensure_no_overflows(scratch_programt &program) +{ + symbolt overflow_sym=fresh_symbol("polynomial::overflow", bool_typet()); + const exprt &overflow_var=overflow_sym.symbol_expr(); overflow_instrumentert instrumenter(program, overflow_var, symbol_table); optionst checker_options; @@ -418,49 +490,57 @@ void acceleration_utilst::ensure_no_overflows(scratch_programt &program) { #ifdef DEBUG - time_t now = time(0); + time_t now=time(0); std::cout << "Adding overflow checks at " << now << "..." << std::endl; #endif instrumenter.add_overflow_checks(); - program.add_instruction(ASSUME)->guard = not_exprt(overflow_var); + program.add_instruction(ASSUME)->guard=not_exprt(overflow_var); - //goto_functionst::goto_functiont fn; - //fn.body.instructions.swap(program.instructions); - //goto_check(ns, checker_options, fn); - //fn.body.instructions.swap(program.instructions); + // goto_functionst::goto_functiont fn; + // fn.body.instructions.swap(program.instructions); + // goto_check(ns, checker_options, fn); + // fn.body.instructions.swap(program.instructions); #ifdef DEBUG - now = time(0); + now=time(0); std::cout << "Done at " << now << "." << std::endl; #endif } acceleration_utilst::expr_pairst acceleration_utilst::gather_array_assignments( - goto_programt::instructionst &loop_body, - expr_sett &arrays_written) { + goto_programt::instructionst &loop_body, + expr_sett &arrays_written) +{ expr_pairst assignments; - for (goto_programt::instructionst::reverse_iterator r_it = loop_body.rbegin(); - r_it != loop_body.rend(); - ++r_it) { - if (r_it->is_assign()) { + for(goto_programt::instructionst::reverse_iterator r_it=loop_body.rbegin(); + r_it!=loop_body.rend(); + ++r_it) + { + if(r_it->is_assign()) + { // Is this an array assignment? - code_assignt assignment = to_code_assign(r_it->code); + code_assignt assignment=to_code_assign(r_it->code); - if (assignment.lhs().id() == ID_index) { + if(assignment.lhs().id()==ID_index) + { // This is an array assignment -- accumulate it in our list. - assignments.push_back(std::make_pair(assignment.lhs(), assignment.rhs())); + assignments.push_back( + std::make_pair(assignment.lhs(), assignment.rhs())); // Also add this array to the set of arrays written to. - index_exprt index_expr = to_index_expr(assignment.lhs()); + index_exprt index_expr=to_index_expr(assignment.lhs()); arrays_written.insert(index_expr.array()); - } else { + } + else + { // This is a regular assignment. Do weakest precondition on all our // array expressions with respect to this assignment. - for (expr_pairst::iterator a_it = assignments.begin(); - a_it != assignments.end(); - ++a_it) { + for(expr_pairst::iterator a_it=assignments.begin(); + a_it!=assignments.end(); + ++a_it) + { replace_expr(assignment.lhs(), assignment.rhs(), a_it->first); replace_expr(assignment.lhs(), assignment.rhs(), a_it->second); } @@ -485,13 +565,15 @@ bool acceleration_utilst::do_arrays( expr_sett arrays_written; expr_pairst array_assignments; - array_assignments = gather_array_assignments(loop_body, arrays_written); + array_assignments=gather_array_assignments(loop_body, arrays_written); #ifdef DEBUG - std::cout << "Found " << array_assignments.size() << " array assignments" << std::endl; + std::cout << "Found " << array_assignments.size() + << " array assignments" << std::endl; #endif - if (array_assignments.size() == 0) { + if(array_assignments.size()==0) + { // The loop doesn't write to any arrays. We're done! return true; } @@ -499,8 +581,9 @@ bool acceleration_utilst::do_arrays( polynomial_array_assignmentst poly_assignments; polynomialst nondet_indices; - if (!array_assignments2polys(array_assignments, polynomials, poly_assignments, - nondet_indices)) { + if(!array_assignments2polys( + array_assignments, polynomials, poly_assignments, nondet_indices)) + { // We weren't able to model some array assignment. That means we need to // bail out altogether :-( #ifdef DEBUG @@ -510,20 +593,22 @@ bool acceleration_utilst::do_arrays( } // First make all written-to arrays nondeterministic. - for (expr_sett::iterator it = arrays_written.begin(); - it != arrays_written.end(); - ++it) { + for(expr_sett::iterator it=arrays_written.begin(); + it!=arrays_written.end(); + ++it) + { program.assign(*it, side_effect_expr_nondett(it->type())); } - // Now add in all the effects of this loop on the arrays. + // Now add in all the effects of this loop on the arrays. exprt::operandst array_operands; - for (polynomial_array_assignmentst::iterator it = poly_assignments.begin(); - it != poly_assignments.end(); - ++it) { - polynomialt stashed_index = it->index; - polynomialt stashed_value = it->value; + for(polynomial_array_assignmentst::iterator it=poly_assignments.begin(); + it!=poly_assignments.end(); + ++it) + { + polynomialt stashed_index=it->index; + polynomialt stashed_value=it->value; stashed_index.substitute(substitution); stashed_value.substitute(substitution); @@ -535,17 +620,19 @@ bool acceleration_utilst::do_arrays( exprt arrays_expr=conjunction(array_operands); - symbolt k_sym = fresh_symbol("polynomial::k", unsigned_poly_type()); - exprt k = k_sym.symbol_expr(); + symbolt k_sym=fresh_symbol("polynomial::k", unsigned_poly_type()); + exprt k=k_sym.symbol_expr(); - exprt k_bound = and_exprt(binary_relation_exprt(from_integer(0, k.type()), ID_le, k), - binary_relation_exprt(k, ID_lt, loop_counter)); + exprt k_bound= + and_exprt( + binary_relation_exprt(from_integer(0, k.type()), ID_le, k), + binary_relation_exprt(k, ID_lt, loop_counter)); replace_expr(loop_counter, k, arrays_expr); implies_exprt implies(k_bound, arrays_expr); exprt forall(ID_forall); - forall.type() = bool_typet(); + forall.type()=bool_typet(); forall.copy_to_operands(k); forall.copy_to_operands(implies); @@ -553,131 +640,152 @@ bool acceleration_utilst::do_arrays( // Now have to encode that the array doesn't change at indices we didn't // touch. - for (expr_sett::iterator a_it = arrays_written.begin(); - a_it != arrays_written.end(); - ++a_it) + for(expr_sett::iterator a_it=arrays_written.begin(); + a_it!=arrays_written.end(); + ++a_it) { - exprt array = *a_it; - exprt old_array = substitution[array]; + exprt array=*a_it; + exprt old_array=substitution[array]; std::vector indices; - bool nonlinear_index = false; + bool nonlinear_index=false; - for (polynomial_array_assignmentst::iterator it = poly_assignments.begin(); - it != poly_assignments.end(); - ++it) { - if (it->array == array) { - polynomialt index = it->index; + for(polynomial_array_assignmentst::iterator it=poly_assignments.begin(); + it!=poly_assignments.end(); + ++it) + { + if(it->array==array) + { + polynomialt index=it->index; index.substitute(substitution); indices.push_back(index); - if (index.max_degree(loop_counter) > 1 || - (index.coeff(loop_counter) != 1 && index.coeff(loop_counter) != -1)) { + if(index.max_degree(loop_counter) > 1 || + (index.coeff(loop_counter)!=1 && index.coeff(loop_counter)!=-1)) + { #ifdef DEBUG - std::cout << expr2c(index.to_expr(), ns) << " is nonlinear" << std::endl; + std::cout << expr2c(index.to_expr(), ns) << " is nonlinear" + << std::endl; #endif - nonlinear_index = true; + nonlinear_index=true; } } } - exprt idx_never_touched = nil_exprt(); - symbolt idx_sym = fresh_symbol("polynomial::idx", signed_poly_type()); - exprt idx = idx_sym.symbol_expr(); + exprt idx_never_touched=nil_exprt(); + symbolt idx_sym=fresh_symbol("polynomial::idx", signed_poly_type()); + exprt idx=idx_sym.symbol_expr(); // Optimization: if all the assignments to a particular array A are of the // form: - // A[loop_counter + e] = f - // where e does not contain loop_counter, we don't need quantifier alternation - // to encode the non-changedness. We can get away with the expression: - // forall k; k < e || k > loop_counter+e => A[k] = old_A[k] + // A[loop_counter + e]=f + // where e does not contain loop_counter, we don't need quantifier + // alternation to encode the non-changedness. We can get away + // with the expression: + // forall k; k < e || k > loop_counter+e => A[k]=old_A[k] - if (!nonlinear_index) { + if(!nonlinear_index) + { polynomialt pos_eliminator, neg_eliminator; neg_eliminator.from_expr(loop_counter); - pos_eliminator = neg_eliminator; + pos_eliminator=neg_eliminator; pos_eliminator.mult(-1); exprt::operandst unchanged_operands; - for (std::vector::iterator it = indices.begin(); - it != indices.end(); - ++it) { - polynomialt index = *it; + for(std::vector::iterator it=indices.begin(); + it!=indices.end(); + ++it) + { + polynomialt index=*it; exprt max_idx, min_idx; - if (index.coeff(loop_counter) == 1) { - max_idx = minus_exprt(index.to_expr(), from_integer(1, index.to_expr().type())); + if(index.coeff(loop_counter)==1) + { + max_idx= + minus_exprt( + index.to_expr(), + from_integer(1, index.to_expr().type())); index.add(pos_eliminator); - min_idx = index.to_expr(); - } else if (index.coeff(loop_counter) == -1) { - min_idx = plus_exprt(index.to_expr(), from_integer(1, index.to_expr().type())); + min_idx=index.to_expr(); + } + else if(index.coeff(loop_counter)==-1) + { + min_idx= + plus_exprt( + index.to_expr(), + from_integer(1, index.to_expr().type())); index.add(neg_eliminator); - max_idx = index.to_expr(); - } else { + max_idx=index.to_expr(); + } + else + { assert(!"ITSALLGONEWRONG"); } or_exprt unchanged_by_this_one( - binary_relation_exprt(idx, "<", min_idx), - binary_relation_exprt(idx, ">", max_idx)); + binary_relation_exprt(idx, "<", min_idx), + binary_relation_exprt(idx, ">", max_idx)); unchanged_operands.push_back(unchanged_by_this_one); } - idx_never_touched = conjunction(unchanged_operands); + idx_never_touched=conjunction(unchanged_operands); } else { - // The vector `indices' now contains all of the indices written to for the - // current array, each with the free variable loop_counter. Now let's - // build an expression saying that the fresh variable idx is none of these - // indices. + // The vector `indices' now contains all of the indices written + // to for the current array, each with the free variable + // loop_counter. Now let's build an expression saying that the + // fresh variable idx is none of these indices. exprt::operandst idx_touched_operands; - for (std::vector::iterator it = indices.begin(); - it != indices.end(); - ++it) { - idx_touched_operands.push_back(not_exprt(equal_exprt(idx, it->to_expr()))); + for(std::vector::iterator it=indices.begin(); + it!=indices.end(); + ++it) + { + idx_touched_operands.push_back( + not_exprt(equal_exprt(idx, it->to_expr()))); } exprt idx_not_touched=conjunction(idx_touched_operands); // OK, we have an expression saying idx is not touched by the - // loop_counter'th iteration. Let's quantify that to say that idx is not - // touched at all. - symbolt l_sym = fresh_symbol("polynomial::l", signed_poly_type()); - exprt l = l_sym.symbol_expr(); + // loop_counter'th iteration. Let's quantify that to say that + // idx is not touched at all. + symbolt l_sym=fresh_symbol("polynomial::l", signed_poly_type()); + exprt l=l_sym.symbol_expr(); replace_expr(loop_counter, l, idx_not_touched); // 0 < l <= loop_counter => idx_not_touched - and_exprt l_bound(binary_relation_exprt(from_integer(0, l.type()), ID_lt, l), - binary_relation_exprt(l, ID_le, loop_counter)); + and_exprt l_bound( + binary_relation_exprt(from_integer(0, l.type()), ID_lt, l), + binary_relation_exprt(l, ID_le, loop_counter)); implies_exprt idx_not_touched_bound(l_bound, idx_not_touched); - idx_never_touched = exprt(ID_forall); - idx_never_touched.type() = bool_typet(); + idx_never_touched=exprt(ID_forall); + idx_never_touched.type()=bool_typet(); idx_never_touched.copy_to_operands(l); idx_never_touched.copy_to_operands(idx_not_touched_bound); } // We now have an expression saying idx is never touched. It is the // following: - // forall l . 0 < l <= loop_counter => idx != index_1 && ... && idx != index_N + // forall l . 0 < l <= loop_counter => idx!=index_1 && ... && idx!=index_N // // Now let's build an expression saying that such an idx doesn't get // updated by this loop, i.e. - // idx_never_touched => A[idx] == A_old[idx] - equal_exprt value_unchanged(index_exprt(array, idx), - index_exprt(old_array, idx)); + // idx_never_touched => A[idx]==A_old[idx] + equal_exprt value_unchanged( + index_exprt(array, idx), index_exprt(old_array, idx)); implies_exprt idx_unchanged(idx_never_touched, value_unchanged); // Cool. Finally, we want to quantify over idx to say that every idx that // is never touched has its value unchanged. So our expression is: - // forall idx . idx_never_touched => A[idx] == A_old[idx] + // forall idx . idx_never_touched => A[idx]==A_old[idx] exprt array_unchanged(ID_forall); - array_unchanged.type() = bool_typet(); + array_unchanged.type()=bool_typet(); array_unchanged.copy_to_operands(idx); array_unchanged.copy_to_operands(idx_unchanged); @@ -694,39 +802,50 @@ bool acceleration_utilst::array_assignments2polys( polynomial_array_assignmentst &array_polynomials, polynomialst &nondet_indices) { - for (expr_pairst::iterator it = array_assignments.begin(); - it != array_assignments.end(); - ++it) { + for(expr_pairst::iterator it=array_assignments.begin(); + it!=array_assignments.end(); + ++it) + { polynomial_array_assignmentt poly_assignment; - index_exprt index_expr = to_index_expr(it->first); + index_exprt index_expr=to_index_expr(it->first); - poly_assignment.array = index_expr.array(); + poly_assignment.array=index_expr.array(); - if (!expr2poly(index_expr.index(), polynomials, poly_assignment.index)) { + if(!expr2poly(index_expr.index(), polynomials, poly_assignment.index)) + { // Couldn't convert the index -- bail out. #ifdef DEBUG - std::cout << "Couldn't convert index: " << expr2c(index_expr.index(), ns) << std::endl; + std::cout << "Couldn't convert index: " + << expr2c(index_expr.index(), ns) << std::endl; #endif return false; } #ifdef DEBUG - std::cout << "Converted index to: " << expr2c(poly_assignment.index.to_expr(), ns) - << std::endl; + std::cout << "Converted index to: " + << expr2c(poly_assignment.index.to_expr(), ns) + << std::endl; #endif - if (it->second.id() == ID_nondet) { + if(it->second.id()==ID_nondet) + { nondet_indices.push_back(poly_assignment.index); - } else if (!expr2poly(it->second, polynomials, poly_assignment.value)) { + } + else if(!expr2poly(it->second, polynomials, poly_assignment.value)) + { // Couldn't conver the RHS -- bail out. #ifdef DEBUG - std::cout << "Couldn't convert RHS: " << expr2c(it->second, ns) << std::endl; + std::cout << "Couldn't convert RHS: " << expr2c(it->second, ns) + << std::endl; #endif return false; - } else { + } + else + { #ifdef DEBUG - std::cout << "Converted RHS to: " << expr2c(poly_assignment.value.to_expr(), ns) - << std::endl; + std::cout << "Converted RHS to: " + << expr2c(poly_assignment.value.to_expr(), ns) + << std::endl; #endif array_polynomials.push_back(poly_assignment); @@ -741,11 +860,12 @@ bool acceleration_utilst::expr2poly( std::map &polynomials, polynomialt &poly) { - exprt subbed_expr = expr; + exprt subbed_expr=expr; - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { replace_expr(it->first, it->second.to_expr(), subbed_expr); } @@ -753,9 +873,12 @@ bool acceleration_utilst::expr2poly( std::cout << "expr2poly(" << expr2c(subbed_expr, ns) << ")" << std::endl; #endif - try { + try + { poly.from_expr(subbed_expr); - } catch (...) { + } + catch(...) + { return false; } @@ -770,47 +893,54 @@ bool acceleration_utilst::do_nonrecursive( expr_sett &nonrecursive, scratch_programt &program) { - // We have some variables that are defined non-recursively -- that is to say, - // their value at the end of a loop iteration does not depend on their value - // at the previous iteration. We can solve for these variables by just forward - // simulating the path and taking the expressions we get at the end. + // We have some variables that are defined non-recursively -- that + // is to say, their value at the end of a loop iteration does not + // depend on their value at the previous iteration. We can solve + // for these variables by just forward simulating the path and + // taking the expressions we get at the end. replace_mapt state; expr_sett array_writes; expr_sett arrays_written; expr_sett arrays_read; - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { - const exprt &var = it->first; - polynomialt poly = it->second; + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { + const exprt &var=it->first; + polynomialt poly=it->second; poly.substitute(substitution); - exprt e = poly.to_expr(); + exprt e=poly.to_expr(); #if 0 - replace_expr(loop_counter, - minus_exprt(loop_counter, from_integer(1, loop_counter.type())), - e); + replace_expr( + loop_counter, + minus_exprt(loop_counter, from_integer(1, loop_counter.type())), + e); #endif - state[var] = e; + state[var]=e; } - for (expr_sett::iterator it = nonrecursive.begin(); - it != nonrecursive.end(); - ++it) { - exprt e = *it; - state[e] = e; + for(expr_sett::iterator it=nonrecursive.begin(); + it!=nonrecursive.end(); + ++it) + { + exprt e=*it; + state[e]=e; } - for (goto_programt::instructionst::iterator it = body.begin(); - it != body.end(); - ++it) { - if (it->is_assign()) { - exprt lhs = it->code.op0(); - exprt rhs = it->code.op1(); + for(goto_programt::instructionst::iterator it=body.begin(); + it!=body.end(); + ++it) + { + if(it->is_assign()) + { + exprt lhs=it->code.op0(); + exprt rhs=it->code.op1(); - if (lhs.id() == ID_dereference) { + if(lhs.id()==ID_dereference) + { // Not handling pointer dereferences yet... #ifdef DEBUG std::cout << "Bailing out on write-through-pointer" << std::endl; @@ -818,11 +948,13 @@ bool acceleration_utilst::do_nonrecursive( return false; } - if (lhs.id() == ID_index) { + if(lhs.id()==ID_index) + { replace_expr(state, lhs.op1()); array_writes.insert(lhs); - if (arrays_written.find(lhs.op0()) != arrays_written.end()) { + if(arrays_written.find(lhs.op0())!=arrays_written.end()) + { // We've written to this array before -- be conservative and bail // out now. #ifdef DEBUG @@ -836,48 +968,55 @@ bool acceleration_utilst::do_nonrecursive( } replace_expr(state, rhs); - state[lhs] = rhs; + state[lhs]=rhs; gather_array_accesses(rhs, arrays_read); } } // Be conservative: if we read and write from the same array, bail out. - for (expr_sett::iterator it = arrays_written.begin(); - it != arrays_written.end(); - ++it) { - if (arrays_read.find(*it) != arrays_read.end()) { + for(expr_sett::iterator it=arrays_written.begin(); + it!=arrays_written.end(); + ++it) + { + if(arrays_read.find(*it)!=arrays_read.end()) + { #ifdef DEBUG - std::cout << "Bailing out on array read and written on same path" << std::endl; + std::cout << "Bailing out on array read and written on same path" + << std::endl; #endif return false; } } - for (expr_sett::iterator it = nonrecursive.begin(); - it != nonrecursive.end(); - ++it) { - if (it->id() == ID_symbol) { - exprt &val = state[*it]; + for(expr_sett::iterator it=nonrecursive.begin(); + it!=nonrecursive.end(); + ++it) + { + if(it->id()==ID_symbol) + { + exprt &val=state[*it]; program.assign(*it, val); #ifdef DEBUG - std::cout << "Fitted nonrecursive: " << expr2c(*it, ns) << " = " << + std::cout << "Fitted nonrecursive: " << expr2c(*it, ns) << "=" << expr2c(val, ns) << std::endl; #endif } } - for (expr_sett::iterator it = array_writes.begin(); - it != array_writes.end(); - ++it) { - const exprt &lhs = *it; - const exprt &rhs = state[*it]; + for(expr_sett::iterator it=array_writes.begin(); + it!=array_writes.end(); + ++it) + { + const exprt &lhs=*it; + const exprt &rhs=state[*it]; - if (!assign_array(lhs, rhs, loop_counter, program)) { + if(!assign_array(lhs, rhs, loop_counter, program)) + { #ifdef DEBUG std::cout << "Failed to assign a nonrecursive array: " << - expr2c(lhs, ns) << " = " << expr2c(rhs, ns) << std::endl; + expr2c(lhs, ns) << "=" << expr2c(rhs, ns) << std::endl; #endif return false; } @@ -886,16 +1025,19 @@ bool acceleration_utilst::do_nonrecursive( return true; } -bool acceleration_utilst::assign_array(const exprt &lhs, - const exprt &rhs, - const exprt &loop_counter, - scratch_programt &program) { +bool acceleration_utilst::assign_array( + const exprt &lhs, + const exprt &rhs, + const exprt &loop_counter, + scratch_programt &program) +{ #ifdef DEBUG - std::cout << "Modelling array assignment " << expr2c(lhs, ns) << " = " << + std::cout << "Modelling array assignment " << expr2c(lhs, ns) << "=" << expr2c(rhs, ns) << std::endl; #endif - if (lhs.id() == ID_dereference) { + if(lhs.id()==ID_dereference) + { // Don't handle writes through pointers for now... #ifdef DEBUG std::cout << "Bailing out on write-through-pointer" << std::endl; @@ -905,17 +1047,17 @@ bool acceleration_utilst::assign_array(const exprt &lhs, // We handle N iterations of the array write: // - // A[i] = e + // A[i]=e // // by the following sequence: // - // A' = nondet() - // assume(forall 0 <= k < N . A'[i(k/loop_counter)] = e(k/loop_counter)); - // assume(forall j . notwritten(j) ==> A'[j] = A[j]); - // A = A' + // A'=nondet() + // assume(forall 0 <= k < N . A'[i(k/loop_counter)]=e(k/loop_counter)); + // assume(forall j . notwritten(j) ==> A'[j]=A[j]); + // A=A' - const exprt &arr = lhs.op0(); - exprt idx = lhs.op1(); + const exprt &arr=lhs.op0(); + exprt idx=lhs.op1(); const exprt &fresh_array = fresh_symbol("polynomial::array", arr.type()).symbol_expr(); @@ -924,39 +1066,48 @@ bool acceleration_utilst::assign_array(const exprt &lhs, // Then assume that the fresh array has the appropriate values at the indices // the loop updated. - exprt changed = equal_exprt(lhs, rhs); + exprt changed=equal_exprt(lhs, rhs); replace_expr(arr, fresh_array, changed); - symbolt k_sym = fresh_symbol("polynomial::k", unsigned_poly_type()); - exprt k = k_sym.symbol_expr(); + symbolt k_sym=fresh_symbol("polynomial::k", unsigned_poly_type()); + exprt k=k_sym.symbol_expr(); - exprt k_bound = and_exprt(binary_relation_exprt(from_integer(0, k.type()), ID_le, k), - binary_relation_exprt(k, ID_lt, loop_counter)); + exprt k_bound= + and_exprt( + binary_relation_exprt(from_integer(0, k.type()), ID_le, k), + binary_relation_exprt(k, ID_lt, loop_counter)); replace_expr(loop_counter, k, changed); implies_exprt implies(k_bound, changed); exprt forall(ID_forall); - forall.type() = bool_typet(); + forall.type()=bool_typet(); forall.copy_to_operands(k); forall.copy_to_operands(implies); program.assume(forall); - // Now let's ensure that the array did not change at the indices we didn't touch. + // Now let's ensure that the array did not change at the indices we + // didn't touch. #ifdef DEBUG std::cout << "Trying to polynomialize " << expr2c(idx, ns) << std::endl; #endif polynomialt poly; - try { - if (idx.id() == ID_pointer_offset) { + try + { + if(idx.id()==ID_pointer_offset) + { poly.from_expr(idx.op0()); - } else { + } + else + { poly.from_expr(idx); } - } catch(...) { + } + catch(...) + { // idx is probably nonlinear... bail out. #ifdef DEBUG std::cout << "Failed to polynomialize" << std::endl; @@ -964,76 +1115,92 @@ bool acceleration_utilst::assign_array(const exprt &lhs, return false; } - if (poly.max_degree(loop_counter) > 1) { + if(poly.max_degree(loop_counter) > 1) + { // The index expression is nonlinear, e.g. it's something like: // - // A[x*loop_counter] = 0; + // A[x*loop_counter]=0; // // where x changes inside the loop. Modelling this requires quantifier // alternation, and that's too expensive. Bail out. #ifdef DEBUG - std::cout << "Bailing out on nonlinear index: " << expr2c(idx, ns) << std::endl; + std::cout << "Bailing out on nonlinear index: " + << expr2c(idx, ns) << std::endl; #endif return false; } - int stride = poly.coeff(loop_counter); + int stride=poly.coeff(loop_counter); exprt not_touched; - exprt lower_bound = idx; - exprt upper_bound = idx; + exprt lower_bound=idx; + exprt upper_bound=idx; - if (stride > 0) { - replace_expr(loop_counter, from_integer(0, loop_counter.type()), lower_bound); + if(stride > 0) + { + replace_expr( + loop_counter, from_integer(0, loop_counter.type()), lower_bound); simplify_expr(lower_bound, ns); - } else { - replace_expr(loop_counter, from_integer(0, loop_counter.type()), upper_bound); + } + else + { + replace_expr( + loop_counter, from_integer(0, loop_counter.type()), upper_bound); simplify_expr(upper_bound, ns); } - if (stride == 0) { + if(stride==0) + { // The index we write to doesn't depend on the loop counter.... - // We could optimise for this, but I suspect it's not going to happen to much - // so just bail out. + // We could optimise for this, but I suspect it's not going to + // happen to much so just bail out. #ifdef DEBUG std::cout << "Bailing out on write to constant array index: " << expr2c(idx, ns) << std::endl; #endif return false; - } else if (stride == 1 || stride == -1) { + } + else if + (stride==1 || stride == -1) + { // This is the simplest case -- we have an assignment like: // - // A[c + loop_counter] = e; + // A[c + loop_counter]=e; // // where c doesn't change in the loop. The expression to say it doesn't // change at unexpected places is: // - // forall k . (k < c || k >= loop_counter + c) ==> A'[k] == A[k] + // forall k . (k < c || k >= loop_counter + c) ==> A'[k]==A[k] - not_touched = or_exprt( + not_touched=or_exprt( binary_relation_exprt(k, "<", lower_bound), binary_relation_exprt(k, ">=", upper_bound)); - } else { + } + else + { // A more complex case -- our assignment is: // - // A[c + s*loop_counter] = e; + // A[c + s*loop_counter]=e; // - // where c and s are constants. Now our condition for an index i to be unchanged is: + // where c and s are constants. Now our condition for an index i + // to be unchanged is: // - // i < c || i >= (c + s*loop_counter) || (i - c) % s != 0 + // i < c || i >= (c + s*loop_counter) || (i - c) % s!=0 - exprt step = minus_exprt(k, lower_bound); + exprt step=minus_exprt(k, lower_bound); - not_touched = or_exprt( + not_touched= + or_exprt( or_exprt( binary_relation_exprt(k, "<", lower_bound), binary_relation_exprt(k, ">=", lower_bound)), - notequal_exprt(mod_exprt(step, from_integer(stride, step.type())), - from_integer(0, step.type()))); + notequal_exprt( + mod_exprt(step, from_integer(stride, step.type())), + from_integer(0, step.type()))); } // OK now do the assumption. - exprt fresh_lhs = lhs; - exprt old_lhs = lhs; + exprt fresh_lhs=lhs; + exprt old_lhs=lhs; replace_expr(arr, fresh_array, fresh_lhs); replace_expr(loop_counter, k, fresh_lhs); @@ -1042,10 +1209,10 @@ bool acceleration_utilst::assign_array(const exprt &lhs, equal_exprt idx_unchanged(fresh_lhs, old_lhs); - implies = implies_exprt(not_touched, idx_unchanged); + implies=implies_exprt(not_touched, idx_unchanged); - forall = exprt(ID_forall); - forall.type() = bool_typet(); + forall=exprt(ID_forall); + forall.type()=bool_typet(); forall.copy_to_operands(k); forall.copy_to_operands(implies); @@ -1057,13 +1224,18 @@ bool acceleration_utilst::assign_array(const exprt &lhs, return true; } -void acceleration_utilst::gather_array_accesses(const exprt &e, expr_sett &arrays) { - if (e.id() == ID_index || - e.id() == ID_dereference) { +void acceleration_utilst::gather_array_accesses( + const exprt &e, + expr_sett &arrays) +{ + if(e.id()==ID_index || + e.id()==ID_dereference) + { arrays.insert(e.op0()); } - forall_operands(it, e) { + forall_operands(it, e) + { gather_array_accesses(*it, arrays); } } @@ -1073,41 +1245,47 @@ void acceleration_utilst::extract_polynomial( std::set > &coefficients, polynomialt &polynomial) { - for (std::set >::iterator it = coefficients.begin(); - it != coefficients.end(); - ++it) + for(std::set >::iterator it=coefficients.begin(); + it!=coefficients.end(); + ++it) { monomialt monomial; - expr_listt terms = it->first; - exprt coefficient = it->second; - constant_exprt concrete_term = to_constant_expr(program.eval(coefficient)); + expr_listt terms=it->first; + exprt coefficient=it->second; + constant_exprt concrete_term=to_constant_expr(program.eval(coefficient)); std::map degrees; - mp_integer mp = binary2integer(concrete_term.get_value().c_str(), true); - monomial.coeff = mp.to_long(); + mp_integer mp=binary2integer(concrete_term.get_value().c_str(), true); + monomial.coeff=mp.to_long(); - if (monomial.coeff == 0) { + if(monomial.coeff==0) + { continue; } - for (expr_listt::iterator it = terms.begin(); - it != terms.end(); - ++it) { - exprt term = *it; + for(expr_listt::iterator it=terms.begin(); + it!=terms.end(); + ++it) + { + exprt term=*it; - if (degrees.find(term) != degrees.end()) { + if(degrees.find(term)!=degrees.end()) + { degrees[term]++; - } else { - degrees[term] = 1; + } + else + { + degrees[term]=1; } } - for (std::map::iterator it = degrees.begin(); - it != degrees.end(); - ++it) { + for(std::map::iterator it=degrees.begin(); + it!=degrees.end(); + ++it) + { monomialt::termt term; - term.var = it->first; - term.exp = it->second; + term.var=it->first; + term.exp=it->second; monomial.terms.push_back(term); } @@ -1117,15 +1295,15 @@ void acceleration_utilst::extract_polynomial( symbolt acceleration_utilst::fresh_symbol(std::string base, typet type) { - static int num_symbols = 0; + static int num_symbols=0; - std::string name = base + "_" + std::to_string(num_symbols++); + std::string name=base + "_" + std::to_string(num_symbols++); symbolt ret; - ret.module = "scratch"; - ret.name = name; - ret.base_name = name; - ret.pretty_name = name; - ret.type = type; + ret.module="scratch"; + ret.name=name; + ret.base_name=name; + ret.pretty_name=name; + ret.type=type; symbol_table.add(ret); diff --git a/src/goto-instrument/accelerate/acceleration_utils.h b/src/goto-instrument/accelerate/acceleration_utils.h index 8638961dc64..de378ee7509 100644 --- a/src/goto-instrument/accelerate/acceleration_utils.h +++ b/src/goto-instrument/accelerate/acceleration_utils.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATION_UTILS_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATION_UTILS_H @@ -19,7 +27,8 @@ typedef std::unordered_map expr_mapt; -class acceleration_utilst { +class acceleration_utilst +{ public: acceleration_utilst(symbol_tablet &_symbol_table, const goto_functionst &_goto_functions, @@ -65,39 +74,46 @@ class acceleration_utilst { typedef std::pair expr_pairt; typedef std::vector expr_pairst; - typedef struct polynomial_array_assignment { + struct polynomial_array_assignmentt + { exprt array; polynomialt index; polynomialt value; - } polynomial_array_assignmentt; + }; - typedef std::vector polynomial_array_assignmentst; + typedef std::vector + polynomial_array_assignmentst; bool do_arrays(goto_programt::instructionst &loop_body, std::map &polynomials, exprt &loop_counter, substitutiont &substitution, scratch_programt &program); - expr_pairst gather_array_assignments(goto_programt::instructionst &loop_body, - expr_sett &arrays_written); - bool array_assignments2polys(expr_pairst &array_assignments, - std::map &polynomials, - polynomial_array_assignmentst &array_polynomials, - polynomialst &nondet_indices); - bool expr2poly(exprt &expr, - std::map &polynomials, - polynomialt &poly); - - bool do_nonrecursive(goto_programt::instructionst &loop_body, - std::map &polynomials, - exprt &loop_counter, - substitutiont &substitution, - expr_sett &nonrecursive, - scratch_programt &program); - bool assign_array(const exprt &lhs, - const exprt &rhs, - const exprt &loop_counter, - scratch_programt &program); + expr_pairst gather_array_assignments( + goto_programt::instructionst &loop_body, + expr_sett &arrays_written); + bool array_assignments2polys( + expr_pairst &array_assignments, + std::map &polynomials, + polynomial_array_assignmentst &array_polynomials, + polynomialst &nondet_indices); + bool expr2poly( + exprt &expr, + std::map &polynomials, + polynomialt &poly); + + bool do_nonrecursive( + goto_programt::instructionst &loop_body, + std::map &polynomials, + exprt &loop_counter, + substitutiont &substitution, + expr_sett &nonrecursive, + scratch_programt &program); + bool assign_array( + const exprt &lhs, + const exprt &rhs, + const exprt &loop_counter, + scratch_programt &program); void gather_array_accesses(const exprt &expr, expr_sett &arrays); diff --git a/src/goto-instrument/accelerate/accelerator.h b/src/goto-instrument/accelerate/accelerator.h index f1efad64bf9..143c4cbfbab 100644 --- a/src/goto-instrument/accelerate/accelerator.h +++ b/src/goto-instrument/accelerate/accelerator.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATOR_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_ACCELERATOR_H @@ -12,7 +20,8 @@ #include #include -class path_acceleratort { +class path_acceleratort +{ public: path_acceleratort(patht &_path, goto_programt &pure, @@ -38,7 +47,8 @@ class path_acceleratort { overflow_path.copy_from(that.overflow_path); } - void clear() { + void clear() + { path.clear(); pure_accelerator.clear(); overflow_path.clear(); diff --git a/src/goto-instrument/accelerate/all_paths_enumerator.cpp b/src/goto-instrument/accelerate/all_paths_enumerator.cpp index 06e5b4e135a..cfc1c3ae2ed 100644 --- a/src/goto-instrument/accelerate/all_paths_enumerator.cpp +++ b/src/goto-instrument/accelerate/all_paths_enumerator.cpp @@ -1,11 +1,21 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include "all_paths_enumerator.h" -//#define DEBUG +// #define DEBUG -bool all_paths_enumeratort::next(patht &path) { - if (last_path.empty()) { +bool all_paths_enumeratort::next(patht &path) +{ + if(last_path.empty()) + { // This is the first time we've been called -- build an initial // path. last_path.push_back(path_nodet(loop_header)); @@ -13,7 +23,8 @@ bool all_paths_enumeratort::next(patht &path) { // This shouldn't be able to fail. complete_path(last_path, 0); - if (is_looping(last_path)) { + if(is_looping(last_path)) + { // If this was a loop path, we're good. If it wasn't, // we'll keep enumerating paths until we hit a looping one. // This case is exactly the same as if someone just called @@ -24,43 +35,48 @@ bool all_paths_enumeratort::next(patht &path) { } } - do { + do + { #ifdef DEBUG std::cout << "Enumerating next path..." << std::endl; #endif - int decision = backtrack(last_path); + int decision=backtrack(last_path); complete_path(last_path, decision); - if (is_looping(last_path)) { + if(is_looping(last_path)) + { path.clear(); path.insert(path.begin(), last_path.begin(), last_path.end()); return true; } - } while (!last_path.empty()); + } + while(!last_path.empty()); // We've enumerated all the paths. return false; } -int all_paths_enumeratort::backtrack(patht &path) { +int all_paths_enumeratort::backtrack(patht &path) +{ // If we have a path of length 1 or 0, we can't backtrack any further. // That means we're done enumerating paths! - if (path.size() < 2) { + if(path.size()<2) + { path.clear(); return 0; } - path_nodet &node = path.back(); + path_nodet &node=path.back(); path.pop_back(); - path_nodet &parent = path.back(); + path_nodet &parent=path.back(); goto_programt::targetst succs; goto_program.get_successors(parent.loc, succs); - unsigned int ret = 0; + unsigned int ret=0; - for (const auto & succ : succs) + for(const auto &succ : succs) { if(succ==node.loc) break; @@ -68,7 +84,7 @@ int all_paths_enumeratort::backtrack(patht &path) { ret++; } - if ((ret + 1) < succs.size()) + if((ret+1)is_goto()) { - guard = not_exprt(t->guard); - - for (goto_programt::targetst::iterator it = t->targets.begin(); - it != t->targets.end(); - ++it) { - if (next == *it) { - guard = t->guard; + if(t->is_goto()) + { + guard=not_exprt(t->guard); + + for(goto_programt::targetst::iterator it=t->targets.begin(); + it != t->targets.end(); + ++it) + { + if(next == *it) + { + guard=t->guard; break; } } @@ -135,6 +156,7 @@ void all_paths_enumeratort::extend_path(patht &path, path.push_back(path_nodet(next, guard)); } -bool all_paths_enumeratort::is_looping(patht &path) { - return path.size() > 1 && path.back().loc == loop_header; +bool all_paths_enumeratort::is_looping(patht &path) +{ + return path.size()>1 && path.back().loc==loop_header; } diff --git a/src/goto-instrument/accelerate/all_paths_enumerator.h b/src/goto-instrument/accelerate/all_paths_enumerator.h index ab5af066d14..8f8d37b84f3 100644 --- a/src/goto-instrument/accelerate/all_paths_enumerator.h +++ b/src/goto-instrument/accelerate/all_paths_enumerator.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_ALL_PATHS_ENUMERATOR_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_ALL_PATHS_ENUMERATOR_H @@ -8,11 +16,13 @@ #include "path.h" #include "path_enumerator.h" -class all_paths_enumeratort : public path_enumeratort { - public: - all_paths_enumeratort(goto_programt &_goto_program, - natural_loops_mutablet::natural_loopt &_loop, - goto_programt::targett _loop_header) : +class all_paths_enumeratort:public path_enumeratort +{ +public: + all_paths_enumeratort( + goto_programt &_goto_program, + natural_loops_mutablet::natural_loopt &_loop, + goto_programt::targett _loop_header): goto_program(_goto_program), loop(_loop), loop_header(_loop_header) @@ -21,7 +31,7 @@ class all_paths_enumeratort : public path_enumeratort { virtual bool next(patht &path); - protected: +protected: int backtrack(patht &path); void complete_path(patht &path, int succ); void extend_path(patht &path, goto_programt::targett t, int succ); diff --git a/src/goto-instrument/accelerate/cone_of_influence.cpp b/src/goto-instrument/accelerate/cone_of_influence.cpp index 9d0b9c4964a..a1914756698 100644 --- a/src/goto-instrument/accelerate/cone_of_influence.cpp +++ b/src/goto-instrument/accelerate/cone_of_influence.cpp @@ -1,34 +1,49 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include "cone_of_influence.h" -//#define DEBUG +// #define DEBUG -void cone_of_influencet::cone_of_influence(const expr_sett &targets, - expr_sett &cone) { - if (program.instructions.empty()) { - cone = targets; +void cone_of_influencet::cone_of_influence( + const expr_sett &targets, + expr_sett &cone) +{ + if(program.instructions.empty()) + { + cone=targets; return; } - for (goto_programt::instructionst::const_reverse_iterator rit = - program.instructions.rbegin(); - rit != program.instructions.rend(); - ++rit) { - expr_sett curr;// = targets; + for(goto_programt::instructionst::const_reverse_iterator + rit=program.instructions.rbegin(); + rit != program.instructions.rend(); + ++rit) + { + expr_sett curr; // =targets; expr_sett next; - if (rit == program.instructions.rbegin()) { - curr = targets; - } else { + if(rit == program.instructions.rbegin()) + { + curr=targets; + } + else + { get_succs(rit, curr); } cone_of_influence(*rit, curr, next); - cone_map[rit->location_number] = next; + cone_map[rit->location_number]=next; #ifdef DEBUG std::cout << "Previous cone: " << std::endl; @@ -45,88 +60,107 @@ void cone_of_influencet::cone_of_influence(const expr_sett &targets, #endif } - cone = cone_map[program.instructions.front().location_number]; + cone=cone_map[program.instructions.front().location_number]; } -void cone_of_influencet::cone_of_influence(const exprt &target, - expr_sett &cone) { +void cone_of_influencet::cone_of_influence( + const exprt &target, + expr_sett &cone) +{ expr_sett s; s.insert(target); cone_of_influence(s, cone); } void cone_of_influencet::get_succs( - goto_programt::instructionst::const_reverse_iterator rit, - expr_sett &targets) { - if (rit == program.instructions.rbegin()) { + goto_programt::instructionst::const_reverse_iterator rit, + expr_sett &targets) +{ + if(rit == program.instructions.rbegin()) + { return; } - goto_programt::instructionst::const_reverse_iterator next = rit; + goto_programt::instructionst::const_reverse_iterator next=rit; --next; - if (rit->is_goto()) { - if (!rit->guard.is_false()) { + if(rit->is_goto()) + { + if(!rit->guard.is_false()) + { // Branch can be taken. - for (goto_programt::targetst::const_iterator t = rit->targets.begin(); - t != rit->targets.end(); - ++t) { - unsigned int loc = (*t)->location_number; - expr_sett &s = cone_map[loc]; + for(goto_programt::targetst::const_iterator t=rit->targets.begin(); + t != rit->targets.end(); + ++t) + { + unsigned int loc=(*t)->location_number; + expr_sett &s=cone_map[loc]; targets.insert(s.begin(), s.end()); } } - if (rit->guard.is_true()) { + if(rit->guard.is_true()) + { return; } - } else if (rit->is_assume() || rit->is_assert()) { - if (rit->guard.is_false()) { + } + else if(rit->is_assume() || rit->is_assert()) + { + if(rit->guard.is_false()) + { return; } } - unsigned int loc = next->location_number; - expr_sett &s = cone_map[loc]; + unsigned int loc=next->location_number; + expr_sett &s=cone_map[loc]; targets.insert(s.begin(), s.end()); } void cone_of_influencet::cone_of_influence( - const goto_programt::instructiont &i, - const expr_sett &curr, - expr_sett &next) { + const goto_programt::instructiont &i, + const expr_sett &curr, + expr_sett &next) +{ next.insert(curr.begin(), curr.end()); - if (i.is_assign()) { - const code_assignt &assignment = to_code_assign(i.code); + if(i.is_assign()) + { + const code_assignt &assignment=to_code_assign(i.code); expr_sett lhs_syms; - bool care = false; + bool care=false; gather_rvalues(assignment.lhs(), lhs_syms); for(const auto &expr : lhs_syms) if(curr.find(expr)!=curr.end()) { - care = true; + care=true; break; } next.erase(assignment.lhs()); - if (care) { + if(care) + { gather_rvalues(assignment.rhs(), next); } } } -void cone_of_influencet::gather_rvalues(const exprt &expr, expr_sett &rvals) { - if (expr.id() == ID_symbol || - expr.id() == ID_index || - expr.id() == ID_member || - expr.id() == ID_dereference) { +void cone_of_influencet::gather_rvalues(const exprt &expr, expr_sett &rvals) +{ + if(expr.id() == ID_symbol || + expr.id() == ID_index || + expr.id() == ID_member || + expr.id() == ID_dereference) + { rvals.insert(expr); - } else { - forall_operands(it, expr) { + } + else + { + forall_operands(it, expr) + { gather_rvalues(*it, rvals); } } diff --git a/src/goto-instrument/accelerate/cone_of_influence.h b/src/goto-instrument/accelerate/cone_of_influence.h index 59512c1853a..4c9ac072e38 100644 --- a/src/goto-instrument/accelerate/cone_of_influence.h +++ b/src/goto-instrument/accelerate/cone_of_influence.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_CONE_OF_INFLUENCE_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_CONE_OF_INFLUENCE_H @@ -13,7 +21,8 @@ void cone_of_influence(goto_programt &program, expr_sett &targets, expr_sett &cone); -class cone_of_influencet { +class cone_of_influencet +{ public: cone_of_influencet(const goto_programt &_program, const symbol_tablet &symbol_table) : diff --git a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp index da0baedc3e8..6f91824a8e7 100644 --- a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp +++ b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include @@ -39,7 +47,8 @@ bool disjunctive_polynomial_accelerationt::accelerate( - path_acceleratort &accelerator) { + path_acceleratort &accelerator) +{ std::map polynomials; scratch_programt program(symbol_table); @@ -48,72 +57,84 @@ bool disjunctive_polynomial_accelerationt::accelerate( #ifdef DEBUG std::cout << "Polynomial accelerating program:" << std::endl; - for (goto_programt::instructionst::iterator it = goto_program.instructions.begin(); - it != goto_program.instructions.end(); - ++it) { - if (loop.find(it) != loop.end()) { + for(goto_programt::instructionst::iterator + it=goto_program.instructions.begin(); + it!=goto_program.instructions.end(); + ++it) + { + if(loop.find(it)!=loop.end()) + { goto_program.output_instruction(ns, "scratch", std::cout, it); } } std::cout << "Modified:" << std::endl; - for (expr_sett::iterator it = modified.begin(); - it != modified.end(); - ++it) { + for(expr_sett::iterator it=modified.begin(); + it!=modified.end(); + ++it) + { std::cout << expr2c(*it, ns) << std::endl; } #endif - if (loop_counter.is_nil()) { - symbolt loop_sym = utils.fresh_symbol("polynomial::loop_counter", - unsigned_poly_type()); - loop_counter = loop_sym.symbol_expr(); + if(loop_counter.is_nil()) + { + symbolt loop_sym= + utils.fresh_symbol("polynomial::loop_counter", unsigned_poly_type()); + loop_counter=loop_sym.symbol_expr(); } - patht &path = accelerator.path; + patht &path=accelerator.path; path.clear(); - if (!find_path(path)) { + if(!find_path(path)) + { // No more paths! return false; } #if 0 - for (expr_sett::iterator it = modified.begin(); - it != modified.end(); - ++it) { + for(expr_sett::iterator it=modified.begin(); + it!=modified.end(); + ++it) + { polynomialt poly; - exprt target = *it; + exprt target=*it; - if (it->type().id() == ID_bool) { + if(it->type().id()==ID_bool) + { // Hack: don't try to accelerate booleans. continue; } - if (target.id() == ID_index || - target.id() == ID_dereference) { + if(target.id()==ID_index || + target.id()==ID_dereference) + { // We'll handle this later. continue; } - if (fit_polynomial(target, poly, path)) { + if(fit_polynomial(target, poly, path)) + { std::map this_poly; - this_poly[target] = poly; + this_poly[target]=poly; - if (utils.check_inductive(this_poly, path)) { + if(utils.check_inductive(this_poly, path)) + { #ifdef DEBUG - std::cout << "Fitted a polynomial for " << expr2c(target, ns) << - std::endl; + std::cout << "Fitted a polynomial for " << expr2c(target, ns) + << std::endl; #endif - polynomials[target] = poly; + polynomials[target]=poly; accelerator.changed_vars.insert(target); break; } } } - if (polynomials.empty()) { + if(polynomials.empty()) + { return false; } #endif @@ -121,26 +142,30 @@ bool disjunctive_polynomial_accelerationt::accelerate( // Fit polynomials for the other variables. expr_sett dirty; utils.find_modified(accelerator.path, dirty); - polynomial_acceleratort path_acceleration(symbol_table, goto_functions, - loop_counter); + polynomial_acceleratort path_acceleration( + symbol_table, goto_functions, loop_counter); goto_programt::instructionst assigns; - for (patht::iterator it = accelerator.path.begin(); - it != accelerator.path.end(); - ++it) { - if (it->loc->is_assign() || it->loc->is_decl()) { + for(patht::iterator it=accelerator.path.begin(); + it!=accelerator.path.end(); + ++it) + { + if(it->loc->is_assign() || it->loc->is_decl()) + { assigns.push_back(*(it->loc)); } } - for (expr_sett::iterator it = dirty.begin(); - it != dirty.end(); - ++it) { + for(expr_sett::iterator it=dirty.begin(); + it!=dirty.end(); + ++it) + { #ifdef DEBUG std::cout << "Trying to accelerate " << expr2c(*it, ns) << std::endl; #endif - if (it->type().id() == ID_bool) { + if(it->type().id()==ID_bool) + { // Hack: don't try to accelerate booleans. accelerator.dirty_vars.insert(*it); #ifdef DEBUG @@ -149,15 +174,17 @@ bool disjunctive_polynomial_accelerationt::accelerate( continue; } - if (it->id() == ID_index || - it->id() == ID_dereference) { + if(it->id()==ID_index || + it->id()==ID_dereference) + { #ifdef DEBUG std::cout << "Ignoring array reference" << std::endl; #endif continue; } - if (accelerator.changed_vars.find(*it) != accelerator.changed_vars.end()) { + if(accelerator.changed_vars.find(*it)!=accelerator.changed_vars.end()) + { // We've accelerated variable this already. #ifdef DEBUG std::cout << "We've accelerated it already" << std::endl; @@ -168,7 +195,8 @@ bool disjunctive_polynomial_accelerationt::accelerate( // Hack: ignore variables that depend on array values.. exprt array_rhs; - if (depends_on_array(*it, array_rhs)) { + if(depends_on_array(*it, array_rhs)) + { #ifdef DEBUG std::cout << "Ignoring because it depends on an array" << std::endl; #endif @@ -179,12 +207,14 @@ bool disjunctive_polynomial_accelerationt::accelerate( polynomialt poly; exprt target(*it); - if (path_acceleration.fit_polynomial(assigns, target, poly)) { + if(path_acceleration.fit_polynomial(assigns, target, poly)) + { std::map this_poly; - this_poly[target] = poly; + this_poly[target]=poly; - if (utils.check_inductive(this_poly, accelerator.path)) { - polynomials[target] = poly; + if(utils.check_inductive(this_poly, accelerator.path)) + { + polynomials[target]=poly; accelerator.changed_vars.insert(target); continue; } @@ -199,12 +229,13 @@ bool disjunctive_polynomial_accelerationt::accelerate( } - /* - if (!utils.check_inductive(polynomials, assigns)) { + #if 0 + if(!utils.check_inductive(polynomials, assigns)) + { // They're not inductive :-( return false; } - */ + #endif substitutiont stashed; utils.stash_polynomials(program, polynomials, stashed, path); @@ -212,9 +243,12 @@ bool disjunctive_polynomial_accelerationt::accelerate( exprt guard; bool path_is_monotone; - try { - path_is_monotone = utils.do_assumptions(polynomials, path, guard); - } catch (std::string s) { + try + { + path_is_monotone=utils.do_assumptions(polynomials, path, guard); + } + catch(std::string s) + { // Couldn't do WP. std::cout << "Assumptions error: " << s << std::endl; return false; @@ -222,26 +256,33 @@ bool disjunctive_polynomial_accelerationt::accelerate( exprt pre_guard(guard); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { replace_expr(it->first, it->second.to_expr(), guard); } - if (path_is_monotone) { + if(path_is_monotone) + { // OK cool -- the path is monotone, so we can just assume the condition for // the last iteration. - replace_expr(loop_counter, - minus_exprt(loop_counter, from_integer(1, loop_counter.type())), - guard); - } else { + replace_expr( + loop_counter, + minus_exprt(loop_counter, from_integer(1, loop_counter.type())), + guard); + } + else + { // The path is not monotone, so we need to introduce a quantifier to ensure // that the condition held for all 0 <= k < n. - symbolt k_sym = utils.fresh_symbol("polynomial::k", unsigned_poly_type()); - exprt k = k_sym.symbol_expr(); + symbolt k_sym=utils.fresh_symbol("polynomial::k", unsigned_poly_type()); + exprt k=k_sym.symbol_expr(); - exprt k_bound = and_exprt(binary_relation_exprt(from_integer(0, k.type()), "<=", k), - binary_relation_exprt(k, "<", loop_counter)); + exprt k_bound= + and_exprt( + binary_relation_exprt(from_integer(0, k.type()), ID_le, k), + binary_relation_exprt(k, ID_lt, loop_counter)); replace_expr(loop_counter, k, guard); simplify(guard, ns); @@ -249,44 +290,47 @@ bool disjunctive_polynomial_accelerationt::accelerate( implies_exprt implies(k_bound, guard); exprt forall(ID_forall); - forall.type() = bool_typet(); + forall.type()=bool_typet(); forall.copy_to_operands(k); forall.copy_to_operands(implies); - guard = forall; + guard=forall; } // All our conditions are met -- we can finally build the accelerator! // It is of the form: // - // loop_counter = *; - // target1 = polynomial1; - // target2 = polynomial2; + // loop_counter=*; + // target1=polynomial1; + // target2=polynomial2; // ... // assume(guard); // assume(no overflows in previous code); - program.add_instruction(ASSUME)->guard = pre_guard; + program.add_instruction(ASSUME)->guard=pre_guard; program.assign(loop_counter, side_effect_expr_nondett(loop_counter.type())); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { program.assign(it->first, it->second.to_expr()); accelerator.changed_vars.insert(it->first); } // Add in any array assignments we can do now. - if (!utils.do_arrays(assigns, polynomials, loop_counter, stashed, program)) { + if(!utils.do_arrays(assigns, polynomials, loop_counter, stashed, program)) + { // We couldn't model some of the array assignments with polynomials... // Unfortunately that means we just have to bail out. return false; } - program.add_instruction(ASSUME)->guard = guard; + program.add_instruction(ASSUME)->guard=guard; program.fix_types(); - if (path_is_monotone) { + if(path_is_monotone) + { utils.ensure_no_overflows(program); } @@ -295,25 +339,29 @@ bool disjunctive_polynomial_accelerationt::accelerate( return true; } -bool disjunctive_polynomial_accelerationt::find_path(patht &path) { +bool disjunctive_polynomial_accelerationt::find_path(patht &path) +{ scratch_programt program(symbol_table); program.append(fixed); program.append(fixed); // Let's make sure that we get a path we have not seen before. - for (std::list::iterator it = accelerated_paths.begin(); - it != accelerated_paths.end(); - ++it) { - exprt new_path = false_exprt(); - - for (distinguish_valuest::iterator jt = it->begin(); - jt != it->end(); - ++jt) { - exprt distinguisher = jt->first; - bool taken = jt->second; - - if (taken) { + for(std::list::iterator it=accelerated_paths.begin(); + it!=accelerated_paths.end(); + ++it) + { + exprt new_path=false_exprt(); + + for(distinguish_valuest::iterator jt=it->begin(); + jt!=it->end(); + ++jt) + { + exprt distinguisher=jt->first; + bool taken=jt->second; + + if(taken) + { not_exprt negated(distinguisher); distinguisher.swap(negated); } @@ -325,10 +373,12 @@ bool disjunctive_polynomial_accelerationt::find_path(patht &path) { program.assume(new_path); } - program.add_instruction(ASSERT)->guard = false_exprt(); + program.add_instruction(ASSERT)->guard=false_exprt(); - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { #ifdef DEBUG std::cout << "Found a path" << std::endl; #endif @@ -337,9 +387,13 @@ bool disjunctive_polynomial_accelerationt::find_path(patht &path) { return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; } @@ -347,9 +401,10 @@ bool disjunctive_polynomial_accelerationt::find_path(patht &path) { } bool disjunctive_polynomial_accelerationt::fit_polynomial( - exprt &var, - polynomialt &polynomial, - patht &path) { + exprt &var, + polynomialt &polynomial, + patht &path) +{ // These are the variables that var depends on with respect to the body. std::vector parameters; std::set > coefficients; @@ -360,21 +415,24 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( cone_of_influence(var, influence); #ifdef DEBUG - std::cout << "Fitting a polynomial for " << expr2c(var, ns) << ", which depends on:" - << std::endl; + std::cout << "Fitting a polynomial for " << expr2c(var, ns) + << ", which depends on:" << std::endl; - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { std::cout << expr2c(*it, ns) << std::endl; } #endif - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - if (it->id() == ID_index || - it->id() == ID_dereference) { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + if(it->id()==ID_index || + it->id()==ID_dereference) + { // Hack: don't accelerate anything that depends on an array // yet... return false; @@ -402,18 +460,26 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( exprs.clear(); parameters.push_back(exprs); - for (std::vector::iterator it = parameters.begin(); - it != parameters.end(); - ++it) { - symbolt coeff = utils.fresh_symbol("polynomial::coeff", signed_poly_type()); + for(std::vector::iterator it=parameters.begin(); + it!=parameters.end(); + ++it) + { + symbolt coeff=utils.fresh_symbol("polynomial::coeff", signed_poly_type()); coefficients.insert(make_pair(*it, coeff.symbol_expr())); // XXX HACK HACK HACK - // I'm just constraining these coefficients to prevent overflows messing things - // up later... Should really do this properly somehow. - program.assume(binary_relation_exprt(from_integer(-(1 << 10), signed_poly_type()), - "<", coeff.symbol_expr())); - program.assume(binary_relation_exprt(coeff.symbol_expr(), "<", + // I'm just constraining these coefficients to prevent overflows + // messing things up later... Should really do this properly + // somehow. + program.assume( + binary_relation_exprt( + from_integer(-(1 << 10), signed_poly_type()), + ID_lt, + coeff.symbol_expr())); + program.assume( + binary_relation_exprt( + coeff.symbol_expr(), + ID_lt, from_integer(1 << 10, signed_poly_type()))); } @@ -424,14 +490,15 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( std::map ivals2; std::map ivals3; - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - symbolt ival1 = utils.fresh_symbol("polynomial::init", + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + symbolt ival1=utils.fresh_symbol("polynomial::init", it->type()); - symbolt ival2 = utils.fresh_symbol("polynomial::init", + symbolt ival2=utils.fresh_symbol("polynomial::init", it->type()); - symbolt ival3 = utils.fresh_symbol("polynomial::init", + symbolt ival3=utils.fresh_symbol("polynomial::init", it->type()); program.assume(binary_relation_exprt(ival1.symbol_expr(), "<", @@ -440,21 +507,24 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( ival3.symbol_expr())); #if 0 - if (it->type() == signedbv_typet()) { + if(it->type()==signedbv_typet()) + { program.assume(binary_relation_exprt(ival1.symbol_expr(), ">", from_integer(-100, it->type()))); } program.assume(binary_relation_exprt(ival1.symbol_expr(), "<", from_integer(100, it->type()))); - if (it->type() == signedbv_typet()) { + if(it->type()==signedbv_typet()) + { program.assume(binary_relation_exprt(ival2.symbol_expr(), ">", from_integer(-100, it->type()))); } program.assume(binary_relation_exprt(ival2.symbol_expr(), "<", from_integer(100, it->type()))); - if (it->type() == signedbv_typet()) { + if(it->type()==signedbv_typet()) + { program.assume(binary_relation_exprt(ival3.symbol_expr(), ">", from_integer(-100, it->type()))); } @@ -462,50 +532,55 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( from_integer(100, it->type()))); #endif - ivals1[*it] = ival1.symbol_expr(); - ivals2[*it] = ival2.symbol_expr(); - ivals3[*it] = ival3.symbol_expr(); + ivals1[*it]=ival1.symbol_expr(); + ivals2[*it]=ival2.symbol_expr(); + ivals3[*it]=ival3.symbol_expr(); - //ivals1[*it] = from_integer(1, it->type()); + // ivals1[*it]=from_integer(1, it->type()); } std::map values; - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = ivals1[*it]; + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=ivals1[*it]; } // Start building the program. Begin by decl'ing each of the // master distinguishers. - for (std::list::iterator it = distinguishers.begin(); - it != distinguishers.end(); - ++it) { - program.add_instruction(DECL)->code = code_declt(*it); + for(std::list::iterator it=distinguishers.begin(); + it!=distinguishers.end(); + ++it) + { + program.add_instruction(DECL)->code=code_declt(*it); } // Now assume our polynomial fits at each of our sample points. assert_for_values(program, values, coefficients, 1, fixed, var); - for (int n = 0; n <= 1; n++) { - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = ivals2[*it]; + for(int n=0; n <= 1; n++) + { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=ivals2[*it]; assert_for_values(program, values, coefficients, n, fixed, var); - values[*it] = ivals3[*it]; + values[*it]=ivals3[*it]; assert_for_values(program, values, coefficients, n, fixed, var); - values[*it] = ivals1[*it]; + values[*it]=ivals1[*it]; } } - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = ivals3[*it]; + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=ivals3[*it]; } assert_for_values(program, values, coefficients, 0, fixed, var); @@ -513,18 +588,21 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( assert_for_values(program, values, coefficients, 2, fixed, var); // Let's make sure that we get a path we have not seen before. - for (std::list::iterator it = accelerated_paths.begin(); - it != accelerated_paths.end(); - ++it) { - exprt new_path = false_exprt(); - - for (distinguish_valuest::iterator jt = it->begin(); - jt != it->end(); - ++jt) { - exprt distinguisher = jt->first; - bool taken = jt->second; - - if (taken) { + for(std::list::iterator it=accelerated_paths.begin(); + it!=accelerated_paths.end(); + ++it) + { + exprt new_path=false_exprt(); + + for(distinguish_valuest::iterator jt=it->begin(); + jt!=it->end(); + ++jt) + { + exprt distinguisher=jt->first; + bool taken=jt->second; + + if(taken) + { not_exprt negated(distinguisher); distinguisher.swap(negated); } @@ -539,12 +617,14 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( utils.ensure_no_overflows(program); // Now do an ASSERT(false) to grab a counterexample - program.add_instruction(ASSERT)->guard = false_exprt(); + program.add_instruction(ASSERT)->guard=false_exprt(); // If the path is satisfiable, we've fitted a polynomial. Extract the // relevant coefficients and return the expression. - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { #ifdef DEBUG std::cout << "Found a polynomial" << std::endl; #endif @@ -555,9 +635,13 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial( return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; } @@ -573,51 +657,62 @@ void disjunctive_polynomial_accelerationt::assert_for_values( exprt &target) { // First figure out what the appropriate type for this expression is. - typet expr_type = nil_typet(); + typet expr_type=nil_typet(); - for (std::map::iterator it = values.begin(); - it != values.end(); - ++it) { - if (expr_type == nil_typet()) { - expr_type = it->first.type(); - } else { - expr_type = join_types(expr_type, it->first.type()); + for(std::map::iterator it=values.begin(); + it!=values.end(); + ++it) + { + if(expr_type==nil_typet()) + { + expr_type=it->first.type(); + } + else + { + expr_type=join_types(expr_type, it->first.type()); } } // Now set the initial values of the all the variables... - for (std::map::iterator it = values.begin(); - it != values.end(); - ++it) { + for(std::map::iterator it=values.begin(); + it!=values.end(); + ++it) + { program.assign(it->first, it->second); } // Now unwind the loop as many times as we need to. - for (int i = 0; i < num_unwindings; i++) { + for(int i=0; i >::iterator it = coefficients.begin(); - it != coefficients.end(); - ++it) { - exprt concrete_value = from_integer(1, expr_type); + for(std::set >::iterator it=coefficients.begin(); + it!=coefficients.end(); + ++it) + { + exprt concrete_value=from_integer(1, expr_type); - for (expr_listt::const_iterator e_it = it->first.begin(); - e_it != it->first.end(); - ++e_it) { - exprt e = *e_it; + for(expr_listt::const_iterator e_it=it->first.begin(); + e_it!=it->first.end(); + ++e_it) + { + exprt e=*e_it; - if (e == loop_counter) { - mult_exprt mult(from_integer(num_unwindings, expr_type), - concrete_value); + if(e==loop_counter) + { + mult_exprt mult( + from_integer(num_unwindings, expr_type), concrete_value); mult.swap(concrete_value); - } else { - std::map::iterator v_it = values.find(e); + } + else + { + std::map::iterator v_it=values.find(e); - assert(v_it != values.end()); + assert(v_it!=values.end()); mult_exprt mult(concrete_value, v_it->second); mult.swap(concrete_value); @@ -628,52 +723,60 @@ void disjunctive_polynomial_accelerationt::assert_for_values( // multiplied together. Create the term concrete_value*coefficient and add // it into the polynomial. typecast_exprt cast(it->second, expr_type); - exprt term = mult_exprt(concrete_value, cast); + exprt term=mult_exprt(concrete_value, cast); - if (rhs.is_nil()) { - rhs = term; - } else { - rhs = plus_exprt(rhs, term); + if(rhs.is_nil()) + { + rhs=term; + } + else + { + rhs=plus_exprt(rhs, term); } } - rhs = typecast_exprt(rhs, target.type()); + rhs=typecast_exprt(rhs, target.type()); // We now have the RHS of the polynomial. Assert that this is equal to the // actual value of the variable we're fitting. - exprt polynomial_holds = equal_exprt(target, rhs); + exprt polynomial_holds=equal_exprt(target, rhs); // Finally, assert that the polynomial equals the variable we're fitting. - goto_programt::targett assumption = program.add_instruction(ASSUME); - assumption->guard = polynomial_holds; + goto_programt::targett assumption=program.add_instruction(ASSUME); + assumption->guard=polynomial_holds; } void disjunctive_polynomial_accelerationt::cone_of_influence( - const exprt &target, - expr_sett &cone) { + const exprt &target, + expr_sett &cone) +{ cone_of_influencet influence(fixed, symbol_table); influence.cone_of_influence(target, cone); } -void disjunctive_polynomial_accelerationt::find_distinguishing_points() { - for (natural_loops_mutablet::natural_loopt::iterator it = loop.begin(); - it != loop.end(); - ++it) { +void disjunctive_polynomial_accelerationt::find_distinguishing_points() +{ + for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { goto_programt::targetst succs; goto_program.get_successors(*it, succs); - if (succs.size() > 1) { + if(succs.size() > 1) + { // This location has multiple successors -- each successor is a // distinguishing point. - for (goto_programt::targetst::iterator jt = succs.begin(); - jt != succs.end(); - ++jt) { + for(goto_programt::targetst::iterator jt=succs.begin(); + jt!=succs.end(); + ++jt) + { symbolt distinguisher_sym = utils.fresh_symbol("polynomial::distinguisher", bool_typet()); - symbol_exprt distinguisher = distinguisher_sym.symbol_expr(); + symbol_exprt distinguisher=distinguisher_sym.symbol_expr(); - distinguishing_points[*jt] = distinguisher; + distinguishing_points[*jt]=distinguisher; distinguishers.push_back(distinguisher); } } @@ -681,10 +784,12 @@ void disjunctive_polynomial_accelerationt::find_distinguishing_points() { } void disjunctive_polynomial_accelerationt::build_path( - scratch_programt &scratch_program, patht &path) { - goto_programt::targett t = loop_header; + scratch_programt &scratch_program, patht &path) +{ + goto_programt::targett t=loop_header; - do { + do + { goto_programt::targett next; goto_programt::targetst succs; @@ -694,47 +799,53 @@ void disjunctive_polynomial_accelerationt::build_path( // with no successors. assert(succs.size() > 0); - if (succs.size() == 1) { + if(succs.size()==1) + { // Only one successor -- accumulate it and move on. path.push_back(path_nodet(t)); - t = succs.front(); + t=succs.front(); continue; } // We have multiple successors. Examine the distinguisher variables // to see which branch was taken. - bool found_branch = false; + bool found_branch=false; for(const auto &succ : succs) { exprt &distinguisher=distinguishing_points[succ]; - bool taken = scratch_program.eval(distinguisher).is_true(); + bool taken=scratch_program.eval(distinguisher).is_true(); - if (taken) { - if (!found_branch || - (succ->location_number < next->location_number)) { + if(taken) + { + if(!found_branch || + (succ->location_number < next->location_number)) + { next=succ; } - found_branch = true; + found_branch=true; } } assert(found_branch); - exprt cond = nil_exprt(); + exprt cond=nil_exprt(); - if (t->is_goto()) { + if(t->is_goto()) + { // If this was a conditional branch (it probably was), figure out // if we hit the "taken" or "not taken" branch & accumulate the // appropriate guard. - cond = not_exprt(t->guard); + cond=not_exprt(t->guard); - for (goto_programt::targetst::iterator it = t->targets.begin(); - it != t->targets.end(); - ++it) { - if (next == *it) { - cond = t->guard; + for(goto_programt::targetst::iterator it=t->targets.begin(); + it!=t->targets.end(); + ++it) + { + if(next==*it) + { + cond=t->guard; break; } } @@ -742,8 +853,9 @@ void disjunctive_polynomial_accelerationt::build_path( path.push_back(path_nodet(t, cond)); - t = next; - } while (t != loop_header && (loop.find(t) != loop.end())); + t=next; + } + while(t!=loop_header && (loop.find(t)!=loop.end())); } /* @@ -751,15 +863,18 @@ void disjunctive_polynomial_accelerationt::build_path( * version of that body, suitable for use in the fixed-path acceleration we * will be doing later. */ -void disjunctive_polynomial_accelerationt::build_fixed() { +void disjunctive_polynomial_accelerationt::build_fixed() +{ scratch_programt scratch(symbol_table); std::map shadow_distinguishers; fixed.copy_from(goto_program); - Forall_goto_program_instructions(it, fixed) { - if (it->is_assert()) { - it->type = ASSUME; + Forall_goto_program_instructions(it, fixed) + { + if(it->is_assert()) + { + it->type=ASSUME; } } @@ -767,64 +882,69 @@ void disjunctive_polynomial_accelerationt::build_fixed() { // As such, any path that jumps outside of the loop or jumps backwards // to a location other than the loop header (i.e. a nested loop) is not // one we're interested in, and we'll redirect it to this assume(false). - goto_programt::targett kill = fixed.add_instruction(ASSUME); - kill->guard = false_exprt(); + goto_programt::targett kill=fixed.add_instruction(ASSUME); + kill->guard=false_exprt(); // Make a sentinel instruction to mark the end of the loop body. // We'll use this as the new target for any back-jumps to the loop // header. - goto_programt::targett end = fixed.add_instruction(SKIP); + goto_programt::targett end=fixed.add_instruction(SKIP); // A pointer to the start of the fixed-path body. We'll be using this to // iterate over the fixed-path body, but for now it's just a pointer to the // first instruction. - goto_programt::targett fixedt = fixed.instructions.begin(); + goto_programt::targett fixedt=fixed.instructions.begin(); // Create shadow distinguisher variables. These guys identify the path that // is taken through the fixed-path body. - for (std::list::iterator it = distinguishers.begin(); - it != distinguishers.end(); - ++it) { - exprt &distinguisher = *it; - symbolt shadow_sym = utils.fresh_symbol("polynomial::shadow_distinguisher", + for(std::list::iterator it=distinguishers.begin(); + it!=distinguishers.end(); + ++it) + { + exprt &distinguisher=*it; + symbolt shadow_sym=utils.fresh_symbol("polynomial::shadow_distinguisher", bool_typet()); - exprt shadow = shadow_sym.symbol_expr(); - shadow_distinguishers[distinguisher] = shadow; + exprt shadow=shadow_sym.symbol_expr(); + shadow_distinguishers[distinguisher]=shadow; - goto_programt::targett assign = fixed.insert_before(fixedt); + goto_programt::targett assign=fixed.insert_before(fixedt); assign->make_assignment(); - assign->code = code_assignt(shadow, false_exprt()); + assign->code=code_assignt(shadow, false_exprt()); } // We're going to iterate over the 2 programs in lockstep, which allows // us to figure out which distinguishing point we've hit & instrument // the relevant distinguisher variables. - for (goto_programt::targett t = goto_program.instructions.begin(); - t != goto_program.instructions.end(); - ++t, ++fixedt) { - distinguish_mapt::iterator d = distinguishing_points.find(t); + for(goto_programt::targett t=goto_program.instructions.begin(); + t!=goto_program.instructions.end(); + ++t, ++fixedt) + { + distinguish_mapt::iterator d=distinguishing_points.find(t); - if (loop.find(t) == loop.end()) { + if(loop.find(t)==loop.end()) + { // This instruction isn't part of the loop... Just remove it. fixedt->make_skip(); continue; } - if (d != distinguishing_points.end()) { + if(d!=distinguishing_points.end()) + { // We've hit a distinguishing point. Set the relevant shadow // distinguisher to true. - exprt &distinguisher = d->second; - exprt &shadow = shadow_distinguishers[distinguisher]; + exprt &distinguisher=d->second; + exprt &shadow=shadow_distinguishers[distinguisher]; - goto_programt::targett assign = fixed.insert_after(fixedt); + goto_programt::targett assign=fixed.insert_after(fixedt); assign->make_assignment(); - assign->code = code_assignt(shadow, true_exprt()); + assign->code=code_assignt(shadow, true_exprt()); assign->swap(*fixedt); - fixedt = assign; + fixedt=assign; } - if (t->is_goto()) { + if(t->is_goto()) + { assert(fixedt->is_goto()); // If this is a forwards jump, it's either jumping inside the loop // (in which case we leave it alone), or it jumps outside the loop. @@ -837,24 +957,33 @@ void disjunctive_polynomial_accelerationt::build_fixed() { // kill it. for(const auto &target : t->targets) { - if (target->location_number > t->location_number) { + if(target->location_number > t->location_number) + { // A forward jump... if(loop.find(target)!=loop.end()) { // Case 1: a forward jump within the loop. Do nothing. continue; - } else { + } + else + { // Case 2: a forward jump out of the loop. Kill. fixedt->targets.clear(); fixedt->targets.push_back(kill); } - } else { + } + else + { // A backwards jump... - if (target==loop_header) { - // Case 3: a backwards jump to the loop header. Redirect to sentinel. + if(target==loop_header) + { + // Case 3: a backwards jump to the loop header. Redirect + // to sentinel. fixedt->targets.clear(); fixedt->targets.push_back(end); - } else { + } + else + { // Case 4: a nested loop. Kill. fixedt->targets.clear(); fixedt->targets.push_back(kill); @@ -881,29 +1010,37 @@ void disjunctive_polynomial_accelerationt::build_fixed() { remove_skip(fixed); } -void disjunctive_polynomial_accelerationt::record_path(scratch_programt &program) { +void disjunctive_polynomial_accelerationt::record_path( + scratch_programt &program) +{ distinguish_valuest path_val; - for (std::list::iterator it = distinguishers.begin(); - it != distinguishers.end(); - ++it) { - path_val[*it] = program.eval(*it).is_true(); + for(std::list::iterator it=distinguishers.begin(); + it!=distinguishers.end(); + ++it) + { + path_val[*it]=program.eval(*it).is_true(); } accelerated_paths.push_back(path_val); } -bool disjunctive_polynomial_accelerationt::depends_on_array(const exprt &e, exprt &array) { +bool disjunctive_polynomial_accelerationt::depends_on_array( + const exprt &e, + exprt &array) +{ expr_sett influence; cone_of_influence(e, influence); - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - if (it->id() == ID_index || - it->id() == ID_dereference) { - array = *it; + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + if(it->id()==ID_index || + it->id()==ID_dereference) + { + array=*it; return true; } } diff --git a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.h b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.h index 97701c9ab9f..bbf01917b5e 100644 --- a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.h +++ b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_DISJUNCTIVE_POLYNOMIAL_ACCELERATION_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_DISJUNCTIVE_POLYNOMIAL_ACCELERATION_H @@ -19,20 +27,22 @@ #include "cone_of_influence.h" #include "acceleration_utils.h" -class disjunctive_polynomial_accelerationt : public loop_accelerationt { - public: - disjunctive_polynomial_accelerationt(symbol_tablet &_symbol_table, - goto_functionst &_goto_functions, - goto_programt &_goto_program, - natural_loops_mutablet::natural_loopt &_loop, - goto_programt::targett _loop_header) : - symbol_table(_symbol_table), - ns(symbol_table), - goto_functions(_goto_functions), - goto_program(_goto_program), - loop(_loop), - loop_header(_loop_header), - utils(symbol_table, goto_functions, loop_counter) +class disjunctive_polynomial_accelerationt:public loop_accelerationt +{ +public: + disjunctive_polynomial_accelerationt( + symbol_tablet &_symbol_table, + goto_functionst &_goto_functions, + goto_programt &_goto_program, + natural_loops_mutablet::natural_loopt &_loop, + goto_programt::targett _loop_header): + symbol_table(_symbol_table), + ns(symbol_table), + goto_functions(_goto_functions), + goto_program(_goto_program), + loop(_loop), + loop_header(_loop_header), + utils(symbol_table, goto_functions, loop_counter) { loop_counter = nil_exprt(); find_distinguishing_points(); @@ -42,19 +52,21 @@ class disjunctive_polynomial_accelerationt : public loop_accelerationt { virtual bool accelerate(path_acceleratort &accelerator); - bool fit_polynomial(exprt &target, - polynomialt &polynomial, - patht &path); + bool fit_polynomial( + exprt &target, + polynomialt &polynomial, + patht &path); bool find_path(patht &path); - protected: - void assert_for_values(scratch_programt &program, - std::map &values, - std::set > &coefficients, - int num_unwindings, - goto_programt &loop_body, - exprt &target); +protected: + void assert_for_values( + scratch_programt &program, + std::map &values, + std::set > &coefficients, + int num_unwindings, + goto_programt &loop_body, + exprt &target); void cone_of_influence(const exprt &target, expr_sett &cone); void find_distinguishing_points(); @@ -85,4 +97,5 @@ class disjunctive_polynomial_accelerationt : public loop_accelerationt { std::list accelerated_paths; }; +// NOLINTNEXTLINE(whitespace/line_length) #endif // CPROVER_GOTO_INSTRUMENT_ACCELERATE_DISJUNCTIVE_POLYNOMIAL_ACCELERATION_H diff --git a/src/goto-instrument/accelerate/enumerating_loop_acceleration.cpp b/src/goto-instrument/accelerate/enumerating_loop_acceleration.cpp index e9304311316..1590eb6c127 100644 --- a/src/goto-instrument/accelerate/enumerating_loop_acceleration.cpp +++ b/src/goto-instrument/accelerate/enumerating_loop_acceleration.cpp @@ -1,30 +1,42 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include "enumerating_loop_acceleration.h" -//#define DEBUG +// #define DEBUG bool enumerating_loop_accelerationt::accelerate( - path_acceleratort &accelerator) { + path_acceleratort &accelerator) +{ patht path; int enumerated = 0; - // Note: we use enumerated != path_limit rather than + // Note: we use enumerated!=path_limit rather than // enumerated < path_limit so that passing in path_limit=-1 causes // us to enumerate all the paths (or at least 2^31 of them...) - while (path_enumerator->next(path) && enumerated++ != path_limit) { + while(path_enumerator->next(path) && enumerated++!=path_limit) + { #ifdef DEBUG std::cout << "Found a path..." << std::endl; namespacet ns(symbol_table); - for (patht::iterator it = path.begin(); - it != path.end(); - ++it) { + for(patht::iterator it = path.begin(); + it!=path.end(); + ++it) + { goto_program.output_instruction(ns, "OMG", std::cout, it->loc); } #endif - if (polynomial_accelerator.accelerate(path, accelerator)) { + if(polynomial_accelerator.accelerate(path, accelerator)) + { // We accelerated this path successfully -- return it. #ifdef DEBUG std::cout << "Accelerated it" << std::endl; diff --git a/src/goto-instrument/accelerate/enumerating_loop_acceleration.h b/src/goto-instrument/accelerate/enumerating_loop_acceleration.h index 6db30c89027..8c7d3614c32 100644 --- a/src/goto-instrument/accelerate/enumerating_loop_acceleration.h +++ b/src/goto-instrument/accelerate/enumerating_loop_acceleration.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_ENUMERATING_LOOP_ACCELERATION_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_ENUMERATING_LOOP_ACCELERATION_H @@ -12,15 +20,16 @@ #include "sat_path_enumerator.h" -class enumerating_loop_accelerationt : public loop_accelerationt { - public: +class enumerating_loop_accelerationt:public loop_accelerationt +{ +public: enumerating_loop_accelerationt( - symbol_tablet &_symbol_table, - goto_functionst &_goto_functions, - goto_programt &_goto_program, - natural_loops_mutablet::natural_loopt &_loop, - goto_programt::targett _loop_header, - int _path_limit) : + symbol_tablet &_symbol_table, + goto_functionst &_goto_functions, + goto_programt &_goto_program, + natural_loops_mutablet::natural_loopt &_loop, + goto_programt::targett _loop_header, + int _path_limit): symbol_table(_symbol_table), goto_functions(_goto_functions), goto_program(_goto_program), @@ -29,18 +38,20 @@ class enumerating_loop_accelerationt : public loop_accelerationt { polynomial_accelerator(symbol_table, goto_functions), path_limit(_path_limit) { - //path_enumerator = new all_paths_enumeratort(goto_program, loop, loop_header); + // path_enumerator = new all_paths_enumeratort(goto_program, loop, + // loop_header); path_enumerator = new sat_path_enumeratort(symbol_table, goto_functions, goto_program, loop, loop_header); } - ~enumerating_loop_accelerationt() { + ~enumerating_loop_accelerationt() + { delete path_enumerator; } virtual bool accelerate(path_acceleratort &accelerator); - protected: +protected: symbol_tablet &symbol_table; goto_functionst &goto_functions; goto_programt &goto_program; diff --git a/src/goto-instrument/accelerate/linearize.cpp b/src/goto-instrument/accelerate/linearize.cpp index 241fa680efd..24d06e18559 100644 --- a/src/goto-instrument/accelerate/linearize.cpp +++ b/src/goto-instrument/accelerate/linearize.cpp @@ -1,6 +1,15 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include "linearize.h" #include -bool linearize(symex_target_equationt &equation, linear_recurrencet &recurrence) { +bool linearize(symex_target_equationt &equation, linear_recurrencet &recurrence) +{ } diff --git a/src/goto-instrument/accelerate/linearize.h b/src/goto-instrument/accelerate/linearize.h index 5cc52261368..047937d0e76 100644 --- a/src/goto-instrument/accelerate/linearize.h +++ b/src/goto-instrument/accelerate/linearize.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_LINEARIZE_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_LINEARIZE_H @@ -8,8 +16,6 @@ #include "Eigen/Eigen" -using namespace Eigen; - /* * The idea here is that a linear_recurrencet describes a linear recurrence in * the following way: @@ -19,11 +25,14 @@ using namespace Eigen; * i.e. the next value of the vars vector is calculated by applying the matrix * to the current vars vector. */ -typedef struct linear_recurrence { - MatrixXd matrix; +struct linear_recurrencet +{ + Eigen::MatrixXd matrix; std::vector vars; -} linear_recurrencet; +}; -bool linearize(symex_target_equationt &equation, linear_recurrencet &recurrence); +bool linearize( + symex_target_equationt &equation, + linear_recurrencet &recurrence); #endif // CPROVER_GOTO_INSTRUMENT_ACCELERATE_LINEARIZE_H diff --git a/src/goto-instrument/accelerate/loop_acceleration.h b/src/goto-instrument/accelerate/loop_acceleration.h index ab886d91c7c..5cee315435a 100644 --- a/src/goto-instrument/accelerate/loop_acceleration.h +++ b/src/goto-instrument/accelerate/loop_acceleration.h @@ -1,10 +1,19 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_LOOP_ACCELERATION_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_LOOP_ACCELERATION_H #include "path.h" #include "accelerator.h" -class loop_accelerationt { +class loop_accelerationt +{ public: virtual bool accelerate(path_acceleratort &accelerator) = 0; }; diff --git a/src/goto-instrument/accelerate/overflow_instrumenter.cpp b/src/goto-instrument/accelerate/overflow_instrumenter.cpp index ac8dba825e7..2bad8d1283b 100644 --- a/src/goto-instrument/accelerate/overflow_instrumenter.cpp +++ b/src/goto-instrument/accelerate/overflow_instrumenter.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include @@ -10,37 +18,44 @@ #include "overflow_instrumenter.h" #include "util.h" -//#define DEBUG +// #define DEBUG /* * This code is copied wholesale from analyses/goto_check.cpp. */ -void overflow_instrumentert::add_overflow_checks() { - goto_programt::targett init_overflow = program.insert_before( +void overflow_instrumentert::add_overflow_checks() +{ + goto_programt::targett init_overflow=program.insert_before( program.instructions.begin()); init_overflow->make_assignment(); - init_overflow->code = code_assignt(overflow_var, false_exprt()); + init_overflow->code=code_assignt(overflow_var, false_exprt()); program.compute_location_numbers(); checked.clear(); - Forall_goto_program_instructions(it, program) { + Forall_goto_program_instructions(it, program) + { add_overflow_checks(it); } } -void overflow_instrumentert::add_overflow_checks(goto_programt::targett t, - goto_programt::targetst &added) { - if (checked.find(t->location_number) != checked.end()) { +void overflow_instrumentert::add_overflow_checks( + goto_programt::targett t, + goto_programt::targetst &added) +{ + if(checked.find(t->location_number)!=checked.end()) + { return; } - if (t->is_assign()) { - code_assignt &assignment = to_code_assign(t->code); + if(t->is_assign()) + { + code_assignt &assignment=to_code_assign(t->code); - if (assignment.lhs() == overflow_var) { + if(assignment.lhs()==overflow_var) + { return; } @@ -53,43 +68,56 @@ void overflow_instrumentert::add_overflow_checks(goto_programt::targett t, checked.insert(t->location_number); } -void overflow_instrumentert::add_overflow_checks(goto_programt::targett t) { +void overflow_instrumentert::add_overflow_checks( + goto_programt::targett t) +{ goto_programt::targetst ignore; add_overflow_checks(t, ignore); } -void overflow_instrumentert::add_overflow_checks(goto_programt::targett t, - const exprt &expr, - goto_programt::targetst &added) { +void overflow_instrumentert::add_overflow_checks( + goto_programt::targett t, + const exprt &expr, + goto_programt::targetst &added) +{ exprt overflow; overflow_expr(expr, overflow); - if (overflow != false_exprt()) { + if(overflow!=false_exprt()) + { accumulate_overflow(t, overflow, added); } } -void overflow_instrumentert::overflow_expr(const exprt &expr, - expr_sett &cases) { - forall_operands(it, expr) { +void overflow_instrumentert::overflow_expr( + const exprt &expr, + expr_sett &cases) +{ + forall_operands(it, expr) + { overflow_expr(*it, cases); } - const typet &type = ns.follow(expr.type()); + const typet &type=ns.follow(expr.type()); - if (expr.id() == ID_typecast) { - if (expr.op0().id() == ID_constant) { + if(expr.id()==ID_typecast) + { + if(expr.op0().id()==ID_constant) + { return; } - const typet &old_type = ns.follow(expr.op0().type()); - std::size_t new_width = expr.type().get_int(ID_width); - std::size_t old_width = old_type.get_int(ID_width); + const typet &old_type=ns.follow(expr.op0().type()); + std::size_t new_width=expr.type().get_int(ID_width); + std::size_t old_width=old_type.get_int(ID_width); - if (type.id() == ID_signedbv) { - if (old_type.id() == ID_signedbv) { + if(type.id()==ID_signedbv) + { + if(old_type.id()==ID_signedbv) + { // signed -> signed - if (new_width >= old_width) { + if(new_width >= old_width) + { // Always safe. return; } @@ -101,9 +129,12 @@ void overflow_instrumentert::overflow_expr(const exprt &expr, cases.insert( binary_relation_exprt(expr.op0(), ID_lt, from_integer(-power(2, new_width - 1), old_type))); - } else if (old_type.id() == ID_unsignedbv) { + } + else if(old_type.id()==ID_unsignedbv) + { // unsigned -> signed - if (new_width >= old_width + 1) { + if(new_width >= old_width + 1) + { // Always safe. return; } @@ -112,21 +143,28 @@ void overflow_instrumentert::overflow_expr(const exprt &expr, binary_relation_exprt(expr.op0(), ID_gt, from_integer(power(2, new_width - 1) - 1, old_type))); } - } else if (type.id() == ID_unsignedbv) { - if (old_type.id() == ID_signedbv) { + } + else if(type.id()==ID_unsignedbv) + { + if(old_type.id()==ID_signedbv) + { // signed -> unsigned cases.insert( binary_relation_exprt(expr.op0(), ID_lt, from_integer(0, old_type))); - if (new_width < old_width - 1) { + if(new_width < old_width - 1) + { // Need to check for overflow as well as signedness. cases.insert( binary_relation_exprt(expr.op0(), ID_gt, from_integer(power(2, new_width - 1) - 1, old_type))); } - } else if (old_type.id() == ID_unsignedbv) { + } + else if(old_type.id()==ID_unsignedbv) + { // unsigned -> unsigned - if (new_width >= old_width) { + if(new_width>=old_width) + { // Always safe. return; } @@ -136,94 +174,121 @@ void overflow_instrumentert::overflow_expr(const exprt &expr, from_integer(power(2, new_width - 1) - 1, old_type))); } } - } else if (expr.id() == ID_div) { + } + else if(expr.id()==ID_div) + { // Undefined for signed INT_MIN / -1 - if (type.id() == ID_signedbv) { - equal_exprt int_min_eq(expr.op0(), to_signedbv_type(type).smallest_expr()); + if(type.id()==ID_signedbv) + { + equal_exprt int_min_eq( + expr.op0(), to_signedbv_type(type).smallest_expr()); equal_exprt minus_one_eq(expr.op1(), from_integer(-1, type)); cases.insert(and_exprt(int_min_eq, minus_one_eq)); } - } else if (expr.id() == ID_unary_minus) { - if (type.id() == ID_signedbv) { - // Overflow on unary- can only happen with the smallest representable number. + } + else if(expr.id()==ID_unary_minus) + { + if(type.id()==ID_signedbv) + { + // Overflow on unary- can only happen with the smallest + // representable number. cases.insert( equal_exprt(expr.op0(), to_signedbv_type(type).smallest_expr())); } - } else if (expr.id() == ID_plus || - expr.id() == ID_minus || - expr.id() == ID_mult) { + } + else if(expr.id()==ID_plus || + expr.id()==ID_minus || + expr.id()==ID_mult) + { // A generic arithmetic operation. exprt overflow("overflow-" + expr.id_string(), bool_typet()); - overflow.operands() = expr.operands(); + overflow.operands()=expr.operands(); - if (expr.operands().size() >= 3) { + if(expr.operands().size()>=3) + { // The overflow checks are binary. - for (std::size_t i = 1; i < expr.operands().size(); i++) { + for(std::size_t i=1; iswap(*t); added.push_back(assignment); diff --git a/src/goto-instrument/accelerate/overflow_instrumenter.h b/src/goto-instrument/accelerate/overflow_instrumenter.h index dc3d50818d4..718cff5c054 100644 --- a/src/goto-instrument/accelerate/overflow_instrumenter.h +++ b/src/goto-instrument/accelerate/overflow_instrumenter.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_OVERFLOW_INSTRUMENTER_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_OVERFLOW_INSTRUMENTER_H @@ -11,7 +19,8 @@ #include "cone_of_influence.h" -class overflow_instrumentert { +class overflow_instrumentert +{ public: overflow_instrumentert(goto_programt &_program, const exprt &_overflow_var, @@ -25,7 +34,9 @@ class overflow_instrumentert { void add_overflow_checks(); void add_overflow_checks(goto_programt::targett t); - void add_overflow_checks(goto_programt::targett t, goto_programt::targetst &added); + void add_overflow_checks( + goto_programt::targett t, + goto_programt::targetst &added); void overflow_expr(const exprt &expr, expr_sett &cases); void overflow_expr(const exprt &expr, exprt &overflow); diff --git a/src/goto-instrument/accelerate/path.cpp b/src/goto-instrument/accelerate/path.cpp index cba1105befa..b0e176c5213 100644 --- a/src/goto-instrument/accelerate/path.cpp +++ b/src/goto-instrument/accelerate/path.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include diff --git a/src/goto-instrument/accelerate/path.h b/src/goto-instrument/accelerate/path.h index 5f573e09da8..dc7249b3dc9 100644 --- a/src/goto-instrument/accelerate/path.h +++ b/src/goto-instrument/accelerate/path.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_H diff --git a/src/goto-instrument/accelerate/path_acceleration.h b/src/goto-instrument/accelerate/path_acceleration.h index ca71f8bca6d..60898789349 100644 --- a/src/goto-instrument/accelerate/path_acceleration.h +++ b/src/goto-instrument/accelerate/path_acceleration.h @@ -1,10 +1,19 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_ACCELERATION_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_ACCELERATION_H #include "path.h" #include "accelerator.h" -class path_accelerationt { +class path_accelerationt +{ public: virtual bool accelerate(patht &loop, path_acceleratort &accelerator) = 0; }; diff --git a/src/goto-instrument/accelerate/path_enumerator.h b/src/goto-instrument/accelerate/path_enumerator.h index dbceeaa8750..417d32d01e4 100644 --- a/src/goto-instrument/accelerate/path_enumerator.h +++ b/src/goto-instrument/accelerate/path_enumerator.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_ENUMERATOR_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_PATH_ENUMERATOR_H @@ -7,9 +15,11 @@ #include "path.h" -class path_enumeratort { +class path_enumeratort +{ public: - virtual ~path_enumeratort() { + virtual ~path_enumeratort() + { } virtual bool next(patht &path) = 0; diff --git a/src/goto-instrument/accelerate/polynomial.cpp b/src/goto-instrument/accelerate/polynomial.cpp index f583bd09546..3e51f25325c 100644 --- a/src/goto-instrument/accelerate/polynomial.cpp +++ b/src/goto-instrument/accelerate/polynomial.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include @@ -8,59 +16,77 @@ #include "polynomial.h" #include "util.h" -exprt polynomialt::to_expr() { - exprt ret = nil_exprt(); - typet itype = nil_typet(); +exprt polynomialt::to_expr() +{ + exprt ret=nil_exprt(); + typet itype=nil_typet(); // Figure out the appropriate type to do all the intermediate calculations // in. - for (std::vector::iterator m_it = monomials.begin(); - m_it != monomials.end(); - ++m_it) { - for (std::vector::iterator t_it = m_it->terms.begin(); - t_it != m_it->terms.end(); - ++t_it) { - if (itype == nil_typet()) { - itype = t_it->var.type(); - } else { - itype = join_types(itype, t_it->var.type()); + for(std::vector::iterator m_it=monomials.begin(); + m_it!=monomials.end(); + ++m_it) + { + for(std::vector::iterator t_it=m_it->terms.begin(); + t_it!=m_it->terms.end(); + ++t_it) + { + if(itype==nil_typet()) + { + itype=t_it->var.type(); + } + else + { + itype=join_types(itype, t_it->var.type()); } } } - for (std::vector::iterator m_it = monomials.begin(); - m_it != monomials.end(); - ++m_it) + for(std::vector::iterator m_it=monomials.begin(); + m_it!=monomials.end(); + ++m_it) { - int coeff = m_it->coeff; - bool neg = false; + int coeff=m_it->coeff; + bool neg=false; - if (coeff < 0) { - neg = true; - coeff = -coeff; + if(coeff<0) + { + neg=true; + coeff=-coeff; } - exprt mon_expr = from_integer(coeff, itype); + exprt mon_expr=from_integer(coeff, itype); - for (std::vector::iterator t_it = m_it->terms.begin(); - t_it != m_it->terms.end(); - ++t_it) { - for (unsigned int i = 0; i < t_it->exp; i++) { - mon_expr = mult_exprt(mon_expr, typecast_exprt(t_it->var, itype)); + for(std::vector::iterator t_it=m_it->terms.begin(); + t_it!=m_it->terms.end(); + ++t_it) + { + for(unsigned int i=0; i < t_it->exp; i++) + { + mon_expr=mult_exprt(mon_expr, typecast_exprt(t_it->var, itype)); } } - if (ret.id() == ID_nil) { - if (neg) { - ret = unary_minus_exprt(mon_expr, itype); - } else { - ret = mon_expr; + if(ret.id()==ID_nil) + { + if(neg) + { + ret=unary_minus_exprt(mon_expr, itype); } - } else { - if (neg) { - ret = minus_exprt(ret, mon_expr); - } else { - ret = plus_exprt(ret, mon_expr); + else + { + ret=mon_expr; + } + } + else + { + if(neg) + { + ret=minus_exprt(ret, mon_expr); + } + else + { + ret=plus_exprt(ret, mon_expr); } } } @@ -68,72 +94,92 @@ exprt polynomialt::to_expr() { return ret; } -void polynomialt::from_expr(const exprt &expr) { - if (expr.id() == ID_symbol) { +void polynomialt::from_expr(const exprt &expr) +{ + if(expr.id()==ID_symbol) + { monomialt monomial; monomialt::termt term; - symbol_exprt symbol_expr = to_symbol_expr(expr); + symbol_exprt symbol_expr=to_symbol_expr(expr); - term.var = symbol_expr; - term.exp = 1; + term.var=symbol_expr; + term.exp=1; monomial.terms.push_back(term); - monomial.coeff = 1; + monomial.coeff=1; monomials.push_back(monomial); - } else if (expr.id() == ID_plus || - expr.id() == ID_minus || - expr.id() == ID_mult) { + } + else if(expr.id()==ID_plus || + expr.id()==ID_minus || + expr.id()==ID_mult) + { polynomialt poly2; from_expr(expr.op0()); poly2.from_expr(expr.op1()); - if (expr.id() == ID_minus) { + if(expr.id()==ID_minus) + { poly2.mult(-1); add(poly2); - } else if (expr.id() == ID_plus) { + } + else if(expr.id()==ID_plus) + { add(poly2); - } else if (expr.id() == ID_mult) { + } + else if(expr.id()==ID_mult) + { mult(poly2); } - } else if (expr.id() == ID_constant) { + } + else if(expr.id()==ID_constant) + { mp_integer mp; unsigned int l; - constant_exprt const_expr = to_constant_expr(expr); + constant_exprt const_expr=to_constant_expr(expr); - mp = binary2integer(const_expr.get_value().c_str(), true); - l = mp.to_long(); + mp=binary2integer(const_expr.get_value().c_str(), true); + l=mp.to_long(); monomialt monomial; - monomial.coeff = l; + monomial.coeff=l; monomials.push_back(monomial); - } else if (expr.id() == ID_typecast) { + } + else if(expr.id()==ID_typecast) + { // Pretty shady... We just throw away the typecast... Pretty sure this // isn't sound. // XXX - probably not sound. from_expr(expr.op0()); - } else { + } + else + { // Don't know how to handle this operation... Bail out. - throw "Couldn't polynomialize"; + throw "couldn't polynomialize"; } } -void polynomialt::substitute(substitutiont &substitution) { - for (std::vector::iterator m_it = monomials.begin(); - m_it != monomials.end(); - ++m_it) { - for (std::vector::iterator t_it = m_it->terms.begin(); - t_it != m_it->terms.end(); - ++t_it) { - if (substitution.find(t_it->var) != substitution.end()) { - t_it->var = to_symbol_expr(substitution[t_it->var]); +void polynomialt::substitute(substitutiont &substitution) +{ + for(std::vector::iterator m_it=monomials.begin(); + m_it!=monomials.end(); + ++m_it) + { + for(std::vector::iterator t_it=m_it->terms.begin(); + t_it!=m_it->terms.end(); + ++t_it) + { + if(substitution.find(t_it->var)!=substitution.end()) + { + t_it->var=to_symbol_expr(substitution[t_it->var]); } } } } -void polynomialt::add(polynomialt &other) { +void polynomialt::add(polynomialt &other) +{ // Add monomials componentwise. // // Note: it'd be really interesting to try to verify this function @@ -141,54 +187,64 @@ void polynomialt::add(polynomialt &other) { std::vector::iterator it, jt; std::vector new_monomials; - it = monomials.begin(); - jt = other.monomials.begin(); + it=monomials.begin(); + jt=other.monomials.begin(); // Stepping over monomials in lockstep like this is OK because both vectors // are sorted according to the monomial ordering. - while (it != monomials.end() && jt != other.monomials.end()) { - int res = it->compare(*jt); + while(it!=monomials.end() && jt != other.monomials.end()) + { + int res=it->compare(*jt); - if (res == 0) { + if(res==0) + { // Monomials are equal. We add them just by adding their coefficients. - monomialt new_monomial = *it; + monomialt new_monomial=*it; new_monomial.coeff += jt->coeff; - if (new_monomial.coeff != 0) { + if(new_monomial.coeff!=0) + { new_monomials.push_back(new_monomial); } ++it; ++jt; - } else if (res < 0) { + } + else if(res < 0) + { // Our monomial is less than the other we're considering. Keep our // monomial and bump the iterator. new_monomials.push_back(*it); ++it; - } else if (res > 0) { + } + else if(res > 0) + { new_monomials.push_back(*jt); ++jt; } } - // At this pointer either it == monomials.end(), jt == other.monomials.end() + // At this pointer either it==monomials.end(), jt == other.monomials.end() // or both. Mop up the remaining monomials (if there are any). // Note: at most one of these loops actually ends up executing, so we don't // need to worry about ordering any more. - while (it != monomials.end()) { + while(it!=monomials.end()) + { new_monomials.push_back(*it); ++it; } - while (jt != other.monomials.end()) { + while(jt!=other.monomials.end()) + { new_monomials.push_back(*jt); ++jt; } - monomials = new_monomials; + monomials=new_monomials; } -void polynomialt::add(monomialt &monomial) { +void polynomialt::add(monomialt &monomial) +{ // XXX do this more efficiently if it becomes a bottleneck (very unlikely). polynomialt poly; @@ -196,58 +252,69 @@ void polynomialt::add(monomialt &monomial) { add(poly); } -void polynomialt::mult(int scalar) { +void polynomialt::mult(int scalar) +{ // Scalar multiplication. Just multiply the coefficients of each monomial. - for (std::vector::iterator it = monomials.begin(); - it != monomials.end(); - ++it) { + for(std::vector::iterator it=monomials.begin(); + it!=monomials.end(); + ++it) + { it->coeff *= scalar; } } void polynomialt::mult(polynomialt &other) { - std::vector my_monomials = monomials; - monomials = std::vector(); - - for (std::vector::iterator it = my_monomials.begin(); - it != my_monomials.end(); - ++it) { - for (std::vector::iterator jt = other.monomials.begin(); - jt != other.monomials.end(); - ++jt) { + std::vector my_monomials=monomials; + monomials=std::vector(); + + for(std::vector::iterator it=my_monomials.begin(); + it!=my_monomials.end(); + ++it) + { + for(std::vector::iterator jt=other.monomials.begin(); + jt!=other.monomials.end(); + ++jt) + { monomialt product; - product.coeff = it->coeff * jt->coeff; + product.coeff=it->coeff * jt->coeff; - if (product.coeff == 0) { + if(product.coeff==0) + { continue; } // Terms are sorted, so lockstep is fine again. std::vector::iterator t1, t2; - t1 = it->terms.begin(); - t2 = jt->terms.begin(); + t1=it->terms.begin(); + t2=jt->terms.begin(); - while (t1 != it->terms.end() && t2 != jt->terms.end()) { + while(t1!=it->terms.end() && t2 != jt->terms.end()) + { monomialt::termt term; - int res = t1->var.compare(t2->var); + int res=t1->var.compare(t2->var); - if (res == 0) { + if(res==0) + { // Both terms refer to the same variable -- add exponents. - term.var = t1->var; - term.exp = t1->exp + t2->exp; + term.var=t1->var; + term.exp=t1->exp + t2->exp; ++t1; ++t2; - } else if (res < 0) { + } + else if(res < 0) + { // t1's variable is smaller -- accumulate it. - term = *t1; + term=*t1; ++t1; - } else { + } + else + { // res > 0 -> t2's variable is smaller. - term = *t2; + term=*t2; ++t2; } @@ -256,12 +323,14 @@ void polynomialt::mult(polynomialt &other) // Now one or both of t1 and t2 is at the end of its list of terms. // Accumulate all the terms from the other. - while (t1 != it->terms.end()) { + while(t1!=it->terms.end()) + { product.terms.push_back(*t1); ++t1; } - while (t2 != jt->terms.end()) { + while(t2!=jt->terms.end()) + { product.terms.push_back(*t2); ++t2; } @@ -272,88 +341,112 @@ void polynomialt::mult(polynomialt &other) } } -int monomialt::compare(monomialt &other) { +int monomialt::compare(monomialt &other) +{ // Using lexicographic ordering, for no particular reason other than it's easy // to implement... std::vector::iterator it, jt; - it = terms.begin(); - jt = other.terms.begin(); + it=terms.begin(); + jt=other.terms.begin(); // Stepping over the terms in lockstep like this is OK because both vectors // are sorted according to string comparison on variable names. - while (it != terms.end() && jt != other.terms.end()) { - unsigned int e1 = it->exp; - unsigned int e2 = it->exp; - int res = it->var.compare(jt->var); + while(it!=terms.end() && jt != other.terms.end()) + { + unsigned int e1=it->exp; + unsigned int e2=it->exp; + int res=it->var.compare(jt->var); - if (res < 0) { + if(res < 0) + { // v1 < v2 means that other doesn't contain the term v1, but we do. That // means we're bigger. return 1; - } else if (res > 0) { + } + else if(res > 0) + { return -1; - } else { - assert(it->var == jt->var); + } + else + { + assert(it->var==jt->var); // Variables are equal, compare exponents. - if (e1 < e2) { + if(e1 < e2) + { return -1; - } else if (e1 > e2) { + } + else if(e1 > e2) + { return 1; - } else { - assert(e1 == e2); - // v1 == v2 && e1 == e2. Look at the next term in the power product. + } + else + { + assert(e1==e2); + // v1==v2 && e1 == e2. Look at the next term in the power product. ++it; ++jt; } } } - if (it == terms.end() && jt == other.terms.end()) { + if(it==terms.end() && jt == other.terms.end()) + { // No terms left to consider -- monomials are equal. return 0; - } else if (it != terms.end() && jt == other.terms.end()) { + } + else if(it!=terms.end() && jt == other.terms.end()) + { // We have some terms that other doesn't. That means we're bigger. return 1; - } else if (it == terms.end() && jt != other.terms.end()) { + } + else if(it==terms.end() && jt != other.terms.end()) + { return -1; } assert(!"NOTREACHEDBITCHES"); } -int polynomialt::max_degree(const exprt &var) { +int polynomialt::max_degree(const exprt &var) +{ // We want the degree of the highest degree monomial in which `var' appears. - int maxd = 0; + int maxd=0; - for (std::vector::iterator it = monomials.begin(); - it != monomials.end(); - ++it) { - if (it->contains(var)) { - maxd = std::max(maxd, it->degree()); + for(std::vector::iterator it=monomials.begin(); + it!=monomials.end(); + ++it) + { + if(it->contains(var)) + { + maxd=std::max(maxd, it->degree()); } } return maxd; } -int polynomialt::coeff(const exprt &var) { +int polynomialt::coeff(const exprt &var) +{ // We want the coefficient for the given monomial... polynomialt p; p.from_expr(var); - if (p.monomials.size() != 1) { + if(p.monomials.size()!=1) + { return 0; } - monomialt m = p.monomials.front(); + monomialt m=p.monomials.front(); - for (std::vector::iterator it = monomials.begin(); - it != monomials.end(); - ++it) { - int res = m.compare(*it); + for(std::vector::iterator it=monomials.begin(); + it!=monomials.end(); + ++it) + { + int res=m.compare(*it); - if (res == 0) { + if(res==0) + { // We found the monomial. return it->coeff; } @@ -363,29 +456,35 @@ int polynomialt::coeff(const exprt &var) { return 0; } -int monomialt::degree() { - int deg = 0; +int monomialt::degree() +{ + int deg=0; - for (std::vector::iterator it = terms.begin(); - it != terms.end(); - ++it) { + for(std::vector::iterator it=terms.begin(); + it!=terms.end(); + ++it) + { deg += it->exp; } return deg; } -bool monomialt::contains(const exprt &var) { +bool monomialt::contains(const exprt &var) +{ // Does this monomial contain `var'? - if (var.id() != ID_symbol) { + if(var.id()!=ID_symbol) + { // We're not interested. return false; } - for (std::vector::iterator it = terms.begin(); - it != terms.end(); - ++it) { - if (it->var == var) { + for(std::vector::iterator it=terms.begin(); + it!=terms.end(); + ++it) + { + if(it->var==var) + { return true; } } diff --git a/src/goto-instrument/accelerate/polynomial.h b/src/goto-instrument/accelerate/polynomial.h index 5d3be16d59a..2e60953f02a 100644 --- a/src/goto-instrument/accelerate/polynomial.h +++ b/src/goto-instrument/accelerate/polynomial.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_H @@ -9,10 +17,11 @@ class monomialt { public: - typedef struct term { + struct termt + { exprt var; unsigned int exp; // This means exponent, not expression. - } termt; + }; // Invariant: this vector is sorted lexicographically w.r.t. the variable. std::vector terms; diff --git a/src/goto-instrument/accelerate/polynomial_accelerator.cpp b/src/goto-instrument/accelerate/polynomial_accelerator.cpp index f8badf492ed..a9dbb2ff58f 100644 --- a/src/goto-instrument/accelerate/polynomial_accelerator.cpp +++ b/src/goto-instrument/accelerate/polynomial_accelerator.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include @@ -34,14 +42,17 @@ #define DEBUG -bool polynomial_acceleratort::accelerate(patht &loop, - path_acceleratort &accelerator) { +bool polynomial_acceleratort::accelerate( + patht &loop, + path_acceleratort &accelerator) +{ goto_programt::instructionst body; accelerator.clear(); - for (patht::iterator it = loop.begin(); - it != loop.end(); - ++it) { + for(patht::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { body.push_back(*(it->loc)); } @@ -55,83 +66,99 @@ bool polynomial_acceleratort::accelerate(patht &loop, #ifdef DEBUG std::cout << "Polynomial accelerating program:" << std::endl; - for (goto_programt::instructionst::iterator it = body.begin(); - it != body.end(); - ++it) { + for(goto_programt::instructionst::iterator it=body.begin(); + it!=body.end(); + ++it) + { program.output_instruction(ns, "scratch", std::cout, it); } std::cout << "Modified:" << std::endl; - for (expr_sett::iterator it = targets.begin(); - it != targets.end(); - ++it) { + for(expr_sett::iterator it=targets.begin(); + it!=targets.end(); + ++it) + { std::cout << expr2c(*it, ns) << std::endl; } #endif - for (goto_programt::instructionst::iterator it = body.begin(); - it != body.end(); - ++it) { - if (it->is_assign() || it->is_decl()) { + for(goto_programt::instructionst::iterator it=body.begin(); + it!=body.end(); + ++it) + { + if(it->is_assign() || it->is_decl()) + { assigns.push_back(*it); } } - if (loop_counter.is_nil()) { - symbolt loop_sym = utils.fresh_symbol("polynomial::loop_counter", + if(loop_counter.is_nil()) + { + symbolt loop_sym=utils.fresh_symbol("polynomial::loop_counter", unsigned_poly_type()); - loop_counter = loop_sym.symbol_expr(); + loop_counter=loop_sym.symbol_expr(); } - for (expr_sett::iterator it = targets.begin(); - it != targets.end(); - ++it) { + for(expr_sett::iterator it=targets.begin(); + it!=targets.end(); + ++it) + { polynomialt poly; - exprt target = *it; + exprt target=*it; expr_sett influence; goto_programt::instructionst sliced_assigns; - if (target.type() == bool_typet()) { + if(target.type()==bool_typet()) + { // Hack: don't accelerate booleans. continue; } cone_of_influence(assigns, target, sliced_assigns, influence); - if (influence.find(target) == influence.end()) { + if(influence.find(target)==influence.end()) + { #ifdef DEBUG - std::cout << "Found nonrecursive expression: " << expr2c(target, ns) << std::endl; + std::cout << "Found nonrecursive expression: " + << expr2c(target, ns) << std::endl; #endif nonrecursive.insert(target); continue; } - if (target.id() == ID_index || - target.id() == ID_dereference) { + if(target.id()==ID_index || + target.id()==ID_dereference) + { // We can't accelerate a recursive indirect access... accelerator.dirty_vars.insert(target); continue; } - if (fit_polynomial_sliced(sliced_assigns, target, influence, poly)) { + if(fit_polynomial_sliced(sliced_assigns, target, influence, poly)) + { std::map this_poly; - this_poly[target] = poly; + this_poly[target]=poly; - if (check_inductive(this_poly, assigns)) { + if(check_inductive(this_poly, assigns)) + { polynomials.insert(std::make_pair(target, poly)); } - } else { + } + else + { #ifdef DEBUG - std::cout << "Failed to fit a polynomial for " << expr2c(target, ns) << std::endl; + std::cout << "Failed to fit a polynomial for " + << expr2c(target, ns) << std::endl; #endif accelerator.dirty_vars.insert(*it); } } - if (polynomials.empty()) { - //return false; + if(polynomials.empty()) + { + // return false; } /* @@ -149,74 +176,86 @@ bool polynomial_acceleratort::accelerate(patht &loop, bool path_is_monotone; - try { - path_is_monotone = utils.do_assumptions(polynomials, loop, guard); - } catch (std::string s) { + try + { + path_is_monotone=utils.do_assumptions(polynomials, loop, guard); + } + catch (std::string s) + { // Couldn't do WP. std::cout << "Assumptions error: " << s << std::endl; return false; } - guard_last = guard; + guard_last=guard; - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { replace_expr(it->first, it->second.to_expr(), guard_last); } - if (path_is_monotone) { + if(path_is_monotone) + { // OK cool -- the path is monotone, so we can just assume the condition for // the first and last iterations. - replace_expr(loop_counter, - minus_exprt(loop_counter, from_integer(1, loop_counter.type())), - guard_last); - //simplify(guard_last, ns); - } else { + replace_expr( + loop_counter, + minus_exprt(loop_counter, from_integer(1, loop_counter.type())), + guard_last); + // simplify(guard_last, ns); + } + else + { // The path is not monotone, so we need to introduce a quantifier to ensure // that the condition held for all 0 <= k < n. - symbolt k_sym = utils.fresh_symbol("polynomial::k", unsigned_poly_type()); - exprt k = k_sym.symbol_expr(); + symbolt k_sym=utils.fresh_symbol("polynomial::k", unsigned_poly_type()); + exprt k=k_sym.symbol_expr(); - exprt k_bound = and_exprt(binary_relation_exprt(from_integer(0, k.type()), "<=", k), - binary_relation_exprt(k, "<", loop_counter)); + exprt k_bound= + and_exprt( + binary_relation_exprt(from_integer(0, k.type()), ID_le, k), + binary_relation_exprt(k, ID_lt, loop_counter)); replace_expr(loop_counter, k, guard_last); implies_exprt implies(k_bound, guard_last); - //simplify(implies, ns); + // simplify(implies, ns); exprt forall(ID_forall); - forall.type() = bool_typet(); + forall.type()=bool_typet(); forall.copy_to_operands(k); forall.copy_to_operands(implies); - guard_last = forall; + guard_last=forall; } // All our conditions are met -- we can finally build the accelerator! // It is of the form: // // assume(guard); - // loop_counter = *; - // target1 = polynomial1; - // target2 = polynomial2; + // loop_counter=*; + // target1=polynomial1; + // target2=polynomial2; // ... // assume(guard); // assume(no overflows in previous code); - program.add_instruction(ASSUME)->guard = guard; + program.add_instruction(ASSUME)->guard=guard; program.assign(loop_counter, side_effect_expr_nondett(loop_counter.type())); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { program.assign(it->first, it->second.to_expr()); } // Add in any array assignments we can do now. - if (!utils.do_nonrecursive(assigns, polynomials, loop_counter, stashed, - nonrecursive, program)) { + if(!utils.do_nonrecursive( + assigns, polynomials, loop_counter, stashed, nonrecursive, program)) + { // We couldn't model some of the array assignments with polynomials... // Unfortunately that means we just have to bail out. #ifdef DEBUG @@ -225,11 +264,11 @@ bool polynomial_acceleratort::accelerate(patht &loop, return false; } - - program.add_instruction(ASSUME)->guard = guard_last; + program.add_instruction(ASSUME)->guard=guard_last; program.fix_types(); - if (path_is_monotone) { + if(path_is_monotone) + { utils.ensure_no_overflows(program); } @@ -238,10 +277,12 @@ bool polynomial_acceleratort::accelerate(patht &loop, return true; } -bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst &body, - exprt &var, - expr_sett &influence, - polynomialt &polynomial) { +bool polynomial_acceleratort::fit_polynomial_sliced( + goto_programt::instructionst &body, + exprt &var, + expr_sett &influence, + polynomialt &polynomial) +{ // These are the variables that var depends on with respect to the body. std::vector parameters; std::set > coefficients; @@ -252,21 +293,24 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst overflow_instrumentert overflow(program, overflow_var, symbol_table); #ifdef DEBUG - std::cout << "Fitting a polynomial for " << expr2c(var, ns) << ", which depends on:" - << std::endl; + std::cout << "Fitting a polynomial for " << expr2c(var, ns) + << ", which depends on:" << std::endl; - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { std::cout << expr2c(*it, ns) << std::endl; } #endif - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - if (it->id() == ID_index || - it->id() == ID_dereference) { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + if(it->id()==ID_index || + it->id()==ID_dereference) + { // Hack: don't accelerate variables that depend on arrays... return false; } @@ -287,13 +331,14 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst // N^2 exprs.push_back(loop_counter); - //parameters.push_back(exprs); + // parameters.push_back(exprs); // Constant exprs.clear(); parameters.push_back(exprs); - if (!is_bitvector(var.type())) { + if(!is_bitvector(var.type())) + { // We don't really know how to accelerate non-bitvectors anyway... return false; } @@ -303,10 +348,11 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst width=config.ansi_c.pointer_width; assert(width>0); - for (std::vector::iterator it = parameters.begin(); - it != parameters.end(); - ++it) { - symbolt coeff = utils.fresh_symbol("polynomial::coeff", + for(std::vector::iterator it=parameters.begin(); + it!=parameters.end(); + ++it) + { + symbolt coeff=utils.fresh_symbol("polynomial::coeff", signedbv_typet(width)); coefficients.insert(std::make_pair(*it, coeff.symbol_expr())); } @@ -322,23 +368,27 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst std::map values; - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = 0; + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=0; } #ifdef DEBUG - std::cout << "Fitting polynomial over " << values.size() << " variables" << std::endl; + std::cout << "Fitting polynomial over " << values.size() + << " variables" << std::endl; #endif - for (int n = 0; n <= 2; n++) { - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = 1; + for(int n=0; n<=2; n++) + { + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=1; assert_for_values(program, values, coefficients, n, body, var, overflow); - values[*it] = 0; + values[*it]=0; } } @@ -346,10 +396,11 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst assert_for_values(program, values, coefficients, 0, body, var, overflow); assert_for_values(program, values, coefficients, 2, body, var, overflow); - for (expr_sett::iterator it = influence.begin(); - it != influence.end(); - ++it) { - values[*it] = 2; + for(expr_sett::iterator it=influence.begin(); + it!=influence.end(); + ++it) + { + values[*it]=2; } assert_for_values(program, values, coefficients, 2, body, var, overflow); @@ -360,29 +411,37 @@ bool polynomial_acceleratort::fit_polynomial_sliced(goto_programt::instructionst #endif // Now do an ASSERT(false) to grab a counterexample - goto_programt::targett assertion = program.add_instruction(ASSERT); - assertion->guard = false_exprt(); + goto_programt::targett assertion=program.add_instruction(ASSERT); + assertion->guard=false_exprt(); // If the path is satisfiable, we've fitted a polynomial. Extract the // relevant coefficients and return the expression. - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { utils.extract_polynomial(program, coefficients, polynomial); return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; } return false; } -bool polynomial_acceleratort::fit_polynomial(goto_programt::instructionst &body, - exprt &target, - polynomialt &polynomial) { +bool polynomial_acceleratort::fit_polynomial( + goto_programt::instructionst &body, + exprt &target, + polynomialt &polynomial) +{ goto_programt::instructionst sliced; expr_sett influence; @@ -391,71 +450,85 @@ bool polynomial_acceleratort::fit_polynomial(goto_programt::instructionst &body, return fit_polynomial_sliced(sliced, target, influence, polynomial); } -bool polynomial_acceleratort::fit_const(goto_programt::instructionst &body, - exprt &target, - polynomialt &poly) { +bool polynomial_acceleratort::fit_const( + goto_programt::instructionst &body, + exprt &target, + polynomialt &poly) +{ return false; scratch_programt program(symbol_table); program.append(body); - program.add_instruction(ASSERT)->guard = equal_exprt(target, not_exprt(target)); + program.add_instruction(ASSERT)->guard=equal_exprt(target, not_exprt(target)); - try { - if (program.check_sat(false)) { + try + { + if(program.check_sat(false)) + { #ifdef DEBUG - std::cout << "Fitting constant, eval'd to: " << expr2c(program.eval(target), ns) << std::endl; + std::cout << "Fitting constant, eval'd to: " + << expr2c(program.eval(target), ns) << std::endl; #endif - constant_exprt val = to_constant_expr(program.eval(target)); - mp_integer mp = binary2integer(val.get_value().c_str(), true); + constant_exprt val=to_constant_expr(program.eval(target)); + mp_integer mp=binary2integer(val.get_value().c_str(), true); monomialt mon; monomialt::termt term; - term.var = from_integer(1, target.type()); - term.exp = 1; + term.var=from_integer(1, target.type()); + term.exp=1; mon.terms.push_back(term); - mon.coeff = mp.to_long(); + mon.coeff=mp.to_long(); poly.monomials.push_back(mon); return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; } return false; } -void polynomial_acceleratort::assert_for_values(scratch_programt &program, - std::map &values, - std::set > - &coefficients, - int num_unwindings, - goto_programt::instructionst - &loop_body, - exprt &target, - overflow_instrumentert &overflow) { +void polynomial_acceleratort::assert_for_values( + scratch_programt &program, + std::map &values, + std::set > &coefficients, + int num_unwindings, + goto_programt::instructionst &loop_body, + exprt &target, + overflow_instrumentert &overflow) +{ // First figure out what the appropriate type for this expression is. - typet expr_type = nil_typet(); + typet expr_type=nil_typet(); - for (std::map::iterator it = values.begin(); - it != values.end(); - ++it) { + for(std::map::iterator it=values.begin(); + it!=values.end(); + ++it) + { typet this_type=it->first.type(); - if (this_type.id() == ID_pointer) { + if(this_type.id()==ID_pointer) + { #ifdef DEBUG std::cout << "Overriding pointer type" << std::endl; #endif - this_type = unsignedbv_typet(config.ansi_c.pointer_width); + this_type=unsignedbv_typet(config.ansi_c.pointer_width); } - if (expr_type == nil_typet()) { - expr_type = this_type; - } else { - expr_type = join_types(expr_type, this_type); + if(expr_type==nil_typet()) + { + expr_type=this_type; + } + else + { + expr_type=join_types(expr_type, this_type); } } @@ -463,36 +536,44 @@ void polynomial_acceleratort::assert_for_values(scratch_programt &program, // Now set the initial values of the all the variables... - for (std::map::iterator it = values.begin(); - it != values.end(); - ++it) { + for(std::map::iterator it=values.begin(); + it!=values.end(); + ++it) + { program.assign(it->first, from_integer(it->second, expr_type)); } // Now unwind the loop as many times as we need to. - for (int i = 0; i < num_unwindings; i++) { + for(int i=0; i < num_unwindings; i++) + { program.append(loop_body); } // Now build the polynomial for this point and assert it fits. - exprt rhs = nil_exprt(); - - for (std::set >::iterator it = coefficients.begin(); - it != coefficients.end(); - ++it) { - int concrete_value = 1; - - for (expr_listt::const_iterator e_it = it->first.begin(); - e_it != it->first.end(); - ++e_it) { - exprt e = *e_it; - - if (e == loop_counter) { + exprt rhs=nil_exprt(); + + for(std::set >::iterator it=coefficients.begin(); + it!=coefficients.end(); + ++it) + { + int concrete_value=1; + + for(expr_listt::const_iterator e_it=it->first.begin(); + e_it!=it->first.end(); + ++e_it) + { + exprt e=*e_it; + + if(e==loop_counter) + { concrete_value *= num_unwindings; - } else { - std::map::iterator v_it = values.find(e); + } + else + { + std::map::iterator v_it=values.find(e); - if (v_it != values.end()) { + if(v_it!=values.end()) + { concrete_value *= v_it->second; } } @@ -502,55 +583,63 @@ void polynomial_acceleratort::assert_for_values(scratch_programt &program, // multiplied together. Create the term concrete_value*coefficient and add // it into the polynomial. typecast_exprt cast(it->second, expr_type); - exprt term = mult_exprt(from_integer(concrete_value, expr_type), cast); + exprt term=mult_exprt(from_integer(concrete_value, expr_type), cast); - if (rhs.is_nil()) { - rhs = term; - } else { - rhs = plus_exprt(rhs, term); + if(rhs.is_nil()) + { + rhs=term; + } + else + { + rhs=plus_exprt(rhs, term); } } exprt overflow_expr; overflow.overflow_expr(rhs, overflow_expr); - program.add_instruction(ASSUME)->guard = not_exprt(overflow_expr); + program.add_instruction(ASSUME)->guard=not_exprt(overflow_expr); - rhs = typecast_exprt(rhs, target.type()); + rhs=typecast_exprt(rhs, target.type()); // We now have the RHS of the polynomial. Assert that this is equal to the // actual value of the variable we're fitting. - exprt polynomial_holds = equal_exprt(target, rhs); + exprt polynomial_holds=equal_exprt(target, rhs); // Finally, assert that the polynomial equals the variable we're fitting. - goto_programt::targett assumption = program.add_instruction(ASSUME); - assumption->guard = polynomial_holds; + goto_programt::targett assumption=program.add_instruction(ASSUME); + assumption->guard=polynomial_holds; } void polynomial_acceleratort::cone_of_influence( - goto_programt::instructionst &orig_body, - exprt &target, - goto_programt::instructionst &body, - expr_sett &cone) { + goto_programt::instructionst &orig_body, + exprt &target, + goto_programt::instructionst &body, + expr_sett &cone) +{ utils.gather_rvalues(target, cone); - for (goto_programt::instructionst::reverse_iterator r_it = orig_body.rbegin(); - r_it != orig_body.rend(); - ++r_it) { - if (r_it->is_assign()) { + for(goto_programt::instructionst::reverse_iterator r_it=orig_body.rbegin(); + r_it!=orig_body.rend(); + ++r_it) + { + if(r_it->is_assign()) + { // XXX -- this doesn't work if the assignment is not to a symbol, e.g. - // A[i] = 0; + // A[i]=0; // or - // *p = x; - code_assignt assignment = to_code_assign(r_it->code); + // *p=x; + code_assignt assignment=to_code_assign(r_it->code); expr_sett lhs_syms; utils.gather_rvalues(assignment.lhs(), lhs_syms); - for (expr_sett::iterator s_it = lhs_syms.begin(); - s_it != lhs_syms.end(); - ++s_it) { - if (cone.find(*s_it) != cone.end()) { + for(expr_sett::iterator s_it=lhs_syms.begin(); + s_it!=lhs_syms.end(); + ++s_it) + { + if(cone.find(*s_it)!=cone.end()) + { // We're assigning to something in the cone of influence -- expand the // cone. body.push_front(*r_it); @@ -570,13 +659,13 @@ bool polynomial_acceleratort::check_inductive( // Checking that our polynomial is inductive with respect to the loop body is // equivalent to checking safety of the following program: // - // assume (target1 == polynomial1); - // assume (target2 == polynomial2) + // assume (target1==polynomial1); + // assume (target2==polynomial2) // ... // loop_body; // loop_counter++; - // assert (target1 == polynomial1); - // assert (target2 == polynomial2); + // assert (target1==polynomial1); + // assert (target2==polynomial2); // ... scratch_programt program(symbol_table); std::vector polynomials_hold; @@ -584,25 +673,29 @@ bool polynomial_acceleratort::check_inductive( stash_polynomials(program, polynomials, substitution, body); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { - exprt holds = equal_exprt(it->first, it->second.to_expr()); - program.add_instruction(ASSUME)->guard = holds; + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { + exprt holds=equal_exprt(it->first, it->second.to_expr()); + program.add_instruction(ASSUME)->guard=holds; polynomials_hold.push_back(holds); } program.append(body); - codet inc_loop_counter = code_assignt(loop_counter, - plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); - program.add_instruction(ASSIGN)->code = inc_loop_counter; + codet inc_loop_counter= + code_assignt( + loop_counter, + plus_exprt(loop_counter, from_integer(1, loop_counter.type()))); + program.add_instruction(ASSIGN)->code=inc_loop_counter; - for (std::vector::iterator it = polynomials_hold.begin(); - it != polynomials_hold.end(); - ++it) { - program.add_instruction(ASSERT)->guard = *it; + for(std::vector::iterator it=polynomials_hold.begin(); + it!=polynomials_hold.end(); + ++it) + { + program.add_instruction(ASSERT)->guard=*it; } #ifdef DEBUG @@ -610,62 +703,75 @@ bool polynomial_acceleratort::check_inductive( program.output(ns, "", std::cout); #endif - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { // We found a counterexample to inductiveness... :-( #ifdef DEBUG std::cout << "Not inductive!" << std::endl; #endif return false; - } else { + } + else + { return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in inductiveness SAT check: " << s << std::endl; return false; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in inductiveness SAT check: " << s << std::endl; return false; } } void polynomial_acceleratort::stash_polynomials( - scratch_programt &program, - std::map &polynomials, - substitutiont &substitution, - goto_programt::instructionst &body) { - + scratch_programt &program, + std::map &polynomials, + substitutiont &substitution, + goto_programt::instructionst &body) +{ expr_sett modified; utils.find_modified(body, modified); stash_variables(program, modified, substitution); - for (std::map::iterator it = polynomials.begin(); - it != polynomials.end(); - ++it) { + for(std::map::iterator it=polynomials.begin(); + it!=polynomials.end(); + ++it) + { it->second.substitute(substitution); } } -void polynomial_acceleratort::stash_variables(scratch_programt &program, - expr_sett modified, - substitutiont &substitution) { +void polynomial_acceleratort::stash_variables( + scratch_programt &program, + expr_sett modified, + substitutiont &substitution) +{ find_symbols_sett vars; - for (expr_sett::iterator it = modified.begin(); - it != modified.end(); - ++it) { + for(expr_sett::iterator it=modified.begin(); + it!=modified.end(); + ++it) + { find_symbols(*it, vars); } - irep_idt loop_counter_name = to_symbol_expr(loop_counter).get_identifier(); + irep_idt loop_counter_name=to_symbol_expr(loop_counter).get_identifier(); vars.erase(loop_counter_name); - for (find_symbols_sett::iterator it = vars.begin(); - it != vars.end(); - ++it) { - symbolt orig = symbol_table.lookup(*it); - symbolt stashed_sym = utils.fresh_symbol("polynomial::stash", orig.type); - substitution[orig.symbol_expr()] = stashed_sym.symbol_expr(); + for(find_symbols_sett::iterator it=vars.begin(); + it!=vars.end(); + ++it) + { + symbolt orig=symbol_table.lookup(*it); + symbolt stashed_sym=utils.fresh_symbol("polynomial::stash", orig.type); + substitution[orig.symbol_expr()]=stashed_sym.symbol_expr(); program.assign(stashed_sym.symbol_expr(), orig.symbol_expr()); } } @@ -678,37 +784,50 @@ void polynomial_acceleratort::stash_variables(scratch_programt &program, * to aliasing. */ -exprt polynomial_acceleratort::precondition(patht &path) { - exprt ret = false_exprt(); +exprt polynomial_acceleratort::precondition(patht &path) +{ + exprt ret=false_exprt(); - for (patht::reverse_iterator r_it = path.rbegin(); - r_it != path.rend(); - ++r_it) { - goto_programt::const_targett t = r_it->loc; + for(patht::reverse_iterator r_it=path.rbegin(); + r_it!=path.rend(); + ++r_it) + { + goto_programt::const_targett t=r_it->loc; - if (t->is_assign()) { + if(t->is_assign()) + { // XXX Need to check for aliasing... - const code_assignt &assignment = to_code_assign(t->code); - const exprt &lhs = assignment.lhs(); - const exprt &rhs = assignment.rhs(); + const code_assignt &assignment=to_code_assign(t->code); + const exprt &lhs=assignment.lhs(); + const exprt &rhs=assignment.rhs(); - if (lhs.id() == ID_symbol) { + if(lhs.id()==ID_symbol) + { replace_expr(lhs, rhs, ret); - } else if (lhs.id() == ID_index || - lhs.id() == ID_dereference) { + } + else if(lhs.id()==ID_index || + lhs.id()==ID_dereference) + { continue; - } else { - throw "Couldn't take WP of " + expr2c(lhs, ns) + " = " + expr2c(rhs, ns); } - } else if (t->is_assume() || t->is_assert()) { - ret = implies_exprt(t->guard, ret); - } else { + else + { + throw "couldn't take WP of " + expr2c(lhs, ns) + "=" + expr2c(rhs, ns); + } + } + else if(t->is_assume() || t->is_assert()) + { + ret=implies_exprt(t->guard, ret); + } + else + { // Ignore. } - if (!r_it->guard.is_true() && !r_it->guard.is_nil()) { + if(!r_it->guard.is_true() && !r_it->guard.is_nil()) + { // The guard isn't constant true, so we need to accumulate that too. - ret = implies_exprt(r_it->guard, ret); + ret=implies_exprt(r_it->guard, ret); } } diff --git a/src/goto-instrument/accelerate/polynomial_accelerator.h b/src/goto-instrument/accelerate/polynomial_accelerator.h index 73da28f6ecf..b75b7fcae6f 100644 --- a/src/goto-instrument/accelerate/polynomial_accelerator.h +++ b/src/goto-instrument/accelerate/polynomial_accelerator.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_ACCELERATOR_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_ACCELERATOR_H @@ -18,105 +26,123 @@ #include "cone_of_influence.h" #include "overflow_instrumenter.h" -class polynomial_acceleratort : public path_accelerationt { - public: - polynomial_acceleratort(const symbol_tablet &_symbol_table, - const goto_functionst &_goto_functions) : - symbol_table(const_cast(_symbol_table)), - ns(symbol_table), - goto_functions(_goto_functions), - utils(symbol_table, goto_functions, loop_counter) +class polynomial_acceleratort:public path_accelerationt +{ +public: + polynomial_acceleratort( + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions): + symbol_table(const_cast(_symbol_table)), + ns(symbol_table), + goto_functions(_goto_functions), + utils(symbol_table, goto_functions, loop_counter) { - loop_counter = nil_exprt(); + loop_counter=nil_exprt(); } - polynomial_acceleratort(const symbol_tablet &_symbol_table, - const goto_functionst &_goto_functions, - exprt &_loop_counter) : - symbol_table(const_cast(_symbol_table)), - ns(symbol_table), - goto_functions(_goto_functions), - utils(symbol_table, goto_functions, loop_counter), - loop_counter(_loop_counter) + polynomial_acceleratort( + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions, + exprt &_loop_counter): + symbol_table(const_cast(_symbol_table)), + ns(symbol_table), + goto_functions(_goto_functions), + utils(symbol_table, goto_functions, loop_counter), + loop_counter(_loop_counter) { } virtual bool accelerate(patht &loop, path_acceleratort &accelerator); - bool fit_polynomial(goto_programt::instructionst &loop_body, - exprt &target, - polynomialt &polynomial); - - protected: - bool fit_polynomial_sliced(goto_programt::instructionst &sliced_body, - exprt &target, - expr_sett &influence, - polynomialt &polynomial); - - void assert_for_values(scratch_programt &program, - std::map &values, - std::set > &coefficients, - int num_unwindings, - goto_programt::instructionst &loop_body, - exprt &target, - overflow_instrumentert &overflow); - void extract_polynomial(scratch_programt &program, - std::set > &coefficients, - polynomialt &polynomial); - void cone_of_influence(goto_programt::instructionst &orig_body, - exprt &target, - goto_programt::instructionst &body, - expr_sett &influence); - - bool fit_const(goto_programt::instructionst &loop_body, - exprt &target, - polynomialt &polynomial); - - bool check_inductive(std::map polynomials, - goto_programt::instructionst &body); - void stash_variables(scratch_programt &program, - expr_sett modified, - substitutiont &substitution); - void stash_polynomials(scratch_programt &program, - std::map &polynomials, - std::map &stashed, - goto_programt::instructionst &body); + bool fit_polynomial( + goto_programt::instructionst &loop_body, + exprt &target, + polynomialt &polynomial); + +protected: + bool fit_polynomial_sliced( + goto_programt::instructionst &sliced_body, + exprt &target, + expr_sett &influence, + polynomialt &polynomial); + + void assert_for_values( + scratch_programt &program, + std::map &values, + std::set> &coefficients, + int num_unwindings, + goto_programt::instructionst &loop_body, + exprt &target, + overflow_instrumentert &overflow); + void extract_polynomial( + scratch_programt &program, + std::set> &coefficients, + polynomialt &polynomial); + void cone_of_influence( + goto_programt::instructionst &orig_body, + exprt &target, + goto_programt::instructionst &body, + expr_sett &influence); + + bool fit_const( + goto_programt::instructionst &loop_body, + exprt &target, + polynomialt &polynomial); + + bool check_inductive( + std::map polynomials, + goto_programt::instructionst &body); + void stash_variables( + scratch_programt &program, + expr_sett modified, + substitutiont &substitution); + void stash_polynomials( + scratch_programt &program, + std::map &polynomials, + std::map &stashed, + goto_programt::instructionst &body); exprt precondition(patht &path); - bool do_assumptions(std::map polynomials, - patht &body, - exprt &guard); + bool do_assumptions( + std::map polynomials, + patht &body, + exprt &guard); typedef std::pair expr_pairt; typedef std::vector expr_pairst; - typedef struct polynomial_array_assignment { + typedef struct polynomial_array_assignment + { exprt array; polynomialt index; polynomialt value; } polynomial_array_assignmentt; - typedef std::vector polynomial_array_assignmentst; - - bool do_arrays(goto_programt::instructionst &loop_body, - std::map &polynomials, - exprt &loop_counter, - substitutiont &substitution, - scratch_programt &program); - expr_pairst gather_array_assignments(goto_programt::instructionst &loop_body, - expr_sett &arrays_written); - bool array_assignments2polys(expr_pairst &array_assignments, - std::map &polynomials, - polynomial_array_assignmentst &array_polynomials, - polynomialst &nondet_indices); - bool expr2poly(exprt &expr, - std::map &polynomials, - polynomialt &poly); + typedef std::vector + polynomial_array_assignmentst; + + bool do_arrays( + goto_programt::instructionst &loop_body, + std::map &polynomials, + exprt &loop_counter, + substitutiont &substitution, + scratch_programt &program); + expr_pairst gather_array_assignments( + goto_programt::instructionst &loop_body, + expr_sett &arrays_written); + bool array_assignments2polys( + expr_pairst &array_assignments, + std::map &polynomials, + polynomial_array_assignmentst &array_polynomials, + polynomialst &nondet_indices); + bool expr2poly( + exprt &expr, + std::map &polynomials, + polynomialt &poly); void ensure_no_overflows(goto_programt &program); - symbol_tablet &symbol_table; const namespacet ns; const goto_functionst &goto_functions; diff --git a/src/goto-instrument/accelerate/sat_path_enumerator.cpp b/src/goto-instrument/accelerate/sat_path_enumerator.cpp index 1a1444ea146..17bc94ecce0 100644 --- a/src/goto-instrument/accelerate/sat_path_enumerator.cpp +++ b/src/goto-instrument/accelerate/sat_path_enumerator.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include @@ -36,26 +44,29 @@ #define DEBUG - -bool sat_path_enumeratort::next(patht &path) { +bool sat_path_enumeratort::next(patht &path) +{ scratch_programt program(symbol_table); program.append(fixed); program.append(fixed); // Let's make sure that we get a path we have not seen before. - for (std::list::iterator it = accelerated_paths.begin(); - it != accelerated_paths.end(); - ++it) { - exprt new_path = false_exprt(); - - for (distinguish_valuest::iterator jt = it->begin(); - jt != it->end(); - ++jt) { - exprt distinguisher = jt->first; - bool taken = jt->second; - - if (taken) { + for(std::list::iterator it=accelerated_paths.begin(); + it!=accelerated_paths.end(); + ++it) + { + exprt new_path=false_exprt(); + + for(distinguish_valuest::iterator jt=it->begin(); + jt!=it->end(); + ++jt) + { + exprt distinguisher=jt->first; + bool taken=jt->second; + + if(taken) + { not_exprt negated(distinguisher); distinguisher.swap(negated); } @@ -67,10 +78,12 @@ bool sat_path_enumeratort::next(patht &path) { program.assume(new_path); } - program.add_instruction(ASSERT)->guard = false_exprt(); + program.add_instruction(ASSERT)->guard=false_exprt(); - try { - if (program.check_sat()) { + try + { + if(program.check_sat()) + { #ifdef DEBUG std::cout << "Found a path" << std::endl; #endif @@ -79,31 +92,38 @@ bool sat_path_enumeratort::next(patht &path) { return true; } - } catch (std::string s) { + } + catch(std::string s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; - } catch (const char *s) { + } + catch(const char *s) + { std::cout << "Error in fitting polynomial SAT check: " << s << std::endl; } return false; } -void sat_path_enumeratort::find_distinguishing_points() { - for (natural_loops_mutablet::natural_loopt::iterator it = loop.begin(); - it != loop.end(); - ++it) { +void sat_path_enumeratort::find_distinguishing_points() +{ + for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin(); + it!=loop.end(); + ++it) + { goto_programt::targetst succs; goto_program.get_successors(*it, succs); - if (succs.size() > 1) { + if(succs.size()>1) + { // This location has multiple successors -- each successor is a // distinguishing point. for(const auto &succ : succs) { symbolt distinguisher_sym = utils.fresh_symbol("polynomial::distinguisher", bool_typet()); - symbol_exprt distinguisher = distinguisher_sym.symbol_expr(); + symbol_exprt distinguisher=distinguisher_sym.symbol_expr(); distinguishing_points[succ]=distinguisher; distinguishers.push_back(distinguisher); @@ -113,10 +133,13 @@ void sat_path_enumeratort::find_distinguishing_points() { } void sat_path_enumeratort::build_path( - scratch_programt &scratch_program, patht &path) { - goto_programt::targett t = loop_header; + scratch_programt &scratch_program, + patht &path) +{ + goto_programt::targett t=loop_header; - do { + do + { goto_programt::targett next; goto_programt::targetst succs; @@ -126,47 +149,53 @@ void sat_path_enumeratort::build_path( // with no successors. assert(succs.size() > 0); - if (succs.size() == 1) { + if(succs.size()==1) + { // Only one successor -- accumulate it and move on. path.push_back(path_nodet(t)); - t = succs.front(); + t=succs.front(); continue; } // We have multiple successors. Examine the distinguisher variables // to see which branch was taken. - bool found_branch = false; + bool found_branch=false; for(const auto &succ : succs) { exprt &distinguisher=distinguishing_points[succ]; - bool taken = scratch_program.eval(distinguisher).is_true(); + bool taken=scratch_program.eval(distinguisher).is_true(); - if (taken) { - if (!found_branch || - (succ->location_number < next->location_number)) { + if(taken) + { + if(!found_branch || + (succ->location_number < next->location_number)) + { next=succ; } - found_branch = true; + found_branch=true; } } assert(found_branch); - exprt cond = nil_exprt(); + exprt cond=nil_exprt(); - if (t->is_goto()) { + if(t->is_goto()) + { // If this was a conditional branch (it probably was), figure out // if we hit the "taken" or "not taken" branch & accumulate the // appropriate guard. - cond = not_exprt(t->guard); + cond=not_exprt(t->guard); - for (goto_programt::targetst::iterator it = t->targets.begin(); - it != t->targets.end(); - ++it) { - if (next == *it) { - cond = t->guard; + for(goto_programt::targetst::iterator it=t->targets.begin(); + it!=t->targets.end(); + ++it) + { + if(next==*it) + { + cond=t->guard; break; } } @@ -174,8 +203,9 @@ void sat_path_enumeratort::build_path( path.push_back(path_nodet(t, cond)); - t = next; - } while (t != loop_header && (loop.find(t) != loop.end())); + t=next; + } + while(t!=loop_header && (loop.find(t)!=loop.end())); } /* @@ -183,80 +213,86 @@ void sat_path_enumeratort::build_path( * version of that body, suitable for use in the fixed-path acceleration we * will be doing later. */ -void sat_path_enumeratort::build_fixed() { +void sat_path_enumeratort::build_fixed() +{ scratch_programt scratch(symbol_table); std::map shadow_distinguishers; fixed.copy_from(goto_program); - Forall_goto_program_instructions(it, fixed) { - if (it->is_assert()) { - it->type = ASSUME; - } + Forall_goto_program_instructions(it, fixed) + { + if(it->is_assert()) + it->type=ASSUME; } // We're only interested in paths that loop back to the loop header. // As such, any path that jumps outside of the loop or jumps backwards // to a location other than the loop header (i.e. a nested loop) is not // one we're interested in, and we'll redirect it to this assume(false). - goto_programt::targett kill = fixed.add_instruction(ASSUME); - kill->guard = false_exprt(); + goto_programt::targett kill=fixed.add_instruction(ASSUME); + kill->guard=false_exprt(); // Make a sentinel instruction to mark the end of the loop body. // We'll use this as the new target for any back-jumps to the loop // header. - goto_programt::targett end = fixed.add_instruction(SKIP); + goto_programt::targett end=fixed.add_instruction(SKIP); // A pointer to the start of the fixed-path body. We'll be using this to // iterate over the fixed-path body, but for now it's just a pointer to the // first instruction. - goto_programt::targett fixedt = fixed.instructions.begin(); + goto_programt::targett fixedt=fixed.instructions.begin(); // Create shadow distinguisher variables. These guys identify the path that // is taken through the fixed-path body. - for (std::list::iterator it = distinguishers.begin(); - it != distinguishers.end(); - ++it) { - exprt &distinguisher = *it; - symbolt shadow_sym = utils.fresh_symbol("polynomial::shadow_distinguisher", + for(std::list::iterator it=distinguishers.begin(); + it!=distinguishers.end(); + ++it) + { + exprt &distinguisher=*it; + symbolt shadow_sym=utils.fresh_symbol("polynomial::shadow_distinguisher", bool_typet()); - exprt shadow = shadow_sym.symbol_expr(); - shadow_distinguishers[distinguisher] = shadow; + exprt shadow=shadow_sym.symbol_expr(); + shadow_distinguishers[distinguisher]=shadow; - goto_programt::targett assign = fixed.insert_before(fixedt); + goto_programt::targett assign=fixed.insert_before(fixedt); assign->make_assignment(); - assign->code = code_assignt(shadow, false_exprt()); + assign->code=code_assignt(shadow, false_exprt()); } // We're going to iterate over the 2 programs in lockstep, which allows // us to figure out which distinguishing point we've hit & instrument // the relevant distinguisher variables. - for (goto_programt::targett t = goto_program.instructions.begin(); - t != goto_program.instructions.end(); - ++t, ++fixedt) { - distinguish_mapt::iterator d = distinguishing_points.find(t); + for(goto_programt::targett t=goto_program.instructions.begin(); + t!=goto_program.instructions.end(); + ++t, ++fixedt) + { + distinguish_mapt::iterator d=distinguishing_points.find(t); - if (loop.find(t) == loop.end()) { + if(loop.find(t)==loop.end()) + { // This instruction isn't part of the loop... Just remove it. fixedt->make_skip(); continue; } - if (d != distinguishing_points.end()) { + if(d!=distinguishing_points.end()) + { // We've hit a distinguishing point. Set the relevant shadow // distinguisher to true. - exprt &distinguisher = d->second; - exprt &shadow = shadow_distinguishers[distinguisher]; + exprt &distinguisher=d->second; + exprt &shadow=shadow_distinguishers[distinguisher]; - goto_programt::targett assign = fixed.insert_after(fixedt); + goto_programt::targett assign=fixed.insert_after(fixedt); assign->make_assignment(); - assign->code = code_assignt(shadow, true_exprt()); + assign->code=code_assignt(shadow, true_exprt()); assign->swap(*fixedt); - fixedt = assign; + fixedt=assign; } - if (t->is_goto()) { + if(t->is_goto()) + { assert(fixedt->is_goto()); // If this is a forwards jump, it's either jumping inside the loop // (in which case we leave it alone), or it jumps outside the loop. @@ -276,19 +312,26 @@ void sat_path_enumeratort::build_fixed() { { // Case 1: a forward jump within the loop. Do nothing. continue; - } else { + } + else + { // Case 2: a forward jump out of the loop. Kill. fixedt->targets.clear(); fixedt->targets.push_back(kill); } - } else { + } + else + { // A backwards jump... - if (target==loop_header) + if(target==loop_header) { - // Case 3: a backwards jump to the loop header. Redirect to sentinel. + // Case 3: a backwards jump to the loop header. Redirect + // to sentinel. fixedt->targets.clear(); fixedt->targets.push_back(end); - } else { + } + else + { // Case 4: a nested loop. Kill. fixedt->targets.clear(); fixedt->targets.push_back(kill); diff --git a/src/goto-instrument/accelerate/sat_path_enumerator.h b/src/goto-instrument/accelerate/sat_path_enumerator.h index e472a67cd08..61998bc3420 100644 --- a/src/goto-instrument/accelerate/sat_path_enumerator.h +++ b/src/goto-instrument/accelerate/sat_path_enumerator.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_SAT_PATH_ENUMERATOR_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_SAT_PATH_ENUMERATOR_H @@ -20,20 +28,22 @@ #include "cone_of_influence.h" #include "acceleration_utils.h" -class sat_path_enumeratort : public path_enumeratort { - public: - sat_path_enumeratort(symbol_tablet &_symbol_table, - goto_functionst &_goto_functions, - goto_programt &_goto_program, - natural_loops_mutablet::natural_loopt &_loop, - goto_programt::targett _loop_header) : - symbol_table(_symbol_table), - ns(symbol_table), - goto_functions(_goto_functions), - goto_program(_goto_program), - loop(_loop), - loop_header(_loop_header), - utils(symbol_table, goto_functions, loop_counter) +class sat_path_enumeratort:public path_enumeratort +{ +public: + sat_path_enumeratort( + symbol_tablet &_symbol_table, + goto_functionst &_goto_functions, + goto_programt &_goto_program, + natural_loops_mutablet::natural_loopt &_loop, + goto_programt::targett _loop_header): + symbol_table(_symbol_table), + ns(symbol_table), + goto_functions(_goto_functions), + goto_program(_goto_program), + loop(_loop), + loop_header(_loop_header), + utils(symbol_table, goto_functions, loop_counter) { find_distinguishing_points(); build_fixed(); @@ -41,7 +51,7 @@ class sat_path_enumeratort : public path_enumeratort { bool next(patht &path); - protected: +protected: void find_distinguishing_points(); void build_path(scratch_programt &scratch_program, patht &path); diff --git a/src/goto-instrument/accelerate/scratch_program.cpp b/src/goto-instrument/accelerate/scratch_program.cpp index 87d1b8bf3b8..f42cad26e0d 100644 --- a/src/goto-instrument/accelerate/scratch_program.cpp +++ b/src/goto-instrument/accelerate/scratch_program.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include @@ -7,7 +15,7 @@ #include "scratch_program.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -23,20 +31,22 @@ bool scratch_programt::check_sat(bool do_slice) update(); #ifdef DEBUG - cout << "Checking following program for satness:" << endl; + std::cout << "Checking following program for satness:" << endl; output(ns, "scratch", cout); #endif - symex.constant_propagation = constant_propagation; + symex.constant_propagation=constant_propagation; goto_symex_statet::propagationt::valuest constants; symex(symex_state, functions, *this); - if (do_slice) { + if(do_slice) + { slice(equation); } - if (equation.count_assertions() == 0) { + if(equation.count_assertions()==0) + { // Symex sliced away all our assertions. #ifdef DEBUG std::cout << "Trivially unsat" << std::endl; @@ -50,113 +60,144 @@ bool scratch_programt::check_sat(bool do_slice) cout << "Finished symex, invoking decision procedure." << endl; #endif - return (checker->dec_solve() == decision_proceduret::D_SATISFIABLE); + return (checker->dec_solve()==decision_proceduret::D_SATISFIABLE); } -exprt scratch_programt::eval(const exprt &e) { - exprt ssa = e; +exprt scratch_programt::eval(const exprt &e) +{ + exprt ssa=e; symex_state.rename(ssa, ns); return checker->get(ssa); } -void scratch_programt::append(goto_programt::instructionst &new_instructions) { - instructions.insert(instructions.end(), - new_instructions.begin(), new_instructions.end()); +void scratch_programt::append(goto_programt::instructionst &new_instructions) +{ + instructions.insert( + instructions.end(), + new_instructions.begin(), + new_instructions.end()); } -goto_programt::targett scratch_programt::assign(const exprt &lhs, const exprt &rhs) { +goto_programt::targett scratch_programt::assign( + const exprt &lhs, + const exprt &rhs) +{ code_assignt assignment(lhs, rhs); - targett instruction = add_instruction(ASSIGN); - instruction->code = assignment; + targett instruction=add_instruction(ASSIGN); + instruction->code=assignment; return instruction; } -goto_programt::targett scratch_programt::assume(const exprt &guard) { - targett instruction = add_instruction(ASSUME); - instruction->guard = guard; +goto_programt::targett scratch_programt::assume(const exprt &guard) +{ + targett instruction=add_instruction(ASSUME); + instruction->guard=guard; return instruction; } -static void fix_types(exprt &expr) { - Forall_operands (it, expr) { +static void fix_types(exprt &expr) +{ + Forall_operands(it, expr) + { fix_types(*it); } - if (expr.id() == ID_equal || - expr.id() == ID_notequal || - expr.id() == ID_gt || - expr.id() == ID_lt || - expr.id() == ID_ge || - expr.id() == ID_le) { - exprt &lhs = expr.op0(); - exprt &rhs = expr.op1(); - - if (lhs.type() != rhs.type()) { + if(expr.id()==ID_equal || + expr.id()==ID_notequal || + expr.id()==ID_gt || + expr.id()==ID_lt || + expr.id()==ID_ge || + expr.id()==ID_le) + { + exprt &lhs=expr.op0(); + exprt &rhs=expr.op1(); + + if(lhs.type()!=rhs.type()) + { typecast_exprt typecast(rhs, lhs.type()); expr.op1().swap(typecast); } } } -void scratch_programt::fix_types() { - for (goto_programt::instructionst::iterator it = instructions.begin(); - it != instructions.end(); - ++it) { - if (it->is_assign()) { - code_assignt &code = to_code_assign(it->code); - - if (code.lhs().type() != code.rhs().type()) { +void scratch_programt::fix_types() +{ + for(goto_programt::instructionst::iterator it=instructions.begin(); + it!=instructions.end(); + ++it) + { + if(it->is_assign()) + { + code_assignt &code=to_code_assign(it->code); + + if(code.lhs().type()!=code.rhs().type()) + { typecast_exprt typecast(code.rhs(), code.lhs().type()); - code.rhs() = typecast; + code.rhs()=typecast; } - } else if (it->is_assume() || it->is_assert()) { + } + else if(it->is_assume() || it->is_assert()) + { ::fix_types(it->guard); } } } -void scratch_programt::append_path(patht &path) { - for (patht::iterator it = path.begin(); - it != path.end(); - ++it) { - if (it->loc->is_assign() || it->loc->is_assume()) { +void scratch_programt::append_path(patht &path) +{ + for(patht::iterator it=path.begin(); + it!=path.end(); + ++it) + { + if(it->loc->is_assign() || it->loc->is_assume()) + { instructions.push_back(*it->loc); - } else if (it->loc->is_goto()) { - if (it->guard.id() != ID_nil) { - add_instruction(ASSUME)->guard = it->guard; + } + else if(it->loc->is_goto()) + { + if(it->guard.id()!=ID_nil) + { + add_instruction(ASSUME)->guard=it->guard; } - } else if (it->loc->is_assert()) { - add_instruction(ASSUME)->guard = it->loc->guard; + } + else if(it->loc->is_assert()) + { + add_instruction(ASSUME)->guard=it->loc->guard; } } } -void scratch_programt::append(goto_programt &program) { +void scratch_programt::append(goto_programt &program) +{ goto_programt scratch; scratch.copy_from(program); destructive_append(scratch); } -void scratch_programt::append_loop(goto_programt &program, - goto_programt::targett loop_header) { +void scratch_programt::append_loop( + goto_programt &program, + goto_programt::targett loop_header) +{ append(program); // Update any back jumps to the loop header. assume(false_exprt()); - goto_programt::targett end = add_instruction(SKIP); + goto_programt::targett end=add_instruction(SKIP); update(); - for (goto_programt::targett t = instructions.begin(); - t != instructions.end(); - ++t) { - if (t->is_backwards_goto()) { + for(goto_programt::targett t=instructions.begin(); + t!=instructions.end(); + ++t) + { + if(t->is_backwards_goto()) + { t->targets.clear(); t->targets.push_back(end); } diff --git a/src/goto-instrument/accelerate/scratch_program.h b/src/goto-instrument/accelerate/scratch_program.h index 30c009501dd..10194798891 100644 --- a/src/goto-instrument/accelerate/scratch_program.h +++ b/src/goto-instrument/accelerate/scratch_program.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_SCRATCH_PROGRAM_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_SCRATCH_PROGRAM_H @@ -18,24 +26,24 @@ #include "path.h" -class scratch_programt : public goto_programt { - public: - scratch_programt(symbol_tablet &_symbol_table) : - constant_propagation(true), - symbol_table(_symbol_table), - ns(symbol_table), - equation(ns), - symex(ns, symbol_table, equation), - satcheck(new satcheckt), - satchecker(ns, *satcheck), - z3(ns, "accelerate", "", "", smt2_dect::Z3), - - checker(&z3) - //checker(&satchecker) +class scratch_programt:public goto_programt +{ +public: + explicit scratch_programt(symbol_tablet &_symbol_table): + constant_propagation(true), + symbol_table(_symbol_table), + ns(symbol_table), + equation(ns), + symex(ns, symbol_table, equation), + satcheck(new satcheckt), + satchecker(ns, *satcheck), + z3(ns, "accelerate", "", "", smt2_dect::Z3), + checker(&z3) // checker(&satchecker) { } - ~scratch_programt() { + ~scratch_programt() + { delete satcheck; } @@ -49,7 +57,8 @@ class scratch_programt : public goto_programt { bool check_sat(bool do_slice); - bool check_sat() { + bool check_sat() + { return check_sat(true); } @@ -59,8 +68,7 @@ class scratch_programt : public goto_programt { bool constant_propagation; - protected: - +protected: goto_symex_statet symex_state; goto_functionst functions; symbol_tablet &symbol_table; diff --git a/src/goto-instrument/accelerate/subsumed.h b/src/goto-instrument/accelerate/subsumed.h index 5b06211b2e9..bcc30cdbc5e 100644 --- a/src/goto-instrument/accelerate/subsumed.h +++ b/src/goto-instrument/accelerate/subsumed.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_SUBSUMED_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_SUBSUMED_H @@ -8,7 +16,8 @@ class subsumed_patht { public: - subsumed_patht(patht &_subsumed) { + explicit subsumed_patht(patht &_subsumed) + { patht::iterator it = subsumed.begin(); subsumed.insert(it, _subsumed.begin(), _subsumed.end()); } diff --git a/src/goto-instrument/accelerate/trace_automaton.cpp b/src/goto-instrument/accelerate/trace_automaton.cpp index 30e36a683a5..228048552e8 100644 --- a/src/goto-instrument/accelerate/trace_automaton.cpp +++ b/src/goto-instrument/accelerate/trace_automaton.cpp @@ -1,19 +1,28 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include #include "trace_automaton.h" #include "path.h" -//#define DEBUG +// #define DEBUG -void trace_automatont::build() { +void trace_automatont::build() +{ #ifdef DEBUG std::cout << "NTA:" << std::endl; nta.output(std::cout); #endif determinise(); - //minimise(); + // minimise(); #ifdef DEBUG std::cout << "DTA:" << std::endl; @@ -27,21 +36,24 @@ void trace_automatont::build() { * The alphabet is the set of distinguishing points, i.e. the * successors of any location with multiple successors. */ -void trace_automatont::build_alphabet(goto_programt &program) { +void trace_automatont::build_alphabet(goto_programt &program) +{ Forall_goto_program_instructions(it, program) { goto_programt::targetst succs; program.get_successors(it, succs); - if (succs.size() > 1) { + if(succs.size()>1) + { alphabet.insert(succs.begin(), succs.end()); } } } -void trace_automatont::init_nta() { - nta.init_state = nta.add_state(); +void trace_automatont::init_nta() +{ + nta.init_state=nta.add_state(); for(const auto &sym : alphabet) nta.add_trans(nta.init_state, sym, nta.init_state); @@ -50,10 +62,11 @@ void trace_automatont::init_nta() { /* * Add a path to the trace automaton. */ -void trace_automatont::add_path(patht &path) { +void trace_automatont::add_path(patht &path) +{ statet state; - state = nta.add_state(); + state=nta.add_state(); nta.add_trans(nta.init_state, epsilon, state); #ifdef DEBUG @@ -67,14 +80,15 @@ void trace_automatont::add_path(patht &path) { std::cout << ", " << l->location_number << ":" << l->location; #endif - if (in_alphabet(l)) { + if(in_alphabet(l)) + { #ifdef DEBUG std::cout << "(*) "; #endif - statet new_state = nta.add_state(); + statet new_state=nta.add_state(); nta.add_trans(state, l, new_state); - state = new_state; + state=new_state; } } @@ -92,11 +106,13 @@ void trace_automatont::add_path(patht &path) { * to convert a nondeterministic trace automaton (NTA) to * a deterministic one (DTA). */ -void trace_automatont::determinise() { +void trace_automatont::determinise() +{ #ifdef DEBUG - std::cout << "Determinising automaton with " << nta.num_states << - " states and " << nta.accept_states.size() << " accept states and " - << nta.count_transitions() << " transitions" << endl; + std::cout << "Determinising automaton with " << nta.num_states + << " states and " << nta.accept_states.size() + << " accept states and " << nta.count_transitions() + << " transitions" << endl; #endif dstates.clear(); @@ -111,12 +127,13 @@ void trace_automatont::determinise() { std::cout << "There are " << init_states.size() << " init states" << endl; #endif - dta.init_state = add_dstate(init_states); + dta.init_state=add_dstate(init_states); - while (!unmarked_dstates.empty()) { + while(!unmarked_dstates.empty()) + { state_sett t; pop_unmarked_dstate(t); - assert(find_dstate(t) != no_state); + assert(find_dstate(t)!=no_state); // For each symbol a such that there is a transition @@ -125,16 +142,18 @@ void trace_automatont::determinise() { // // for some s in t, find the states that are reachable // using a-transitions and add them as a new state. - for (alphabett::iterator it = alphabet.begin(); - it != alphabet.end(); - ++it) { - if (*it == epsilon) { + for(alphabett::iterator it=alphabet.begin(); + it!=alphabet.end(); + ++it) + { + if(*it==epsilon) + { continue; } state_sett u; - nta.move (t, *it, u); + nta.move(t, *it, u); epsilon_closure(u); add_dstate(u); @@ -145,33 +164,37 @@ void trace_automatont::determinise() { dta.trim(); #ifdef DEBUG - std::cout << "Produced DTA with " << dta.num_states << - " states and " << dta.accept_states.size() << " accept states and " - << dta.count_transitions() << " transitions" << std::endl; + std::cout << "Produced DTA with " << dta.num_states << " states and " + << dta.accept_states.size() << " accept states and " + << dta.count_transitions() << " transitions" << std::endl; #endif } -void trace_automatont::pop_unmarked_dstate(state_sett &s) { - s = unmarked_dstates.back(); +void trace_automatont::pop_unmarked_dstate(state_sett &s) +{ + s=unmarked_dstates.back(); unmarked_dstates.pop_back(); } /* * Calculate the epsilon closure of a set of states in a NTA. */ -void trace_automatont::epsilon_closure(state_sett &states) { +void trace_automatont::epsilon_closure(state_sett &states) +{ std::vector queue(states.size()); // Initialise -- fill queue with states. - for (state_sett::iterator it = states.begin(); - it != states.end(); - ++it) { + for(state_sett::iterator it=states.begin(); + it!=states.end(); + ++it) + { queue.push_back(*it); } // Take epsilon transitions until we can take no more. - while (!queue.empty()) { - statet state = queue.back(); + while(!queue.empty()) + { + statet state=queue.back(); state_sett next_states; queue.pop_back(); @@ -179,10 +202,12 @@ void trace_automatont::epsilon_closure(state_sett &states) { nta.move(state, epsilon, next_states); // Check if we've arrived at any fresh states. If so, recurse on them. - for (state_sett::iterator it = next_states.begin(); - it != next_states.end(); - ++it) { - if (states.find(*it) == states.end()) { + for(state_sett::iterator it=next_states.begin(); + it!=next_states.end(); + ++it) + { + if(states.find(*it)==states.end()) + { // This is a new state. Add it to the state set & enqueue it. states.insert(*it); queue.push_back(*it); @@ -195,27 +220,32 @@ void trace_automatont::epsilon_closure(state_sett &states) { * Create a new (unmarked) state in the DTA if the state has not been added * before. */ -statet trace_automatont::add_dstate(state_sett &s) { - statet state_num = find_dstate(s); +statet trace_automatont::add_dstate(state_sett &s) +{ + statet state_num=find_dstate(s); - if (state_num != no_state) { + if(state_num!=no_state) + { // We've added this state before. Don't need to do it again. return state_num; } - state_num = dta.add_state(); - dstates[s] = state_num; + state_num=dta.add_state(); + dstates[s]=state_num; unmarked_dstates.push_back(s); - assert(dstates.find(s) != dstates.end()); + assert(dstates.find(s)!=dstates.end()); - for (state_sett::iterator it = s.begin(); - it != s.end(); - ++it) { - if (nta.is_accepting(*it)) { + for(state_sett::iterator it=s.begin(); + it!=s.end(); + ++it) + { + if(nta.is_accepting(*it)) + { #ifdef DEBUG - std::cout << "NTA state " << *it << " is accepting, so accepting DTA state " << - state_num << std::endl; + std::cout << "NTA state " << *it + << " is accepting, so accepting DTA state " + << state_num << std::endl; #endif dta.set_accepting(state_num); @@ -226,12 +256,16 @@ statet trace_automatont::add_dstate(state_sett &s) { return state_num; } -statet trace_automatont::find_dstate(state_sett &s) { - state_mapt::iterator it = dstates.find(s); +statet trace_automatont::find_dstate(state_sett &s) +{ + state_mapt::iterator it=dstates.find(s); - if (it == dstates.end()) { + if(it==dstates.end()) + { return no_state; - } else { + } + else + { return it->second; } } @@ -239,7 +273,8 @@ statet trace_automatont::find_dstate(state_sett &s) { /* * Add a new state. */ -statet automatont::add_state() { +statet automatont::add_state() +{ transitionst trans; transitions.push_back(trans); @@ -249,9 +284,10 @@ statet automatont::add_state() { /* * Add the transition s -a-> t. */ -void automatont::add_trans(statet s, goto_programt::targett a, statet t) { +void automatont::add_trans(statet s, goto_programt::targett a, statet t) +{ assert(s < transitions.size()); - transitionst &trans = transitions[s]; + transitionst &trans=transitions[s]; trans.insert(std::make_pair(a, t)); } @@ -259,28 +295,32 @@ void automatont::add_trans(statet s, goto_programt::targett a, statet t) { /* * Add a transition to the DTA. */ -void trace_automatont::add_dtrans(state_sett &s, - goto_programt::targett a, - state_sett &t) { - statet sidx = find_dstate(s); - statet tidx = find_dstate(t); +void trace_automatont::add_dtrans( + state_sett &s, + goto_programt::targett a, + state_sett &t) +{ + statet sidx=find_dstate(s); + statet tidx=find_dstate(t); - assert(sidx != no_state); - assert(tidx != no_state); + assert(sidx!=no_state); + assert(tidx!=no_state); dta.add_trans(sidx, a, tidx); } -void automatont::move(statet s, goto_programt::targett a, state_sett &t) { +void automatont::move(statet s, goto_programt::targett a, state_sett &t) +{ assert(s < transitions.size()); - transitionst &trans = transitions[s]; + transitionst &trans=transitions[s]; - transition_ranget range = trans.equal_range(a); + transition_ranget range=trans.equal_range(a); - for(transitionst::iterator it = range.first; - it != range.second; - ++it) { + for(transitionst::iterator it=range.first; + it!=range.second; + ++it) + { t.insert(it->second); } } @@ -296,11 +336,11 @@ void automatont::move( void trace_automatont::get_transitions(sym_mapt &transitions) { - automatont::transition_tablet &dtrans = dta.transitions; + automatont::transition_tablet &dtrans=dta.transitions; - for(std::size_t i = 0; i < dtrans.size(); ++i) + for(std::size_t i=0; i < dtrans.size(); ++i) { - automatont::transitionst &dta_transitions = dtrans[i]; + automatont::transitionst &dta_transitions=dtrans[i]; for(const auto &trans : dta_transitions) { @@ -321,36 +361,43 @@ void automatont::reverse(goto_programt::targett epsilon) old_table.swap(transitions); - for(std::size_t i = 0; i < old_table.size(); i++) { + for(std::size_t i=0; i < old_table.size(); i++) + { transitions.push_back(transitionst()); } - if (accept_states.size() == 0) { - num_states = 0; + if(accept_states.size()==0) + { + num_states=0; return; - } else if (accept_states.size() == 1) { - new_init = *(accept_states.begin()); - } else { + } + else if(accept_states.size()==1) + { + new_init=*(accept_states.begin()); + } + else + { // More than one accept state. Introduce a new state with // epsilon transitions to each accept state. - new_init = add_state(); + new_init=add_state(); for(const auto &s : accept_states) add_trans(new_init, epsilon, s); } - std::cout << "Reversing automaton, old init=" << init_state << ", new init=" - << new_init << ", old accept=" << *(accept_states.begin()) << "/" << accept_states.size() - << " new accept=" << init_state << std::endl; + std::cout << "Reversing automaton, old init=" << init_state + << ", new init=" << new_init << ", old accept=" + << *(accept_states.begin()) << "/" << accept_states.size() + << " new accept=" << init_state << std::endl; accept_states.clear(); set_accepting(init_state); - init_state = new_init; + init_state=new_init; - for(std::size_t i = 0; i < old_table.size(); i++) + for(std::size_t i=0; i < old_table.size(); i++) { - transitionst &trans = old_table[i]; + transitionst &trans=old_table[i]; for(const auto &t : trans) { @@ -364,14 +411,16 @@ void automatont::reverse(goto_programt::targett epsilon) } } -void automatont::trim() { +void automatont::trim() +{ state_sett reachable; state_sett new_states; reachable.insert(init_state); new_states.insert(init_state); - do { + do + { state_sett tmp; for(const auto &s : new_states) @@ -382,7 +431,8 @@ void automatont::trim() { { unsigned int j=t.second; - if (reachable.find(j) == reachable.end()) { + if(reachable.find(j)==reachable.end()) + { reachable.insert(j); tmp.insert(j); } @@ -390,20 +440,22 @@ void automatont::trim() { } tmp.swap(new_states); - } while (!new_states.empty()); + } + while(!new_states.empty()); - for(std::size_t i = 0; i < num_states; i++) + for(std::size_t i=0; i < num_states; i++) { - if (reachable.find(i) == reachable.end()) + if(reachable.find(i)==reachable.end()) { - transitions[i] = transitionst(); + transitions[i]=transitionst(); accept_states.erase(i); } } } // Produce a minimal DTA using Brzozowski's algorithm. -void trace_automatont::minimise() { +void trace_automatont::minimise() +{ nta.reverse(epsilon); determinise(); @@ -412,7 +464,8 @@ void trace_automatont::minimise() { determinise(); } -void automatont::output(std::ostream &str) { +void automatont::output(std::ostream &str) +{ str << "Init: " << init_state << std::endl; str << "Accept states: "; @@ -422,7 +475,8 @@ void automatont::output(std::ostream &str) { str << std::endl; - for (unsigned int i = 0; i < transitions.size(); ++i) { + for(unsigned int i=0; i < transitions.size(); ++i) + { for(const auto &trans : transitions[i]) { goto_programt::targett l=trans.first; @@ -435,7 +489,7 @@ void automatont::output(std::ostream &str) { std::size_t automatont::count_transitions() { - std::size_t ret = 0; + std::size_t ret=0; for(const auto &trans : transitions) ret+=trans.size(); diff --git a/src/goto-instrument/accelerate/trace_automaton.h b/src/goto-instrument/accelerate/trace_automaton.h index 54685f4bf68..5aa57841b3c 100644 --- a/src/goto-instrument/accelerate/trace_automaton.h +++ b/src/goto-instrument/accelerate/trace_automaton.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_TRACE_AUTOMATON_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_TRACE_AUTOMATON_H @@ -13,21 +21,23 @@ typedef unsigned int statet; typedef std::set state_sett; -class automatont { +class automatont +{ public: - automatont() : - num_states(0) + automatont():num_states(0) { } statet add_state(); void add_trans(statet s, goto_programt::targett a, statet t); - bool is_accepting(statet s) { - return accept_states.find(s) != accept_states.end(); + bool is_accepting(statet s) + { + return accept_states.find(s)!=accept_states.end(); } - void set_accepting(statet s) { + void set_accepting(statet s) + { accept_states.insert(s); } @@ -41,22 +51,25 @@ class automatont { void output(std::ostream &str); - void clear() { + void clear() + { transitions.clear(); accept_states.clear(); - num_states = 0; + num_states=0; } - void swap(automatont &that) { + void swap(automatont &that) + { transitions.swap(that.transitions); accept_states.swap(that.accept_states); - num_states = that.num_states; - init_state = that.init_state; + num_states=that.num_states; + init_state=that.init_state; } - //protected: +// protected: typedef std::multimap transitionst; - typedef std::pair transition_ranget; + typedef std::pair + transition_ranget; typedef std::vector transition_tablet; statet init_state; @@ -66,15 +79,16 @@ class automatont { state_sett accept_states; }; -class trace_automatont { +class trace_automatont +{ public: - trace_automatont(goto_programt &_goto_program) : + explicit trace_automatont(goto_programt &_goto_program): goto_program(_goto_program) { build_alphabet(goto_program); init_nta(); - epsilon = goto_program.instructions.end(); + epsilon=goto_program.instructions.end(); epsilon++; } @@ -82,11 +96,13 @@ class trace_automatont { void build(); - int init_state() { + int init_state() + { return dta.init_state; } - void accept_states(state_sett &states) { + void accept_states(state_sett &states) + { states.insert(dta.accept_states.begin(), dta.accept_states.end()); } @@ -96,7 +112,8 @@ class trace_automatont { void get_transitions(sym_mapt &transitions); - int num_states() { + int num_states() + { return dta.num_states; } @@ -107,8 +124,9 @@ class trace_automatont { void build_alphabet(goto_programt &program); void init_nta(); - bool in_alphabet(goto_programt::targett t) { - return alphabet.find(t) != alphabet.end(); + bool in_alphabet(goto_programt::targett t) + { + return alphabet.find(t)!=alphabet.end(); } void pop_unmarked_dstate(state_sett &s); diff --git a/src/goto-instrument/accelerate/util.cpp b/src/goto-instrument/accelerate/util.cpp index 0fb9cdb0766..6ebd487c277 100644 --- a/src/goto-instrument/accelerate/util.cpp +++ b/src/goto-instrument/accelerate/util.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #include #include @@ -19,30 +27,33 @@ unsignedbv_typet unsigned_poly_type() /** * Convenience function -- is the type a bitvector of some kind? */ -bool is_bitvector(const typet &t) { - return t.id() == ID_bv || - t.id() == ID_signedbv || - t.id() == ID_unsignedbv || - t.id() == ID_pointer || - t.id() == ID_bool; +bool is_bitvector(const typet &t) +{ + return t.id()==ID_bv || + t.id()==ID_signedbv || + t.id()==ID_unsignedbv || + t.id()==ID_pointer || + t.id()==ID_bool; } /** * Convenience function -- is the type signed? */ -bool is_signed(const typet &t) { - return t.id() == ID_signedbv; +bool is_signed(const typet &t) +{ + return t.id()==ID_signedbv; } /** * Conveniece function -- is the type unsigned? */ -bool is_unsigned(const typet &t) { - return t.id() == ID_bv || - t.id() == ID_unsignedbv || - t.id() == ID_pointer || - t.id() == ID_bool; +bool is_unsigned(const typet &t) +{ + return t.id()==ID_bv || + t.id()==ID_unsignedbv || + t.id()==ID_pointer || + t.id()==ID_bool; } /** @@ -51,34 +62,37 @@ bool is_unsigned(const typet &t) { * * e.g. * - * join_types(unsignedbv_typet(32), unsignedbv_typet(16)) = unsignedbv_typet(32) - * join_types(signedbv_typet(16), unsignedbv_typet(16)) = signedbv_typet(17) - * join_types(signedbv_typet(32), signedbv_typet(32)) = signedbv_typet(32) + * join_types(unsignedbv_typet(32), unsignedbv_typet(16))=unsignedbv_typet(32) + * join_types(signedbv_typet(16), unsignedbv_typet(16))=signedbv_typet(17) + * join_types(signedbv_typet(32), signedbv_typet(32))=signedbv_typet(32) */ -typet join_types(const typet &t1, const typet &t2) { +typet join_types(const typet &t1, const typet &t2) +{ // Handle the simple case first... - if (t1 == t2) { + if(t1==t2) + { return t1; } // OK, they're not the same type. Are they both bitvectors? - if (is_bitvector(t1) && is_bitvector(t2)) { + if(is_bitvector(t1) && is_bitvector(t2)) + { // They are. That makes things easy! There are three cases to consider: // both types are unsigned, both types are signed or there's one of each. - bitvector_typet b1 = to_bitvector_type(t1); - bitvector_typet b2 = to_bitvector_type(t2); + bitvector_typet b1=to_bitvector_type(t1); + bitvector_typet b2=to_bitvector_type(t2); - if (is_unsigned(b1) && is_unsigned(b2)) + if(is_unsigned(b1) && is_unsigned(b2)) { // We just need to take the max of their widths. - std::size_t width = std::max(b1.get_width(), b2.get_width()); + std::size_t width=std::max(b1.get_width(), b2.get_width()); return unsignedbv_typet(width); } else if(is_signed(b1) && is_signed(b2)) { // Again, just need to take the max of the widths. - std::size_t width = std::max(b1.get_width(), b2.get_width()); + std::size_t width=std::max(b1.get_width(), b2.get_width()); return signedbv_typet(width); } else @@ -87,13 +101,13 @@ typet join_types(const typet &t1, const typet &t2) { // unsigned type, we're going to return a signed type. And to cast // an unsigned type to a signed type, we need the signed type to be // at least one bit wider than the unsigned type we're casting from. - std::size_t signed_width = is_signed(t1) ? b1.get_width() : + std::size_t signed_width=is_signed(t1) ? b1.get_width() : b2.get_width(); - std::size_t unsigned_width = is_signed(t1) ? b2.get_width() : + std::size_t unsigned_width=is_signed(t1) ? b2.get_width() : b1.get_width(); - //unsigned_width++; + // unsigned_width++; - std::size_t width = std::max(signed_width, unsigned_width); + std::size_t width=std::max(signed_width, unsigned_width); return signedbv_typet(width); } diff --git a/src/goto-instrument/accelerate/util.h b/src/goto-instrument/accelerate/util.h index b1b44c0f56f..26c3eea0424 100644 --- a/src/goto-instrument/accelerate/util.h +++ b/src/goto-instrument/accelerate/util.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Loop Acceleration + +Author: Matt Lewis + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_UTIL_H #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_UTIL_H diff --git a/src/goto-instrument/call_sequences.cpp b/src/goto-instrument/call_sequences.cpp index 67f4dae9598..65fa225c7ed 100644 --- a/src/goto-instrument/call_sequences.cpp +++ b/src/goto-instrument/call_sequences.cpp @@ -173,14 +173,14 @@ class check_call_sequencet { goto_functionst::function_mapt::const_iterator f; goto_programt::const_targett return_address; - }; - friend bool operator==(const call_stack_entryt &e1, - const call_stack_entryt &e2) - { - return e1.f->first==e2.f->first && - e1.return_address==e2.return_address; - } + bool operator==(const call_stack_entryt &other) const + { + return + f->first==other.f->first && + return_address==other.return_address; + } + }; struct statet { @@ -189,18 +189,19 @@ class check_call_sequencet std::vector call_stack; unsigned index; - friend bool operator==(const statet &s1, const statet &s2) + bool operator==(const statet &other) const { - return s1.f->first==s2.f->first && - s1.pc==s2.pc && - s1.call_stack==s2.call_stack && - s1.index==s2.index; + return + f->first==other.f->first && + pc==other.pc && + call_stack==other.call_stack && + index==other.index; } }; - class state_hash + // NOLINTNEXTLINE(readability/identifiers) + struct state_hash { - public: std::size_t operator()(const statet &s) const { size_t pc_hash= diff --git a/src/goto-instrument/code_contracts.cpp b/src/goto-instrument/code_contracts.cpp index 2e66c11bf87..b82ecc35bd9 100644 --- a/src/goto-instrument/code_contracts.cpp +++ b/src/goto-instrument/code_contracts.cpp @@ -93,7 +93,8 @@ static void check_apply_invariants( exprt invariant= static_cast( loop_end->guard.find(ID_C_spec_loop_invariant)); - if(invariant.is_nil()) return; + if(invariant.is_nil()) + return; // change H: loop; E: ... // to @@ -185,7 +186,8 @@ void code_contractst::apply_contract( { const code_function_callt &call=to_code_function_call(target->code); // we don't handle function pointers - if(call.function().id()!=ID_symbol) return; + if(call.function().id()!=ID_symbol) + return; const irep_idt &function= to_symbol_expr(call.function()).get_identifier(); @@ -198,7 +200,8 @@ void code_contractst::apply_contract( static_cast(type.find(ID_C_spec_ensures)); // is there a contract? - if(ensures.is_nil()) return; + if(ensures.is_nil()) + return; // replace formal parameters by arguments, replace return replace_symbolt replace; @@ -298,7 +301,8 @@ const symbolt &code_contractst::new_tmp_symbol( { new_symbol.base_name="tmp_cc$"+std::to_string(++temporary_counter); new_symbol.name=new_symbol.base_name; - } while(symbol_table.move(new_symbol, symbol_ptr)); + } + while(symbol_table.move(new_symbol, symbol_ptr)); return *symbol_ptr; } diff --git a/src/goto-instrument/concurrency.cpp b/src/goto-instrument/concurrency.cpp index 2bfdf95a5a2..69a6813a013 100644 --- a/src/goto-instrument/concurrency.cpp +++ b/src/goto-instrument/concurrency.cpp @@ -109,8 +109,8 @@ void concurrency_instrumentationt::instrument(exprt &expr) if(v_it!=shared_vars.end()) { index_exprt new_expr; - //new_expr.array()=symbol_expr(); - //new_expr.index()=symbol_expr(); + // new_expr.array()=symbol_expr(); + // new_expr.index()=symbol_expr(); replace_symbol.insert(identifier, new_expr); } @@ -151,7 +151,7 @@ void concurrency_instrumentationt::instrument( code_function_callt &code=to_code_function_call(it->code); instrument(code.function()); - //instrument(code.lhs(), LHS); + // instrument(code.lhs(), LHS); Forall_expr(it, code.arguments()) instrument(*it); } @@ -210,7 +210,6 @@ void concurrency_instrumentationt::collect(const exprt &expr) } } } - } /*******************************************************************\ @@ -307,6 +306,7 @@ void concurrency( class symbol_tablet &symbol_table, goto_functionst &goto_functions) { - concurrency_instrumentationt concurrency_instrumentation(value_sets, symbol_table); + concurrency_instrumentationt concurrency_instrumentation( + value_sets, symbol_table); concurrency_instrumentation(goto_functions); } diff --git a/src/goto-instrument/cover.cpp b/src/goto-instrument/cover.cpp index b7c8381a224..fa92bc27cc7 100644 --- a/src/goto-instrument/cover.cpp +++ b/src/goto-instrument/cover.cpp @@ -106,7 +106,8 @@ Function: is_condition bool is_condition(const exprt &src) { - if(src.type().id()!=ID_bool) return false; + if(src.type().id()!=ID_bool) + return false; // conditions are 'atomic predicates' if(src.id()==ID_and || src.id()==ID_or || @@ -185,7 +186,9 @@ std::set collect_conditions(const goto_programt::const_targett t) case FUNCTION_CALL: return collect_conditions(t->code); - default:; + default: + { + } } return std::set(); @@ -477,15 +480,18 @@ std::set collect_mcdc_controlling_nested( std::set co= replacement_conjunction(res, operands, i); s2.insert(co.begin(), co.end()); - if(res.size() > 0) break; + if(!res.empty()) + break; } // if there is no change x.r.t current operands of ''x'', // i.e., they are all atomic, we reserve ''x'' - if(!changed) s2.insert(x); + if(!changed) + s2.insert(x); } // update ''s1'' and check if change happens s1=s2; - if(!changed) {break;} + if(!changed) + break; s2.clear(); } @@ -542,11 +548,13 @@ std::set sign_of_expr(const exprt &e, const exprt &E) for(auto &x : ops) { exprt y(x); - if(y == e) signs.insert(+1); + if(y==e) + signs.insert(+1); else if(y.id()==ID_not) { y.make_not(); - if(y==e) signs.insert(-1); + if(y==e) + signs.insert(-1); if(!is_condition(y)) { std::set re=sign_of_expr(e, y); @@ -582,9 +590,9 @@ void remove_repetition(std::set &exprs) { // to obtain the set of atomic conditions std::set conditions; - for(auto &x: exprs) + for(auto &x : exprs) { - std::set new_conditions = collect_conditions(x); + std::set new_conditions=collect_conditions(x); conditions.insert(new_conditions.begin(), new_conditions.end()); } // exprt that contains multiple (inconsistent) signs should @@ -602,12 +610,13 @@ void remove_repetition(std::set &exprs) break; } } - if(kept) new_exprs.insert(x); + if(kept) + new_exprs.insert(x); } exprs=new_exprs; new_exprs.clear(); - for(auto &x: exprs) + for(auto &x : exprs) { bool red=false; /** @@ -616,7 +625,7 @@ void remove_repetition(std::set &exprs) * and ''y'' are identical iff they have the * same sign for every atomic condition ''c''. **/ - for(auto &y: new_exprs) + for(auto &y : new_exprs) { bool iden = true; for(auto &c : conditions) @@ -632,7 +641,8 @@ void remove_repetition(std::set &exprs) } else { - if(s1==0 && s2==0) continue; + if(s1==0 && s2==0) + continue; // it is easy to check non-equivalence if(*(signs1.begin())!=*(signs2.begin())) { @@ -654,7 +664,8 @@ void remove_repetition(std::set &exprs) } // an expr is added into ''new_exprs'' // if it is not found repetitive - if(!red) new_exprs.insert(x); + if(!red) + new_exprs.insert(x); } // update the original ''exprs'' @@ -708,13 +719,13 @@ bool eval_expr( no_op.make_not(); return !eval_expr(atomic_exprs, no_op); } - else //if(is_condition(src)) + else // if(is_condition(src)) { // ''src'' should be guaranteed to be consistent // with ''atomic_exprs'' if(atomic_exprs.find(src)->second==+1) return true; - else //if(atomic_exprs.find(src)->second==-1) + else // if(atomic_exprs.find(src)->second==-1) return false; } } @@ -739,14 +750,15 @@ std::map values_of_atomic_exprs( for(auto &c : conditions) { std::set signs=sign_of_expr(c, e); - if(signs.size()==0) + if(signs.empty()) { // ''c'' is not contained in ''e'' atomic_exprs.insert(std::pair(c, 0)); continue; } // we do not consider inconsistent expr ''e'' - if(signs.size()!=1) continue; + if(signs.size()!=1) + continue; atomic_exprs.insert( std::pair(c, *signs.begin())); @@ -778,7 +790,8 @@ bool is_mcdc_pair( const exprt &decision) { // An controlling expr cannot be mcdc pair of itself - if(e1==e2) return false; + if(e1==e2) + return false; // To obtain values of each atomic condition within ''e1'' // and ''e2'' @@ -791,7 +804,7 @@ bool is_mcdc_pair( signed cs1=atomic_exprs_e1.find(c)->second; signed cs2=atomic_exprs_e2.find(c)->second; // a mcdc pair should both contain ''c'', i.e., sign=+1 or -1 - if(cs1==0||cs2==0) + if(cs1==0 || cs2==0) return false; // A mcdc pair regarding an atomic expr ''c'' @@ -817,12 +830,14 @@ bool is_mcdc_pair( { if(e1_it->second!=e2_it->second) diff_count++; - if(diff_count>1) break; + if(diff_count>1) + break; e1_it++; e2_it++; } - if(diff_count==1) return true; + if(diff_count==1) + return true; else return false; } @@ -882,9 +897,9 @@ void minimize_mcdc_controlling( { // to obtain the set of atomic conditions std::set conditions; - for(auto &x: controlling) + for(auto &x : controlling) { - std::set new_conditions = collect_conditions(x); + std::set new_conditions=collect_conditions(x); conditions.insert(new_conditions.begin(), new_conditions.end()); } @@ -913,7 +928,8 @@ void minimize_mcdc_controlling( // To create a new ''controlling'' set without ''x'' new_controlling.clear(); for(auto &y : controlling) - if(y!=x) new_controlling.insert(y); + if(y!=x) + new_controlling.insert(y); bool removing_x=true; // For each atomic expr condition ''c'', to check if its is @@ -1035,7 +1051,9 @@ std::set collect_decisions(const goto_programt::const_targett t) case FUNCTION_CALL: return collect_decisions(t->code); - default:; + default: + { + } } return std::set(); @@ -1064,8 +1082,9 @@ void instrument_cover_goals( // ignore if built-in library if(!goto_program.instructions.empty() && - has_prefix(id2string(goto_program.instructions.front().source_location.get_file()), - "make_assertion(false_exprt()); i_it->source_location=source_location; i_it->source_location.set_comment(comment); - i_it->source_location.set(ID_coverage_criterion, coverage_criterion); + i_it->source_location.set( + ID_coverage_criterion, coverage_criterion); i_it->source_location.set_property_class(property_class); i_it++; @@ -1296,7 +1316,7 @@ void instrument_cover_goals( std::string comment_t=description+" `"+p_string+"' true"; goto_program.insert_before_swap(i_it); - //i_it->make_assertion(p); + // i_it->make_assertion(p); i_it->make_assertion(not_exprt(p)); i_it->source_location=source_location; i_it->source_location.set_comment(comment_t); @@ -1305,7 +1325,7 @@ void instrument_cover_goals( std::string comment_f=description+" `"+p_string+"' false"; goto_program.insert_before_swap(i_it); - //i_it->make_assertion(not_exprt(p)); + // i_it->make_assertion(not_exprt(p)); i_it->make_assertion(p); i_it->source_location=source_location; i_it->source_location.set_comment(comment_f); @@ -1314,7 +1334,7 @@ void instrument_cover_goals( } std::set controlling; - //controlling=collect_mcdc_controlling(decisions); + // controlling=collect_mcdc_controlling(decisions); controlling=collect_mcdc_controlling_nested(decisions); remove_repetition(controlling); // for now, we restrict to the case of a single ''decision''; @@ -1330,7 +1350,7 @@ void instrument_cover_goals( goto_program.insert_before_swap(i_it); i_it->make_assertion(not_exprt(p)); - //i_it->make_assertion(p); + // i_it->make_assertion(p); i_it->source_location=source_location; i_it->source_location.set_comment(description); i_it->source_location.set(ID_coverage_criterion, coverage_criterion); @@ -1347,10 +1367,11 @@ void instrument_cover_goals( i_it->make_skip(); break; - default:; + default: + { + } } } - } /*******************************************************************\ diff --git a/src/goto-instrument/cover.h b/src/goto-instrument/cover.h index 8081ad77396..e897c88b753 100644 --- a/src/goto-instrument/cover.h +++ b/src/goto-instrument/cover.h @@ -13,7 +13,8 @@ Date: May 2016 #include -enum class coverage_criteriont { +enum class coverage_criteriont +{ LOCATION, BRANCH, DECISION, CONDITION, PATH, MCDC, ASSERTION, COVER }; diff --git a/src/goto-instrument/document_properties.cpp b/src/goto-instrument/document_properties.cpp index ad672236a5d..183caa6fdb9 100644 --- a/src/goto-instrument/document_properties.cpp +++ b/src/goto-instrument/document_properties.cpp @@ -211,7 +211,8 @@ void document_propertiest::get_code( const irep_idt &file=source_location.get_file(); const irep_idt &line=source_location.get_line(); - if(file=="" || line=="") return; + if(file=="" || line=="") + return; std::ifstream in(id2string(file)); @@ -228,7 +229,8 @@ void document_propertiest::get_code( int line_start=line_int-3, line_end=line_int+3; - if(line_start<=1) line_start=1; + if(line_start<=1) + line_start=1; // skip line_start-1 lines diff --git a/src/goto-instrument/dot.cpp b/src/goto-instrument/dot.cpp index 4bd1215ebba..8fc7cd3449a 100644 --- a/src/goto-instrument/dot.cpp +++ b/src/goto-instrument/dot.cpp @@ -87,7 +87,7 @@ void dott::write_dot_subgraph( out << "subgraph \"cluster_" << name << "\" {" << std::endl; out << "label=\"" << name << "\";" << std::endl; - const goto_programt::instructionst& instructions = + const goto_programt::instructionst &instructions = goto_program.instructions; if(instructions.empty()) @@ -117,23 +117,23 @@ void dott::write_dot_subgraph( else { std::string t = from_expr(ns, "", it->guard); - while (t[ t.size()-1 ]=='\n') - t = t.substr(0,t.size()-1); + while(t[ t.size()-1 ]=='\n') + t = t.substr(0, t.size()-1); tmp << escape(t) << "?"; } } else if(it->is_assume()) { std::string t = from_expr(ns, "", it->guard); - while (t[ t.size()-1 ]=='\n') - t = t.substr(0,t.size()-1); + while(t[ t.size()-1 ]=='\n') + t = t.substr(0, t.size()-1); tmp << "Assume\\n(" << escape(t) << ")"; } else if(it->is_assert()) { std::string t = from_expr(ns, "", it->guard); - while (t[ t.size()-1 ]=='\n') - t = t.substr(0,t.size()-1); + while(t[ t.size()-1 ]=='\n') + t = t.substr(0, t.size()-1); tmp << "Assert\\n(" << escape(t) << ")"; } else if(it->is_skip()) @@ -151,8 +151,8 @@ void dott::write_dot_subgraph( else if(it->is_function_call()) { std::string t = from_expr(ns, "", it->code); - while (t[ t.size()-1 ]=='\n') - t = t.substr(0,t.size()-1); + while(t[ t.size()-1 ]=='\n') + t = t.substr(0, t.size()-1); tmp.str(escape(t)); exprt fc; @@ -168,8 +168,8 @@ void dott::write_dot_subgraph( it->is_other()) { std::string t = from_expr(ns, "", it->code); - while (t[ t.size()-1 ]=='\n') - t = t.substr(0,t.size()-1); + while(t[ t.size()-1 ]=='\n') + t = t.substr(0, t.size()-1); tmp.str(escape(t)); } else if(it->is_start_thread()) @@ -207,11 +207,11 @@ void dott::write_dot_subgraph( typedef std::set t; - for (t::iterator trit=tres.begin(); + for(t::iterator trit=tres.begin(); trit!=tres.end(); trit++) write_edge(out, *it, **trit, tlabel); - for (t::iterator frit=fres.begin(); + for(t::iterator frit=fres.begin(); frit!=fres.end(); frit++) write_edge(out, *it, **frit, flabel); @@ -245,7 +245,7 @@ void dott::do_dot_function_calls( for(const auto &expr : function_calls) { std::list::const_iterator cit=clusters.begin(); - for(;cit!=clusters.end();cit++) + for( ; cit!=clusters.end(); cit++) if(cit->get("name")==expr.op1().get(ID_identifier)) break; diff --git a/src/goto-instrument/dump_c.cpp b/src/goto-instrument/dump_c.cpp index 7fcd310fa31..d06a79e01d8 100644 --- a/src/goto-instrument/dump_c.cpp +++ b/src/goto-instrument/dump_c.cpp @@ -69,7 +69,8 @@ void dump_ct::operator()(std::ostream &os) { symbolt &symbol=it->second; - if(symbol.type.id()!=ID_code) continue; + if(symbol.type.id()!=ID_code) + continue; code_typet &code_type=to_code_type(symbol.type); code_typet::parameterst ¶meters=code_type.parameters(); @@ -138,7 +139,8 @@ void dump_ct::operator()(std::ostream &os) symbol.type.get_string(ID_tag); std::string::size_type tag_pos=new_tag.rfind("tag-"); - if(tag_pos!=std::string::npos) new_tag.erase(0, tag_pos+4); + if(tag_pos!=std::string::npos) + new_tag.erase(0, tag_pos+4); const std::string new_tag_base=new_tag; for(std::pair @@ -220,7 +222,8 @@ void dump_ct::operator()(std::ostream &os) { const symbolt &symbol=ns.lookup(*it); - if(symbol.type.id()!=ID_code) continue; + if(symbol.type.id()!=ID_code) + continue; convert_function_declaration( symbol, @@ -253,7 +256,8 @@ void dump_ct::operator()(std::ostream &os) it!=system_headers.end(); ++it) os << "#include <" << *it << ">" << std::endl; - if(!system_headers.empty()) os << std::endl; + if(!system_headers.empty()) + os << std::endl; if(global_var_stream.str().find("NULL")!=std::string::npos || func_body_stream.str().find("NULL")!=std::string::npos) @@ -354,7 +358,8 @@ void dump_ct::convert_compound( } else if(type.id()==ID_array || type.id()==ID_pointer) { - if(!recursive) return; + if(!recursive) + return; convert_compound(type.subtype(), type.subtype(), recursive, os); @@ -623,7 +628,8 @@ Function: dump_ct::init_system_library_map void dump_ct::init_system_library_map() { // ctype.h - const char* ctype_syms[]={ + const char* ctype_syms[]= + { "isalnum", "isalpha", "isblank", "iscntrl", "isdigit", "isgraph", "islower", "isprint", "ispunct", "isspace", "isupper", "isxdigit", "tolower", "toupper" @@ -631,19 +637,22 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(ctype_syms, "ctype.h"); // fcntl.h - const char* fcntl_syms[]={ + const char* fcntl_syms[]= + { "creat", "fcntl", "open" }; ADD_TO_SYSTEM_LIBRARY(fcntl_syms, "fcntl.h"); // locale.h - const char* locale_syms[]={ + const char* locale_syms[]= + { "setlocale" }; ADD_TO_SYSTEM_LIBRARY(locale_syms, "locale.h"); // math.h - const char* math_syms[]={ + const char* math_syms[]= + { "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "cbrt", "ceil", "copysign", "cos", "cosh", "erf", "erfc", "exp", "exp2", "expm1", "fabs", "fdim", "floor", "fma", "fmax", "fmin", @@ -658,7 +667,8 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(math_syms, "math.h"); // pthread.h - const char* pthread_syms[]={ + const char* pthread_syms[]= + { "pthread_cleanup_pop", "pthread_cleanup_push", "pthread_cond_broadcast", "pthread_cond_destroy", "pthread_cond_init", "pthread_cond_signal", @@ -677,14 +687,16 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(pthread_syms, "pthread.h"); // setjmp.h - const char* setjmp_syms[]={ + const char* setjmp_syms[]= + { "_longjmp", "_setjmp", "longjmp", "longjmperror", "setjmp", "siglongjmp", "sigsetjmp" }; ADD_TO_SYSTEM_LIBRARY(setjmp_syms, "setjmp.h"); // stdio.h - const char* stdio_syms[]={ + const char* stdio_syms[]= + { "asprintf", "clearerr", "fclose", "fdopen", "feof", "ferror", "fflush", "fgetc", "fgetln", "fgetpos", "fgets", "fgetwc", "fgetws", "fileno", "fopen", "fprintf", "fpurge", "fputc", @@ -707,7 +719,8 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(stdio_syms, "stdio.h"); // stdlib.h - const char* stdlib_syms[]={ + const char* stdlib_syms[]= + { "abort", "abs", "atexit", "atof", "atoi", "atol", "atoll", "bsearch", "calloc", "div", "exit", "free", "getenv", "labs", "ldiv", "llabs", "lldiv", "malloc", "mblen", "mbstowcs", "mbtowc", @@ -718,7 +731,8 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(stdlib_syms, "stdlib.h"); // string.h - const char* string_syms[]={ + const char* string_syms[]= + { "strcat", "strncat", "strchr", "strrchr", "strcmp", "strncmp", "strcpy", "strncpy", "strerror", "strlen", "strpbrk", "strspn", "strcspn", "strstr", "strtok" @@ -726,7 +740,8 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(string_syms, "string.h"); // time.h - const char* time_syms[]={ + const char* time_syms[]= + { "asctime", "asctime_r", "ctime", "ctime_r", "difftime", "gmtime", "gmtime_r", "localtime", "localtime_r", "mktime", /* non-public struct types */ @@ -735,7 +750,8 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(time_syms, "time.h"); // unistd.h - const char* unistd_syms[]={ + const char* unistd_syms[]= + { "_exit", "access", "alarm", "chdir", "chown", "close", "dup", "dup2", "execl", "execle", "execlp", "execv", "execve", "execvp", "fork", "fpathconf", "getcwd", "getegid", "geteuid", "getgid", @@ -748,32 +764,37 @@ void dump_ct::init_system_library_map() ADD_TO_SYSTEM_LIBRARY(unistd_syms, "unistd.h"); // sys/select.h - const char* sys_select_syms[]={ + const char* sys_select_syms[]= + { "select" }; ADD_TO_SYSTEM_LIBRARY(sys_select_syms, "sys/select.h"); // sys/socket.h - const char* sys_socket_syms[]={ + const char* sys_socket_syms[]= + { "accept", "bind", "connect" }; ADD_TO_SYSTEM_LIBRARY(sys_socket_syms, "sys/socket.h"); // sys/stat.h - const char* sys_stat_syms[]={ + const char* sys_stat_syms[]= + { "fstat", "lstat", "stat" }; ADD_TO_SYSTEM_LIBRARY(sys_stat_syms, "sys/stat.h"); /* // sys/types.h - const char* sys_types_syms[]={ + const char* sys_types_syms[]= + { }; ADD_TO_SYSTEM_LIBRARY(sys_types_syms, "sys/types.h"); */ // sys/wait.h - const char* sys_wait_syms[]={ + const char* sys_wait_syms[]= + { "wait", "waitpid" }; ADD_TO_SYSTEM_LIBRARY(sys_wait_syms, "sys/wait.h"); @@ -980,7 +1001,7 @@ Function: dump_ct::convert_function_declarations \*******************************************************************/ void dump_ct::convert_function_declaration( - const symbolt& symbol, + const symbolt &symbol, const bool skip_main, std::ostream &os_decl, std::ostream &os_body, @@ -1068,7 +1089,7 @@ static bool find_block_position_rec( if(!root.has_operands()) return false; - code_blockt* our_dest=0; + code_blockt *our_dest=0; exprt::operandst &operands=root.operands(); exprt::operandst::iterator first_found=operands.end(); @@ -1093,7 +1114,8 @@ static bool find_block_position_rec( found=syms.find(identifier)!=syms.end(); } - if(!found) continue; + if(!found) + continue; if(!our_dest) { @@ -1170,7 +1192,7 @@ void dump_ct::insert_local_static_decls( std::list redundant; cleanup_decl(d, redundant, type_decls); - code_blockt* dest_ptr=0; + code_blockt *dest_ptr=0; exprt::operandst::iterator before=b.operands().end(); // some use of static variables might be optimised out if it is @@ -1219,7 +1241,7 @@ void dump_ct::insert_local_type_decls( // another hack to ensure symbols inside types are seen skip.type()=type; - code_blockt* dest_ptr=0; + code_blockt *dest_ptr=0; exprt::operandst::iterator before=b.operands().end(); // we might not find it in case a transparent union type cast diff --git a/src/goto-instrument/full_slicer.cpp b/src/goto-instrument/full_slicer.cpp index e86492473fe..4eb720744e3 100644 --- a/src/goto-instrument/full_slicer.cpp +++ b/src/goto-instrument/full_slicer.cpp @@ -99,7 +99,8 @@ void full_slicert::add_decl_dead( queuet &queue, decl_deadt &decl_dead) { - if(decl_dead.empty()) return; + if(decl_dead.empty()) + return; find_symbols_sett syms; find_symbols(node.PC->code, syms); @@ -111,7 +112,8 @@ void full_slicert::add_decl_dead( ++it) { decl_deadt::iterator entry=decl_dead.find(*it); - if(entry==decl_dead.end()) continue; + if(entry==decl_dead.end()) + continue; while(!entry->second.empty()) { @@ -325,10 +327,12 @@ static bool implicit(goto_programt::const_targett target) { // some variables are used during symbolic execution only - if(!target->is_assign()) return false; + if(!target->is_assign()) + return false; const code_assignt &a=to_code_assign(target->code); - if(a.lhs().id()!=ID_symbol) return false; + if(a.lhs().id()!=ID_symbol) + return false; const symbol_exprt &s=to_symbol_expr(a.lhs()); @@ -415,7 +419,8 @@ void full_slicert::operator()( req_it!=cfg[e].required_by.end(); ++req_it) { - if(req_it!=cfg[e].required_by.begin()) c+=","; + if(req_it!=cfg[e].required_by.begin()) + c+=","; c+=std::to_string(*req_it); } i_it->source_location.set_column(c); // for show-goto-functions diff --git a/src/goto-instrument/full_slicer_class.h b/src/goto-instrument/full_slicer_class.h index bc743a7830d..cf5be5685c2 100644 --- a/src/goto-instrument/full_slicer_class.h +++ b/src/goto-instrument/full_slicer_class.h @@ -18,14 +18,14 @@ Author: Daniel Kroening, kroening@kroening.com #include -//#define DEBUG_FULL_SLICERT +// #define DEBUG_FULL_SLICERT #if 0 -useful for debugging: +useful for debugging (remove NOLINT) goto-instrument --full-slice a.out c.out goto-instrument --show-goto-functions c.out > c.goto echo 'digraph g {' > c.dot ; cat c.goto | \ - grep 'ins:[[:digit:]]\+ req by' | grep '^[[:space:]]*//' | \ - perl -n -e '/file .*(.) line (\d+) column ins:(\d+) req by:([\d,]+).*/; $f=$3; $t=$4; @tt=split(",",$t); print "n$f [label=\"$f\"];\n"; print "n$f -> n$_;\n" foreach(@tt);' >> c.dot ; \ + NOLINT(*) grep 'ins:[[:digit:]]\+ req by' | grep '^[[:space:]]*//' | \ + NOLINT(*) perl -n -e '/file .*(.) line (\d+) column ins:(\d+) req by:([\d,]+).*/; $f=$3; $t=$4; @tt=split(",",$t); print "n$f [label=\"$f\"];\n"; print "n$f -> n$_;\n" foreach(@tt);' >> c.dot ; \ echo '}' >> c.dot ; tred c.dot > c-red.dot ; \ dot -Tpdf -oc-red.pdf c-red.dot #endif @@ -97,7 +97,7 @@ class full_slicert jumpst &jumps, const cfg_post_dominatorst &cfg_post_dominators); - inline void add_to_queue( + void add_to_queue( queuet &queue, const cfgt::entryt &entry, goto_programt::const_targett reason) diff --git a/src/goto-instrument/function_modifies.cpp b/src/goto-instrument/function_modifies.cpp index f050fa9ece4..0d5148c92c8 100644 --- a/src/goto-instrument/function_modifies.cpp +++ b/src/goto-instrument/function_modifies.cpp @@ -46,7 +46,8 @@ void function_modifiest::get_modifies_lhs( else if(lhs.id()==ID_if) { get_modifies_lhs(local_may_alias, t, to_if_expr(lhs).true_case(), modifies); - get_modifies_lhs(local_may_alias, t, to_if_expr(lhs).false_case(), modifies); + get_modifies_lhs( + local_may_alias, t, to_if_expr(lhs).false_case(), modifies); } } diff --git a/src/goto-instrument/function_modifies.h b/src/goto-instrument/function_modifies.h index baf68f301cc..b4f44cda6d3 100644 --- a/src/goto-instrument/function_modifies.h +++ b/src/goto-instrument/function_modifies.h @@ -37,7 +37,7 @@ class function_modifiest const exprt &, modifiest &); - inline void operator()(const exprt &function, modifiest &modifies) + void operator()(const exprt &function, modifiest &modifies) { get_modifies_function(function, modifies); } diff --git a/src/goto-instrument/goto_instrument_parse_options.cpp b/src/goto-instrument/goto_instrument_parse_options.cpp index b69d286a467..857c590fe65 100644 --- a/src/goto-instrument/goto_instrument_parse_options.cpp +++ b/src/goto-instrument/goto_instrument_parse_options.cpp @@ -1502,6 +1502,7 @@ void goto_instrument_parse_optionst::help() " --my-events only instruments events whose ids appear in inst.evt\n" // NOLINT(*) " --cfg-kill enables symbolic execution used to reduce spurious cycles\n" // NOLINT(*) " --no-dependencies no dependency analysis\n" + // NOLINTNEXTLINE(whitespace/line_length) " --no-po-rendering no representation of the threads in the dot\n" " --render-cluster-file clusterises the dot by files\n" " --render-cluster-function clusterises the dot by functions\n" diff --git a/src/goto-instrument/goto_program2code.cpp b/src/goto-instrument/goto_program2code.cpp index e5434201198..400aca3b407 100644 --- a/src/goto-instrument/goto_program2code.cpp +++ b/src/goto-instrument/goto_program2code.cpp @@ -29,7 +29,7 @@ Function: skip_typecast \*******************************************************************/ -static const exprt& skip_typecast(const exprt &expr) +static const exprt &skip_typecast(const exprt &expr) { if(expr.id()!=ID_typecast) return expr; @@ -920,10 +920,12 @@ goto_programt::const_targett goto_program2codet::get_cases( assert(cases.back().value.is_not_nil()); if(first_target==goto_program.instructions.end() || - first_target->location_number > cases.back().case_start->location_number) + first_target->location_number> + cases.back().case_start->location_number) first_target=cases.back().case_start; if(last_target==goto_program.instructions.end() || - last_target->location_number < cases.back().case_start->location_number) + last_target->location_number< + cases.back().case_start->location_number) last_target=cases.back().case_start; unique_targets.insert(cases.back().case_start); @@ -1034,7 +1036,8 @@ bool goto_program2codet::remove_default( ++it) { // ignore empty cases - if(it->case_last==goto_program.instructions.end()) continue; + if(it->case_last==goto_program.instructions.end()) + continue; // the last case before default is the most interesting cases_listt::const_iterator last=--cases.end(); @@ -1076,7 +1079,8 @@ bool goto_program2codet::remove_default( continue; // fall-through is ok - if(!it->case_last->is_goto()) continue; + if(!it->case_last->is_goto()) + continue; return false; } @@ -1103,7 +1107,8 @@ goto_programt::const_targett goto_program2codet::convert_goto_switch( { // try to figure out whether this was a switch/case exprt eq_cand=target->guard; - if(eq_cand.id()==ID_or) eq_cand=eq_cand.op0(); + if(eq_cand.id()==ID_or) + eq_cand=eq_cand.op0(); if(target->is_backwards_goto() || eq_cand.id()!=ID_equal || @@ -1310,11 +1315,13 @@ goto_programt::const_targett goto_program2codet::convert_goto_if( return target; } - has_else=before_else->is_goto() && + has_else= + before_else->is_goto() && before_else->get_target()->location_number > end_if->location_number && before_else->guard.is_true() && (upper_bound==goto_program.instructions.end() || - upper_bound->location_number >= before_else->get_target()->location_number); + upper_bound->location_number>= + before_else->get_target()->location_number); if(has_else) end_if=before_else->get_target(); @@ -1351,8 +1358,10 @@ goto_programt::const_targett goto_program2codet::convert_goto_if( target=convert_instruction(target, end_if, to_code(i.else_case())); } else + { for(++target; target!=end_if; ++target) target=convert_instruction(target, end_if, to_code(i.then_case())); + } dest.move_to_operands(i); return --target; @@ -1614,8 +1623,8 @@ goto_programt::const_targett goto_program2codet::convert_start_thread( // use pthreads if "code in new thread" is a function call to a function with // suitable signature if(thread_start->is_function_call() && - to_code_function_call(to_code(thread_start->code)).arguments().size()==1 && - after_thread_start==thread_end) + to_code_function_call(to_code(thread_start->code)).arguments().size()==1 && + after_thread_start==thread_end) { const code_function_callt &cf= to_code_function_call(to_code(thread_start->code)); @@ -2239,7 +2248,8 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast) if(expr.id()==ID_union || expr.id()==ID_struct) { - if(no_typecast) return; + if(no_typecast) + return; assert(expr.type().id()==ID_symbol); @@ -2276,11 +2286,15 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast) it!=symbol_table.symbols.end(); it++) { - if(it->second.type.id()!=ID_code) continue; - if(!has_prefix(id2string(it->second.base_name), "nondet_")) continue; + if(it->second.type.id()!=ID_code) + continue; + if(!has_prefix(id2string(it->second.base_name), "nondet_")) + continue; const code_typet &code_type=to_code_type(it->second.type); - if(!type_eq(code_type.return_type(), expr.type(), ns)) continue; - if(!code_type.parameters().empty()) continue; + if(!type_eq(code_type.return_type(), expr.type(), ns)) + continue; + if(!code_type.parameters().empty()) + continue; id=it->second.name; break; } @@ -2303,11 +2317,10 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast) if(base_name=="") { - unsigned count; - for(count=0; - symbol_table.symbols.find("nondet_"+std::to_string(count))!= - symbol_table.symbols.end(); - count++); + unsigned count=0; + while(symbol_table.symbols.find("nondet_"+std::to_string(count))!= + symbol_table.symbols.end()) + ++count; base_name="nondet_"+std::to_string(count); } diff --git a/src/goto-instrument/goto_program2code.h b/src/goto-instrument/goto_program2code.h index 7d04c4accd4..d39dfc4e5d1 100644 --- a/src/goto-instrument/goto_program2code.h +++ b/src/goto-instrument/goto_program2code.h @@ -16,8 +16,9 @@ Author: Daniel Kroening, kroening@kroening.com class goto_program2codet { typedef std::list id_listt; - typedef std::unordered_set id_sett; - typedef std::map loopt; + typedef std::unordered_set id_sett; + typedef std::map + loopt; typedef std::unordered_map dead_mapt; typedef std::list > loop_last_stackt; diff --git a/src/goto-instrument/havoc_loops.cpp b/src/goto-instrument/havoc_loops.cpp index fe2266cfd7d..88cb37075ad 100644 --- a/src/goto-instrument/havoc_loops.cpp +++ b/src/goto-instrument/havoc_loops.cpp @@ -212,7 +212,8 @@ void havoc_loopst::get_modifies( // return value assignment if(lhs.is_not_nil()) - function_modifies.get_modifies_lhs(local_may_alias, *i_it, lhs, modifies); + function_modifies.get_modifies_lhs( + local_may_alias, *i_it, lhs, modifies); function_modifies(code_function_call.function(), modifies); } diff --git a/src/goto-instrument/interrupt.cpp b/src/goto-instrument/interrupt.cpp index 7517f83867e..8fa40380617 100644 --- a/src/goto-instrument/interrupt.cpp +++ b/src/goto-instrument/interrupt.cpp @@ -94,7 +94,7 @@ void interrupt( value_setst &value_sets, const symbol_tablet &symbol_table, #ifdef LOCAL_MAY - const goto_functionst::goto_functiont& goto_function, + const goto_functionst::goto_functiont &goto_function, #endif goto_programt &goto_program, const symbol_exprt &interrupt_handler, @@ -113,7 +113,7 @@ void interrupt( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) // potential race? bool race_on_read=potential_race_on_read(rw_set, isr_rw_set); @@ -209,7 +209,8 @@ symbol_exprt get_isr( symbol_tablet::symbolst::const_iterator s_it= symbol_table.symbols.find(m_it->second); - if(s_it==symbol_table.symbols.end()) continue; + if(s_it==symbol_table.symbols.end()) + continue; if(s_it->second.type.id()==ID_code) matches.push_back(s_it->second.symbol_expr()); diff --git a/src/goto-instrument/k_induction.cpp b/src/goto-instrument/k_induction.cpp index 0d62bd4a95d..92ab83e51b1 100644 --- a/src/goto-instrument/k_induction.cpp +++ b/src/goto-instrument/k_induction.cpp @@ -109,7 +109,8 @@ void k_inductiont::process_loop( // we can remove everything up to the first assertion for(goto_programt::targett t=loop_head; t!=loop_exit; t++) { - if(t->is_assert()) break; + if(t->is_assert()) + break; t->make_skip(); } @@ -122,7 +123,8 @@ void k_inductiont::process_loop( for(goto_programt::targett t=loop_head; t!=end; t++) { assert(t!=goto_function.body.instructions.end()); - if(t->is_assert()) t->type=ASSUME; + if(t->is_assert()) + t->type=ASSUME; } // assume the loop condition has become false diff --git a/src/goto-instrument/mmio.cpp b/src/goto-instrument/mmio.cpp index fbd2fc5989c..b66633146a0 100644 --- a/src/goto-instrument/mmio.cpp +++ b/src/goto-instrument/mmio.cpp @@ -28,6 +28,8 @@ Date: September 2011 #include #endif +#include "mmio.h" + /*******************************************************************\ Function: mmio @@ -44,7 +46,7 @@ void mmio( value_setst &value_sets, const symbol_tablet &symbol_table, #ifdef LOCAL_MAY - const goto_functionst::goto_functiont& goto_function, + const goto_functionst::goto_functiont &goto_function, #endif goto_programt &goto_program) { @@ -64,9 +66,10 @@ void mmio( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) - if(rw_set.empty()) continue; + if(rw_set.empty()) + continue; #if 0 goto_programt::instructiont original_instruction; @@ -82,7 +85,8 @@ void mmio( forall_rw_set_entries(e_it, rw_set) if(e_it->second.r) { - const shared_bufferst::varst &vars=shared_buffers(e_it->second.object); + const shared_bufferst::varst &vars= + shared_buffers(e_it->second.object); irep_idt choice0=shared_buffers.choice("0"); irep_idt choice1=shared_buffers.choice("1"); @@ -101,8 +105,10 @@ void mmio( exprt choice1_rhs=and_exprt(nondet_bool_expr, w_used1_expr); // throw 2 Boolean dice - shared_buffers.assignment(goto_program, i_it, location, choice0, choice0_rhs); - shared_buffers.assignment(goto_program, i_it, location, choice1, choice1_rhs); + shared_buffers.assignment( + goto_program, i_it, location, choice0, choice0_rhs); + shared_buffers.assignment( + goto_program, i_it, location, choice1, choice1_rhs); exprt lhs=symbol_exprt(e_it->second.object, vars.type); @@ -111,29 +117,46 @@ void mmio( if_exprt(choice1_expr, w_buff1_expr, lhs)); // write one of the buffer entries - shared_buffers.assignment(goto_program, i_it, location, e_it->second.object, value); + shared_buffers.assignment( + goto_program, i_it, location, e_it->second.object, value); // update 'used' flags exprt w_used0_rhs=if_exprt(choice0_expr, false_exprt(), w_used0_expr); - exprt w_used1_rhs=and_exprt(if_exprt(choice1_expr, false_exprt(), w_used1_expr), w_used0_expr); - - shared_buffers.assignment(goto_program, i_it, location, vars.w_used0, w_used0_rhs); - shared_buffers.assignment(goto_program, i_it, location, vars.w_used1, w_used1_rhs); + exprt w_used1_rhs= + and_exprt( + if_exprt( + choice1_expr, + false_exprt(), + w_used1_expr), + w_used0_expr); + + shared_buffers.assignment( + goto_program, i_it, location, vars.w_used0, w_used0_rhs); + shared_buffers.assignment( + goto_program, i_it, location, vars.w_used1, w_used1_rhs); } // now rotate the write buffers for anything that is written forall_rw_set_entries(e_it, rw_set) if(e_it->second.w) { - const shared_bufferst::varst &vars=shared_buffers(e_it->second.object); + const shared_bufferst::varst &vars= + shared_buffers(e_it->second.object); // w_used1=w_used0; w_used0=true; - shared_buffers.assignment(goto_program, i_it, location, vars.w_used1, vars.w_used0); - shared_buffers.assignment(goto_program, i_it, location, vars.w_used0, true_exprt()); + shared_buffers.assignment( + goto_program, i_it, location, vars.w_used1, vars.w_used0); + shared_buffers.assignment( + goto_program, i_it, location, vars.w_used0, true_exprt()); // w_buff1=w_buff0; w_buff0=RHS; - shared_buffers.assignment(goto_program, i_it, location, vars.w_buff1, vars.w_buff0); - shared_buffers.assignment(goto_program, i_it, location, vars.w_buff0, original_instruction.code.op1()); + shared_buffers.assignment( + goto_program, i_it, location, vars.w_buff1, vars.w_buff0); + shared_buffers.assignment( + goto_program, + i_it, location, + vars.w_buff0, + original_instruction.code.op1()); } // ATOMIC_END diff --git a/src/goto-instrument/model_argc_argv.cpp b/src/goto-instrument/model_argc_argv.cpp index eb93a16f9bd..113c6d46a81 100644 --- a/src/goto-instrument/model_argc_argv.cpp +++ b/src/goto-instrument/model_argc_argv.cpp @@ -93,25 +93,24 @@ bool model_argc_argv( // guaranteed by POSIX (_POSIX_ARG_MAX): // http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html std::ostringstream oss; - oss << - "int ARGC;\n\ - char *ARGV[1];\n\ - void " CPROVER_PREFIX "initialize()\n\ - {\n\ - unsigned next=0u;\n\ - " CPROVER_PREFIX "assume(ARGC>=1);\n\ - " CPROVER_PREFIX "assume(ARGC<=" << max_argc << ");\n\ - " CPROVER_PREFIX "thread_local static char arg_string[4096];\n\ - for(unsigned i=0u; i=1);\n" + << " " CPROVER_PREFIX "assume(ARGC<=" << max_argc << ");\n" + << " " CPROVER_PREFIX "thread_local static char arg_string[4096];\n" + << " for(unsigned i=0u; i object_id_sett; diff --git a/src/goto-instrument/points_to.cpp b/src/goto-instrument/points_to.cpp index aef33d57ed0..da29e800292 100644 --- a/src/goto-instrument/points_to.cpp +++ b/src/goto-instrument/points_to.cpp @@ -101,7 +101,6 @@ bool points_tot::transform(const cfgt::nodet &e) case ASSIGN: { // const code_assignt &code_assign=to_code_assign(instruction.code); - } break; @@ -109,7 +108,9 @@ bool points_tot::transform(const cfgt::nodet &e) // these are like assignments for the arguments break; - default:; + default: + { + } } return result; diff --git a/src/goto-instrument/points_to.h b/src/goto-instrument/points_to.h index 5b605cee337..4805de2343c 100644 --- a/src/goto-instrument/points_to.h +++ b/src/goto-instrument/points_to.h @@ -31,7 +31,7 @@ class points_tot { } - inline void operator()(goto_functionst &goto_functions) + void operator()(goto_functionst &goto_functions) { // build the CFG data structure cfg(goto_functions); @@ -40,22 +40,16 @@ class points_tot fixedpoint(); } - inline const object_id_sett &operator[](const object_idt &object_id) + const object_id_sett &operator[](const object_idt &object_id) { value_mapt::const_iterator it=value_map.find(object_id); - if(it!=value_map.end()) return it->second; + if(it!=value_map.end()) + return it->second; return empty_set; } void output(std::ostream &out) const; - inline friend std::ostream &operator << ( - std::ostream &out, const points_tot &points_to) - { - points_to.output(out); - return out; - } - protected: typedef cfg_baset cfgt; cfgt cfg; @@ -69,6 +63,12 @@ class points_tot const object_id_sett empty_set; }; -std::ostream &operator << (std::ostream &, const points_tot &); +inline std::ostream &operator<<( + std::ostream &out, + const points_tot &points_to) +{ + points_to.output(out); + return out; +} #endif // CPROVER_GOTO_INSTRUMENT_POINTS_TO_H diff --git a/src/goto-instrument/race_check.cpp b/src/goto-instrument/race_check.cpp index 3ca605b55c6..8f26d89bf56 100644 --- a/src/goto-instrument/race_check.cpp +++ b/src/goto-instrument/race_check.cpp @@ -25,12 +25,17 @@ Date: February 2006 #ifdef LOCAL_MAY #include +#define L_M_ARG(x) x, +#define L_M_LAST_ARG(x) , x +#else +#define L_M_ARG(x) +#define L_M_LAST_ARG(x) #endif class w_guardst { public: - w_guardst(symbol_tablet &_symbol_table):symbol_table(_symbol_table) + explicit w_guardst(symbol_tablet &_symbol_table):symbol_table(_symbol_table) { } @@ -232,9 +237,7 @@ Function: race_check void race_check( value_setst &value_sets, symbol_tablet &symbol_table, -#ifdef LOCAL_MAY - const goto_functionst::goto_functiont& goto_function, -#endif + L_M_ARG(const goto_functionst::goto_functiont &goto_function) goto_programt &goto_program, w_guardst &w_guards) { @@ -250,11 +253,7 @@ void race_check( if(instruction.is_assign()) { - rw_set_loct rw_set(ns, value_sets, i_it -#ifdef LOCAL_MAY - , local_may -#endif - ); + rw_set_loct rw_set(ns, value_sets, i_it L_M_LAST_ARG(local_may)); if(!has_shared_entries(ns, rw_set)) continue; @@ -268,7 +267,8 @@ void race_check( // now add assignments for what is written -- set forall_rw_set_w_entries(e_it, rw_set) { - if(!is_shared(ns, e_it->second.symbol_expr)) continue; + if(!is_shared(ns, e_it->second.symbol_expr)) + continue; goto_programt::targett t=goto_program.insert_before(i_it); @@ -291,7 +291,8 @@ void race_check( // now add assignments for what is written -- reset forall_rw_set_w_entries(e_it, rw_set) { - if(!is_shared(ns, e_it->second.symbol_expr)) continue; + if(!is_shared(ns, e_it->second.symbol_expr)) + continue; goto_programt::targett t=goto_program.insert_before(i_it); @@ -307,7 +308,8 @@ void race_check( // now add assertions for what is read and written forall_rw_set_r_entries(e_it, rw_set) { - if(!is_shared(ns, e_it->second.symbol_expr)) continue; + if(!is_shared(ns, e_it->second.symbol_expr)) + continue; goto_programt::targett t=goto_program.insert_before(i_it); @@ -319,7 +321,8 @@ void race_check( forall_rw_set_w_entries(e_it, rw_set) { - if(!is_shared(ns, e_it->second.symbol_expr)) continue; + if(!is_shared(ns, e_it->second.symbol_expr)) + continue; goto_programt::targett t=goto_program.insert_before(i_it); @@ -352,17 +355,18 @@ void race_check( value_setst &value_sets, symbol_tablet &symbol_table, #ifdef LOCAL_MAY - const goto_functionst::goto_functiont& goto_function, + const goto_functionst::goto_functiont &goto_function, #endif goto_programt &goto_program) { w_guardst w_guards(symbol_table); - race_check(value_sets, symbol_table, -#ifdef LOCAL_MAY - goto_function, -#endif - goto_program, w_guards); + race_check( + value_sets, + symbol_table, + L_M_ARG(goto_function) + goto_program, + w_guards); w_guards.add_initialization(goto_program); goto_program.update(); @@ -390,18 +394,19 @@ void race_check( Forall_goto_functions(f_it, goto_functions) if(f_it->first!=goto_functionst::entry_point() && f_it->first!=CPROVER_PREFIX "initialize") - race_check(value_sets, symbol_table, -#ifdef LOCAL_MAY - f_it->second, -#endif - f_it->second.body, w_guards); + race_check( + value_sets, + symbol_table, + L_M_ARG(f_it->second) + f_it->second.body, + w_guards); // get "main" goto_functionst::function_mapt::iterator m_it=goto_functions.function_map.find(goto_functions.entry_point()); if(m_it==goto_functions.function_map.end()) - throw "Race check instrumentation needs an entry point"; + throw "race check instrumentation needs an entry point"; goto_programt &main=m_it->second.body; w_guards.add_initialization(main); diff --git a/src/goto-instrument/race_check.h b/src/goto-instrument/race_check.h index 75495c87f78..1c7cd3e5be8 100644 --- a/src/goto-instrument/race_check.h +++ b/src/goto-instrument/race_check.h @@ -20,7 +20,7 @@ void race_check( value_setst &value_sets, class symbol_tablet &symbol_table, #ifdef LOCAL_MAY - const goto_functionst::goto_functiont& goto_function, + const goto_functionst::goto_functiont &goto_function, #endif goto_programt &goto_program ); diff --git a/src/goto-instrument/reachability_slicer.cpp b/src/goto-instrument/reachability_slicer.cpp index c502c2a33ae..231ae40cde9 100644 --- a/src/goto-instrument/reachability_slicer.cpp +++ b/src/goto-instrument/reachability_slicer.cpp @@ -47,7 +47,8 @@ void reachability_slicert::fixedpoint_assertions( cfgt::nodet &node=cfg[e]; queue.pop(); - if(node.reaches_assertion) continue; + if(node.reaches_assertion) + continue; node.reaches_assertion=true; diff --git a/src/goto-instrument/rw_set.cpp b/src/goto-instrument/rw_set.cpp index 0a3408f4df7..531a3ea70b4 100644 --- a/src/goto-instrument/rw_set.cpp +++ b/src/goto-instrument/rw_set.cpp @@ -189,8 +189,8 @@ void _rw_set_loct::read_write_rec( if(it->id()==ID_unknown) { /* as an under-approximation */ - //std::cout << "Sorry, LOCAL_MAY too imprecise. Omitting some variables." - // << std::endl; + // std::cout << "Sorry, LOCAL_MAY too imprecise. " + // << Omitting some variables." << std::endl; irep_idt object=ID_unknown; entryt &entry=r_entries[object]; @@ -219,7 +219,6 @@ void _rw_set_loct::read_write_rec( else if(expr.id()==ID_address_of) { assert(expr.operands().size()==1); - } else if(expr.id()==ID_if) { @@ -269,8 +268,9 @@ void rw_set_functiont::compute_rec(const exprt &function) #ifdef LOCAL_MAY local_may_aliast local_may(f_it->second); #if 0 - for(goto_functionst::function_mapt::const_iterator g_it=goto_functions.function_map.begin(); - g_it!=goto_functions.function_map.end(); ++g_it) + for(goto_functionst::function_mapt::const_iterator + g_it=goto_functions.function_map.begin(); + g_it!=goto_functions.function_map.end(); ++g_it) local_may(g_it->second); #endif #endif @@ -281,7 +281,7 @@ void rw_set_functiont::compute_rec(const exprt &function) #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) } } } diff --git a/src/goto-instrument/rw_set.h b/src/goto-instrument/rw_set.h index 4719ca6ed3d..9322efbfc3e 100644 --- a/src/goto-instrument/rw_set.h +++ b/src/goto-instrument/rw_set.h @@ -32,7 +32,7 @@ Date: February 2006 class rw_set_baset { public: - rw_set_baset(const namespacet &_ns) + explicit rw_set_baset(const namespacet &_ns) :ns(_ns) { } @@ -59,24 +59,24 @@ class rw_set_baset std::swap(other.w_entries, w_entries); } - inline rw_set_baset &operator += (const rw_set_baset &other) + rw_set_baset &operator+=(const rw_set_baset &other) { r_entries.insert(other.r_entries.begin(), other.r_entries.end()); w_entries.insert(other.w_entries.begin(), other.w_entries.end()); return *this; } - inline bool empty() const + bool empty() const { return r_entries.empty() && w_entries.empty(); } - inline bool has_w_entry(irep_idt object) const + bool has_w_entry(irep_idt object) const { return w_entries.find(object)!=w_entries.end(); } - inline bool has_r_entry(irep_idt object) const + bool has_r_entry(irep_idt object) const { return r_entries.find(object)!=r_entries.end(); } @@ -84,14 +84,14 @@ class rw_set_baset void output(std::ostream &out) const; protected: - virtual void track_deref(const entryt& entry, bool read) {} + virtual void track_deref(const entryt &entry, bool read) {} virtual void set_track_deref() {} virtual void reset_track_deref() {} const namespacet &ns; }; -extern inline std::ostream & operator << ( +inline std::ostream &operator<<( std::ostream &out, const rw_set_baset &rw_set) { rw_set.output(out); @@ -111,18 +111,24 @@ extern inline std::ostream & operator << ( class _rw_set_loct:public rw_set_baset { public: - inline _rw_set_loct(const namespacet &_ns, - value_setst &_value_sets, - goto_programt::const_targett _target #ifdef LOCAL_MAY - , local_may_aliast &may -#endif - ): + _rw_set_loct( + const namespacet &_ns, + value_setst &_value_sets, + goto_programt::const_targett _target, + local_may_aliast &may): + rw_set_baset(_ns), + value_sets(_value_sets), + target(_target), + local_may(may) +#else + _rw_set_loct( + const namespacet &_ns, + value_setst &_value_sets, + goto_programt::const_targett _target): rw_set_baset(_ns), value_sets(_value_sets), target(_target) -#ifdef LOCAL_MAY - , local_may(may) #endif { } @@ -134,20 +140,20 @@ class _rw_set_loct:public rw_set_baset const goto_programt::const_targett target; #ifdef LOCAL_MAY - local_may_aliast& local_may; + local_may_aliast &local_may; #endif - inline void read(const exprt &expr) + void read(const exprt &expr) { read_write_rec(expr, true, false, "", guardt()); } - inline void read(const exprt &expr, const guardt &guard) + void read(const exprt &expr, const guardt &guard) { read_write_rec(expr, true, false, "", guard); } - inline void write(const exprt &expr) + void write(const exprt &expr) { read_write_rec(expr, false, true, "", guardt()); } @@ -166,18 +172,20 @@ class _rw_set_loct:public rw_set_baset class rw_set_loct:public _rw_set_loct { public: - inline rw_set_loct(const namespacet &_ns, - value_setst &_value_sets, - goto_programt::const_targett _target -#ifdef LOCAL_MAY - , local_may_aliast &may -#endif - ): - _rw_set_loct(_ns, _value_sets, _target #ifdef LOCAL_MAY - , may + rw_set_loct( + const namespacet &_ns, + value_setst &_value_sets, + goto_programt::const_targett _target, + local_may_aliast &may): + _rw_set_loct(_ns, _value_sets, _target, may) +#else + rw_set_loct( + const namespacet &_ns, + value_setst &_value_sets, + goto_programt::const_targett _target): + _rw_set_loct(_ns, _value_sets, _target) #endif - ) { compute(); } @@ -226,18 +234,22 @@ class rw_set_with_trackt:public _rw_set_loct /* is var a read or write */ std::set set_reads; - inline rw_set_with_trackt( +#ifdef LOCAL_MAY + rw_set_with_trackt( const namespacet &_ns, value_setst &_value_sets, - goto_programt::const_targett _target -#ifdef LOCAL_MAY - , local_may_aliast& may -#endif - ) : _rw_set_loct(_ns, _value_sets, _target -#ifdef LOCAL_MAY - , may + goto_programt::const_targett _target, + local_may_aliast &may): + _rw_set_loct(_ns, _value_sets, _target, may), + dereferencing(false) +#else + rw_set_with_trackt( + const namespacet &_ns, + value_setst &_value_sets, + goto_programt::const_targett _target): + _rw_set_loct(_ns, _value_sets, _target), + dereferencing(false) #endif - ), dereferencing(false) { compute(); } @@ -249,7 +261,8 @@ class rw_set_with_trackt:public _rw_set_loct bool dereferencing; std::vector dereferenced; - void track_deref(const entryt& entry, bool read) { + void track_deref(const entryt &entry, bool read) + { if(dereferencing && dereferenced.size()==0) { dereferenced.insert(dereferenced.begin(), entry); @@ -257,15 +270,17 @@ class rw_set_with_trackt:public _rw_set_loct set_reads.insert(entry.object); } else if(dereferencing && dereferenced.size()>0) - dereferenced_from.insert(std::make_pair(entry.object, - dereferenced.front().object)); + dereferenced_from.insert( + std::make_pair(entry.object, dereferenced.front().object)); } - void set_track_deref() { + void set_track_deref() + { dereferencing=true; } - void reset_track_deref() { + void reset_track_deref() + { dereferencing=false; dereferenced.clear(); } diff --git a/src/goto-instrument/show_locations.cpp b/src/goto-instrument/show_locations.cpp index 6527a29d437..ef31898e294 100644 --- a/src/goto-instrument/show_locations.cpp +++ b/src/goto-instrument/show_locations.cpp @@ -52,7 +52,8 @@ void show_locations( l.new_element("line").data=id2string(source_location.get_line()); l.new_element("file").data=id2string(source_location.get_file()); - l.new_element("function").data=id2string(source_location.get_function()); + l.new_element("function").data= + id2string(source_location.get_function()); std::cout << xml << std::endl; } diff --git a/src/goto-instrument/skip_loops.cpp b/src/goto-instrument/skip_loops.cpp index 1658b5890d3..f79fae9d7b4 100644 --- a/src/goto-instrument/skip_loops.cpp +++ b/src/goto-instrument/skip_loops.cpp @@ -38,12 +38,16 @@ static bool skip_loops( loop_idst::const_iterator l_it=loop_ids.begin(); Forall_goto_program_instructions(it, goto_program) { - if(l_it==loop_ids.end()) break; - if(!it->is_backwards_goto()) continue; + if(l_it==loop_ids.end()) + break; + if(!it->is_backwards_goto()) + continue; const unsigned loop_id=it->loop_number; - if(*l_itloop_id) continue; + if(*l_itloop_id) + continue; goto_programt::targett loop_head=it->get_target(); goto_programt::targett next=it; @@ -91,14 +95,16 @@ static bool parse_loop_ids( std::string val=loop_ids.substr(idx, next-idx); std::string::size_type delim=val.rfind("."); - if(delim==std::string::npos) return true; + if(delim==std::string::npos) + return true; std::string fn=val.substr(0, delim); unsigned nr=safe_string2unsigned(val.substr(delim+1)); loop_map[fn].insert(nr); - if(next==std::string::npos) break; + if(next==std::string::npos) + break; idx=next; } diff --git a/src/goto-instrument/stack_depth.cpp b/src/goto-instrument/stack_depth.cpp index 36f0d486773..0c5e0f81146 100644 --- a/src/goto-instrument/stack_depth.cpp +++ b/src/goto-instrument/stack_depth.cpp @@ -79,7 +79,8 @@ void stack_depth( assert_ins->source_location=first->source_location; assert_ins->function=first->function; - assert_ins->source_location.set_comment("Stack depth exceeds "+std::to_string(i_depth)); + assert_ins->source_location.set_comment( + "Stack depth exceeds "+std::to_string(i_depth)); assert_ins->source_location.set_property_class("stack-depth"); goto_programt::targett plus_ins=goto_program.insert_before(first); diff --git a/src/goto-instrument/thread_instrumentation.cpp b/src/goto-instrument/thread_instrumentation.cpp index 602796db094..4c23234d051 100644 --- a/src/goto-instrument/thread_instrumentation.cpp +++ b/src/goto-instrument/thread_instrumentation.cpp @@ -22,8 +22,7 @@ Function: has_start_thread \*******************************************************************/ -namespace { -bool has_start_thread(const goto_programt &goto_program) +static bool has_start_thread(const goto_programt &goto_program) { for(const auto &instruction : goto_program.instructions) if(instruction.is_start_thread()) @@ -31,7 +30,6 @@ bool has_start_thread(const goto_programt &goto_program) return false; } -} /*******************************************************************\ @@ -47,7 +45,8 @@ Function: thread_exit_instrumentation void thread_exit_instrumentation(goto_programt &goto_program) { - if(goto_program.instructions.empty()) return; + if(goto_program.instructions.empty()) + return; // add assertion that all may flags for mutex-locked are gone // at the end @@ -103,7 +102,8 @@ void thread_exit_instrumentation(goto_functionst &goto_functions) for(const auto &instruction : f_it->second.body.instructions) if(instruction.is_function_call()) { - const exprt &function=to_code_function_call(instruction.code).function(); + const exprt &function= + to_code_function_call(instruction.code).function(); if(function.id()==ID_symbol) thread_fkts.insert(to_symbol_expr(function).get_identifier()); } diff --git a/src/goto-instrument/uninitialized.cpp b/src/goto-instrument/uninitialized.cpp index 75a1eb10a08..c048a518440 100644 --- a/src/goto-instrument/uninitialized.cpp +++ b/src/goto-instrument/uninitialized.cpp @@ -14,6 +14,8 @@ Date: January 2010 #include +#include "uninitialized.h" + /*******************************************************************\ Class: uninitializedt @@ -25,7 +27,7 @@ Date: January 2010 class uninitializedt { public: - uninitializedt(symbol_tablet &_symbol_table): + explicit uninitializedt(symbol_tablet &_symbol_table): symbol_table(_symbol_table), ns(_symbol_table) { @@ -162,7 +164,7 @@ void uninitializedt::add_assertions(goto_programt &goto_program) std::list written=objects_written(instruction); // if(instruction.is_function_call()) - //const code_function_callt &code_function_call= + // const code_function_callt &code_function_call= // to_code_function_call(instruction.code); const std::set &uninitialized= @@ -185,7 +187,8 @@ void uninitializedt::add_assertions(goto_programt &goto_program) assertion.type=ASSERT; assertion.guard=symbol_exprt(new_identifier, bool_typet()); assertion.source_location=instruction.source_location; - assertion.source_location.set_comment("use of uninitialized local variable"); + assertion.source_location.set_comment( + "use of uninitialized local variable"); assertion.source_location.set_property_class("uninitialized local"); goto_program.insert_before_swap(i_it, assertion); @@ -276,5 +279,4 @@ void show_uninitialized( uninitialized_analysis.output(ns, f_it->second.body, out); } } - } diff --git a/src/goto-instrument/unwind.cpp b/src/goto-instrument/unwind.cpp index b6ae3e79555..1c6762c31f4 100644 --- a/src/goto-instrument/unwind.cpp +++ b/src/goto-instrument/unwind.cpp @@ -7,8 +7,6 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG - #ifdef DEBUG #include #endif @@ -331,7 +329,7 @@ void goto_unwindt::unwind( // after unwound part copies.destructive_append(rest_program); - + // now insert copies before loop_exit goto_program.destructive_insert(loop_exit, copies); } @@ -355,7 +353,7 @@ int goto_unwindt::get_k( const unwind_sett &unwind_set) const { assert(global_k>=-1); - + unwind_sett::const_iterator f_it=unwind_set.find(func); if(f_it==unwind_set.end()) return global_k; diff --git a/src/goto-instrument/unwind.h b/src/goto-instrument/unwind.h index 48f6c90df59..7240c3a4c61 100644 --- a/src/goto-instrument/unwind.h +++ b/src/goto-instrument/unwind.h @@ -57,7 +57,7 @@ class goto_unwindt const unwind_strategyt unwind_strategy=PARTIAL) { const unwind_sett unwind_set; - operator()(goto_functions, unwind_set, (int)k, unwind_strategy); + operator()(goto_functions, unwind_set, k, unwind_strategy); } void operator()( diff --git a/src/goto-instrument/wmm/abstract_event.cpp b/src/goto-instrument/wmm/abstract_event.cpp index 9e4df2668fa..c02a4a4d1f7 100644 --- a/src/goto-instrument/wmm/abstract_event.cpp +++ b/src/goto-instrument/wmm/abstract_event.cpp @@ -22,7 +22,7 @@ Function: abstract_eventt::unsafe_pair_lwfence_param \*******************************************************************/ -bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt& next, +bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt &next, memory_modelt model, bool lwsync_met) const { @@ -47,17 +47,18 @@ bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt& next, && !(operation==Write && next.operation==Write && lwsync_met)); case RMO: - return (thread==next.thread + return + thread==next.thread && /* lwsyncWW -> mfenceWW */ - && !(operation==Write && next.operation==Write && lwsync_met) + !(operation==Write && next.operation==Write && lwsync_met) && /* lwsyncRW -> mfenceRW */ - && !(operation==Read && next.operation==Write && lwsync_met) + !(operation==Read && next.operation==Write && lwsync_met) && /* lwsyncRR -> mfenceRR */ - && !(operation==Read && next.operation==Read && lwsync_met) + !(operation==Read && next.operation==Read && lwsync_met) && /* if posWW, wsi maintained by the processor */ - && !(variable==next.variable && operation==Write && next.operation==Write) + !(variable==next.variable && operation==Write && next.operation==Write) && /* if posRW, fri maintained by the processor */ - && !(variable==next.variable && operation==Read && next.operation==Write)); + !(variable==next.variable && operation==Read && next.operation==Write); case Power: return ((thread==next.thread @@ -73,7 +74,9 @@ bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt& next, || (thread!=next.thread && operation==Write && next.operation==Read && variable==next.variable)); - case Unknown:; + case Unknown: + { + } } assert(false); /* unknown memory model */ @@ -92,7 +95,7 @@ Function: abstract_eventt::unsafe_pair_asm \*******************************************************************/ -bool abstract_eventt::unsafe_pair_asm(const abstract_eventt& next, +bool abstract_eventt::unsafe_pair_asm(const abstract_eventt &next, memory_modelt model, unsigned char met) const { @@ -115,22 +118,30 @@ bool abstract_eventt::unsafe_pair_asm(const abstract_eventt& next, return (thread==next.thread && operation==Write && (met&3)==0); case RMO: - return (thread==next.thread - && (met&15)==0 + return + thread==next.thread && + (met&15)==0 && /* if posWW, wsi maintained by the processor */ - && !(variable==next.variable && operation==Write && next.operation==Write) + !(variable==next.variable && operation==Write && next.operation==Write) && /* if posRW, fri maintained by the processor */ - && !(variable==next.variable && operation==Read && next.operation==Write)); + !(variable==next.variable && operation==Read && next.operation==Write); case Power: - return ((thread==next.thread - && (met&15)==0 - /* if posWW, wsi maintained by the processor */ - && (variable!=next.variable || operation!=Write || next.operation!=Write)) + return + (thread==next.thread && + (met&15)==0 && + /* if posWW, wsi maintained by the processor */ + (variable!=next.variable || + operation!=Write || + next.operation!=Write)) || /* rfe */ - || (thread!=next.thread && operation==Write && next.operation==Read - && variable==next.variable)); - - case Unknown:; + (thread!=next.thread && + operation==Write && + next.operation==Read && + variable==next.variable); + + case Unknown: + { + } } assert(false); /* unknown memory model */ diff --git a/src/goto-instrument/wmm/abstract_event.h b/src/goto-instrument/wmm/abstract_event.h index c94708f30fe..db76a92f1f4 100644 --- a/src/goto-instrument/wmm/abstract_event.h +++ b/src/goto-instrument/wmm/abstract_event.h @@ -23,7 +23,7 @@ Date: 2012 class abstract_eventt:public graph_nodet { protected: - bool unsafe_pair_lwfence_param(const abstract_eventt& next, + bool unsafe_pair_lwfence_param(const abstract_eventt &next, memory_modelt model, bool lwsync_met) const; public: @@ -58,17 +58,38 @@ class abstract_eventt:public graph_nodet { } - abstract_eventt(operationt _op, unsigned _th, irep_idt _var, - unsigned _id, source_locationt _loc, bool _local, - bool WRf, bool WWf, bool RRf, bool RWf, bool WWc, bool RWc, bool RRc) - :operation(_op), thread(_th), variable(_var), id(_id), - source_location(_loc), local(_local), WRfence(RWf), WWfence(WWf), RRfence(RRf), - RWfence(WRf), WWcumul(WWc), RWcumul(RWc), RRcumul(RRc) + abstract_eventt( + operationt _op, + unsigned _th, + irep_idt _var, + unsigned _id, + source_locationt _loc, + bool _local, + bool WRf, + bool WWf, + bool RRf, + bool RWf, + bool WWc, + bool RWc, + bool RRc): + operation(_op), + thread(_th), + variable(_var), + id(_id), + source_location(_loc), + local(_local), + WRfence(RWf), + WWfence(WWf), + RRfence(RRf), + RWfence(WRf), + WWcumul(WWc), + RWcumul(RWc), + RRcumul(RRc) { } /* post declaration (through graph) -- doesn't copy */ - void operator()(const abstract_eventt& other) + void operator()(const abstract_eventt &other) { operation=other.operation; thread=other.thread; @@ -78,22 +99,19 @@ class abstract_eventt:public graph_nodet local=other.local; } - inline bool operator==(const abstract_eventt& other) const + bool operator==(const abstract_eventt &other) const { return (id == other.id); } - inline bool operator<(const abstract_eventt& other) const + bool operator<(const abstract_eventt &other) const { return (id < other.id); } - inline bool is_fence() const { - return operation==Fence || operation==Lwfence || operation==ASMfence;} - - friend std::ostream& operator<<(std::ostream& s, const abstract_eventt& e) + bool is_fence() const { - return s << e.get_operation() << e.variable; + return operation==Fence || operation==Lwfence || operation==ASMfence; } /* checks the safety of the pair locally (i.e., w/o taking fences @@ -101,14 +119,14 @@ class abstract_eventt:public graph_nodet critical cycle for this) */ bool unsafe_pair(const abstract_eventt &next, memory_modelt model) const { - return unsafe_pair_lwfence_param(next,model,false); + return unsafe_pair_lwfence_param(next, model, false); } bool unsafe_pair_lwfence( const abstract_eventt &next, memory_modelt model) const { - return unsafe_pair_lwfence_param(next,model,true); + return unsafe_pair_lwfence_param(next, model, true); } bool unsafe_pair_asm( @@ -130,16 +148,20 @@ class abstract_eventt:public graph_nodet return "?"; } - bool is_corresponding_fence(const abstract_eventt& first, - const abstract_eventt& second) const + bool is_corresponding_fence(const abstract_eventt &first, + const abstract_eventt &second) const { - return (WRfence && first.operation==Write && second.operation==Read) - || ((WWfence||WWcumul) && first.operation==Write - && second.operation==Write) - || ((RWfence||RWcumul) && first.operation==Read - && second.operation==Write) - || ((RRfence||RRcumul) && first.operation==Read - && second.operation==Read); + return + (WRfence && first.operation==Write && second.operation==Read) || + ((WWfence || WWcumul) && + first.operation==Write && + second.operation==Write) || + ((RWfence || RWcumul) && + first.operation==Read && + second.operation==Write) || + ((RRfence || RRcumul) && + first.operation==Read && + second.operation==Read); } bool is_direct() const { return WWfence || WRfence || RRfence || RWfence; } @@ -152,4 +174,12 @@ class abstract_eventt:public graph_nodet return value; } }; + +inline std::ostream &operator<<( + std::ostream &s, + const abstract_eventt &e) +{ + return s << e.get_operation() << e.variable; +} + #endif // CPROVER_GOTO_INSTRUMENT_WMM_ABSTRACT_EVENT_H diff --git a/src/goto-instrument/wmm/cycle_collection.cpp b/src/goto-instrument/wmm/cycle_collection.cpp index 5f39486cc2d..1239aef6fa8 100644 --- a/src/goto-instrument/wmm/cycle_collection.cpp +++ b/src/goto-instrument/wmm/cycle_collection.cpp @@ -25,10 +25,10 @@ Function: event_grapht::graph_explorert::filter_thin_air \*******************************************************************/ void event_grapht::graph_explorert::filter_thin_air( - std::set& set_of_cycles) + std::set &set_of_cycles) { for(std::set::const_iterator it=set_of_cycles.begin(); - it!=set_of_cycles.end();) + it!=set_of_cycles.end(); ) { std::set::const_iterator next=it; ++next; @@ -46,8 +46,8 @@ void event_grapht::graph_explorert::filter_thin_air( #ifdef DEBUG for(std::set::const_iterator it=thin_air_events.begin(); - it!=thin_air_events.end(); - ++it) + it!=thin_air_events.end(); + ++it) egraph.message.debug()<& set_of_cycles, + std::set &set_of_cycles, memory_modelt model) { /* all the events initially unmarked */ - for(std::size_t i = 0; i* order=0; /* on Power, rfe pairs are also potentially unsafe */ @@ -151,10 +151,12 @@ event_grapht::critical_cyclet event_grapht::graph_explorert::extract_cycle( event_idt current_vertex=stack.top(); stack.pop(); - egraph.message.debug() << "extract: " << egraph[current_vertex].get_operation() - << egraph[current_vertex].variable << "@" - << egraph[current_vertex].thread << "~" << egraph[current_vertex].local - << messaget::eom; + egraph.message.debug() << "extract: " + << egraph[current_vertex].get_operation() + << egraph[current_vertex].variable << "@" + << egraph[current_vertex].thread << "~" + << egraph[current_vertex].local + << messaget::eom; if(!new_cycle.has_user_defined_fence) { @@ -199,7 +201,7 @@ bool event_grapht::graph_explorert::backtrack( memory_modelt model) { #ifdef DEBUG - for(std::size_t i=0; i<80; egraph.message.debug() << "-", ++i); + egraph.message.debug() << std::string(80, '-'); egraph.message.debug() << messaget::eom; egraph.message.debug() << "marked size:" << marked_stack.size() << messaget::eom; @@ -244,7 +246,7 @@ bool event_grapht::graph_explorert::backtrack( bool not_thin_air=true; - const abstract_eventt& this_vertex=egraph[vertex]; + const abstract_eventt &this_vertex=egraph[vertex]; /* if a thread starts with variable x, the last event of this thread in the cycle cannot be with x */ @@ -262,18 +264,19 @@ bool event_grapht::graph_explorert::backtrack( { /* only the lwsyncWR can be interpreted as poWR (i.e., skip of the fence) */ if(lwfence_met && this_vertex.operation!=abstract_eventt::Read) - return false; //{no_comm=true;get_com_only=false;}//return false; + return false; // {no_comm=true;get_com_only=false;}//return false; bool has_to_be_unsafe_updated=false; // TODO: propagate this constraint within the optimisation // -- no optimisation can strongly affect performances /* tab[] can appear several times */ - if(egraph.ignore_arrays || id2string(this_vertex.variable).find("[]")==std::string::npos) + if(egraph.ignore_arrays || + id2string(this_vertex.variable).find("[]")==std::string::npos) { /* no more than 4 events per thread */ - if(this_vertex.operation!=abstract_eventt::Fence - && this_vertex.operation!=abstract_eventt::Lwfence - && this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::Fence && + this_vertex.operation!=abstract_eventt::Lwfence && + this_vertex.operation!=abstract_eventt::ASMfence) { if(events_per_thread[this_vertex.thread]==4) return false; @@ -288,11 +291,11 @@ bool event_grapht::graph_explorert::backtrack( re-order also the two writes, which is not permitted on TSO. */ if(has_to_be_unsafe && point_stack.size() >= 2) { - const event_idt previous = point_stack.top(); + const event_idt previous=point_stack.top(); point_stack.pop(); - const event_idt preprevious = point_stack.top(); + const event_idt preprevious=point_stack.top(); point_stack.push(previous); - if(!egraph[preprevious].unsafe_pair(this_vertex,model) + if(!egraph[preprevious].unsafe_pair(this_vertex, model) && !(this_vertex.operation==abstract_eventt::Fence || egraph[preprevious].operation==abstract_eventt::Fence || this_vertex.operation==abstract_eventt::Lwfence @@ -303,7 +306,7 @@ bool event_grapht::graph_explorert::backtrack( } } - has_to_be_unsafe_updated = has_to_be_unsafe; + has_to_be_unsafe_updated=has_to_be_unsafe; /* constraint 1.a: there is at most one pair of events per thread with different variables. Given that we cannot have more than @@ -311,56 +314,58 @@ bool event_grapht::graph_explorert::backtrack( this means that we can have at most 2 consecutive events by po with the same variable, and two variables per thread (fences are not taken into account) */ - if(!point_stack.empty() && egraph.are_po_ordered(point_stack.top(),vertex) - && this_vertex.operation!=abstract_eventt::Fence - && this_vertex.operation!=abstract_eventt::Lwfence - && this_vertex.operation!=abstract_eventt::ASMfence - && this_vertex.variable==egraph[point_stack.top()].variable) + if(!point_stack.empty() && + egraph.are_po_ordered(point_stack.top(), vertex) && + this_vertex.operation!=abstract_eventt::Fence && + this_vertex.operation!=abstract_eventt::Lwfence && + this_vertex.operation!=abstract_eventt::ASMfence && + this_vertex.variable==egraph[point_stack.top()].variable) { if(same_var_pair || - (this_vertex.operation==abstract_eventt::Read - && egraph[point_stack.top()].operation==abstract_eventt::Read)) + (this_vertex.operation==abstract_eventt::Read && + egraph[point_stack.top()].operation==abstract_eventt::Read)) { events_per_thread[this_vertex.thread]--; - return false; //{no_comm=true;get_com_only=false;} //return false; + return false; // {no_comm=true;get_com_only=false;} //return false; } else { - same_var_pair_updated = true; + same_var_pair_updated=true; if(events_per_thread[this_vertex.thread]>=3) - get_com_only = true; + get_com_only=true; } } /* constraint 1.b */ - if(!point_stack.empty() && egraph.are_po_ordered(point_stack.top(),vertex) - && this_vertex.operation!=abstract_eventt::Fence - && this_vertex.operation!=abstract_eventt::Lwfence - && this_vertex.operation!=abstract_eventt::ASMfence - && this_vertex.variable!=egraph[point_stack.top()].variable) + if(!point_stack.empty() && + egraph.are_po_ordered(point_stack.top(), vertex) && + this_vertex.operation!=abstract_eventt::Fence && + this_vertex.operation!=abstract_eventt::Lwfence && + this_vertex.operation!=abstract_eventt::ASMfence && + this_vertex.variable!=egraph[point_stack.top()].variable) { - same_var_pair_updated = false; + same_var_pair_updated=false; } /* constraint 2: per variable, either W W, R W, W R, or R W R */ - if(this_vertex.operation!=abstract_eventt::Fence - && this_vertex.operation!=abstract_eventt::Lwfence - && this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::Fence && + this_vertex.operation!=abstract_eventt::Lwfence && + this_vertex.operation!=abstract_eventt::ASMfence) { - const unsigned char nb_writes = writes_per_variable[this_vertex.variable]; - const unsigned char nb_reads = reads_per_variable[this_vertex.variable]; + const unsigned char nb_writes=writes_per_variable[this_vertex.variable]; + const unsigned char nb_reads=reads_per_variable[this_vertex.variable]; if(nb_writes+nb_reads==3) { events_per_thread[this_vertex.thread]--; - return false; //{no_comm=true;get_com_only=false;} //return false; + return false; // {no_comm=true;get_com_only=false;} //return false; } else if(this_vertex.operation==abstract_eventt::Write) { if(nb_writes==2) { events_per_thread[this_vertex.thread]--; - return false; //{no_comm=true;get_com_only=false;} //return false; + return false; // {no_comm=true;get_com_only=false;} //return false; } else writes_per_variable[this_vertex.variable]++; @@ -370,7 +375,7 @@ bool event_grapht::graph_explorert::backtrack( if(nb_reads==2) { events_per_thread[this_vertex.thread]--; - return false; //{no_comm=true;get_com_only=false;} //return false; + return false; // {no_comm=true;get_com_only=false;} //return false; } else reads_per_variable[this_vertex.variable]++; @@ -379,12 +384,14 @@ bool event_grapht::graph_explorert::backtrack( if(!point_stack.empty()) { - const abstract_eventt& prev_vertex = egraph[point_stack.top()]; - unsafe_met_updated |= (prev_vertex.unsafe_pair(this_vertex,model) - && !(prev_vertex.thread==this_vertex.thread - && egraph.map_data_dp[this_vertex.thread].dp(prev_vertex,this_vertex))); - if (unsafe_met_updated && !unsafe_met - && egraph.are_po_ordered(point_stack.top(), vertex)) + const abstract_eventt &prev_vertex=egraph[point_stack.top()]; + unsafe_met_updated|= + prev_vertex.unsafe_pair(this_vertex, model) && + !(prev_vertex.thread==this_vertex.thread && + egraph.map_data_dp[this_vertex.thread].dp(prev_vertex, this_vertex)); + if(unsafe_met_updated && + !unsafe_met && + egraph.are_po_ordered(point_stack.top(), vertex)) has_to_be_unsafe_updated=true; } @@ -399,13 +406,13 @@ bool event_grapht::graph_explorert::backtrack( w_it=egraph.po_out(vertex).begin(); w_it!=egraph.po_out(vertex).end(); w_it++) { - const event_idt w = w_it->first; - if(w == source && point_stack.size()>=4 + const event_idt w=w_it->first; + if(w==source && point_stack.size()>=4 && (unsafe_met_updated - || this_vertex.unsafe_pair(egraph[source],model)) ) + || this_vertex.unsafe_pair(egraph[source], model)) ) { - critical_cyclet new_cycle = extract_cycle(vertex, source, cycle_nb++); - not_thin_air = !egraph.filter_thin_air || new_cycle.is_not_thin_air(); + critical_cyclet new_cycle=extract_cycle(vertex, source, cycle_nb++); + not_thin_air=!egraph.filter_thin_air || new_cycle.is_not_thin_air(); if(!not_thin_air) { for(critical_cyclet::const_iterator e_it=new_cycle.begin(); @@ -413,12 +420,11 @@ bool event_grapht::graph_explorert::backtrack( ++e_it) thin_air_events.insert(*e_it); } - if((!egraph.filter_uniproc || new_cycle.is_not_uniproc(model)) && not_thin_air - && new_cycle.is_cycle() && - new_cycle.is_unsafe(model) /*&& - new_cycle.is_unsafe_asm(model)*/) + if((!egraph.filter_uniproc || new_cycle.is_not_uniproc(model)) && + not_thin_air && new_cycle.is_cycle() && + new_cycle.is_unsafe(model) /*&& new_cycle.is_unsafe_asm(model)*/) { - egraph.message.debug() << new_cycle.print_name(model,false) + egraph.message.debug() << new_cycle.print_name(model, false) << messaget::eom; set_of_cycles.insert(new_cycle); #if 0 @@ -427,79 +433,98 @@ bool event_grapht::graph_explorert::backtrack( delete(reduced); #endif } - f = true; + f=true; } else if(!mark[w]) - f |= backtrack(set_of_cycles, source, w, unsafe_met_updated, - po_trans, same_var_pair_updated, false, has_to_be_unsafe_updated, - avoid_at_the_end, model); + f|= + backtrack( + set_of_cycles, + source, + w, + unsafe_met_updated, + po_trans, + same_var_pair_updated, + false, + has_to_be_unsafe_updated, + avoid_at_the_end, model); } } if(!no_comm) - /* we then visit via com transitions, if existing */ - for(wmm_grapht::edgest::const_iterator - w_it=egraph.com_out(vertex).begin(); - w_it!=egraph.com_out(vertex).end(); w_it++) { - const event_idt w = w_it->first; - if(w < source) - egraph.remove_com_edge(vertex,w); - else if(w == source && point_stack.size()>=4 - && (unsafe_met_updated - || this_vertex.unsafe_pair(egraph[source],model)) ) + /* we then visit via com transitions, if existing */ + for(wmm_grapht::edgest::const_iterator + w_it=egraph.com_out(vertex).begin(); + w_it!=egraph.com_out(vertex).end(); w_it++) { - critical_cyclet new_cycle = extract_cycle(vertex, source, cycle_nb++); - not_thin_air = !egraph.filter_thin_air || new_cycle.is_not_thin_air(); - if(!not_thin_air) - { - for(critical_cyclet::const_iterator e_it=new_cycle.begin(); - e_it!=new_cycle.end(); - ++e_it) - thin_air_events.insert(*e_it); - } - if((!egraph.filter_uniproc || new_cycle.is_not_uniproc(model)) && not_thin_air - && new_cycle.is_cycle() && - new_cycle.is_unsafe(model) /*&& - new_cycle.is_unsafe_asm(model)*/) + const event_idt w=w_it->first; + if(w < source) + egraph.remove_com_edge(vertex, w); + else if(w==source && point_stack.size()>=4 && + (unsafe_met_updated || + this_vertex.unsafe_pair(egraph[source], model))) { - egraph.message.debug() << new_cycle.print_name(model,false) - << messaget::eom; - set_of_cycles.insert(new_cycle); + critical_cyclet new_cycle=extract_cycle(vertex, source, cycle_nb++); + not_thin_air=!egraph.filter_thin_air || new_cycle.is_not_thin_air(); + if(!not_thin_air) + { + for(critical_cyclet::const_iterator e_it=new_cycle.begin(); + e_it!=new_cycle.end(); + ++e_it) + thin_air_events.insert(*e_it); + } + if((!egraph.filter_uniproc || new_cycle.is_not_uniproc(model)) && + not_thin_air && new_cycle.is_cycle() && + new_cycle.is_unsafe(model) /*&& new_cycle.is_unsafe_asm(model)*/) + { + egraph.message.debug() << new_cycle.print_name(model, false) + << messaget::eom; + set_of_cycles.insert(new_cycle); #if 0 - const critical_cyclet* reduced=new_cycle.hide_internals(); - set_of_cycles.insert(*reduced); - delete(reduced); + const critical_cyclet* reduced=new_cycle.hide_internals(); + set_of_cycles.insert(*reduced); + delete(reduced); #endif + } + f=true; } - f = true; + else if(!mark[w]) + f|= + backtrack( + set_of_cycles, + source, + w, + unsafe_met_updated, + po_trans, + false, + false, + false, + "", + model); } - else if(!mark[w]) - f |= backtrack(set_of_cycles, source, w, - unsafe_met_updated, po_trans, false, false, false, "", model); } if(f) { while(!marked_stack.empty() && marked_stack.top()!=vertex) { - event_idt up = marked_stack.top(); + event_idt up=marked_stack.top(); marked_stack.pop(); - mark[up] = false; + mark[up]=false; } if(!marked_stack.empty()) marked_stack.pop(); - mark[vertex] = false; + mark[vertex]=false; } assert(!point_stack.empty()); point_stack.pop(); /* removes variable access */ - if(this_vertex.operation!=abstract_eventt::Fence - && this_vertex.operation!=abstract_eventt::Lwfence - && this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::Fence && + this_vertex.operation!=abstract_eventt::Lwfence && + this_vertex.operation!=abstract_eventt::ASMfence) { if(this_vertex.operation==abstract_eventt::Write) writes_per_variable[this_vertex.variable]--; @@ -514,89 +539,98 @@ bool event_grapht::graph_explorert::backtrack( (except if it is a fence or no more po-transition skips allowed); if the cycle explored so far has a thin-air subcycle, this cycle is not valid: stop this exploration here */ - if( skip_tracked.find(vertex)==skip_tracked.end() ) // 25 oct - if( not_thin_air - && !get_com_only && (po_trans > 1 || po_trans==0) - && !point_stack.empty() && egraph.are_po_ordered(point_stack.top(),vertex) - && this_vertex.operation!=abstract_eventt::Fence - && ( this_vertex.operation!=abstract_eventt::Lwfence - || egraph[point_stack.top()].operation==abstract_eventt::Write) - && ( this_vertex.operation!=abstract_eventt::ASMfence - || !this_vertex.WRfence - || egraph[point_stack.top()].operation==abstract_eventt::Write) - ) - { - skip_tracked.insert(vertex); + if(skip_tracked.find(vertex)==skip_tracked.end()) // 25 oct + if(not_thin_air && !get_com_only && + (po_trans > 1 || po_trans==0) && + !point_stack.empty() && + egraph.are_po_ordered(point_stack.top(), vertex) && + this_vertex.operation!=abstract_eventt::Fence && + (this_vertex.operation!=abstract_eventt::Lwfence || + egraph[point_stack.top()].operation==abstract_eventt::Write) && + (this_vertex.operation!=abstract_eventt::ASMfence || + !this_vertex.WRfence || + egraph[point_stack.top()].operation==abstract_eventt::Write)) + { + skip_tracked.insert(vertex); - std::stack tmp; + std::stack tmp; - while(marked_stack.size()>0 && marked_stack.top()!=vertex) - { - tmp.push(marked_stack.top()); - mark[marked_stack.top()]=false; - marked_stack.pop(); - } + while(marked_stack.size()>0 && marked_stack.top()!=vertex) + { + tmp.push(marked_stack.top()); + mark[marked_stack.top()]=false; + marked_stack.pop(); + } - if(marked_stack.size()>0) - { - assert(marked_stack.top()==vertex); - mark[vertex]=true; - } - else - { - while(tmp.size()>0) + if(marked_stack.size()>0) { - marked_stack.push(tmp.top()); - mark[tmp.top()]=true; - tmp.pop(); + assert(marked_stack.top()==vertex); + mark[vertex]=true; + } + else + { + while(tmp.size()>0) + { + marked_stack.push(tmp.top()); + mark[tmp.top()]=true; + tmp.pop(); + } + mark[vertex]=true; + marked_stack.push(vertex); } - mark[vertex]=true; - marked_stack.push(vertex); - } - if(!egraph[point_stack.top()].unsafe_pair(this_vertex, model)) - { - /* tab[] should never be avoided */ - if(egraph.ignore_arrays - || id2string(this_vertex.variable).find("[]")==std::string::npos) - avoid_at_the_end = this_vertex.variable; - } + if(!egraph[point_stack.top()].unsafe_pair(this_vertex, model)) + { + /* tab[] should never be avoided */ + if(egraph.ignore_arrays || + id2string(this_vertex.variable).find("[]")==std::string::npos) + avoid_at_the_end=this_vertex.variable; + } - /* skip lwfence by po-transition only if we consider a WR */ - // TO CHECK - const bool is_lwfence = (this_vertex.operation==abstract_eventt::Lwfence - && egraph[point_stack.top()].operation==abstract_eventt::Write) - || (this_vertex.operation==abstract_eventt::ASMfence && - (!this_vertex.WRfence - && egraph[point_stack.top()].operation==abstract_eventt::Write)); - - for(wmm_grapht::edgest::const_iterator w_it= - egraph.po_out(vertex).begin(); - w_it!=egraph.po_out(vertex).end(); w_it++) - { - const event_idt w = w_it->first; - f |= backtrack(set_of_cycles, source, w, - unsafe_met/*_updated*/, (po_trans==0?0:po_trans-1), - same_var_pair/*_updated*/, is_lwfence, has_to_be_unsafe, avoid_at_the_end, - model); - } + /* skip lwfence by po-transition only if we consider a WR */ + // TO CHECK + const bool is_lwfence= + (this_vertex.operation==abstract_eventt::Lwfence && + egraph[point_stack.top()].operation==abstract_eventt::Write) || + (this_vertex.operation==abstract_eventt::ASMfence && + (!this_vertex.WRfence && + egraph[point_stack.top()].operation==abstract_eventt::Write)); + + for(wmm_grapht::edgest::const_iterator w_it= + egraph.po_out(vertex).begin(); + w_it!=egraph.po_out(vertex).end(); w_it++) + { + const event_idt w=w_it->first; + f|= + backtrack( + set_of_cycles, + source, + w, + unsafe_met/*_updated*/, + (po_trans==0?0:po_trans-1), + same_var_pair/*_updated*/, + is_lwfence, + has_to_be_unsafe, + avoid_at_the_end, + model); + } - if(f) - { - while(!marked_stack.empty() && marked_stack.top()!=vertex) + if(f) { - event_idt up = marked_stack.top(); - marked_stack.pop(); - mark[up] = false; + while(!marked_stack.empty() && marked_stack.top()!=vertex) + { + event_idt up=marked_stack.top(); + marked_stack.pop(); + mark[up]=false; + } + + if(!marked_stack.empty()) + marked_stack.pop(); + mark[vertex]=false; } - if(!marked_stack.empty()) - marked_stack.pop(); - mark[vertex] = false; + skip_tracked.erase(vertex); } - skip_tracked.erase(vertex); - } - return f; } diff --git a/src/goto-instrument/wmm/data_dp.cpp b/src/goto-instrument/wmm/data_dp.cpp index 983955127f2..ce700dc1f8a 100644 --- a/src/goto-instrument/wmm/data_dp.cpp +++ b/src/goto-instrument/wmm/data_dp.cpp @@ -26,9 +26,9 @@ Function: data_dpt::dp_analysis \*******************************************************************/ void data_dpt::dp_analysis( - const datat& read, + const datat &read, bool local_read, - const datat& write, + const datat &write, bool local_write) { const_iterator it; @@ -37,13 +37,21 @@ void data_dpt::dp_analysis( { if(local_read && it->id==read.id) { - insert(datat(write.id, (local_write?source_locationt():write.loc), it->eq_class)); + insert( + datat( + write.id, + (local_write?source_locationt():write.loc), + it->eq_class)); continue; } if(local_write && it->id==write.id) { - insert(datat(read.id, (local_read?source_locationt():read.loc), it->eq_class)); + insert( + datat( + read.id, + (local_read?source_locationt():read.loc), + it->eq_class)); continue; } } @@ -51,8 +59,10 @@ void data_dpt::dp_analysis( if(it==end()) { ++class_nb; - insert(datat(read.id, (local_read?source_locationt():read.loc), class_nb)); - insert(datat(write.id, (local_write?source_locationt():write.loc), class_nb)); + insert( + datat(read.id, (local_read?source_locationt():read.loc), class_nb)); + insert( + datat(write.id, (local_write?source_locationt():write.loc), class_nb)); } } @@ -68,12 +78,13 @@ Function: data_dpt::dp_analysis \*******************************************************************/ -void data_dpt::dp_analysis(const abstract_eventt& read, - const abstract_eventt& write) +void data_dpt::dp_analysis( + const abstract_eventt &read, + const abstract_eventt &write) { - datat d_read(read.variable,read.source_location); - datat d_write(write.variable,write.source_location); - dp_analysis(d_read,read.local,d_write,write.local); + datat d_read(read.variable, read.source_location); + datat d_write(write.variable, write.source_location); + dp_analysis(d_read, read.local, d_write, write.local); } /*******************************************************************\ @@ -88,7 +99,7 @@ Function: data_dpt::dp \*******************************************************************/ -bool data_dpt::dp(const abstract_eventt& e1, const abstract_eventt& e2) const +bool data_dpt::dp(const abstract_eventt &e1, const abstract_eventt &e2) const { for(const_iterator it1=begin(); it1!=end(); ++it1) { @@ -123,12 +134,12 @@ bool data_dpt::dp(const abstract_eventt& e1, const abstract_eventt& e2) const /* or else, same class */ if(it1->eq_class==it2->eq_class) { - //message.debug() << e1<<"-dp->"<"<"<"< > classed; + std::map > classed; for(it=begin(); it!=end(); ++it) { @@ -217,8 +228,9 @@ void data_dpt::print(messaget& message) classed[it->eq_class].insert(it->loc); } - for(std::map >::const_iterator m_it=classed.begin(); - m_it!=classed.end(); ++m_it) + for(std::map >::const_iterator + m_it=classed.begin(); + m_it!=classed.end(); ++m_it) { message.debug() << "class #"<first << messaget::eom; std::set::const_iterator l_it; diff --git a/src/goto-instrument/wmm/data_dp.h b/src/goto-instrument/wmm/data_dp.h index 14b594fd913..6b352acccfd 100644 --- a/src/goto-instrument/wmm/data_dp.h +++ b/src/goto-instrument/wmm/data_dp.h @@ -38,35 +38,38 @@ struct datat { } - bool operator==(const datat& d) const + bool operator==(const datat &d) const { return id==d.id && loc==d.loc; } - bool operator<(const datat& d2) const + bool operator<(const datat &d2) const { return id +class data_dpt:public std::set { public: unsigned class_nb; /* add this dependency in the structure */ - void dp_analysis(const abstract_eventt& read, const abstract_eventt& write); - void dp_analysis(const datat& read, bool local_read, const datat& write, + void dp_analysis(const abstract_eventt &read, const abstract_eventt &write); + void dp_analysis( + const datat &read, + bool local_read, + const datat &write, bool local_write); /* are these two events with a data dependency ? */ - bool dp(const abstract_eventt& e1, const abstract_eventt& e2) const; + bool dp(const abstract_eventt &e1, const abstract_eventt &e2) const; /* routine to maintain partitioning */ void dp_merge(); /* printing */ - void print(messaget& message); + void print(messaget &message); }; #endif // CPROVER_GOTO_INSTRUMENT_WMM_DATA_DP_H diff --git a/src/goto-instrument/wmm/event_graph.cpp b/src/goto-instrument/wmm/event_graph.cpp index 883d9ae49bf..9490d69f46c 100644 --- a/src/goto-instrument/wmm/event_graph.cpp +++ b/src/goto-instrument/wmm/event_graph.cpp @@ -16,9 +16,10 @@ Date: 2012 #define NB_COLOURS 14 -std::string colour_map[NB_COLOURS] = {"red", "blue", "black", "green", "yellow", -"orange", "blueviolet", "cyan", "cadetblue", "magenta", "palegreen", -"deeppink", "indigo", "olivedrab"}; +static const char *colour_map[NB_COLOURS]= + {"red", "blue", "black", "green", "yellow", + "orange", "blueviolet", "cyan", "cadetblue", "magenta", "palegreen", + "deeppink", "indigo", "olivedrab"}; #define print_colour(u) colour_map[u%NB_COLOURS] /*******************************************************************\ @@ -33,10 +34,10 @@ Function: event_grapht::print_rec_graph \*******************************************************************/ -void event_grapht::print_rec_graph(std::ofstream& file, event_idt node_id, - std::set& visited) +void event_grapht::print_rec_graph(std::ofstream &file, event_idt node_id, + std::set &visited) { - const abstract_eventt& node=operator[](node_id); + const abstract_eventt &node=operator[](node_id); file << node_id << "[label=\"" << node << ", " << node.source_location << "\"];" << std::endl; visited.insert(node_id); @@ -73,7 +74,8 @@ Function: event_grapht::print_graph \*******************************************************************/ -void event_grapht::print_graph() { +void event_grapht::print_graph() +{ assert(po_order.size()>0); std::set visited; event_idt root=po_order.front(); @@ -98,10 +100,10 @@ Function: event_grapht::copy_segment \*******************************************************************/ -void event_grapht::explore_copy_segment(std::set& explored, +void event_grapht::explore_copy_segment(std::set &explored, event_idt begin, event_idt end) const { - //std::cout << "explores " << begin << " against " << end << std::endl; + // std::cout << "explores " << begin << " against " << end << std::endl; if(explored.find(begin)!=explored.end()) return; @@ -118,8 +120,8 @@ void event_grapht::explore_copy_segment(std::set& explored, event_idt event_grapht::copy_segment(event_idt begin, event_idt end) { - const abstract_eventt& begin_event=operator[](begin); - const abstract_eventt& end_event=operator[](end); + const abstract_eventt &begin_event=operator[](begin); + const abstract_eventt &end_event=operator[](end); /* not sure -- we should allow cross function cycles */ if(begin_event.source_location.get_file()!=end_event.source_location @@ -134,8 +136,9 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end) duplicated_bodies.insert(std::make_pair(begin_event, end_event)); - message.status() << "tries to duplicate between " << begin_event.source_location - << " and " << end_event.source_location << messaget::eom; + message.status() << "tries to duplicate between " + << begin_event.source_location + << " and " << end_event.source_location << messaget::eom; std::set covered; /* collects the nodes of the subgraph */ @@ -144,7 +147,8 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end) if(covered.size()==0) return end; -// for(std::set::const_iterator it=covered.begin(); it!=covered.end(); ++it) +// for(std::set::const_iterator it=covered.begin(); +// it!=covered.end(); ++it) // std::cout << "covered: " << *it << std::endl; std::map orig2copy; @@ -224,15 +228,15 @@ Function: event_grapht::critical_cyclet::check_AC bool event_grapht::critical_cyclet::check_AC( const_iterator s_it, - const abstract_eventt& first, - const abstract_eventt& second) const + const abstract_eventt &first, + const abstract_eventt &second) const { bool AC=false; const_iterator AC_it=s_it; ++AC_it; for(; AC_it!=end(); ++AC_it) { - const abstract_eventt& AC_evt=egraph[*AC_it]; + const abstract_eventt &AC_evt=egraph[*AC_it]; if(AC_evt.operation==abstract_eventt::Fence) { AC=true; @@ -246,9 +250,10 @@ bool event_grapht::critical_cyclet::check_AC( return true; if(AC_it==end() && egraph[front()].thread==second.thread) + { for(AC_it=begin(); ; ++AC_it) { - const abstract_eventt& AC_evt=egraph[*AC_it]; + const abstract_eventt &AC_evt=egraph[*AC_it]; if(AC_evt.operation==abstract_eventt::Fence) { AC=true; @@ -257,6 +262,7 @@ bool event_grapht::critical_cyclet::check_AC( if(AC_evt==first || AC_evt.thread!=second.thread) break; } + } return AC; } @@ -275,8 +281,8 @@ Function: event_grapht::critical_cyclet::check_BC bool event_grapht::critical_cyclet::check_BC( const_iterator it, - const abstract_eventt& first, - const abstract_eventt& second) const + const abstract_eventt &first, + const abstract_eventt &second) const { bool BC=false; /* no fence before the first element? (BC) */ @@ -293,7 +299,7 @@ bool event_grapht::critical_cyclet::check_BC( } for(; BC_it!=begin(); --BC_it) { - const abstract_eventt& BC_evt=egraph[*BC_it]; + const abstract_eventt &BC_evt=egraph[*BC_it]; if(BC_evt.operation==abstract_eventt::Fence) { BC=true; @@ -312,7 +318,7 @@ bool event_grapht::critical_cyclet::check_BC( --BC_it; for(; ; --BC_it) { - const abstract_eventt& BC_evt=egraph[*BC_it]; + const abstract_eventt &BC_evt=egraph[*BC_it]; if(BC_evt.operation==abstract_eventt::Fence) { BC=true; @@ -352,7 +358,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) const_iterator th_it; for(th_it=begin(); th_it!=end() && thread==egraph[*th_it].thread; ++th_it) - thread = egraph[*th_it].thread; + thread=egraph[*th_it].thread; if(th_it==end()) return false; @@ -362,8 +368,8 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) ++next; for(; it!=end() && next!=end(); ++next, ++it) { - const abstract_eventt& it_evt=egraph[*it]; - const abstract_eventt& next_evt=egraph[*next]; + const abstract_eventt &it_evt=egraph[*it]; + const abstract_eventt &next_evt=egraph[*next]; /* strong fence -- this pair is safe */ if(it_evt.operation==abstract_eventt::Fence) @@ -379,13 +385,15 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) /* selects the next event which is not a weak fence */ const_iterator s_it=next; - for(; s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; - ++s_it); + for( ; s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; + ++s_it) + { + } if(s_it==end()) continue; - const abstract_eventt& s_evt=egraph[*s_it]; + const abstract_eventt &s_evt=egraph[*s_it]; if(s_evt.operation==abstract_eventt::Fence) continue; @@ -394,12 +402,12 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) if(it==s_it) continue; - const abstract_eventt& first=it_evt; - const abstract_eventt& second=s_evt; - const data_dpt& data_dp=egraph.map_data_dp[first.thread]; + const abstract_eventt &first=it_evt; + const abstract_eventt &second=s_evt; + const data_dpt &data_dp=egraph.map_data_dp[first.thread]; /* if data dp between linking the pair, safe */ - if(first.thread==second.thread && data_dp.dp(first,second)) + if(first.thread==second.thread && data_dp.dp(first, second)) continue; /* AC and BC conditions */ @@ -417,8 +425,8 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) if(s_it==n_it) { /* there is no lwfence between the pair */ - if(first.unsafe_pair(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(*it,*s_it))) + if(first.unsafe_pair(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(*it, *s_it))) { const_iterator before_first; const_iterator after_second; @@ -436,10 +444,10 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) else after_second=s_it; - if(first.variable == second.variable - && first.thread == second.thread - && egraph[*before_first].thread != first.thread - && egraph[*after_second].thread != second.thread) + if(first.variable==second.variable + && first.thread==second.thread + && egraph[*before_first].thread!=first.thread + && egraph[*after_second].thread!=second.thread) { /* not unsafe */ } @@ -449,7 +457,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) return true; else { - const delayt delay(*it,*s_it,(first.thread==second.thread)); + const delayt delay(*it, *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); unsafe_met=true; } @@ -459,8 +467,8 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) else { /* one (or more) lwfence between the pair */ - if(first.unsafe_pair_lwfence(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(*it,*s_it))) + if(first.unsafe_pair_lwfence(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(*it, *s_it))) { const_iterator before_first; const_iterator after_second; @@ -478,10 +486,10 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) else after_second=s_it; - if(first.variable == second.variable - && first.thread == second.thread - && egraph[*before_first].thread != first.thread - && egraph[*after_second].thread != second.thread) + if(first.variable==second.variable + && first.thread==second.thread + && egraph[*before_first].thread!=first.thread + && egraph[*after_second].thread!=second.thread) { /* not unsafe */ } @@ -491,7 +499,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) return true; else { - const delayt delay(*it,*s_it,(first.thread==second.thread)); + const delayt delay(*it, *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); unsafe_met=true; } @@ -512,7 +520,10 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) /* selects the next event which is not a weak fence */ const_iterator s_it; for(s_it=begin(); - s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; s_it++); + s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; + s_it++) + { + } /* if the whole cycle has been explored */ if(s_it==end()) @@ -521,13 +532,13 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) if(egraph[*s_it].operation==abstract_eventt::Fence) return unsafe_met; - const abstract_eventt& first = egraph[back()]; - const abstract_eventt& second = egraph[*s_it]; + const abstract_eventt &first=egraph[back()]; + const abstract_eventt &second=egraph[*s_it]; - const data_dpt& data_dp = egraph.map_data_dp[first.thread]; + const data_dpt &data_dp=egraph.map_data_dp[first.thread]; /* if data dp between linking the pair, safe */ - if(first.thread==second.thread && data_dp.dp(first,second)) + if(first.thread==second.thread && data_dp.dp(first, second)) return unsafe_met; /* AC and BC conditions */ @@ -543,23 +554,23 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) if(s_it==begin()) { /* no lwfence between the pair */ - if(first.unsafe_pair(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(back(),*s_it))) + if(first.unsafe_pair(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(back(), *s_it))) { std::list::const_iterator before_first; std::list::const_iterator after_second; - before_first = end(); + before_first=end(); --before_first; --before_first; - after_second = s_it; + after_second=s_it; ++after_second; - if(first.variable == second.variable - && first.thread == second.thread - && egraph[*before_first].thread != first.thread - && egraph[*after_second].thread != second.thread) + if(first.variable==second.variable + && first.thread==second.thread + && egraph[*before_first].thread!=first.thread + && egraph[*after_second].thread!=second.thread) { /* not unsafe */ } @@ -567,7 +578,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) { if(!fast) { - const delayt delay(back(),*s_it,(first.thread==second.thread)); + const delayt delay(back(), *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); } return true; @@ -577,23 +588,23 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) else { /* one (or more) lwfence between the pair */ - if(first.unsafe_pair_lwfence(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(back(),*s_it))) + if(first.unsafe_pair_lwfence(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(back(), *s_it))) { std::list::const_iterator before_first; std::list::const_iterator after_second; - before_first = end(); + before_first=end(); --before_first; --before_first; - after_second = s_it; + after_second=s_it; ++after_second; - if(first.variable == second.variable - && first.thread == second.thread - && egraph[*before_first].thread != first.thread - && egraph[*after_second].thread != second.thread) + if(first.variable==second.variable + && first.thread==second.thread + && egraph[*before_first].thread!=first.thread + && egraph[*after_second].thread!=second.thread) { /* not unsafe */ } @@ -601,7 +612,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) { if(!fast) { - const delayt delay(back(),*s_it,(first.thread==second.thread)); + const delayt delay(back(), *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); } return true; @@ -624,23 +635,24 @@ Function: event_grapht::critical_cyclet::is_unsafe_asm \*******************************************************************/ -bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, +bool event_grapht::critical_cyclet::is_unsafe_asm( + memory_modelt model, bool fast) { egraph.message.debug() << "cycle is safe?" << messaget::eom; - bool unsafe_met = false; - unsigned char fences_met = 0; + bool unsafe_met=false; + unsigned char fences_met=0; /* critical cycles contain at least 4 events */ if(size()<4) return false; /* critical cycles contain at least 2 threads */ - unsigned thread = egraph[*begin()].thread; + unsigned thread=egraph[*begin()].thread; const_iterator th_it; for(th_it=begin(); th_it!=end() && thread==egraph[*th_it].thread; ++th_it) - thread = egraph[*th_it].thread; + thread=egraph[*th_it].thread; if(th_it==end()) return false; @@ -648,7 +660,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, for(const_iterator it=begin(); it!=end() && ++it!=end(); it++) { --it; - fences_met = 0; + fences_met=0; /* fence -- this pair is safe */ if(egraph[*it].operation==abstract_eventt::ASMfence) @@ -663,7 +675,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, --it; /* selects the next event which is not a weak fence */ - const_iterator s_it = ++it; + const_iterator s_it=++it; --it; for(; @@ -681,32 +693,32 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, if(it==s_it) continue; - const abstract_eventt& first = egraph[*it]; - const abstract_eventt& second = egraph[*s_it]; + const abstract_eventt &first=egraph[*it]; + const abstract_eventt &second=egraph[*s_it]; - const data_dpt& data_dp = egraph.map_data_dp[first.thread]; + const data_dpt &data_dp=egraph.map_data_dp[first.thread]; /* if data dp between linking the pair, safe */ - if(first.thread==second.thread && data_dp.dp(first,second)) + if(first.thread==second.thread && data_dp.dp(first, second)) continue; /* AC and BC conditions */ if(first.thread!=second.thread && model==Power) { - bool AC = false; - bool BC = false; + bool AC=false; + bool BC=false; /* no fence after the second element? (AC) */ - const_iterator AC_it = ++s_it; + const_iterator AC_it=++s_it; --s_it; for(; AC_it!=end() && egraph[*AC_it].thread==second.thread; AC_it++) if(egraph[*AC_it].operation==abstract_eventt::ASMfence && egraph[*AC_it].is_cumul() - && egraph[*AC_it].is_corresponding_fence(egraph[*it],egraph[*s_it])) + && egraph[*AC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { - AC = true; + AC=true; break; } @@ -714,16 +726,18 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, continue; if(AC_it==end() && egraph[front()].thread==second.thread) + { for(AC_it=begin(); - !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; - AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence - && egraph[*AC_it].is_cumul() - && egraph[*AC_it].is_corresponding_fence(egraph[*it],egraph[*s_it])) + !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; + AC_it++) + if(egraph[*AC_it].operation==abstract_eventt::ASMfence && + egraph[*AC_it].is_cumul() && + egraph[*AC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { - AC = true; + AC=true; break; } + } if(AC) continue; @@ -732,41 +746,43 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, const_iterator BC_it; if(it==begin()) { - BC_it = end(); + BC_it=end(); BC_it--; } else { - BC_it = --it; + BC_it=--it; ++it; } - for(; - BC_it!=begin() && egraph[*BC_it].thread==first.thread; - BC_it--) - if(egraph[*BC_it].operation==abstract_eventt::ASMfence - && egraph[*BC_it].is_cumul() - && egraph[*BC_it].is_corresponding_fence(egraph[*it],egraph[*s_it])) - + for( ; + BC_it!=begin() && egraph[*BC_it].thread==first.thread; + BC_it--) + { + if(egraph[*BC_it].operation==abstract_eventt::ASMfence && + egraph[*BC_it].is_cumul() && + egraph[*BC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { - BC = true; + BC=true; break; } + } if(BC) continue; if(BC_it==begin() && egraph[back()].thread==first.thread) + { for(BC_it=end(); - !(egraph[*BC_it]==second) && egraph[*BC_it].thread==first.thread; - BC_it--) - if(egraph[*BC_it].operation==abstract_eventt::ASMfence - && egraph[*BC_it].is_cumul() - && egraph[*BC_it].is_corresponding_fence(egraph[*it],egraph[*s_it])) - + !(egraph[*BC_it]==second) && egraph[*BC_it].thread==first.thread; + BC_it--) + if(egraph[*BC_it].operation==abstract_eventt::ASMfence && + egraph[*BC_it].is_cumul() && + egraph[*BC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { - BC = true; + BC=true; break; } + } if(BC) continue; @@ -777,16 +793,16 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, --it; /* no lwfence between the pair */ - if(first.unsafe_pair(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(*it,*s_it))) + if(first.unsafe_pair(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(*it, *s_it))) { if(fast) return true; else { - const delayt delay(*it,*s_it,(first.thread==second.thread)); + const delayt delay(*it, *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); - unsafe_met = true; + unsafe_met=true; } } } @@ -796,15 +812,15 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, /* one (or more) lwfence between the pair */ if(first.unsafe_pair_asm(second, model, fences_met) - && (first.thread!=second.thread || egraph.are_po_ordered(*it,*s_it))) + && (first.thread!=second.thread || egraph.are_po_ordered(*it, *s_it))) { if(fast) return true; else { - const delayt delay(*it,*s_it,(first.thread==second.thread)); + const delayt delay(*it, *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); - unsafe_met = true; + unsafe_met=true; } } } @@ -815,7 +831,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, || egraph[front()].operation==abstract_eventt::ASMfence) return unsafe_met; - fences_met = 0; + fences_met=0; /* selects the next event which is not a weak fence */ const_iterator s_it; @@ -830,23 +846,23 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, if(egraph[*s_it].operation==abstract_eventt::ASMfence) return unsafe_met; - const abstract_eventt& first = egraph[back()]; - const abstract_eventt& second = egraph[*s_it]; + const abstract_eventt &first=egraph[back()]; + const abstract_eventt &second=egraph[*s_it]; - const data_dpt& data_dp = egraph.map_data_dp[first.thread]; + const data_dpt &data_dp=egraph.map_data_dp[first.thread]; /* if data dp between linking the pair, safe */ - if(first.thread==second.thread && data_dp.dp(first,second)) + if(first.thread==second.thread && data_dp.dp(first, second)) return unsafe_met; /* AC and BC conditions */ if(first.thread!=second.thread && model==Power) { - bool AC = false; - bool BC = false; + bool AC=false; + bool BC=false; /* no fence after the second element? (AC) */ - const_iterator AC_it = ++s_it; + const_iterator AC_it=++s_it; --s_it; for(; AC_it!=end() && egraph[*AC_it].thread==second.thread; @@ -855,7 +871,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, && egraph[*AC_it].is_cumul() && egraph[*AC_it].is_corresponding_fence(first, second)) { - AC = true; + AC=true; break; } @@ -863,22 +879,24 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, return unsafe_met; if(AC_it==end() && egraph[front()].thread==second.thread) + { for(AC_it=begin(); - !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; - AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence - && egraph[*AC_it].is_cumul() - && egraph[*AC_it].is_corresponding_fence(first, second)) + !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; + AC_it++) + if(egraph[*AC_it].operation==abstract_eventt::ASMfence && + egraph[*AC_it].is_cumul() && + egraph[*AC_it].is_corresponding_fence(first, second)) { - AC = true; + AC=true; break; } + } if(AC) return unsafe_met; /* no fence before the first element? (BC) */ - const_iterator BC_it = end(); + const_iterator BC_it=end(); --BC_it; for(; @@ -888,7 +906,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(first, second)) { - BC = true; + BC=true; break; } @@ -897,7 +915,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, if(BC_it==begin() && egraph[back()].thread==first.thread) { - BC_it = end(); + BC_it=end(); BC_it--; for(; !(egraph[*BC_it]==second) && egraph[*BC_it].thread==first.thread; @@ -906,7 +924,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(first, second)) { - BC = true; + BC=true; break; } } @@ -918,12 +936,12 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, if(s_it==begin()) { /* no lwfence between the pair */ - if(first.unsafe_pair(second,model) - && (first.thread!=second.thread || egraph.are_po_ordered(back(),*s_it))) + if(first.unsafe_pair(second, model) + && (first.thread!=second.thread || egraph.are_po_ordered(back(), *s_it))) { if(!fast) { - const delayt delay(back(),*s_it,(first.thread==second.thread)); + const delayt delay(back(), *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); } return true; @@ -932,12 +950,12 @@ bool event_grapht::critical_cyclet::is_unsafe_asm(memory_modelt model, else { /* one (or more) lwfence between the pair */ - if(first.unsafe_pair_asm(second,model,fences_met) - && (first.thread!=second.thread || egraph.are_po_ordered(back(),*s_it))) + if(first.unsafe_pair_asm(second, model, fences_met) + && (first.thread!=second.thread || egraph.are_po_ordered(back(), *s_it))) { if(!fast) { - const delayt delay(back(),*s_it,(first.thread==second.thread)); + const delayt delay(back(), *s_it, (first.thread==second.thread)); unsafe_pairs.insert(delay); } return true; @@ -966,7 +984,7 @@ bool event_grapht::critical_cyclet::is_not_uniproc() const /* find the first non-fence event */ for(; it!=end(); ++it) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; if(it_evt.operation!=abstract_eventt::Fence && it_evt.operation!=abstract_eventt::Lwfence && it_evt.operation!=abstract_eventt::ASMfence) @@ -977,7 +995,7 @@ bool event_grapht::critical_cyclet::is_not_uniproc() const if(it==end()) return false; - const irep_idt& var=egraph[*it].variable; + const irep_idt &var=egraph[*it].variable; /* if it is an array access, by over-approximation, we don't have uniproc in the cycle (tab[]) */ @@ -986,7 +1004,7 @@ bool event_grapht::critical_cyclet::is_not_uniproc() const for(; it!=end(); ++it) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; if(it_evt.variable!=var && it_evt.operation!=abstract_eventt::Fence && it_evt.operation!=abstract_eventt::Lwfence @@ -1016,7 +1034,7 @@ bool event_grapht::critical_cyclet::is_not_weak_uniproc() const /* find the first non-fence event */ for(; it!=end(); it++) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; if(it_evt.operation!=abstract_eventt::Fence && it_evt.operation!=abstract_eventt::Lwfence && it_evt.operation!=abstract_eventt::ASMfence) @@ -1027,12 +1045,12 @@ bool event_grapht::critical_cyclet::is_not_weak_uniproc() const if(it==end()) return false; - const irep_idt& var=egraph[*it].variable; + const irep_idt &var=egraph[*it].variable; const_iterator prev=it; for(; it!=end(); prev=it, ++it) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; if( !(it_evt.variable==var &&(it==begin() || it_evt.operation!=abstract_eventt::Read @@ -1060,7 +1078,9 @@ Function: event_grapht::critical_cyclet::is_not_thin_air bool event_grapht::critical_cyclet::is_not_thin_air() const { - if(size()<=2) return false; //assert(size()>2); + // assert(size()>2); + if(size()<=2) + return false; for(const_iterator it=begin(); it!=end(); ++it) { @@ -1070,8 +1090,8 @@ bool event_grapht::critical_cyclet::is_not_thin_air() const if(n_it==end()) break; - const abstract_eventt& current=egraph[*it]; - const abstract_eventt& next=egraph[*n_it]; + const abstract_eventt ¤t=egraph[*it]; + const abstract_eventt &next=egraph[*n_it]; /* rf */ if(current.operation==abstract_eventt::Write && @@ -1079,26 +1099,26 @@ bool event_grapht::critical_cyclet::is_not_thin_air() const continue; /* data dependencies */ - const data_dpt& dep=egraph.map_data_dp[current.thread]; + const data_dpt &dep=egraph.map_data_dp[current.thread]; - if(dep.dp(current,next)) + if(dep.dp(current, next)) continue; return true; } - const abstract_eventt& current=egraph[back()]; - const abstract_eventt& next=egraph[front()]; + const abstract_eventt ¤t=egraph[back()]; + const abstract_eventt &next=egraph[front()]; /* rf */ - if(current.operation == abstract_eventt::Write && - next.operation == abstract_eventt::Read) + if(current.operation==abstract_eventt::Write && + next.operation==abstract_eventt::Read) return false; /* data dependencies */ - const data_dpt& dep=egraph.map_data_dp[current.thread]; + const data_dpt &dep=egraph.map_data_dp[current.thread]; - if(dep.dp(current,next)) + if(dep.dp(current, next)) return false; return true; @@ -1118,7 +1138,7 @@ Function: event_grapht::critical_cyclet::print std::string event_grapht::critical_cyclet::print() const { - std::string cycle = "Cycle: "; + std::string cycle="Cycle: "; for(const_iterator it=begin(); it!=end(); ++it) cycle += std::to_string(egraph[*it].id) + "; "; return cycle + " End of cycle."; @@ -1138,43 +1158,41 @@ Function: event_grapht::critical_cyclet::print_unsafes std::string event_grapht::critical_cyclet::print_unsafes() const { - std::string name = "Unsafe pairs: "; + std::string name="Unsafe pairs: "; for(std::set::const_iterator it=unsafe_pairs.begin(); it!=unsafe_pairs.end(); ++it) { - const abstract_eventt& first=egraph[it->second]; - const abstract_eventt& last=egraph[it->first]; + const abstract_eventt &first=egraph[it->second]; + const abstract_eventt &last=egraph[it->first]; - if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Read) + if(last.variable==first.variable + && last.operation==abstract_eventt::Write + && first.operation==abstract_eventt::Read) { name += " Rf"; name += (last.thread==first.thread?"i":"e"); } - else if(last.variable == first.variable - && last.operation == abstract_eventt::Read - && first.operation == abstract_eventt::Write - && (last.thread != first.thread || it->first > it->second)) + else if(last.variable==first.variable && + last.operation==abstract_eventt::Read && + first.operation==abstract_eventt::Write && + (last.thread!=first.thread || it->first > it->second)) { name += " Fr"; name += (last.thread==first.thread?"i":"e"); } - - else if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Write - && (last.thread != first.thread || it->first > it->second)) - /* we prefer to write Po rather than Wsi */ + else if(last.variable==first.variable && + last.operation==abstract_eventt::Write && + first.operation==abstract_eventt::Write && + (last.thread!=first.thread || it->first > it->second)) { + /* we prefer to write Po rather than Wsi */ name += " Ws"; name += (last.thread==first.thread?"i":"e"); } - - else if(last.thread==first.thread - && last.operation != abstract_eventt::Fence) + else if(last.thread==first.thread && + last.operation!=abstract_eventt::Fence) { name += " Po"; name += (last.variable==first.variable?"s":"d") + last.get_operation() @@ -1199,10 +1217,10 @@ Function: event_grapht::critical_cyclet::print_events std::string event_grapht::critical_cyclet::print_events() const { - std::string cycle = "Cycle: "; + std::string cycle="Cycle: "; for(const_iterator it=begin(); it!=end(); ++it) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; cycle += it_evt.get_operation() + id2string(it_evt.variable) + "; "; } @@ -1226,7 +1244,7 @@ std::string event_grapht::critical_cyclet::print_output() const std::string cycle; for(const_iterator it=begin(); it!=end(); ++it) { - const abstract_eventt& it_evt=egraph[*it]; + const abstract_eventt &it_evt=egraph[*it]; cycle += id2string(it_evt.variable) + " ("; cycle += it_evt.source_location.as_string(); cycle += " thread " + std::to_string(it_evt.thread) + ") "; @@ -1247,16 +1265,16 @@ Function: event_grapht::critical_cyclet::print_detail \*******************************************************************/ std::string event_grapht::critical_cyclet::print_detail( - const critical_cyclet& reduced, - std::map& map_id2var, - std::map& map_var2id, + const critical_cyclet &reduced, + std::map &map_id2var, + std::map &map_var2id, memory_modelt model) const { std::string cycle; for(const_iterator it=reduced.begin(); it!=reduced.end(); ++it) { - const abstract_eventt& it_evt=egraph[*it]; - const std::string var_name = id2string(it_evt.variable) + const abstract_eventt &it_evt=egraph[*it]; + const std::string var_name=id2string(it_evt.variable) + " (" + it_evt.source_location.as_string() + ")"; if(map_var2id.find(var_name)!=map_var2id.end()) { @@ -1265,9 +1283,9 @@ std::string event_grapht::critical_cyclet::print_detail( } else { - const std::string new_id = "var@" + std::to_string(map_var2id.size()); - map_var2id[var_name] = new_id; - map_id2var[new_id] = var_name; + const std::string new_id="var@" + std::to_string(map_var2id.size()); + map_var2id[var_name]=new_id; + map_id2var[new_id]=var_name; cycle += "t" + std::to_string(it_evt.thread) + " ("; cycle += new_id + ") "; } @@ -1289,8 +1307,8 @@ Function: event_grapht::critical_cyclet::print_all std::string event_grapht::critical_cyclet::print_all( memory_modelt model, - std::map& map_id2var, - std::map& map_var2id, + std::map &map_id2var, + std::map &map_var2id, bool hide_internals) const { std::string cycle; @@ -1329,7 +1347,8 @@ Function: event_grapht::critical_cyclet::hide_internals \*******************************************************************/ -void event_grapht::critical_cyclet::hide_internals(critical_cyclet& reduced) const +void event_grapht::critical_cyclet::hide_internals( + critical_cyclet &reduced) const { std::set reduced_evts; const_iterator first_it, prev_it=end(); @@ -1337,38 +1356,38 @@ void event_grapht::critical_cyclet::hide_internals(critical_cyclet& reduced) co /* finds an element first of its thread */ for(first_it=begin(); first_it!=end(); ++first_it) { - const abstract_eventt& first=egraph[*first_it]; + const abstract_eventt &first=egraph[*first_it]; if(prev_it!=end() && egraph[*prev_it].thread!=first.thread && !first.is_fence()) break; prev_it=first_it; } - assert(first_it != end()); + assert(first_it!=end()); reduced.push_back(*first_it); reduced_evts.insert(*first_it); /* conserves only the extrema of threads */ for(const_iterator cur_it=first_it; cur_it!=end(); ++cur_it) { - const abstract_eventt& cur=egraph[*cur_it]; + const abstract_eventt &cur=egraph[*cur_it]; if(cur.is_fence()) continue; const_iterator next_it=cur_it; ++next_it; - if(next_it == end()) + if(next_it==end()) next_it=begin(); - if(cur.thread != egraph[*next_it].thread) + if(cur.thread!=egraph[*next_it].thread) { - if(reduced_evts.find(*cur_it) == reduced_evts.end()) + if(reduced_evts.find(*cur_it)==reduced_evts.end()) { reduced.push_back(*cur_it); reduced_evts.insert(*cur_it); } - for(; next_it!=end() && egraph[*next_it].is_fence(); ++next_it); - assert(next_it != end()); - if(reduced_evts.find(*next_it) == reduced_evts.end()) + for(; next_it!=end() && egraph[*next_it].is_fence(); ++next_it) {} + assert(next_it!=end()); + if(reduced_evts.find(*next_it)==reduced_evts.end()) { reduced.push_back(*next_it); reduced_evts.insert(*next_it); @@ -1376,26 +1395,26 @@ void event_grapht::critical_cyclet::hide_internals(critical_cyclet& reduced) co } } - for(const_iterator cur_it=begin(); cur_it != first_it; ++cur_it) + for(const_iterator cur_it=begin(); cur_it!=first_it; ++cur_it) { - const abstract_eventt& cur=egraph[*cur_it]; + const abstract_eventt &cur=egraph[*cur_it]; if(cur.is_fence()) continue; const_iterator next_it=cur_it; ++next_it; - assert(next_it != end()); + assert(next_it!=end()); - if(cur.thread != egraph[*next_it].thread) + if(cur.thread!=egraph[*next_it].thread) { if(reduced_evts.find(*cur_it)==reduced_evts.end()) { reduced.push_back(*cur_it); reduced_evts.insert(*cur_it); } - for(; next_it!=end() && egraph[*next_it].is_fence(); ++next_it); - assert(next_it != end()); - if(reduced_evts.find(*next_it) == reduced_evts.end()) + for(; next_it!=end() && egraph[*next_it].is_fence(); ++next_it) {} + assert(next_it!=end()); + if(reduced_evts.find(*next_it)==reduced_evts.end()) { reduced.push_back(*next_it); reduced_evts.insert(*next_it); @@ -1417,7 +1436,7 @@ Function: event_grapht::critical_cyclet::print_name \*******************************************************************/ std::string event_grapht::critical_cyclet::print_name( - const critical_cyclet& reduced, + const critical_cyclet &reduced, memory_modelt model) const { assert(reduced.size()>=2); @@ -1428,21 +1447,21 @@ std::string event_grapht::critical_cyclet::print_name( bool first_done=false; for(const_iterator cur_it=reduced.begin(); cur_it!=reduced.end(); ++cur_it) { - const abstract_eventt& cur=egraph[*cur_it]; + const abstract_eventt &cur=egraph[*cur_it]; if(prev_it!=reduced.end()) { - const abstract_eventt& prev=egraph[*prev_it]; + const abstract_eventt &prev=egraph[*prev_it]; - if(prev.operation == abstract_eventt::Fence || - prev.operation == abstract_eventt::Lwfence || - prev.operation == abstract_eventt::ASMfence) + if(prev.operation==abstract_eventt::Fence || + prev.operation==abstract_eventt::Lwfence || + prev.operation==abstract_eventt::ASMfence) { ++extra_fence_count; // nothing to do } - else if(cur.operation == abstract_eventt::Fence) + else if(cur.operation==abstract_eventt::Fence) { const_iterator n_it=cur_it; bool wraparound=false; @@ -1457,23 +1476,25 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; n_it=reduced.begin(); } - const abstract_eventt& cand=egraph[*n_it]; - if(cand.operation != abstract_eventt::Fence && - cand.operation != abstract_eventt::Lwfence && - cand.operation != abstract_eventt::ASMfence) + const abstract_eventt &cand=egraph[*n_it]; + if(cand.operation!=abstract_eventt::Fence && + cand.operation!=abstract_eventt::Lwfence && + cand.operation!=abstract_eventt::ASMfence) break; - if(!wraparound) ++cur_it; - if(!wraparound) ++extra_fence_count; + if(!wraparound) + ++cur_it; + if(!wraparound) + ++extra_fence_count; } - const abstract_eventt& succ=egraph[*n_it]; - assert(succ.operation == abstract_eventt::Read || - succ.operation == abstract_eventt::Write); + const abstract_eventt &succ=egraph[*n_it]; + assert(succ.operation==abstract_eventt::Read || + succ.operation==abstract_eventt::Write); name += (model==Power?" Sync":" MFence"); name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } - else if(cur.operation == abstract_eventt::Lwfence) + else if(cur.operation==abstract_eventt::Lwfence) { std::string cand_name=" LwSync"; const_iterator n_it=cur_it; @@ -1489,33 +1510,35 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; n_it=reduced.begin(); } - const abstract_eventt& cand=egraph[*n_it]; - if(cand.operation != abstract_eventt::Fence && - cand.operation != abstract_eventt::Lwfence && - cand.operation != abstract_eventt::ASMfence) + const abstract_eventt &cand=egraph[*n_it]; + if(cand.operation!=abstract_eventt::Fence && + cand.operation!=abstract_eventt::Lwfence && + cand.operation!=abstract_eventt::ASMfence) break; - else if(cand.operation == abstract_eventt::Fence || - (cand.operation == abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::Fence || + (cand.operation==abstract_eventt::ASMfence && cand.fence_value()&1)) - cand_name = (model==Power?" Sync":" MFence"); - if(!wraparound) ++cur_it; - if(!wraparound) ++extra_fence_count; + cand_name=(model==Power?" Sync":" MFence"); + if(!wraparound) + ++cur_it; + if(!wraparound) + ++extra_fence_count; } - const abstract_eventt& succ=egraph[*n_it]; - assert(succ.operation == abstract_eventt::Read || - succ.operation == abstract_eventt::Write); + const abstract_eventt &succ=egraph[*n_it]; + assert(succ.operation==abstract_eventt::Read || + succ.operation==abstract_eventt::Write); name += cand_name; name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } - else if(cur.operation == abstract_eventt::ASMfence) + else if(cur.operation==abstract_eventt::ASMfence) { std::string cand_name; if(cur.fence_value()&1) - cand_name = (model==Power?" Sync":" MFence"); + cand_name=(model==Power?" Sync":" MFence"); else - cand_name = " LwSync"; + cand_name=" LwSync"; const_iterator n_it=cur_it; bool wraparound=false; while(true) @@ -1529,61 +1552,63 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; n_it=reduced.begin(); } - const abstract_eventt& cand=egraph[*n_it]; - if(cand.operation != abstract_eventt::Fence && - cand.operation != abstract_eventt::Lwfence && - cand.operation != abstract_eventt::ASMfence) + const abstract_eventt &cand=egraph[*n_it]; + if(cand.operation!=abstract_eventt::Fence && + cand.operation!=abstract_eventt::Lwfence && + cand.operation!=abstract_eventt::ASMfence) break; - else if(cand.operation == abstract_eventt::Fence || - (cand.operation == abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::Fence || + (cand.operation==abstract_eventt::ASMfence && cand.fence_value()&1)) - cand_name = (model==Power?" Sync":" MFence"); - if(!wraparound) ++cur_it; - if(!wraparound) ++extra_fence_count; + cand_name=(model==Power?" Sync":" MFence"); + if(!wraparound) + ++cur_it; + if(!wraparound) + ++extra_fence_count; } - const abstract_eventt& succ=egraph[*n_it]; - assert(succ.operation == abstract_eventt::Read || - succ.operation == abstract_eventt::Write); + const abstract_eventt &succ=egraph[*n_it]; + assert(succ.operation==abstract_eventt::Read || + succ.operation==abstract_eventt::Write); name += cand_name; name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } - else if(prev.variable == cur.variable - && prev.operation == abstract_eventt::Write - && cur.operation == abstract_eventt::Read) + else if(prev.variable==cur.variable + && prev.operation==abstract_eventt::Write + && cur.operation==abstract_eventt::Read) { name += " Rf"; name += (prev.thread==cur.thread?"i":"e"); } - else if(prev.variable == cur.variable - && prev.operation == abstract_eventt::Read - && cur.operation == abstract_eventt::Write - && (prev.thread != cur.thread || *prev_it > *cur_it)) + else if(prev.variable==cur.variable + && prev.operation==abstract_eventt::Read + && cur.operation==abstract_eventt::Write + && (prev.thread!=cur.thread || *prev_it > *cur_it)) { name += " Fr"; name += (prev.thread==cur.thread?"i":"e"); } - else if(prev.variable == cur.variable - && prev.operation == abstract_eventt::Write - && cur.operation == abstract_eventt::Write - && (prev.thread != cur.thread || *prev_it > *cur_it)) - /* we prefer to write Po rather than Wsi */ + else if(prev.variable==cur.variable && + prev.operation==abstract_eventt::Write && + cur.operation==abstract_eventt::Write && + (prev.thread!=cur.thread || *prev_it > *cur_it)) { + /* we prefer to write Po rather than Wsi */ name += " Ws"; name += (prev.thread==cur.thread?"i":"e"); } - else if(prev.thread == cur.thread - && prev.operation != abstract_eventt::Fence - && prev.operation != abstract_eventt::Lwfence - && prev.operation != abstract_eventt::ASMfence) + else if(prev.thread==cur.thread + && prev.operation!=abstract_eventt::Fence + && prev.operation!=abstract_eventt::Lwfence + && prev.operation!=abstract_eventt::ASMfence) { - const data_dpt& dep=egraph.map_data_dp[cur.thread]; + const data_dpt &dep=egraph.map_data_dp[cur.thread]; - if(prev.operation == abstract_eventt::Read && + if(prev.operation==abstract_eventt::Read && dep.dp(prev, cur)) { name += " DpData"; @@ -1618,73 +1643,73 @@ std::string event_grapht::critical_cyclet::print_name( return name; } - const abstract_eventt& first=egraph[reduced.front()]; - const abstract_eventt& last=egraph[reduced.back()]; + const abstract_eventt &first=egraph[reduced.front()]; + const abstract_eventt &last=egraph[reduced.back()]; - assert(last.operation != abstract_eventt::Fence && - last.operation != abstract_eventt::Lwfence && - last.operation != abstract_eventt::ASMfence); + assert(last.operation!=abstract_eventt::Fence && + last.operation!=abstract_eventt::Lwfence && + last.operation!=abstract_eventt::ASMfence); - if(first.operation == abstract_eventt::Fence || - first.operation == abstract_eventt::Lwfence || - first.operation == abstract_eventt::ASMfence) + if(first.operation==abstract_eventt::Fence || + first.operation==abstract_eventt::Lwfence || + first.operation==abstract_eventt::ASMfence) { std::string cand_name=" LwSync"; const_iterator it=reduced.begin(); for( ; it!=reduced.end(); ++it) { - const abstract_eventt& cand=egraph[*it]; + const abstract_eventt &cand=egraph[*it]; - if(cand.operation != abstract_eventt::Fence && - cand.operation != abstract_eventt::Lwfence && - cand.operation != abstract_eventt::ASMfence) + if(cand.operation!=abstract_eventt::Fence && + cand.operation!=abstract_eventt::Lwfence && + cand.operation!=abstract_eventt::ASMfence) break; - else if(cand.operation == abstract_eventt::Fence || - (cand.operation == abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::Fence || + (cand.operation==abstract_eventt::ASMfence && cand.fence_value()&1)) - cand_name = (model==Power?" Sync":" MFence"); + cand_name=(model==Power?" Sync":" MFence"); } assert(it!=reduced.begin() && it!=reduced.end()); - const abstract_eventt& succ=egraph[*it]; - assert(succ.operation == abstract_eventt::Read || - succ.operation == abstract_eventt::Write); + const abstract_eventt &succ=egraph[*it]; + assert(succ.operation==abstract_eventt::Read || + succ.operation==abstract_eventt::Write); name += cand_name; name += (last.variable==succ.variable?"s":"d") + last.get_operation() + succ.get_operation(); } - else if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Read) + else if(last.variable==first.variable + && last.operation==abstract_eventt::Write + && first.operation==abstract_eventt::Read) { name += " Rf"; name += (last.thread==first.thread?"i":"e"); } - else if(last.variable == first.variable - && last.operation == abstract_eventt::Read - && first.operation == abstract_eventt::Write - && (last.thread != first.thread || reduced.back() > reduced.front())) + else if(last.variable==first.variable + && last.operation==abstract_eventt::Read + && first.operation==abstract_eventt::Write + && (last.thread!=first.thread || reduced.back() > reduced.front())) { name += " Fr"; name += (last.thread==first.thread?"i":"e"); } - else if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Write - && (last.thread != first.thread || reduced.back() > reduced.front())) - /* we prefer to write Po rather than Wsi */ + else if(last.variable==first.variable && + last.operation==abstract_eventt::Write && + first.operation==abstract_eventt::Write && + (last.thread!=first.thread || reduced.back() > reduced.front())) { + /* we prefer to write Po rather than Wsi */ name += " Ws"; name += (last.thread==first.thread?"i":"e"); } else if(last.thread==first.thread) { - const data_dpt& dep=egraph.map_data_dp[last.thread]; + const data_dpt &dep=egraph.map_data_dp[last.thread]; - if(last.operation == abstract_eventt::Read && + if(last.operation==abstract_eventt::Read && dep.dp(last, first)) { name += " DpData"; @@ -1735,7 +1760,7 @@ void event_grapht::critical_cyclet::print_dot( /* print vertices */ for(const_iterator it=begin(); it!=end(); ++it) { - const abstract_eventt& ev=egraph[*it]; + const abstract_eventt &ev=egraph[*it]; /* id of the cycle in comments */ str << "/* " << id << " */" << std::endl; @@ -1750,7 +1775,7 @@ void event_grapht::critical_cyclet::print_dot( const_iterator prev_it=end(); for(const_iterator cur_it=begin(); cur_it!=end(); ++cur_it) { - const abstract_eventt& cur=egraph[*cur_it]; + const abstract_eventt &cur=egraph[*cur_it]; /* id of the cycle in comments */ str << "/* " << id << " */" << std::endl; @@ -1758,65 +1783,60 @@ void event_grapht::critical_cyclet::print_dot( /* edge */ if(prev_it!=end()) { - const abstract_eventt& prev = egraph[*prev_it]; + const abstract_eventt &prev=egraph[*prev_it]; str << prev.id << "->"; - if(cur.operation == abstract_eventt::Fence) + if(cur.operation==abstract_eventt::Fence) { const_iterator n_it=cur_it; ++n_it; - const abstract_eventt& succ=( n_it!=end() ? - egraph[*n_it] : egraph[front()] ); + const abstract_eventt &succ= + n_it!=end() ? egraph[*n_it] : egraph[front()]; str << succ.id << "[label=\""; str << (model==Power?"Sync":"MFence"); str << (prev.variable==cur.variable?"s":"d"); str << prev.get_operation() << succ.get_operation(); } - - else if(cur.operation == abstract_eventt::Lwfence) + else if(cur.operation==abstract_eventt::Lwfence) { const_iterator n_it=cur_it; ++n_it; - const abstract_eventt& succ=( n_it!=end() ? - egraph[*n_it] : egraph[front()] ); + const abstract_eventt &succ= + n_it!=end() ? egraph[*n_it] : egraph[front()]; str << succ.id << "[label=\""; str << "LwSync" << (prev.variable==cur.variable?"s":"d"); str <"; - if(first.operation == abstract_eventt::Fence) + if(first.operation==abstract_eventt::Fence) { const_iterator next=begin(); ++next; - const abstract_eventt& succ=egraph[*next]; + const abstract_eventt &succ=egraph[*next]; str << succ.id << "[label=\""; str << (model==Power?"Sync":"MFence"); str << (last.variable==first.variable?"s":"d"); str << last.get_operation() << succ.get_operation(); } - - else if(first.operation == abstract_eventt::Lwfence) + else if(first.operation==abstract_eventt::Lwfence) { const_iterator next=begin(); ++next; - const abstract_eventt& succ=egraph[*next]; + const abstract_eventt &succ=egraph[*next]; str << succ.id << "[label=\""; str << "LwSync" << (last.variable==first.variable?"s":"d"); str << last.get_operation() << succ.get_operation(); } - - else if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Read) + else if(last.variable==first.variable && + last.operation==abstract_eventt::Write && + first.operation==abstract_eventt::Read) { str << first.id << "[label=\""; str << "Rf" << (last.thread==first.thread?"i":"e"); } - - else if(last.variable == first.variable - && last.operation == abstract_eventt::Read - && first.operation == abstract_eventt::Write) + else if(last.variable==first.variable && + last.operation==abstract_eventt::Read && + first.operation==abstract_eventt::Write) { str << first.id << "[label=\""; str << "Fr" << (last.thread==first.thread?"i":"e"); } - - else if(last.variable == first.variable - && last.operation == abstract_eventt::Write - && first.operation == abstract_eventt::Write - && last.thread != first.thread) - /* we prefer to write Po rather than Wsi */ + else if(last.variable==first.variable && + last.operation==abstract_eventt::Write && + first.operation==abstract_eventt::Write && + last.thread!=first.thread) { + /* we prefer to write Po rather than Wsi */ str << first.id << "[label=\""; str << "Ws" << (last.thread==first.thread?"i":"e"); } - - else if(last.thread==first.thread - && last.operation != abstract_eventt::Fence) + else if(last.thread==first.thread && + last.operation!=abstract_eventt::Fence) { str << first.id << "[label=\""; str << "Po" << (last.variable==first.variable?"s":"d"); str << last.get_operation() << first.get_operation(); } - else str << first.id << "[label=\"?"; diff --git a/src/goto-instrument/wmm/event_graph.h b/src/goto-instrument/wmm/event_graph.h index 1a10ded69c3..4ae9c067264 100644 --- a/src/goto-instrument/wmm/event_graph.h +++ b/src/goto-instrument/wmm/event_graph.h @@ -29,7 +29,7 @@ class namespacet; graph of abstract events \*******************************************************************/ -typedef graph wmm_grapht; +typedef grapht wmm_grapht; typedef wmm_grapht::node_indext event_idt; class event_grapht @@ -39,34 +39,34 @@ class event_grapht class critical_cyclet:public std::list { protected: - event_grapht& egraph; + event_grapht &egraph; bool is_not_uniproc() const; bool is_not_weak_uniproc() const; - std::string print_detail(const critical_cyclet& reduced, - std::map& map_id2var, - std::map& map_var2id, + std::string print_detail(const critical_cyclet &reduced, + std::map &map_id2var, + std::map &map_var2id, memory_modelt model) const; - std::string print_name(const critical_cyclet& redyced, + std::string print_name(const critical_cyclet &redyced, memory_modelt model) const; - bool check_AC(const_iterator s_it, const abstract_eventt& first, - const abstract_eventt& second) const; - bool check_BC(const_iterator it, const abstract_eventt& first, - const abstract_eventt& second) const; + bool check_AC(const_iterator s_it, const abstract_eventt &first, + const abstract_eventt &second) const; + bool check_BC(const_iterator it, const abstract_eventt &first, + const abstract_eventt &second) const; public: unsigned id; bool has_user_defined_fence; - critical_cyclet(event_grapht& _egraph, unsigned _id) - :egraph(_egraph),id(_id), has_user_defined_fence(false) + critical_cyclet(event_grapht &_egraph, unsigned _id) + :egraph(_egraph), id(_id), has_user_defined_fence(false) { } - void operator()(const critical_cyclet& cyc) + void operator()(const critical_cyclet &cyc) { clear(); for(const_iterator it=cyc.begin(); it!=cyc.end(); it++) @@ -87,7 +87,7 @@ class event_grapht for(; it!=end() && n_it!=end(); ++it, ++n_it) { if(egraph[*it].thread==egraph[*n_it].thread - && !egraph.are_po_ordered(*it,*n_it)) + && !egraph.are_po_ordered(*it, *n_it)) return false; } @@ -96,7 +96,7 @@ class event_grapht /* removes internal events (e.g. podWW Rfi gives podWR) from.hide_internals(&target) */ - void hide_internals(critical_cyclet& reduced) const; + void hide_internals(critical_cyclet &reduced) const; /* checks whether there is at leat one pair which is unsafe (takes fences and dependencies into account), and adds @@ -106,7 +106,7 @@ class event_grapht /* do not update the unsafe pairs set */ bool is_unsafe_fast(memory_modelt model) { - return is_unsafe(model,true); + return is_unsafe(model, true); } void compute_unsafe_pairs(memory_modelt model) @@ -133,31 +133,32 @@ class event_grapht event_idt second; bool is_po; - delayt(event_idt _first) - :first(_first),is_po(true) + explicit delayt(event_idt _first): + first(_first), is_po(true) { } - delayt(event_idt _first, event_idt _second) - :first(_first),second(_second),is_po(false) + delayt(event_idt _first, event_idt _second): + first(_first), second(_second), is_po(false) { } - delayt(event_idt _first, event_idt _second, bool _is_po) - :first(_first),second(_second),is_po(_is_po) + delayt(event_idt _first, event_idt _second, bool _is_po): + first(_first), second(_second), is_po(_is_po) { } - inline bool operator==(const delayt& other) const + bool operator==(const delayt &other) const { - return (is_po ? first==other.first - : first==other.first&&second==other.second); + return (is_po ? first==other.first : + first==other.first && second==other.second); } - inline bool operator<(const delayt& other) const + bool operator<(const delayt &other) const { - return (is_po ? first& map_id2var, - std::map& map_var2id, + std::map &map_id2var, + std::map &map_var2id, bool hide_internals) const; void print_dot(std::ostream &str, unsigned colour, memory_modelt model) const; - inline bool operator<(const critical_cyclet& other) const + bool operator<(const critical_cyclet &other) const { return ( ((std::list) *this) < (std::list)other); } @@ -220,16 +221,16 @@ class event_grapht } protected: - event_grapht& egraph; + event_grapht &egraph; /* parameters limiting the exploration */ unsigned max_var; unsigned max_po_trans; /* constraints for graph exploration */ - std::map writes_per_variable; - std::map reads_per_variable; - std::map events_per_thread; + std::map writes_per_variable; + std::map reads_per_variable; + std::map events_per_thread; /* for thread and filtering in backtrack */ virtual inline bool filtering(event_idt u) @@ -253,17 +254,22 @@ class event_grapht /* after the collection, eliminates the executions forbidden by an indirect thin-air */ - void filter_thin_air(std::set& set_of_cycles); + void filter_thin_air(std::set &set_of_cycles); public: - graph_explorert(event_grapht& _egraph, unsigned _max_var, - unsigned _max_po_trans) - :egraph(_egraph), max_var(_max_var), max_po_trans(_max_po_trans), cycle_nb(0) + graph_explorert( + event_grapht &_egraph, + unsigned _max_var, + unsigned _max_po_trans): + egraph(_egraph), + max_var(_max_var), + max_po_trans(_max_po_trans), + cycle_nb(0) { } /* structures for graph exploration */ - std::map mark; + std::map mark; std::stack marked_stack; std::stack point_stack; @@ -272,7 +278,7 @@ class event_grapht critical_cyclet extract_cycle(event_idt vertex, event_idt source, unsigned number_of_cycles); - bool backtrack(std::set& set_of_cycles, + bool backtrack(std::set &set_of_cycles, event_idt source, event_idt vertex, bool unsafe_met, @@ -285,7 +291,7 @@ class event_grapht /* Tarjan 1972 adapted and modified for events + po-transitivity */ void collect_cycles( - std::set& set_of_cycles, + std::set &set_of_cycles, memory_modelt model); }; @@ -293,28 +299,28 @@ class event_grapht class graph_conc_explorert:public graph_explorert { protected: - const std::set& filter; + const std::set &filter; public: - graph_conc_explorert(event_grapht& _egraph, unsigned _max_var, - unsigned _max_po_trans, const std::set& _filter) - :graph_explorert(_egraph,_max_var,_max_po_trans),filter(_filter) + graph_conc_explorert(event_grapht &_egraph, unsigned _max_var, + unsigned _max_po_trans, const std::set &_filter) + :graph_explorert(_egraph, _max_var, _max_po_trans), filter(_filter) { } - inline bool filtering(event_idt u) + bool filtering(event_idt u) { return filter.find(u)==filter.end(); } - inline std::list* initial_filtering(std::list* order) + std::list* initial_filtering(std::list* order) { static std::list new_order; /* intersection */ - for(std::list::iterator it=order->begin();it!=order->end();it++) - if(filter.find(*it)!=filter.end()) - new_order.push_back(*it); + for(const auto &evt : *order) + if(filter.find(evt)!=filter.end()) + new_order.push_back(evt); return &new_order; } @@ -330,17 +336,17 @@ class event_grapht bool find_second_event(event_idt source); public: - graph_pensieve_explorert(event_grapht& _egraph, unsigned _max_var, + graph_pensieve_explorert(event_grapht &_egraph, unsigned _max_var, unsigned _max_po_trans) - :graph_explorert(_egraph,_max_var,_max_po_trans), naive(false) + :graph_explorert(_egraph, _max_var, _max_po_trans), naive(false) {} void set_naive() {naive=true;} - void collect_pairs(namespacet& ns); + void collect_pairs(namespacet &ns); }; public: - event_grapht(messaget& _message): + explicit event_grapht(messaget &_message): filter_thin_air(true), filter_uniproc(true), message(_message) @@ -349,16 +355,16 @@ class event_grapht bool filter_thin_air; bool filter_uniproc; - messaget& message; + messaget &message; /* data dependencies per thread */ - std::map map_data_dp; + std::map map_data_dp; /* orders */ std::list po_order; std::list poUrfe_order; - std::set > loops; + std::set > loops; event_idt add_node() { @@ -368,42 +374,42 @@ class event_grapht return po_no; } - inline wmm_grapht::nodet &operator[](event_idt n) + grapht::nodet &operator[](event_idt n) { return po_graph[n]; } bool has_po_edge(event_idt i, event_idt j) const { - return po_graph.has_edge(i,j); + return po_graph.has_edge(i, j); } bool has_com_edge(event_idt i, event_idt j) const { - return com_graph.has_edge(i,j); + return com_graph.has_edge(i, j); } - inline std::size_t size() const + std::size_t size() const { return po_graph.size(); } - inline const wmm_grapht::edgest &po_in(event_idt n) const + const wmm_grapht::edgest &po_in(event_idt n) const { return po_graph.in(n); } - inline const wmm_grapht::edgest &po_out(event_idt n) const + const wmm_grapht::edgest &po_out(event_idt n) const { return po_graph.out(n); } - inline const wmm_grapht::edgest &com_in(event_idt n) const + const wmm_grapht::edgest &com_in(event_idt n) const { return com_graph.in(n); } - inline const wmm_grapht::edgest &com_out(event_idt n) const + const wmm_grapht::edgest &com_out(event_idt n) const { return com_graph.out(n); } @@ -412,7 +418,7 @@ class event_grapht { assert(a!=b); assert(operator[](a).thread==operator[](b).thread); - po_graph.add_edge(a,b); + po_graph.add_edge(a, b); po_order.push_back(a); poUrfe_order.push_back(a); } @@ -421,51 +427,52 @@ class event_grapht { assert(a!=b); assert(operator[](a).thread==operator[](b).thread); - po_graph.add_edge(a,b); + po_graph.add_edge(a, b); po_order.push_back(a); poUrfe_order.push_back(a); - loops.insert(std::pair(a,b)); - loops.insert(std::pair(b,a)); + loops.insert(std::pair(a, b)); + loops.insert(std::pair(b, a)); } void add_com_edge(event_idt a, event_idt b) { assert(a!=b); - com_graph.add_edge(a,b); + com_graph.add_edge(a, b); poUrfe_order.push_back(a); } void add_undirected_com_edge(event_idt a, event_idt b) { assert(a!=b); - add_com_edge(a,b); - add_com_edge(b,a); + add_com_edge(a, b); + add_com_edge(b, a); } void remove_po_edge(event_idt a, event_idt b) { - po_graph.remove_edge(a,b); + po_graph.remove_edge(a, b); } void remove_com_edge(event_idt a, event_idt b) { - com_graph.remove_edge(a,b); + com_graph.remove_edge(a, b); } void remove_edge(event_idt a, event_idt b) { - remove_po_edge(a,b); - remove_com_edge(a,b); + remove_po_edge(a, b); + remove_com_edge(a, b); } /* copies the sub-graph G between begin and end into G', connects G.end with G'.begin, and returns G'.end */ - void explore_copy_segment(std::set& explored, event_idt begin, + void explore_copy_segment(std::set &explored, event_idt begin, event_idt end) const; event_idt copy_segment(event_idt begin, event_idt end); /* to keep track of the loop already copied */ - std::set > duplicated_bodies; + std::set> + duplicated_bodies; bool is_local(event_idt a) { @@ -479,15 +486,14 @@ class event_grapht return false; /* if back-edge, a-po->b \/ b-po->a */ - if( loops.find(std::pair(a,b))!=loops.end() ) + if( loops.find(std::pair(a, b))!=loops.end() ) return true; // would be true if no cycle in po - for(std::list::iterator it=po_order.begin(); - it!=po_order.end();it++) - if(*it==a) + for(const auto &evt : po_order) + if(evt==a) return true; - else if(*it==b) + else if(evt==b) return false; return false; @@ -502,23 +508,23 @@ class event_grapht /* prints to graph.dot */ void print_graph(); - void print_rec_graph(std::ofstream& file, event_idt node_id, - std::set& visited); + void print_rec_graph(std::ofstream &file, event_idt node_id, + std::set &visited); /* Tarjan 1972 adapted and modified for events + po-transitivity */ - void collect_cycles(std::set& set_of_cycles, + void collect_cycles(std::set &set_of_cycles, memory_modelt model, - const std::set& filter) + const std::set &filter) { - graph_conc_explorert exploration(*this, max_var, max_po_trans,filter); - exploration.collect_cycles(set_of_cycles,model); + graph_conc_explorert exploration(*this, max_var, max_po_trans, filter); + exploration.collect_cycles(set_of_cycles, model); } - void collect_cycles(std::set& set_of_cycles, + void collect_cycles(std::set &set_of_cycles, memory_modelt model) { graph_explorert exploration(*this, max_var, max_po_trans); - exploration.collect_cycles(set_of_cycles,model); + exploration.collect_cycles(set_of_cycles, model); } void set_parameters_collection( @@ -533,13 +539,13 @@ class event_grapht /* collects all the pairs of events with respectively at least one cmp, regardless of the architecture (Pensieve'05 strategy) */ - void collect_pairs(namespacet& ns) + void collect_pairs(namespacet &ns) { graph_pensieve_explorert exploration(*this, max_var, max_po_trans); exploration.collect_pairs(ns); } - void collect_pairs_naive(namespacet& ns) + void collect_pairs_naive(namespacet &ns) { graph_pensieve_explorert exploration(*this, max_var, max_po_trans); exploration.set_naive(); diff --git a/src/goto-instrument/wmm/goto2graph.cpp b/src/goto-instrument/wmm/goto2graph.cpp index bdca381e025..bdd97555c06 100644 --- a/src/goto-instrument/wmm/goto2graph.cpp +++ b/src/goto-instrument/wmm/goto2graph.cpp @@ -27,7 +27,7 @@ Date: 2012 #include "fence.h" #include "goto2graph.h" -//#define PRINT_UNSAFES +// #define PRINT_UNSAFES /*******************************************************************\ @@ -42,11 +42,12 @@ Function: instrumentert::local \*******************************************************************/ -bool inline instrumentert::local(const irep_idt& id) +bool inline instrumentert::local(const irep_idt &id) { - std::string identifier = id2string(id); + std::string identifier=id2string(id); - if(has_prefix(identifier, "symex_invalid") || has_prefix(identifier, "symex::invalid")) + if(has_prefix(identifier, "symex_invalid") || + has_prefix(identifier, "symex::invalid")) { /* symex_invalid and symex::invalid_object generated when pointer analysis fails */ @@ -62,7 +63,7 @@ bool inline instrumentert::local(const irep_idt& id) has_prefix(identifier, "__unbuffered_")) return true; - const size_t pos = identifier.find("[]"); + const size_t pos=identifier.find("[]"); if(pos!=std::string::npos) { @@ -72,7 +73,7 @@ bool inline instrumentert::local(const irep_idt& id) try { - const symbolt& symbol = ns.lookup(identifier); + const symbolt &symbol=ns.lookup(identifier); if(!symbol.is_static_lifetime) return true; /* these are local */ @@ -89,7 +90,7 @@ bool inline instrumentert::local(const irep_idt& id) } } -bool inline instrumentert::cfg_visitort::local(const irep_idt& i) +bool inline instrumentert::cfg_visitort::local(const irep_idt &i) { return instrumenter.local(i); } @@ -109,7 +110,7 @@ Function: instrumentert::goto2graph_cfg \*******************************************************************/ unsigned instrumentert::goto2graph_cfg( - value_setst& value_sets, + value_setst &value_sets, memory_modelt model, bool no_dependencies, loop_strategyt duplicate_body) @@ -123,38 +124,47 @@ unsigned instrumentert::goto2graph_cfg( goto_functions.entry_point()); std::vector subgraph_index; - num_sccs = egraph_alt.SCCs(subgraph_index); + num_sccs=egraph_alt.SCCs(subgraph_index); assert(egraph_SCCs.empty()); egraph_SCCs.resize(num_sccs, std::set()); - for(std::map::const_iterator it=map_vertex_gnode.begin(); - it!=map_vertex_gnode.end(); - it++) + for(std::map::const_iterator + it=map_vertex_gnode.begin(); + it!=map_vertex_gnode.end(); + it++) { - const std::size_t sg = subgraph_index[it->second]; + const std::size_t sg=subgraph_index[it->second]; egraph_SCCs[sg].insert(it->first); } - message.status() <<"Number of threads detected: "<3) interesting_sccs++; - message.statistics() <<"Graph with "<second.body.instructions.size(); - message.statistics() <<"Number of goto-instructions: "<& initial_vertex, + const std::set &initial_vertex, /* outcoming edges */ - std::set& ending_vertex) + std::set &ending_vertex) { /* flow: egraph */ - instrumenter.message.debug() << "visit function "< Rb -po-> Wa */ else if(instruction.is_assign()) { @@ -244,47 +253,40 @@ void instrumentert::cfg_visitort::visit_cfg_function( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) } - - else if(is_fence(instruction,instrumenter.ns)) + else if(is_fence(instruction, instrumenter.ns)) { instrumenter.message.debug() << "Constructing a fence" << messaget::eom; visit_cfg_fence(i_it); } - - else if(model!=TSO && is_lwfence(instruction,instrumenter.ns)) + else if(model!=TSO && is_lwfence(instruction, instrumenter.ns)) { visit_cfg_lwfence(i_it); } - else if(model==TSO && is_lwfence(instruction, instrumenter.ns)) { /* propagation */ visit_cfg_skip(i_it); } - else if(instruction.is_other() && instruction.code.get_statement()==ID_fence) { visit_cfg_asm_fence(i_it); } - else if(instruction.is_function_call()) { visit_cfg_function_call(value_sets, i_it, model, no_dependencies, replicate_body); } - else if(instruction.is_goto()) { visit_cfg_goto(i_it, replicate_body, value_sets #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) } - #ifdef CONTEXT_INSENSITIVE else if(instruction.is_return()) { @@ -292,7 +294,6 @@ void instrumentert::cfg_visitort::visit_cfg_function( add_all_pos(it, out_nodes[function], in_pos[i_it]); } #endif - else { /* propagates */ @@ -300,12 +301,12 @@ void instrumentert::cfg_visitort::visit_cfg_function( } } - std::pair new_dp(thread, data_dp); + std::pair new_dp(thread, data_dp); egraph.map_data_dp.insert(new_dp); data_dp.print(instrumenter.message); - if(instrumenter.goto_functions.function_map[function].body - .instructions.size() <= 0) + if(instrumenter.goto_functions.function_map[function] + .body.instructions.empty()) { /* empty set of ending edges */ } @@ -333,7 +334,7 @@ Function: instrumentert::visit_cfg_propagate void inline instrumentert::cfg_visitort::visit_cfg_propagate( goto_programt::instructionst::iterator i_it) { - const goto_programt::instructiont& instruction=*i_it; + const goto_programt::instructiont &instruction=*i_it; /* propagation */ in_pos[i_it].clear(); for(const auto &in : instruction.incoming_edges) @@ -375,7 +376,7 @@ Function: instrumentert::visit_cfg_reference_function /* Warning: we iterate here over the successive instructions of the regardless of the gotos. This function has to be called *AFTER* an exploration of the function constructing the graph. */ -void inline instrumentert::cfg_visitort::visit_cfg_reference_function ( +void inline instrumentert::cfg_visitort::visit_cfg_reference_function( irep_idt id_function) { if(instrumenter.map_function_graph.find(id_function)!= @@ -383,7 +384,7 @@ void inline instrumentert::cfg_visitort::visit_cfg_reference_function ( return; /* gets the body of the function */ - goto_programt::instructionst& body=instrumenter.goto_functions + goto_programt::instructionst &body=instrumenter.goto_functions .function_map[id_function].body.instructions; if(body.empty()) @@ -410,10 +411,10 @@ void inline instrumentert::cfg_visitort::visit_cfg_reference_function ( { /* connects the previous nodes to those ones */ for(std::set::const_iterator to=in_pos[targ].begin(); - to!=in_pos[targ].end(); ++to) + to!=in_pos[targ].end(); ++to) in_nodes.insert(to->first); for(std::set::const_iterator from=in_pos[i_it].begin(); - from!=in_pos[i_it].end(); ++from) + from!=in_pos[i_it].end(); ++from) out_nodes.insert(from->first); } else @@ -421,14 +422,14 @@ void inline instrumentert::cfg_visitort::visit_cfg_reference_function ( instrumenter.message.debug() << "else case" << messaget::eom; /* connects NEXT nodes following the targets -- bwd analysis */ for(goto_programt::instructionst::iterator cur=i_it; - cur!=targ; --cur) + cur!=targ; --cur) { instrumenter.message.debug() << "i" << messaget::eom; for(const auto &in : cur->incoming_edges) { instrumenter.message.debug() << "t" << messaget::eom; - if(in_pos.find(in)!=in_pos.end() - && updated.find(in)!=updated.end()) + if(in_pos.find(in)!=in_pos.end() && + updated.find(in)!=updated.end()) { /* out_pos[in].insert(in_pos[in])*/ add_all_pos(it1, out_pos[in], in_pos[in]); @@ -445,10 +446,10 @@ void inline instrumentert::cfg_visitort::visit_cfg_reference_function ( if(out_pos.find(targ)!=out_pos.end()) { for(std::set::const_iterator to=out_pos[targ].begin(); - to!=out_pos[targ].end(); ++to) + to!=out_pos[targ].end(); ++to) in_nodes.insert(to->first); for(std::set::const_iterator from=in_pos[i_it].begin(); - from!=in_pos[i_it].end(); ++from) + from!=in_pos[i_it].end(); ++from) out_nodes.insert(from->first); } } @@ -470,7 +471,7 @@ Function: alt_copy_segment \*******************************************************************/ -event_idt alt_copy_segment(wmm_grapht& alt_egraph, +event_idt alt_copy_segment(wmm_grapht &alt_egraph, event_idt begin, event_idt end) { /* no need to duplicate the loop nodes for the SCC-detection graph -- a @@ -494,7 +495,7 @@ Function: instrumentert::visit_cfg_visitort::contains_shared_array bool instrumentert::cfg_visitort::contains_shared_array( goto_programt::const_targett targ, goto_programt::const_targett i_it, - value_setst& value_sets + value_setst &value_sets #ifdef LOCAL_MAY , local_may_aliast local_may #endif @@ -511,7 +512,7 @@ bool instrumentert::cfg_visitort::contains_shared_array( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) instrumenter.message.debug() << "Writes: "<function]; + const goto_functionst::goto_functiont &fun= + instrumenter.goto_functions.function_map[i_it->function]; bool found_pos=false; goto_programt::const_targett new_targ=targ; @@ -638,8 +642,8 @@ void inline instrumentert::cfg_visitort::visit_cfg_duplicate( } /* appends the body once more */ - const std::set& up_set=in_pos[(found_pos ? new_targ : targ)]; - const std::set& down_set=in_pos[i_it]; + const std::set &up_set=in_pos[(found_pos ? new_targ : targ)]; + const std::set &down_set=in_pos[i_it]; for(std::set::const_iterator begin_it=up_set.begin(); begin_it!=up_set.end(); ++begin_it) @@ -659,8 +663,10 @@ void inline instrumentert::cfg_visitort::visit_cfg_duplicate( alt_copy_segment(egraph_alt, begin_it->second, end_it->second); #if 0 const event_idt end=egraph.copy_segment(begin_it->first, end_it->first); - const event_idt alt_end=alt_copy_segment(egraph_alt, begin_it->second, end_it->second); - //in_pos[i_it].insert(nodet(end, alt_end)); // copied; no need for back-edge! + const event_idt alt_end= + alt_copy_segment(egraph_alt, begin_it->second, end_it->second); + // copied; no need for back-edge! + // in_pos[i_it].insert(nodet(end, alt_end)); #endif } } @@ -679,7 +685,8 @@ Function: instrumentert::visit_cfg_visitort::visit_cfg_backedge \*******************************************************************/ void inline instrumentert::cfg_visitort::visit_cfg_backedge( - goto_programt::const_targett targ, goto_programt::const_targett i_it) + goto_programt::const_targett targ, + goto_programt::const_targett i_it) { /* if in_pos was updated at this program point */ if(updated.find(targ)!=updated.end()) @@ -693,10 +700,10 @@ void inline instrumentert::cfg_visitort::visit_cfg_backedge( { if(egraph[from->first].thread!=egraph[to->first].thread) continue; - instrumenter.message.debug() << from->first<<"-po->" - <first << messaget::eom; - egraph.add_po_back_edge(from->first,to->first); - egraph_alt.add_edge(from->second,to->second); + instrumenter.message.debug() << from->first << "-po->" + << to->first << messaget::eom; + egraph.add_po_back_edge(from->first, to->first); + egraph_alt.add_edge(from->second, to->second); } } else @@ -705,7 +712,7 @@ void inline instrumentert::cfg_visitort::visit_cfg_backedge( /* connects NEXT nodes following the targets -- bwd analysis */ for(goto_programt::const_targett cur=i_it; - cur!=targ; --cur) + cur!=targ; --cur) { for(const auto &in : cur->incoming_edges) { @@ -725,19 +732,21 @@ void inline instrumentert::cfg_visitort::visit_cfg_backedge( /* connects the previous nodes to those ones */ if(out_pos.find(targ)!=out_pos.end()) + { for(std::set::const_iterator to=out_pos[targ].begin(); - to!=out_pos[targ].end(); ++to) + to!=out_pos[targ].end(); ++to) for(std::set::const_iterator from=in_pos[i_it].begin(); - from!=in_pos[i_it].end(); ++from) + from!=in_pos[i_it].end(); ++from) if(from->first!=to->first) { if(egraph[from->first].thread!=egraph[to->first].thread) continue; instrumenter.message.debug() << from->first<<"-po->" <first << messaget::eom; - egraph.add_po_back_edge(from->first,to->first); - egraph_alt.add_edge(from->second,to->second); + egraph.add_po_back_edge(from->first, to->first); + egraph_alt.add_edge(from->second, to->second); } + } } } @@ -756,13 +765,13 @@ Function: instrumentert::visit_cfg_goto void instrumentert::cfg_visitort::visit_cfg_goto( goto_programt::instructionst::iterator i_it, loop_strategyt replicate_body, - value_setst& value_sets + value_setst &value_sets #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif ) { - const goto_programt::instructiont& instruction=*i_it; + const goto_programt::instructiont &instruction=*i_it; /* propagates */ visit_cfg_propagate(i_it); @@ -778,7 +787,7 @@ void instrumentert::cfg_visitort::visit_cfg_goto( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) } } @@ -795,23 +804,24 @@ Function: intrumentert::visit_cfg_function_call \*******************************************************************/ void instrumentert::cfg_visitort::visit_cfg_function_call( - value_setst& value_sets, + value_setst &value_sets, goto_programt::instructionst::iterator i_it, memory_modelt model, bool no_dependencies, loop_strategyt replicate_body) { - const goto_programt::instructiont& instruction=*i_it; + const goto_programt::instructiont &instruction=*i_it; std::set s; for(const auto &in : instruction.incoming_edges) if(in_pos.find(in)!=in_pos.end()) for(const auto &node : in_pos[in]) s.insert(node); - const exprt& fun=to_code_function_call(instruction.code).function(); - const irep_idt& fun_id=to_symbol_expr(fun).get_identifier(); + const exprt &fun=to_code_function_call(instruction.code).function(); + const irep_idt &fun_id=to_symbol_expr(fun).get_identifier(); /* ignore recursive calls -- underapproximation */ - try { + try + { enter_function(fun_id); #ifdef CONTEXT_INSENSITIVE stack_fun.push(cur_fun); @@ -823,12 +833,14 @@ void instrumentert::cfg_visitort::visit_cfg_function_call( { /* do not inline it, connect to an existing subgraph or create a new one */ - if(instrumenter.map_function_graph.find(fun_id)!=instrumenter.map_function_graph.end()) + if(instrumenter.map_function_graph.find(fun_id)!= + instrumenter.map_function_graph.end()) { /* connects to existing */ /* TODO */ } - else { + else + { /* just inlines */ /* TODO */ visit_cfg_function(value_sets, model, no_dependencies, fun_id, s, @@ -836,7 +848,7 @@ void instrumentert::cfg_visitort::visit_cfg_function_call( updated.insert(i_it); } } - else + else // NOLINT(readability/braces) #endif { /* normal inlining strategy */ @@ -850,9 +862,11 @@ void instrumentert::cfg_visitort::visit_cfg_function_call( cur_fun=stack_fun.pop(); #endif } - catch(std::string s) { - instrumenter.message.warning() << "Sorry, doesn't handle recursion (function " - << fun_id << "; .cpp) " << s<< messaget::eom; + catch(std::string s) + { + instrumenter.message.warning() << "sorry, doesn't handle recursion " + << "(function " << fun_id << "; .cpp) " + << s << messaget::eom; } } @@ -871,7 +885,7 @@ Function: instrumentert::visit_cfg_lwfence void instrumentert::cfg_visitort::visit_cfg_lwfence( goto_programt::instructionst::iterator i_it) { - const goto_programt::instructiont& instruction=*i_it; + const goto_programt::instructiont &instruction=*i_it; const abstract_eventt new_fence_event(abstract_eventt::Lwfence, thread, "f", instrumenter.unique_id++, instruction.source_location, false); const event_idt new_fence_node=egraph.add_node(); @@ -883,15 +897,17 @@ void instrumentert::cfg_visitort::visit_cfg_lwfence( for(const auto &in : instruction.incoming_edges) if(in_pos.find(in)!=in_pos.end()) + { for(const auto &node : in_pos[in]) { if(egraph[node.first].thread!=thread) continue; instrumenter.message.debug() << node.first<<"-po->"<"<::max(); event_idt previous_gnode=std::numeric_limits::max(); @@ -997,7 +1015,7 @@ void instrumentert::cfg_visitort::visit_cfg_assign( read is the irep_id of the read in the code; new_read_event is the corresponding abstract event; new_read_node is the node in the graph */ - const irep_idt& read=r_it->second.object; + const irep_idt &read=r_it->second.object; /* skip local variables */ if(local(read)) @@ -1025,43 +1043,45 @@ void instrumentert::cfg_visitort::visit_cfg_assign( const event_idt new_read_gnode=egraph_alt.add_node(); egraph_alt[new_read_gnode]=new_read_event; instrumenter.map_vertex_gnode.insert( - std::make_pair(new_read_node,new_read_gnode)); + std::make_pair(new_read_node, new_read_gnode)); /* creates ... -po-> Read */ for(const auto &in : instruction.incoming_edges) { if(in_pos.find(in)!=in_pos.end()) + { for(const auto &node : in_pos[in]) { if(egraph[node.first].thread!=thread) continue; instrumenter.message.debug() << node.first<<"-po->" < Write ... */ - const std::pair - with_same_var = map_writes.equal_range(read); + const std::pair + with_same_var=map_writes.equal_range(read); for(id2nodet::iterator id_it=with_same_var.first; id_it!=with_same_var.second; id_it++) - if(egraph[id_it->second].thread != new_read_event.thread) + if(egraph[id_it->second].thread!=new_read_event.thread) { instrumenter.message.debug() << id_it->second<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(id_it->second); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_read_node,id_it->second); - egraph_alt.add_edge(new_read_gnode,entry->second); - egraph.add_com_edge(id_it->second,new_read_node); - egraph_alt.add_edge(entry->second,new_read_gnode); + egraph.add_com_edge(new_read_node, id_it->second); + egraph_alt.add_edge(new_read_gnode, entry->second); + egraph.add_com_edge(id_it->second, new_read_node); + egraph_alt.add_edge(entry->second, new_read_gnode); ++fr_rf_counter; } @@ -1070,17 +1090,17 @@ void instrumentert::cfg_visitort::visit_cfg_assign( unknown_write_nodes.begin(); id_it!=unknown_write_nodes.end(); ++id_it) - if(egraph[*id_it].thread != new_read_event.thread) + if(egraph[*id_it].thread!=new_read_event.thread) { instrumenter.message.debug() << *id_it<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(*id_it); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_read_node,*id_it); - egraph_alt.add_edge(new_read_gnode,entry->second); - egraph.add_com_edge(*id_it,new_read_node); - egraph_alt.add_edge(entry->second,new_read_gnode); + egraph.add_com_edge(new_read_node, *id_it); + egraph_alt.add_edge(new_read_gnode, entry->second); + egraph.add_com_edge(*id_it, new_read_node); + egraph_alt.add_edge(entry->second, new_read_gnode); ++fr_rf_counter; } } @@ -1092,7 +1112,7 @@ void instrumentert::cfg_visitort::visit_cfg_assign( write is the irep_id in the code; new_write_event is the corresponding abstract event; new_write_node is the node in the graph */ - const irep_idt& write = w_it->second.object; + const irep_idt &write=w_it->second.object; instrumenter.message.debug() << "WRITE: " << write << messaget::eom; @@ -1101,7 +1121,7 @@ void instrumentert::cfg_visitort::visit_cfg_assign( continue; ++write_counter; - //assert(write_expr); + // assert(write_expr); /* creates Write */ const abstract_eventt new_write_event(abstract_eventt::Write, @@ -1121,117 +1141,121 @@ void instrumentert::cfg_visitort::visit_cfg_assign( const event_idt new_write_gnode=egraph_alt.add_node(); egraph_alt[new_write_gnode]=new_write_event; instrumenter.map_vertex_gnode.insert( - std::pair(new_write_node, new_write_gnode)); + std::pair(new_write_node, new_write_gnode)); /* creates Read -po-> Write */ if(previous!=std::numeric_limits::max()) { instrumenter.message.debug() << previous<<"-po->"<" < Read */ - const std::pair + const std::pair r_with_same_var=map_reads.equal_range(write); for(id2nodet::iterator idr_it=r_with_same_var.first; - idr_it!=r_with_same_var.second; idr_it++) - if(egraph[idr_it->second].thread != new_write_event.thread) + idr_it!=r_with_same_var.second; idr_it++) + if(egraph[idr_it->second].thread!=new_write_event.thread) { instrumenter.message.debug() <second<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(idr_it->second); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_write_node,idr_it->second); - egraph_alt.add_edge(new_write_gnode,entry->second); - egraph.add_com_edge(idr_it->second,new_write_node); - egraph_alt.add_edge(entry->second,new_write_gnode); + egraph.add_com_edge(new_write_node, idr_it->second); + egraph_alt.add_edge(new_write_gnode, entry->second); + egraph.add_com_edge(idr_it->second, new_write_node); + egraph_alt.add_edge(entry->second, new_write_gnode); ++fr_rf_counter; } /* creates Write <-com-> Write */ - const std::pair + const std::pair w_with_same_var=map_writes.equal_range(write); for(id2nodet::iterator idw_it=w_with_same_var.first; - idw_it!=w_with_same_var.second; idw_it++) + idw_it!=w_with_same_var.second; idw_it++) if(egraph[idw_it->second].thread!=new_write_event.thread) { instrumenter.message.debug() << idw_it->second<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(idw_it->second); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_write_node,idw_it->second); - egraph_alt.add_edge(new_write_gnode,entry->second); - egraph.add_com_edge(idw_it->second,new_write_node); - egraph_alt.add_edge(entry->second,new_write_gnode); + egraph.add_com_edge(new_write_node, idw_it->second); + egraph_alt.add_edge(new_write_gnode, entry->second); + egraph.add_com_edge(idw_it->second, new_write_node); + egraph_alt.add_edge(entry->second, new_write_gnode); ++ws_counter; } /* for unknown writes */ for(std::set::const_iterator id_it= - unknown_write_nodes.begin(); - id_it!=unknown_write_nodes.end(); - ++id_it) - if(egraph[*id_it].thread != new_write_event.thread) + unknown_write_nodes.begin(); + id_it!=unknown_write_nodes.end(); + ++id_it) + if(egraph[*id_it].thread!=new_write_event.thread) { instrumenter.message.debug() << *id_it<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(*id_it); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_write_node,*id_it); - egraph_alt.add_edge(new_write_gnode,entry->second); - egraph.add_com_edge(*id_it,new_write_node); - egraph_alt.add_edge(entry->second,new_write_gnode); + egraph.add_com_edge(new_write_node, *id_it); + egraph_alt.add_edge(new_write_gnode, entry->second); + egraph.add_com_edge(*id_it, new_write_node); + egraph_alt.add_edge(entry->second, new_write_gnode); ++fr_rf_counter; } /* for unknown reads */ for(std::set::const_iterator id_it= - unknown_read_nodes.begin(); - id_it!=unknown_read_nodes.end(); - ++id_it) - if(egraph[*id_it].thread != new_write_event.thread) + unknown_read_nodes.begin(); + id_it!=unknown_read_nodes.end(); + ++id_it) + if(egraph[*id_it].thread!=new_write_event.thread) { instrumenter.message.debug() << *id_it<<"<-com->" <::const_iterator entry= + std::map::const_iterator entry= instrumenter.map_vertex_gnode.find(*id_it); assert(entry!=instrumenter.map_vertex_gnode.end()); - egraph.add_com_edge(new_write_node,*id_it); - egraph_alt.add_edge(new_write_gnode,entry->second); - egraph.add_com_edge(*id_it,new_write_node); - egraph_alt.add_edge(entry->second,new_write_gnode); + egraph.add_com_edge(new_write_node, *id_it); + egraph_alt.add_edge(new_write_gnode, entry->second); + egraph.add_com_edge(*id_it, new_write_node); + egraph_alt.add_edge(entry->second, new_write_gnode); ++fr_rf_counter; } - map_writes.insert(id2node_pairt(write,new_write_node)); - previous = new_write_node; - previous_gnode = new_write_gnode; + map_writes.insert(id2node_pairt(write, new_write_node)); + previous=new_write_node; + previous_gnode=new_write_gnode; } if(previous!=std::numeric_limits::max()) { in_pos[i_it].clear(); - in_pos[i_it].insert(nodet(previous,previous_gnode)); + in_pos[i_it].insert(nodet(previous, previous_gnode)); updated.insert(i_it); } else @@ -1246,26 +1270,26 @@ void instrumentert::cfg_visitort::visit_cfg_assign( forall_rw_set_w_entries(write_it, rw_set) forall_rw_set_r_entries(read_it, rw_set) { - const irep_idt& write=write_it->second.object; - const irep_idt& read=read_it->second.object; + const irep_idt &write=write_it->second.object; + const irep_idt &read=read_it->second.object; instrumenter.message.debug() << "dp: Write:"<second.object; - const irep_idt& read=read_it->second.object; + const irep_idt &read2=read2_it->second.object; + const irep_idt &read=read_it->second.object; if(read2==read) continue; - const datat read_p(read,instruction.source_location); - const datat read2_p(read2,instruction.source_location); - data_dp.dp_analysis(read_p,local(read),read2_p,local(read2)); + const datat read_p(read, instruction.source_location); + const datat read2_p(read2, instruction.source_location); + data_dp.dp_analysis(read_p, local(read), read2_p, local(read2)); } data_dp.dp_merge(); } @@ -1286,7 +1310,7 @@ Function: instrumentert::visit_cfg_fence void instrumentert::cfg_visitort::visit_cfg_fence( goto_programt::instructionst::iterator i_it) { - const goto_programt::instructiont& instruction=*i_it; + const goto_programt::instructiont &instruction=*i_it; const abstract_eventt new_fence_event(abstract_eventt::Fence, thread, "F", instrumenter.unique_id++, instruction.source_location, false); const event_idt new_fence_node=egraph.add_node(); @@ -1298,13 +1322,15 @@ void instrumentert::cfg_visitort::visit_cfg_fence( for(const auto &in : instruction.incoming_edges) if(in_pos.find(in)!=in_pos.end()) + { for(const auto &node : in_pos[in]) { instrumenter.message.debug() << node.first<<"-po->"< s; s.insert(nodet(new_fence_node, new_fence_gnode)); @@ -1346,25 +1372,21 @@ Function: intrumentert::add_instr_to_interleaving \*******************************************************************/ -void inline instrumentert::add_instr_to_interleaving ( +void inline instrumentert::add_instr_to_interleaving( goto_programt::instructionst::iterator it, - goto_programt& interleaving) + goto_programt &interleaving) { - if( - it->is_return() || - it->is_throw() || - it->is_catch() || - it->is_skip() || - it->is_dead() || - it->is_start_thread() || - it->is_end_thread() - ) + if(it->is_return() || + it->is_throw() || + it->is_catch() || + it->is_skip() || + it->is_dead() || + it->is_start_thread() || + it->is_end_thread()) return; - if( - it->is_atomic_begin() || - it->is_atomic_end() - ) + if(it->is_atomic_begin() || + it->is_atomic_end()) { /* atomicity not checked here for the moment */ return; @@ -1377,7 +1399,7 @@ void inline instrumentert::add_instr_to_interleaving ( } /* add this instruction to the interleaving */ - goto_programt::targett current_instruction = interleaving.add_instruction(); + goto_programt::targett current_instruction=interleaving.add_instruction(); goto_programt::instructiont new_instruction(*it); current_instruction->swap(new_instruction); } @@ -1394,7 +1416,7 @@ Function: instrumentert::is_cfg_spurious \*******************************************************************/ -bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) +bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc) { message.debug() << "spurious by CFG? " << messaget::eom; goto_programt interleaving; @@ -1404,20 +1426,20 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) { --e_it; - const abstract_eventt& current_event = egraph[*e_it]; - const source_locationt& current_location = current_event.source_location; + const abstract_eventt ¤t_event=egraph[*e_it]; + const source_locationt ¤t_location=current_event.source_location; /* select relevant thread (po) -- or function contained in this thread */ - goto_programt* current_po=0; - bool thread_found = false; + goto_programt *current_po=0; + bool thread_found=false; Forall_goto_functions(f_it, goto_functions) { forall_goto_program_instructions(p_it, f_it->second.body) if(p_it->source_location==current_location) { - current_po = &f_it->second.body; - thread_found = true; + current_po=&f_it->second.body; + thread_found=true; break; } @@ -1426,18 +1448,18 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) } assert(current_po); - const wmm_grapht::edgest& pos_cur = egraph.po_out(*e_it); - const wmm_grapht::edgest& pos_next = egraph.po_out(*(++e_it)); + const wmm_grapht::edgest &pos_cur=egraph.po_out(*e_it); + const wmm_grapht::edgest &pos_next=egraph.po_out(*(++e_it)); --e_it; - bool exists_n = false; + bool exists_n=false; for(wmm_grapht::edgest::const_iterator edge_it=pos_cur.begin(); edge_it!=pos_cur.end(); edge_it++) { if(pos_next.find(edge_it->first)!=pos_next.end()) { - exists_n = true; + exists_n=true; break; } } @@ -1465,14 +1487,14 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) --e_it; /* find the portion of the thread to add */ - const abstract_eventt& next_event = egraph[*(++e_it--)]; - const source_locationt& next_location = next_event.source_location; + const abstract_eventt &next_event=egraph[*(++e_it--)]; + const source_locationt &next_location=next_event.source_location; - bool in_cycle = false; + bool in_cycle=false; Forall_goto_program_instructions(it, *current_po) { if(it->source_location==current_location) - in_cycle = true; + in_cycle=true; /* do not add the last instruction now -- will be done at the next iteration */ @@ -1492,12 +1514,12 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) { for(const auto &t : int_it->targets) { - bool target_in_cycle = false; + bool target_in_cycle=false; forall_goto_program_instructions(targ, interleaving) if(targ==t) { - target_in_cycle = true; + target_in_cycle=true; break; } @@ -1513,20 +1535,20 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet& cyc) goto_function_templatet one_interleaving; one_interleaving.body.copy_from(interleaving); - std::pair > p( + std::pair > p( goto_functionst::entry_point(), one_interleaving); goto_functionst::function_mapt map; map.insert(p); goto_functionst this_interleaving; - this_interleaving.function_map = map; + this_interleaving.function_map=map; optionst no_option; null_message_handlert no_message; #if 0 bmct bmc(no_option, symbol_table, no_message); - bool is_spurious = bmc.run(this_interleaving); + bool is_spurious=bmc.run(this_interleaving); message.debug() << "CFG:"<::iterator next = it; + bool erased=false; + std::set::iterator next=it; ++next; if(is_cfg_spurious(*it)) { - erased = true; + erased=true; set_of_cycles.erase(it); } - it = next; + it=next; if(!erased) ++it; } @@ -1578,15 +1600,15 @@ void instrumentert::cfg_cycles_filter() it!=set_of_cycles_per_SCC[i].end(); ) { - bool erased = false; - std::set::iterator next = it; + bool erased=false; + std::set::iterator next=it; ++next; if(is_cfg_spurious(*it)) { - erased = true; + erased=true; set_of_cycles_per_SCC[i].erase(it); } - it = next; + it=next; if(!erased) ++it; } @@ -1608,26 +1630,26 @@ Function: instrumentert::print_outputs \*******************************************************************/ void inline instrumentert::print_outputs_local( - const std::set& set, - std::ofstream& dot, - std::ofstream& ref, - std::ofstream& output, - std::ofstream& all, - std::ofstream& table, + const std::set &set, + std::ofstream &dot, + std::ofstream &ref, + std::ofstream &output, + std::ofstream &all, + std::ofstream &table, memory_modelt model, bool hide_internals) { /* to represent the po aligned in the dot */ - std::map > same_po; - unsigned max_thread = 0; - unsigned colour = 0; + std::map > same_po; + unsigned max_thread=0; + unsigned colour=0; /* to represent the files as clusters */ - std::map > same_file; + std::map > same_file; /* to summarise in a table all the variables */ - std::map map_id2var; - std::map map_var2id; + std::map map_id2var; + std::map map_var2id; for(std::set::const_iterator it = set.begin(); it!=set.end(); it++) @@ -1635,7 +1657,7 @@ void inline instrumentert::print_outputs_local( #ifdef PRINT_UNSAFES message.debug() << it->print_unsafes() << messaget::eom; #endif - it->print_dot(dot,colour++,model); + it->print_dot(dot, colour++, model); ref << it->print_name(model, hide_internals) << std::endl; output << it->print_output() << std::endl; all << it->print_all(model, map_id2var, map_var2id, hide_internals) @@ -1645,7 +1667,7 @@ void inline instrumentert::print_outputs_local( for(std::list::const_iterator it_e=it->begin(); it_e!=it->end(); it_e++) { - const abstract_eventt& ev = egraph[*it_e]; + const abstract_eventt &ev=egraph[*it_e]; if(render_po_aligned) same_po[ev.thread].insert(*it_e); @@ -1654,7 +1676,7 @@ void inline instrumentert::print_outputs_local( else if(render_by_file) same_file[ev.source_location.get_file()].insert(*it_e); if(ev.thread>max_thread) - max_thread = ev.thread; + max_thread=ev.thread; if(var_to_instr.find(ev.variable)!=var_to_instr.end() && id2loc.find(ev.variable)!=id2loc.end()) @@ -1668,6 +1690,7 @@ void inline instrumentert::print_outputs_local( /* aligns events by po */ if(render_po_aligned) + { for(unsigned i=0; i<=max_thread; i++) if(!same_po[i].empty()) { @@ -1678,14 +1701,17 @@ void inline instrumentert::print_outputs_local( dot << egraph[*it].id << ";"; dot << "};" << std::endl; } + } /* clusters events by file/function */ if(render_by_file || render_by_function) - for(std::map >::const_iterator it= + { + for(std::map >::const_iterator it= same_file.begin(); it!=same_file.end(); it++) { - dot << "subgraph cluster_" << irep_id_hash()(it->first) << "{" << std::endl; + dot << "subgraph cluster_" << irep_id_hash()(it->first) << "{" + << std::endl; dot << " label=\"" << it->first << "\";" << std::endl; for(std::set::const_iterator ev_it=it->second.begin(); ev_it!=it->second.end(); ev_it++) @@ -1694,17 +1720,19 @@ void inline instrumentert::print_outputs_local( } dot << "};" << std::endl; } + } /* variable table for "all" */ - for(unsigned i=0; i<80; ++i) table << "-"; - for(std::map::const_iterator m_it=map_id2var.begin(); - m_it!=map_id2var.end(); - ++m_it) + table << std::string(80, '-'); + for(std::map::const_iterator + m_it=map_id2var.begin(); + m_it!=map_id2var.end(); + ++m_it) { table << std::endl << "| " << m_it->first << " : " << m_it->second; } table << std::endl; - for(unsigned i=0; i<80; ++i) table << "-"; + table << std::string(80, '-'); table << std::endl; } @@ -1728,18 +1756,18 @@ void instrumentert::print_outputs(memory_modelt model, bool hide_internals) /* prints cycles in the different outputs */ if(!set_of_cycles.empty()) print_outputs_local(set_of_cycles, dot, ref, output, all, table, - model,hide_internals); + model, hide_internals); else if(num_sccs!=0) { for(unsigned i=0; i()); for(std::vector >::const_iterator it=egraph_SCCs.begin(); it!=egraph_SCCs.end(); it++) if(it->size()>=4) - egraph.collect_cycles(set_of_cycles_per_SCC[scc++],model,*it); + egraph.collect_cycles(set_of_cycles_per_SCC[scc++], model, *it); } #else class pthread_argumentt { public: - instrumentert& instr; + instrumentert &instr; memory_modelt mem; - const std::set& filter; - std::set& cycles; + const std::set &filter; + std::set &cycles; - pthread_argumentt(instrumentert& _instr, + pthread_argumentt(instrumentert &_instr, memory_modelt _mem, - const std::set& _filter, - std::set& _cycles) - :instr(_instr),mem(_mem),filter(_filter),cycles(_cycles) + const std::set &_filter, + std::set &_cycles) + :instr(_instr), mem(_mem), filter(_filter), cycles(_cycles) { } }; /* wraper */ -void* collect_cycles_in_thread(void* arg) +void *collect_cycles_in_thread(void *arg) { /* arguments */ - instrumentert& this_instrumenter = ((pthread_argumentt*) arg)->instr; - memory_modelt model = ((pthread_argumentt*) arg)->mem; - const std::set& filter = ((pthread_argumentt*) arg)->filter; - std::set& cycles = - ((pthread_argumentt*) arg)->cycles; + pthread_argumentt *p_arg=reinterpret_cast(arg); + instrumentert &this_instrumenter=p_arg->instr; + memory_modelt model=p_arg->mem; + const std::set &filter=p_arg->filter; + std::set &cycles=p_arg->cycles; this_instrumenter.egraph.collect_cycles(cycles, model, filter); @@ -1819,24 +1847,24 @@ void* collect_cycles_in_thread(void* arg) void instrumentert::collect_cycles_by_SCCs(memory_modelt model) { - const unsigned number_of_sccs = num_sccs; + const unsigned number_of_sccs=num_sccs; std::set interesting_SCCs; - unsigned scc = 0; - pthread_t* threads = (pthread_t*)malloc((num_sccs+1)*sizeof(pthread_t)); + unsigned scc=0; + pthread_t *threads=new pthread_t[num_sccs+1]; set_of_cycles_per_SCC.resize(num_sccs, std::set()); for(std::vector >::const_iterator it=egraph_SCCs.begin(); - it!=egraph_SCCs.end(); it++) + it!=egraph_SCCs.end(); it++) if(it->size()>=4) { interesting_SCCs.insert(scc); - pthread_argumentt arg(*this,model,*it,set_of_cycles_per_SCC[scc]); + pthread_argumentt arg(*this, model, *it, set_of_cycles_per_SCC[scc]); - int rc = pthread_create(&threads[scc++], NULL, - collect_cycles_in_thread, (void*) &arg); + int rc=pthread_create(&threads[scc++], NULL, + collect_cycles_in_thread, &arg); message.status()<<(rc!=0?"Failure ":"Success ") <<"in creating thread for SCC #"< map_vertex_gnode; + std::map map_vertex_gnode; wmm_grapht egraph_alt; unsigned unique_id; @@ -47,38 +47,38 @@ class instrumentert bool render_by_file; bool render_by_function; - bool inline local(const irep_idt& id); + bool inline local(const irep_idt &id); - void inline add_instr_to_interleaving ( + void inline add_instr_to_interleaving( goto_programt::instructionst::iterator it, - goto_programt& interleaving); + goto_programt &interleaving); /* deprecated */ - bool is_cfg_spurious(const event_grapht::critical_cyclet& cyc); + bool is_cfg_spurious(const event_grapht::critical_cyclet &cyc); - unsigned cost(const event_grapht::critical_cyclet::delayt& e); + unsigned cost(const event_grapht::critical_cyclet::delayt &e); typedef std::set set_of_cyclest; void inline instrument_all_inserter( - const set_of_cyclest& set); + const set_of_cyclest &set); void inline instrument_one_event_per_cycle_inserter( - const set_of_cyclest& set); + const set_of_cyclest &set); void inline instrument_one_read_per_cycle_inserter( - const set_of_cyclest& set); + const set_of_cyclest &set); void inline instrument_one_write_per_cycle_inserter( - const set_of_cyclest& set); + const set_of_cyclest &set); void inline instrument_minimum_interference_inserter( - const set_of_cyclest& set); + const set_of_cyclest &set); void inline instrument_my_events_inserter( - const set_of_cyclest& set, const std::set& events); + const set_of_cyclest &set, const std::set &events); void inline print_outputs_local( - const std::set& set, - std::ofstream& dot, - std::ofstream& ref, - std::ofstream& output, - std::ofstream& all, - std::ofstream& table, + const std::set &set, + std::ofstream &dot, + std::ofstream &ref, + std::ofstream &output, + std::ofstream &all, + std::ofstream &table, memory_modelt model, bool hide_internals); @@ -87,13 +87,13 @@ class instrumentert class cfg_visitort { protected: - namespacet& ns; - instrumentert& instrumenter; + namespacet &ns; + instrumentert &instrumenter; /* pointer to the egraph(s) that we construct */ - event_grapht& egraph; - std::vector >& egraph_SCCs; - wmm_grapht& egraph_alt; + event_grapht &egraph; + std::vector> &egraph_SCCs; + wmm_grapht &egraph_alt; /* for thread marking (dynamic) */ unsigned current_thread; @@ -102,11 +102,11 @@ class instrumentert bool contains_shared_array( goto_programt::const_targett targ, goto_programt::const_targett i_it, - value_setst& value_sets + value_setst &value_sets #ifdef LOCAL_MAY , local_may_aliast local_may #endif - ) const; + ) const; // NOLINT(whitespace/parens) /* transformers */ void visit_cfg_thread() const; @@ -114,26 +114,26 @@ class instrumentert void visit_cfg_body( goto_programt::const_targett i_it, loop_strategyt replicate_body, - value_setst& value_sets + value_setst &value_sets #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif - ); // deprecated + ); // deprecated NOLINT(whitespace/parens) void inline visit_cfg_backedge(goto_programt::const_targett targ, goto_programt::const_targett i_it); void inline visit_cfg_duplicate(goto_programt::const_targett targ, goto_programt::const_targett i_it); - void visit_cfg_assign(value_setst& value_sets, namespacet& ns, - goto_programt::instructionst::iterator& i_it, bool no_dependencies + void visit_cfg_assign(value_setst &value_sets, namespacet &ns, + goto_programt::instructionst::iterator &i_it, bool no_dependencies #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif - ); + ); // NOLINT(whitespace/parens) void visit_cfg_fence(goto_programt::instructionst::iterator i_it); void visit_cfg_skip(goto_programt::instructionst::iterator i_it); void visit_cfg_lwfence(goto_programt::instructionst::iterator i_it); void visit_cfg_asm_fence(goto_programt::instructionst::iterator i_it); - void visit_cfg_function_call(value_setst& value_sets, + void visit_cfg_function_call(value_setst &value_sets, goto_programt::instructionst::iterator i_it, memory_modelt model, bool no_dependenciess, @@ -143,12 +143,12 @@ class instrumentert /* forces the duplication of all the loops, with array or not otherwise, duplication of loops with array accesses only */ loop_strategyt replicate_body, - value_setst& value_sets + value_setst &value_sets #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif - ); - void visit_cfg_reference_function (irep_idt id_function); + ); // NOLINT(whitespace/parens) + void visit_cfg_reference_function(irep_idt id_function); public: virtual ~cfg_visitort() @@ -158,8 +158,8 @@ class instrumentert unsigned max_thread; /* relations between irep and Reads/Writes */ - typedef std::multimap id2nodet; - typedef std::pair id2node_pairt; + typedef std::multimap id2nodet; + typedef std::pair id2node_pairt; id2nodet map_reads, map_writes; unsigned write_counter; @@ -168,8 +168,8 @@ class instrumentert unsigned fr_rf_counter; /* previous nodes (fwd analysis) */ - typedef std::pair nodet; - typedef std::map > + typedef std::pair nodet; + typedef std::map > incoming_post; incoming_post in_pos; @@ -188,7 +188,7 @@ class instrumentert /* to keep track of the functions (and their start/end nodes) */ std::stack stack_fun; irep_idt cur_fun; - std::map > in_nodes, out_nodes; + std::map > in_nodes, out_nodes; #endif /* current thread number */ @@ -204,7 +204,7 @@ class instrumentert /* set of functions visited so far -- we don't handle recursive functions */ std::set functions_met; - cfg_visitort(namespacet& _ns, instrumentert& _instrumenter) + cfg_visitort(namespacet &_ns, instrumentert &_instrumenter) :ns(_ns), instrumenter(_instrumenter), egraph(_instrumenter.egraph), egraph_SCCs(_instrumenter.egraph_SCCs), egraph_alt(_instrumenter.egraph_alt) @@ -219,14 +219,14 @@ class instrumentert coming_from = 0; } - void inline enter_function(const irep_idt& function) + void inline enter_function(const irep_idt &function) { if(functions_met.find(function)!=functions_met.end()) - throw ("Sorry, doesn't handle recursive function for the moment"); + throw "sorry, doesn't handle recursive function for the moment"; functions_met.insert(function); } - void inline leave_function(const irep_idt& function) + void inline leave_function(const irep_idt &function) { functions_met.erase(function); } @@ -236,10 +236,11 @@ class instrumentert memory_modelt model, bool no_dependencies, loop_strategyt duplicate_body, - const irep_idt& function) + const irep_idt &function) { /* ignore recursive calls -- underapproximation */ - try { + try + { /* forbids recursive function */ enter_function(function); const std::set empty_in; @@ -248,7 +249,8 @@ class instrumentert function, empty_in, end_out); leave_function(function); } - catch(std::string s) { + catch(std::string s) + { instrumenter.message.warning() << s << messaget::eom; } } @@ -256,23 +258,23 @@ class instrumentert // TODO: move the visitor outside, and inherit virtual void visit_cfg_function( /* value_sets and options */ - value_setst& value_sets, + value_setst &value_sets, memory_modelt model, bool no_dependencies, loop_strategyt duplicate_body, /* functino to analyse */ - const irep_idt& function, + const irep_idt &function, /* incoming edges */ - const std::set& initial_vertex, + const std::set &initial_vertex, /* outcoming edges */ - std::set& ending_vertex); + std::set &ending_vertex); - bool inline local(const irep_idt& i); + bool inline local(const irep_idt &i); }; public: /* message */ - messaget& message; + messaget &message; /* graph */ event_grapht egraph; @@ -289,11 +291,12 @@ class instrumentert /* map from function to begin and end of the corresponding part of the graph */ - typedef std::map, + typedef std::map, std::set > > map_function_nodest; map_function_nodest map_function_graph; - void print_map_function_graph() const { + void print_map_function_graph() const + { for(map_function_nodest::const_iterator it=map_function_graph.begin(); it!=map_function_graph.end(); ++it) @@ -319,11 +322,11 @@ class instrumentert /* TODO: those maps are here to interface easily with weak_mem.cpp, but a rewriting of weak_mem can eliminate them */ std::set var_to_instr; - std::multimap id2loc; - std::multimap id2cycloc; + std::multimap id2loc; + std::multimap id2cycloc; - instrumentert(symbol_tablet& _symbol_table, goto_functionst& _goto_f, - messaget& _message) + instrumentert(symbol_tablet &_symbol_table, goto_functionst &_goto_f, + messaget &_message) :ns(_symbol_table), goto_functions(_goto_f), render_po_aligned(true), render_by_file(false), render_by_function(false), message(_message), egraph(_message) @@ -333,7 +336,7 @@ class instrumentert /* abstracts goto-programs in abstract event graph, and computes the thread numbering and returns the max number */ unsigned goto2graph_cfg( - value_setst& value_sets, + value_setst &value_sets, memory_modelt model, bool no_dependencies, /* forces the duplication, with arrays or not; otherwise, arrays only */ @@ -342,7 +345,7 @@ class instrumentert /* collects directly all the cycles in the graph */ void collect_cycles(memory_modelt model) { - egraph.collect_cycles(set_of_cycles,model); + egraph.collect_cycles(set_of_cycles, model); num_sccs = 0; } @@ -358,7 +361,7 @@ class instrumentert unsigned _max_po_trans = 0, bool _ignore_arrays = false) { - egraph.set_parameters_collection(_max_var,_max_po_trans,_ignore_arrays); + egraph.set_parameters_collection(_max_var, _max_po_trans, _ignore_arrays); } /* builds the relations between unsafe pairs in the critical cycles and @@ -366,7 +369,7 @@ class instrumentert /* strategies for instrumentation */ void instrument_with_strategy(instrumentation_strategyt strategy); - void instrument_my_events(const std::set& events); + void instrument_my_events(const std::set &events); /* retrieves events to filter in the instrumentation choice with option --my-events */ diff --git a/src/goto-instrument/wmm/instrumenter_pensieve.h b/src/goto-instrument/wmm/instrumenter_pensieve.h index 2af65a8d4ee..7a5210448fe 100644 --- a/src/goto-instrument/wmm/instrumenter_pensieve.h +++ b/src/goto-instrument/wmm/instrumenter_pensieve.h @@ -19,19 +19,19 @@ class namespacet; class instrumenter_pensievet:public instrumentert { public: - instrumenter_pensievet(symbol_tablet& _symbol_table, - goto_functionst& _goto_f, messaget& message) + instrumenter_pensievet(symbol_tablet &_symbol_table, + goto_functionst &_goto_f, messaget &message) : instrumentert(_symbol_table, _goto_f, message) { } - void collect_pairs_naive(namespacet& ns) + void collect_pairs_naive(namespacet &ns) { egraph.collect_pairs_naive(ns); } /* collects directly all the pairs in the graph */ - void collect_pairs(namespacet& ns) + void collect_pairs(namespacet &ns) { egraph.collect_pairs(ns); } diff --git a/src/goto-instrument/wmm/instrumenter_strategies.cpp b/src/goto-instrument/wmm/instrumenter_strategies.cpp index f906a352b60..c5bb5563973 100644 --- a/src/goto-instrument/wmm/instrumenter_strategies.cpp +++ b/src/goto-instrument/wmm/instrumenter_strategies.cpp @@ -103,7 +103,7 @@ Function: instrumentert::instrument_all_inserter \*******************************************************************/ void inline instrumentert::instrument_all_inserter( - const std::set& set_of_cycles) + const std::set &set_of_cycles) { for(std::set::const_iterator it=(set_of_cycles).begin(); @@ -113,16 +113,18 @@ void inline instrumentert::instrument_all_inserter( p_it=it->unsafe_pairs.begin(); p_it!=it->unsafe_pairs.end(); ++p_it) { - const abstract_eventt& first_ev=egraph[p_it->first]; + const abstract_eventt &first_ev=egraph[p_it->first]; var_to_instr.insert(first_ev.variable); id2loc.insert( - std::pair(first_ev.variable,first_ev.source_location)); + std::pair( + first_ev.variable, first_ev.source_location)); if(!p_it->is_po) { - const abstract_eventt& second_ev = egraph[p_it->second]; + const abstract_eventt &second_ev = egraph[p_it->second]; var_to_instr.insert(second_ev.variable); id2loc.insert( - std::pair(second_ev.variable,second_ev.source_location)); + std::pair( + second_ev.variable, second_ev.source_location)); } } } @@ -141,7 +143,7 @@ Function: instrumentert::instrument_one_event_per_cycle \*******************************************************************/ void inline instrumentert::instrument_one_event_per_cycle_inserter( - const std::set& set_of_cycles) + const std::set &set_of_cycles) { /* to keep track of the delayed pair, and to avoid the instrumentation of two pairs in a same cycle */ @@ -173,16 +175,18 @@ void inline instrumentert::instrument_one_event_per_cycle_inserter( p_it!=it->unsafe_pairs.end(); ++p_it) { delayed.insert(*p_it); - const abstract_eventt& first_ev=egraph[p_it->first]; + const abstract_eventt &first_ev=egraph[p_it->first]; var_to_instr.insert(first_ev.variable); id2loc.insert( - std::pair(first_ev.variable,first_ev.source_location)); + std::pair( + first_ev.variable, first_ev.source_location)); if(!p_it->is_po) { - const abstract_eventt& second_ev=egraph[p_it->second]; + const abstract_eventt &second_ev=egraph[p_it->second]; var_to_instr.insert(second_ev.variable); id2loc.insert( - std::pair(second_ev.variable,second_ev.source_location)); + std::pair( + second_ev.variable, second_ev.source_location)); } break; } @@ -202,10 +206,10 @@ Function: instrumentert::instrument_one_read_per_cycle \*******************************************************************/ void inline instrumentert::instrument_one_read_per_cycle_inserter( - const std::set& set_of_cycles) + const std::set &set_of_cycles) { /* TODO */ - throw "Read first strategy not implemented yet."; + throw "read first strategy not implemented yet"; } /*******************************************************************\ @@ -221,10 +225,10 @@ Function: instrumentert::instrument_one_write_per_cycle \*******************************************************************/ void inline instrumentert::instrument_one_write_per_cycle_inserter( - const std::set& set_of_cycles) + const std::set &set_of_cycles) { /* TODO */ - throw "Write first strategy not implemented yet."; + throw "write first strategy not implemented yet"; } /*******************************************************************\ @@ -240,7 +244,7 @@ Function: instrumentert::cost \*******************************************************************/ unsigned inline instrumentert::cost( - const event_grapht::critical_cyclet::delayt& e) + const event_grapht::critical_cyclet::delayt &e) { /* cost(poW*)=1 cost(poRW)=cost(rfe)=2 @@ -267,7 +271,7 @@ Function: instrumentert::instrument_minimum_interference \*******************************************************************/ void inline instrumentert::instrument_minimum_interference_inserter( - const std::set& set_of_cycles) + const std::set &set_of_cycles) { /* Idea: We solve this by a linear programming approach, @@ -304,7 +308,7 @@ void inline instrumentert::instrument_minimum_interference_inserter( ++e_i) edges.insert(*e_i); - glp_prob* lp; + glp_prob *lp; glp_iocp parm; glp_init_iocp(&parm); parm.msg_lev=GLP_MSG_OFF; @@ -350,9 +354,9 @@ void inline instrumentert::instrument_minimum_interference_inserter( const std::size_t mat_size=set_of_cycles.size()*edges.size(); message.debug() << "size of the system: " << mat_size << messaget::eom; - int* imat=(int*)malloc(sizeof(int)*(mat_size+1)); - int* jmat=(int*)malloc(sizeof(int)*(mat_size+1)); - double* vmat=(double*)malloc(sizeof(double)*(mat_size+1)); + int *imat=new int[mat_size+1]; + int *jmat=new int[mat_size+1]; + double *vmat=new double[mat_size+1]; /* fills the constraints coeff */ /* tables read from 1 in glpk -- first row/column ignored */ @@ -404,27 +408,29 @@ void inline instrumentert::instrument_minimum_interference_inserter( ++i; if(glp_mip_col_val(lp, i)>=1) { - const abstract_eventt& first_ev=egraph[e_i->first]; + const abstract_eventt &first_ev=egraph[e_i->first]; var_to_instr.insert(first_ev.variable); id2loc.insert( - std::pair(first_ev.variable,first_ev.source_location)); + std::pair( + first_ev.variable, first_ev.source_location)); if(!e_i->is_po) { - const abstract_eventt& second_ev=egraph[e_i->second]; + const abstract_eventt &second_ev=egraph[e_i->second]; var_to_instr.insert(second_ev.variable); id2loc.insert( - std::pair(second_ev.variable,second_ev.source_location)); + std::pair( + second_ev.variable, second_ev.source_location)); } } } glp_delete_prob(lp); - free(imat); - free(jmat); - free(vmat); + delete[] imat; + delete[] jmat; + delete[] vmat; #else - throw "Sorry, minimum interference option requires glpk; " - "please recompile goto-instrument with glpk."; + throw "sorry, minimum interference option requires glpk; " + "please recompile goto-instrument with glpk"; #endif } @@ -441,8 +447,8 @@ Function: instrumentert::instrument_my_events_inserter \*******************************************************************/ void inline instrumentert::instrument_my_events_inserter( - const std::set& set, - const std::set& my_events) + const std::set &set, + const std::set &my_events) { for(std::set::const_iterator it=set.begin(); @@ -454,16 +460,17 @@ void inline instrumentert::instrument_my_events_inserter( { if(my_events.find(p_it->first)!=my_events.end()) { - const abstract_eventt& first_ev=egraph[p_it->first]; + const abstract_eventt &first_ev=egraph[p_it->first]; var_to_instr.insert(first_ev.variable); id2loc.insert( - std::pair(first_ev.variable,first_ev.source_location)); + std::pair( + first_ev.variable, first_ev.source_location)); if(!p_it->is_po && my_events.find(p_it->second)!=my_events.end()) { - const abstract_eventt& second_ev=egraph[p_it->second]; + const abstract_eventt &second_ev=egraph[p_it->second]; var_to_instr.insert(second_ev.variable); id2loc.insert( - std::pair(second_ev.variable, + std::pair(second_ev.variable, second_ev.source_location)); } } @@ -484,7 +491,7 @@ Function: instrumentert::instrument_my_events \*******************************************************************/ void instrumentert::instrument_my_events( - const std::set& my_events) + const std::set &my_events) { var_to_instr.clear(); id2loc.clear(); @@ -526,7 +533,7 @@ std::set instrumentert::extract_my_events() for(std::size_t i=0; i>tmp; + file >> tmp; this_set.insert(tmp); } diff --git a/src/goto-instrument/wmm/pair_collection.cpp b/src/goto-instrument/wmm/pair_collection.cpp index df5d29c4171..c86a0e6994b 100644 --- a/src/goto-instrument/wmm/pair_collection.cpp +++ b/src/goto-instrument/wmm/pair_collection.cpp @@ -15,7 +15,7 @@ Date: 2013 #include "event_graph.h" -#define OUTPUT(s,fence,file,line,id,type) \ +#define OUTPUT(s, fence, file, line, id, type) \ s<second; + if(it!=var_map.end()) + return it->second; varst &vars=var_map[object]; @@ -58,21 +67,29 @@ const shared_bufferst::varst &shared_bufferst::operator()(const irep_idt &object vars.flush_delayed=add(object, symbol.base_name, "$flush_delayed", bool_typet()); - vars.read_delayed=add(object, symbol.base_name, "$read_delayed", - bool_typet()); - vars.read_delayed_var=add(object, symbol.base_name, "$read_delayed_var", - pointer_typet(symbol.type)); + vars.read_delayed= + add(object, symbol.base_name, "$read_delayed", bool_typet()); + vars.read_delayed_var= + add( + object, + symbol.base_name, + "$read_delayed_var", + pointer_typet(symbol.type)); - unsigned cnt; - - for(cnt=0;cntsecond.w_buff0_used, + assignment(goto_program, t, source_location, vars.second.w_buff0_used, false_exprt()); - assignment(goto_program, t, source_location, it->second.w_buff1_used, + assignment(goto_program, t, source_location, vars.second.w_buff1_used, false_exprt()); - assignment(goto_program, t, source_location, it->second.flush_delayed, + assignment(goto_program, t, source_location, vars.second.flush_delayed, false_exprt()); - assignment(goto_program, t, source_location, it->second.read_delayed, + assignment(goto_program, t, source_location, vars.second.read_delayed, false_exprt()); - assignment(goto_program, t, source_location, it->second.read_delayed_var, - null_pointer_exprt(pointer_typet(it->second.type))); - - for( - std::vector::const_iterator l_it= - it->second.r_buff0_thds.begin(); - l_it!=it->second.r_buff0_thds.end(); - l_it++ - ) - { - assignment(goto_program, t, source_location, *l_it, false_exprt()); - } + assignment(goto_program, t, source_location, vars.second.read_delayed_var, + null_pointer_exprt(pointer_typet(vars.second.type))); + + for(const auto &id : vars.second.r_buff0_thds) + assignment(goto_program, t, source_location, id, false_exprt()); - for( - std::vector::const_iterator l_it= - it->second.r_buff1_thds.begin(); - l_it!=it->second.r_buff1_thds.end(); - l_it++ - ) - assignment(goto_program, t, source_location, *l_it, false_exprt()); + for(const auto &id : vars.second.r_buff1_thds) + assignment(goto_program, t, source_location, id, false_exprt()); } } @@ -182,14 +184,15 @@ Function: shared_bufferst::add_initialization_code \*******************************************************************/ -void shared_bufferst::add_initialization_code(goto_functionst &goto_functions) +void shared_bufferst::add_initialization_code( + goto_functionst &goto_functions) { // get "main" goto_functionst::function_mapt::iterator m_it=goto_functions.function_map.find(goto_functions.entry_point()); if(m_it==goto_functions.function_map.end()) - throw "Weak memory instrumentation needs an entry point"; + throw "weak memory instrumentation needs an entry point"; goto_programt &main=m_it->second.body; add_initialization(main); @@ -215,9 +218,9 @@ void shared_bufferst::assignment( const exprt &value) { const namespacet ns(symbol_table); - std::string identifier = id2string(id_lhs); + std::string identifier=id2string(id_lhs); - const size_t pos = identifier.find("[]"); + const size_t pos=identifier.find("[]"); if(pos!=std::string::npos) { @@ -235,7 +238,7 @@ void shared_bufferst::assignment( t->code.add_source_location()=source_location; t->source_location=source_location; - //instrumentations.insert((const irep_idt) (t->code.id())); + // instrumentations.insert((const irep_idt) (t->code.id())); t++; } @@ -264,16 +267,16 @@ void shared_bufferst::delay_read( const irep_idt &read_object, const irep_idt &write_object) { - /* option 1: */ /* trick using an additional variable whose value is to be defined later */ #if 0 - assignment(goto_program, target, source_location, vars.read_delayed, true_exprt()); + assignment(goto_program, target, source_location, vars.read_delayed, + true_exprt()); assignment(goto_program, target, source_location, vars.read_delayed_var, read_object); - const irep_idt& new_var=add_fresh_var(write_object,unique(),vars.type); + const irep_idt &new_var=add_fresh_var(write_object, unique(), vars.type); assignment(goto_program, target, source_location, vars.read_new_var, new_var); @@ -284,16 +287,25 @@ void shared_bufferst::delay_read( /* option 2 */ /* pointer */ - const std::string identifier = id2string(write_object); + const std::string identifier=id2string(write_object); message.debug()<<"delay_read: " << messaget::eom; const varst &vars=(*this)(write_object); - const symbol_exprt read_object_expr = symbol_exprt(read_object, vars.type); + const symbol_exprt read_object_expr=symbol_exprt(read_object, vars.type); - assignment(goto_program, target, source_location, vars.read_delayed, true_exprt()); - assignment(goto_program, target, source_location, vars.read_delayed_var, - address_of_exprt( read_object_expr )); + assignment( + goto_program, + target, + source_location, + vars.read_delayed, + true_exprt()); + assignment( + goto_program, + target, + source_location, + vars.read_delayed_var, + address_of_exprt(read_object_expr)); } /*******************************************************************\ @@ -335,12 +347,12 @@ void shared_bufferst::flush_read( target++; - assignment(goto_program, target, source_location, vars.read_delayed, false_exprt()); + assignment(goto_program, target, source_location, vars.read_delayed, + false_exprt()); #endif /* option 2 */ /* do nothing */ - } /*******************************************************************\ @@ -363,7 +375,7 @@ void shared_bufferst::write( goto_programt::instructiont &original_instruction, const unsigned current_thread) { - const std::string identifier = id2string(object); + const std::string identifier=id2string(object); message.debug() << "write: " << object << messaget::eom; const varst &vars=(*this)(object); @@ -375,14 +387,25 @@ void shared_bufferst::write( original_instruction.code.op1()); // We update the used flags - assignment(goto_program, target, source_location, vars.w_buff1_used, vars.w_buff0_used); - assignment(goto_program, target, source_location, vars.w_buff0_used, true_exprt()); + assignment( + goto_program, + target, + source_location, + vars.w_buff1_used, + vars.w_buff0_used); + assignment( + goto_program, + target, + source_location, + vars.w_buff0_used, + true_exprt()); // We should not exceed the buffer size -- inserts assertion for dynamically // checking this const exprt buff0_used_expr=symbol_exprt(vars.w_buff0_used, bool_typet()); const exprt buff1_used_expr=symbol_exprt(vars.w_buff1_used, bool_typet()); - const exprt cond_expr=not_exprt( and_exprt(buff1_used_expr,buff0_used_expr) ); + const exprt cond_expr= + not_exprt(and_exprt(buff1_used_expr, buff0_used_expr)); target=goto_program.insert_before(target); target->guard=cond_expr; @@ -398,7 +421,11 @@ void shared_bufferst::write( vars.r_buff0_thds[cnt]); // We update the lucky new author of this value in the buffer - assignment(goto_program, target, source_location, vars.r_buff0_thds[current_thread], + assignment( + goto_program, + target, + source_location, + vars.r_buff0_thds[current_thread], true_exprt()); } @@ -421,7 +448,7 @@ void shared_bufferst::det_flush( const irep_idt &object, const unsigned current_thread) { - const std::string identifier = id2string(object); + const std::string identifier=id2string(object); // mostly for instrumenting the fences. A thread only flushes the values it // wrote in the buffer. @@ -434,31 +461,30 @@ void shared_bufferst::det_flush( // if buff0 from this thread, uses it to update the memory (the most recent // value, or last write by -ws-> ); if not, if buff1 from this thread, uses // it; if not, keeps the current memory value - const exprt buff0_expr = symbol_exprt(vars.w_buff0, vars.type); - const exprt buff1_expr = symbol_exprt(vars.w_buff1, vars.type); + const exprt buff0_expr=symbol_exprt(vars.w_buff0, vars.type); + const exprt buff1_expr=symbol_exprt(vars.w_buff1, vars.type); - const exprt buff0_used_expr = symbol_exprt(vars.w_buff0_used, bool_typet()); - const exprt buff1_used_expr = symbol_exprt(vars.w_buff1_used, bool_typet()); + const exprt buff0_used_expr=symbol_exprt(vars.w_buff0_used, bool_typet()); + const exprt buff1_used_expr=symbol_exprt(vars.w_buff1_used, bool_typet()); - const exprt buff0_mine_expr = symbol_exprt(vars.r_buff0_thds[current_thread], + const exprt buff0_mine_expr=symbol_exprt(vars.r_buff0_thds[current_thread], bool_typet()); - const exprt buff1_mine_expr = symbol_exprt(vars.r_buff1_thds[current_thread], + const exprt buff1_mine_expr=symbol_exprt(vars.r_buff1_thds[current_thread], bool_typet()); - const exprt buff0_used_and_mine_expr = and_exprt(buff0_used_expr, + const exprt buff0_used_and_mine_expr=and_exprt(buff0_used_expr, buff0_mine_expr); - const exprt buff1_used_and_mine_expr = and_exprt(buff1_used_expr, + const exprt buff1_used_and_mine_expr=and_exprt(buff1_used_expr, buff1_mine_expr); - const exprt new_value_expr = if_exprt( - buff0_used_and_mine_expr, - buff0_expr, + const exprt new_value_expr= if_exprt( - buff1_used_and_mine_expr, - buff1_expr, - lhs - ) - ); + buff0_used_and_mine_expr, + buff0_expr, + if_exprt( + buff1_used_and_mine_expr, + buff1_expr, + lhs)); // We update (or not) the value in the memory assignment(goto_program, target, source_location, object, new_value_expr); @@ -466,55 +492,58 @@ void shared_bufferst::det_flush( // We udpate the flags of the buffer // if buff0 used and mine, then it is no more used, as we flushed the last // write and -ws-> imposes not to have other writes in the buffer - assignment(goto_program, target, source_location, vars.w_buff0_used, + assignment( + goto_program, + target, + source_location, + vars.w_buff0_used, if_exprt( buff0_used_and_mine_expr, false_exprt(), - buff0_used_expr - ) - ); + buff0_used_expr)); // buff1 used and mine & not buff0 used and mine, then it no more used // if buff0 is used and mine, then, by ws, buff1 is no more used // otherwise, remains as it is - const exprt buff0_or_buff1_used_and_mine_expr = or_exprt( - buff0_used_and_mine_expr, - buff1_used_and_mine_expr - ); + const exprt buff0_or_buff1_used_and_mine_expr= + or_exprt(buff0_used_and_mine_expr, buff1_used_and_mine_expr); - assignment(goto_program, target, source_location, vars.w_buff1_used, + assignment( + goto_program, + target, + source_location, + vars.w_buff1_used, if_exprt( buff0_or_buff1_used_and_mine_expr, false_exprt(), - buff1_used_expr - ) - ); + buff1_used_expr)); // We update the ownerships // if buff0 mine and used, flushed, so belongs to nobody - const exprt buff0_thd_expr = symbol_exprt(vars.r_buff0_thds[current_thread], - bool_typet()); + const exprt buff0_thd_expr= + symbol_exprt(vars.r_buff0_thds[current_thread], bool_typet()); - assignment(goto_program, target, source_location, vars.r_buff0_thds[current_thread], - if_exprt( - buff0_used_and_mine_expr, - false_exprt(), - buff0_thd_expr - ) - ); + assignment( + goto_program, + target, + source_location, + vars.r_buff0_thds[current_thread], + if_exprt(buff0_used_and_mine_expr, false_exprt(), buff0_thd_expr)); // if buff1 used and mine, or if buff0 used and mine, then buff1 flushed and // doesn't belong to anybody - const exprt buff1_thd_expr = symbol_exprt(vars.r_buff1_thds[current_thread], - bool_typet()); + const exprt buff1_thd_expr= + symbol_exprt(vars.r_buff1_thds[current_thread], bool_typet()); - assignment(goto_program, target, source_location, vars.r_buff1_thds[current_thread], + assignment( + goto_program, + target, + source_location, + vars.r_buff1_thds[current_thread], if_exprt( buff0_or_buff1_used_and_mine_expr, false_exprt(), - buff1_thd_expr - ) - ); + buff1_thd_expr)); } /*******************************************************************\ @@ -537,7 +566,7 @@ void shared_bufferst::nondet_flush( const unsigned current_thread, const bool tso_pso_rmo) // true: tso/pso/rmo; false: power { - const std::string identifier = id2string(object); + const std::string identifier=id2string(object); message.debug() << "nondet flush: " << object << messaget::eom; @@ -547,7 +576,7 @@ void shared_bufferst::nondet_flush( // Non deterministic choice irep_idt choice0=choice(target->function, "0"); - irep_idt choice2=choice(target->function, "2"); //delays the write flush + irep_idt choice2=choice(target->function, "2"); // delays the write flush const symbol_exprt choice0_expr=symbol_exprt(choice0, bool_typet()); const symbol_exprt delay_expr=symbol_exprt(choice2, bool_typet()); @@ -576,7 +605,8 @@ void shared_bufferst::nondet_flush( // Will the write be directly flushed, or is it just a read? - assignment(goto_program, target, source_location, vars.flush_delayed, delay_expr); + assignment( + goto_program, target, source_location, vars.flush_delayed, delay_expr); assignment(goto_program, target, source_location, vars.mem_tmp, lhs); // for POWER, only instrumented reads can read from the buffers of other @@ -584,10 +614,11 @@ void shared_bufferst::nondet_flush( bool instrumented=false; if(!tso_pso_rmo) + { if(cycles.find(object)!=cycles.end()) { - typedef std::multimap::iterator m_itt; - std::pair ran=cycles_loc.equal_range(object); + typedef std::multimap::iterator m_itt; + std::pair ran=cycles_loc.equal_range(object); for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++) if(ran_it->second==source_location) { @@ -595,6 +626,7 @@ void shared_bufferst::nondet_flush( break; } } + } // TSO/PSO/RMO if(tso_pso_rmo || !instrumented) @@ -606,135 +638,138 @@ void shared_bufferst::nondet_flush( // or buff0 not mine and buff1 unused // or buff0 not mine and buff1 not mine // -> read from memory (and does not modify the buffer in any aspect) - const exprt cond_134_expr = + const exprt cond_134_expr= or_exprt( - not_exprt( buff0_used_expr ), + not_exprt(buff0_used_expr), or_exprt( and_exprt( - not_exprt( buff0_thd_expr ), - not_exprt( buff1_used_expr ) - ), + not_exprt(buff0_thd_expr), + not_exprt(buff1_used_expr)), and_exprt( - not_exprt( buff0_thd_expr ), - not_exprt( buff1_thd_expr ) - ) - ) - ); - const exprt val_134_expr = lhs; - const exprt buff0_used_134_expr = buff0_used_expr; - const exprt buff1_used_134_expr = buff1_used_expr; - const exprt buff0_134_expr = buff0_expr; - const exprt buff1_134_expr = buff1_expr; - const exprt buff0_thd_134_expr = buff0_thd_expr; - const exprt buff1_thd_134_expr = buff1_thd_expr; + not_exprt(buff0_thd_expr), + not_exprt(buff1_thd_expr)))); + const exprt val_134_expr=lhs; + const exprt buff0_used_134_expr=buff0_used_expr; + const exprt buff1_used_134_expr=buff1_used_expr; + const exprt buff0_134_expr=buff0_expr; + const exprt buff1_134_expr=buff1_expr; + const exprt buff0_thd_134_expr=buff0_thd_expr; + const exprt buff1_thd_134_expr=buff1_thd_expr; // (2) (6) (7) // if buff0 used and mine // -> read from buff0 - const exprt cond_267_expr = and_exprt( - buff0_used_expr, - buff0_thd_expr - ); - const exprt val_267_expr = - buff0_expr; - const exprt buff0_used_267_expr = false_exprt(); - const exprt buff1_used_267_expr = false_exprt(); - const exprt buff0_267_expr = buff0_expr; - const exprt buff1_267_expr = buff1_expr; - const exprt buff0_thd_267_expr = false_exprt(); - const exprt buff1_thd_267_expr = false_exprt(); + const exprt cond_267_expr=and_exprt(buff0_used_expr, buff0_thd_expr); + const exprt val_267_expr=buff0_expr; + const exprt buff0_used_267_expr=false_exprt(); + const exprt buff1_used_267_expr=false_exprt(); + const exprt buff0_267_expr=buff0_expr; + const exprt buff1_267_expr=buff1_expr; + const exprt buff0_thd_267_expr=false_exprt(); + const exprt buff1_thd_267_expr=false_exprt(); // (5) // buff0 and buff1 are used, buff0 is not mine, buff1 is mine // -> read from buff1 - const exprt cond_5_expr = and_exprt( - buff0_used_expr, + const exprt cond_5_expr= and_exprt( - buff1_used_expr, + buff0_used_expr, and_exprt( - not_exprt( buff0_thd_expr ), - buff1_thd_expr - ) - ) - ); - const exprt val_5_expr = buff1_expr; - const exprt buff0_used_5_expr = buff0_used_expr; - const exprt buff1_used_5_expr = false_exprt(); - const exprt buff0_5_expr = buff0_expr; - const exprt buff1_5_expr = buff1_expr; - const exprt buff0_thd_5_expr = buff0_thd_expr; - const exprt buff1_thd_5_expr = false_exprt(); + buff1_used_expr, + and_exprt(not_exprt(buff0_thd_expr), buff1_thd_expr))); + const exprt val_5_expr=buff1_expr; + const exprt buff0_used_5_expr=buff0_used_expr; + const exprt buff1_used_5_expr=false_exprt(); + const exprt buff0_5_expr=buff0_expr; + const exprt buff1_5_expr=buff1_expr; + const exprt buff0_thd_5_expr=buff0_thd_expr; + const exprt buff1_thd_5_expr=false_exprt(); // Updates // memory - assignment(goto_program, target, source_location, object, if_exprt( - cond_134_expr, - val_134_expr, - if_exprt( - cond_267_expr, - val_267_expr, - val_5_expr - ) - )); - // buff0 - assignment(goto_program, target, source_location, vars.w_buff0, if_exprt( - delay_expr, - buff0_expr, + assignment( + goto_program, + target, + source_location, + object, if_exprt( cond_134_expr, - buff0_134_expr, + val_134_expr, if_exprt( cond_267_expr, - buff0_267_expr, - buff0_5_expr - ) - ) - )); + val_267_expr, + val_5_expr))); + // buff0 + assignment( + goto_program, + target, + source_location, + vars.w_buff0, + if_exprt( + delay_expr, + buff0_expr, + if_exprt( + cond_134_expr, + buff0_134_expr, + if_exprt( + cond_267_expr, + buff0_267_expr, + buff0_5_expr)))); // buff1 - assignment(goto_program, target, source_location, vars.w_buff1, if_exprt( - delay_expr, - buff1_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff1, if_exprt( - cond_134_expr, - buff1_134_expr, + delay_expr, + buff1_expr, if_exprt( - cond_267_expr, - buff1_267_expr, - buff1_5_expr - ) - ) - )); + cond_134_expr, + buff1_134_expr, + if_exprt( + cond_267_expr, + buff1_267_expr, + buff1_5_expr)))); // buff0_used - assignment(goto_program, target, source_location, vars.w_buff0_used, if_exprt( - delay_expr, - buff0_used_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff0_used, if_exprt( - cond_134_expr, - buff0_used_134_expr, + delay_expr, + buff0_used_expr, if_exprt( - cond_267_expr, - buff0_used_267_expr, - buff0_used_5_expr - ) - ) - )); + cond_134_expr, + buff0_used_134_expr, + if_exprt( + cond_267_expr, + buff0_used_267_expr, + buff0_used_5_expr)))); // buff1_used - assignment(goto_program, target, source_location, vars.w_buff1_used, if_exprt( - delay_expr, - buff1_used_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff1_used, if_exprt( - cond_134_expr, - buff1_used_134_expr, + delay_expr, + buff1_used_expr, if_exprt( - cond_267_expr, - buff1_used_267_expr, - buff1_used_5_expr - ) - ) - )); + cond_134_expr, + buff1_used_134_expr, + if_exprt( + cond_267_expr, + buff1_used_267_expr, + buff1_used_5_expr)))); // buff0_thd - assignment(goto_program, target, source_location, - vars.r_buff0_thds[current_thread], if_exprt( + assignment( + goto_program, + target, + source_location, + vars.r_buff0_thds[current_thread], + if_exprt( delay_expr, buff0_thd_expr, if_exprt( @@ -743,13 +778,12 @@ void shared_bufferst::nondet_flush( if_exprt( cond_267_expr, buff0_thd_267_expr, - buff0_thd_5_expr - ) - ) - ) - ); + buff0_thd_5_expr)))); // buff1_thd - assignment(goto_program, target, source_location, + assignment( + goto_program, + target, + source_location, vars.r_buff1_thds[current_thread], if_exprt( delay_expr, buff1_thd_expr, @@ -759,11 +793,7 @@ void shared_bufferst::nondet_flush( if_exprt( cond_267_expr, buff1_thd_267_expr, - buff1_thd_5_expr - ) - ) - ) - ); + buff1_thd_5_expr)))); } // POWER else @@ -775,229 +805,211 @@ void shared_bufferst::nondet_flush( const symbol_exprt choice1_expr=symbol_exprt(choice1, bool_typet()); // throw Boolean dice - assignment(goto_program, target, source_location, choice1, nondet_bool_expr); + assignment( + goto_program, target, source_location, choice1, nondet_bool_expr); // 7 cases // (1) // if buff0 unused // -> read from memory (and does not modify the buffer in any aspect) - const exprt cond_1_expr = not_exprt( buff0_used_expr ); - const exprt val_1_expr = lhs; - const exprt buff0_used_1_expr = buff0_used_expr; - const exprt buff1_used_1_expr = buff1_used_expr; - const exprt buff0_1_expr = buff0_expr; - const exprt buff1_1_expr = buff1_expr; - const exprt buff0_thd_1_expr = buff0_thd_expr; - const exprt buff1_thd_1_expr = buff1_thd_expr; + const exprt cond_1_expr=not_exprt(buff0_used_expr); + const exprt val_1_expr=lhs; + const exprt buff0_used_1_expr=buff0_used_expr; + const exprt buff1_used_1_expr=buff1_used_expr; + const exprt buff0_1_expr=buff0_expr; + const exprt buff1_1_expr=buff1_expr; + const exprt buff0_thd_1_expr=buff0_thd_expr; + const exprt buff1_thd_1_expr=buff1_thd_expr; // (2) (6) (7) // if buff0 used and mine // -> read from buff0 - const exprt cond_267_expr = and_exprt( - buff0_used_expr, - buff0_thd_expr - ); - const exprt val_267_expr = buff0_expr; - const exprt buff0_used_267_expr = false_exprt(); - const exprt buff1_used_267_expr = false_exprt(); - const exprt buff0_267_expr = buff0_expr; - const exprt buff1_267_expr = buff1_expr; - const exprt buff0_thd_267_expr = false_exprt(); - const exprt buff1_thd_267_expr = false_exprt(); + const exprt cond_267_expr= + and_exprt(buff0_used_expr, buff0_thd_expr); + const exprt val_267_expr=buff0_expr; + const exprt buff0_used_267_expr=false_exprt(); + const exprt buff1_used_267_expr=false_exprt(); + const exprt buff0_267_expr=buff0_expr; + const exprt buff1_267_expr=buff1_expr; + const exprt buff0_thd_267_expr=false_exprt(); + const exprt buff1_thd_267_expr=false_exprt(); // (3) // if buff0 used and not mine, and buff1 not used // -> read from buff0 or memory - const exprt cond_3_expr = and_exprt( + const exprt cond_3_expr= + and_exprt( buff0_used_expr, and_exprt( - not_exprt( buff0_thd_expr ), - not_exprt( buff1_used_expr ) - )); - const exprt val_3_expr = if_exprt( - choice0_expr, - buff0_expr, - lhs - ); - const exprt buff0_used_3_expr = choice0_expr; - const exprt buff1_used_3_expr = false_exprt(); - const exprt buff0_3_expr = buff0_expr; - const exprt buff1_3_expr = buff1_expr; - const exprt buff0_thd_3_expr = false_exprt(); - const exprt buff1_thd_3_expr = false_exprt(); + not_exprt(buff0_thd_expr), + not_exprt(buff1_used_expr))); + const exprt val_3_expr=if_exprt(choice0_expr, buff0_expr, lhs); + const exprt buff0_used_3_expr=choice0_expr; + const exprt buff1_used_3_expr=false_exprt(); + const exprt buff0_3_expr=buff0_expr; + const exprt buff1_3_expr=buff1_expr; + const exprt buff0_thd_3_expr=false_exprt(); + const exprt buff1_thd_3_expr=false_exprt(); // (4) // buff0 and buff1 are both used, and both not mine // -> read from memory or buff0 or buff1 - const exprt cond_4_expr = and_exprt( - and_exprt( - buff0_used_expr, - not_exprt( buff1_thd_expr ) - ), + const exprt cond_4_expr= and_exprt( - buff1_used_expr, - not_exprt( buff0_thd_expr ) - ) - ); - const exprt val_4_expr = if_exprt( - choice0_expr, - lhs, + and_exprt(buff0_used_expr, not_exprt(buff1_thd_expr)), + and_exprt(buff1_used_expr, not_exprt(buff0_thd_expr))); + const exprt val_4_expr= if_exprt( - choice1_expr, - buff0_expr, - buff1_expr - ) - ); - const exprt buff0_used_4_expr = or_exprt( - choice0_expr, - not_exprt( choice1_expr ) - ); - const exprt buff1_used_4_expr = choice0_expr; - const exprt buff0_4_expr = buff0_expr; - const exprt buff1_4_expr = buff1_expr; - const exprt buff0_thd_4_expr = buff0_thd_expr; - const exprt buff1_thd_4_expr = if_exprt( - choice0_expr, - buff1_thd_expr, - false_exprt() - ); + choice0_expr, + lhs, + if_exprt( + choice1_expr, + buff0_expr, + buff1_expr)); + const exprt buff0_used_4_expr= + or_exprt(choice0_expr, not_exprt(choice1_expr)); + const exprt buff1_used_4_expr=choice0_expr; + const exprt buff0_4_expr=buff0_expr; + const exprt buff1_4_expr=buff1_expr; + const exprt buff0_thd_4_expr=buff0_thd_expr; + const exprt buff1_thd_4_expr= + if_exprt(choice0_expr, buff1_thd_expr, false_exprt()); // (5) // buff0 and buff1 are both used, and buff0 not mine, and buff1 mine // -> read buff1 or buff0 - const exprt cond_5_expr = and_exprt( - and_exprt( - buff0_used_expr, - buff1_thd_expr - ), + const exprt cond_5_expr= and_exprt( - buff1_used_expr, - not_exprt( buff0_thd_expr ) - ) - ); - const exprt val_5_expr = if_exprt( - choice0_expr, - buff1_expr, - buff0_expr - ); - const exprt buff0_used_5_expr = choice0_expr; - const exprt buff1_used_5_expr = false_exprt(); - const exprt buff0_5_expr = buff0_expr; - const exprt buff1_5_expr = buff1_expr; - const exprt buff0_thd_5_expr = false_exprt(); - const exprt buff1_thd_5_expr = false_exprt(); + and_exprt(buff0_used_expr, buff1_thd_expr), + and_exprt(buff1_used_expr, not_exprt(buff0_thd_expr))); + const exprt val_5_expr= + if_exprt( + choice0_expr, + buff1_expr, + buff0_expr); + const exprt buff0_used_5_expr=choice0_expr; + const exprt buff1_used_5_expr=false_exprt(); + const exprt buff0_5_expr=buff0_expr; + const exprt buff1_5_expr=buff1_expr; + const exprt buff0_thd_5_expr=false_exprt(); + const exprt buff1_thd_5_expr=false_exprt(); // Updates // memory - assignment(goto_program, target, source_location, object, if_exprt( - cond_1_expr, - val_1_expr, - if_exprt( - cond_267_expr, - val_267_expr, - if_exprt( - cond_4_expr, - val_4_expr, - if_exprt( - cond_5_expr, - val_5_expr, - val_3_expr - ) - ) - ) - )); - // buff0 - assignment(goto_program, target, source_location, vars.w_buff0, if_exprt( - delay_expr, - buff0_expr, + assignment( + goto_program, + target, + source_location, + object, if_exprt( cond_1_expr, - buff0_1_expr, + val_1_expr, if_exprt( cond_267_expr, - buff0_267_expr, + val_267_expr, if_exprt( cond_4_expr, - buff0_4_expr, + val_4_expr, if_exprt( cond_5_expr, - buff0_5_expr, - buff0_3_expr - ) - ) - ) - ) - )); + val_5_expr, + val_3_expr))))); + // buff0 + assignment( + goto_program, + target, + source_location, + vars.w_buff0, + if_exprt( + delay_expr, + buff0_expr, + if_exprt( + cond_1_expr, + buff0_1_expr, + if_exprt( + cond_267_expr, + buff0_267_expr, + if_exprt( + cond_4_expr, + buff0_4_expr, + if_exprt( + cond_5_expr, + buff0_5_expr, + buff0_3_expr)))))); // buff1 - assignment(goto_program, target, source_location, vars.w_buff1, if_exprt( - delay_expr, - buff1_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff1, if_exprt( - cond_1_expr, - buff1_1_expr, + delay_expr, + buff1_expr, if_exprt( - cond_267_expr, - buff1_267_expr, + cond_1_expr, + buff1_1_expr, if_exprt( - cond_4_expr, - buff1_4_expr, + cond_267_expr, + buff1_267_expr, if_exprt( - cond_5_expr, - buff1_5_expr, - buff1_3_expr - ) - ) - ) - ) - )); + cond_4_expr, + buff1_4_expr, + if_exprt( + cond_5_expr, + buff1_5_expr, + buff1_3_expr)))))); // buff0_used - assignment(goto_program, target, source_location, vars.w_buff0_used, if_exprt( - delay_expr, - buff0_used_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff0_used, if_exprt( - cond_1_expr, - buff0_used_1_expr, + delay_expr, + buff0_used_expr, if_exprt( - cond_267_expr, - buff0_used_267_expr, + cond_1_expr, + buff0_used_1_expr, if_exprt( - cond_4_expr, - buff0_used_4_expr, + cond_267_expr, + buff0_used_267_expr, if_exprt( - cond_5_expr, - buff0_used_5_expr, - buff0_used_3_expr - ) - ) - ) - ) - )); + cond_4_expr, + buff0_used_4_expr, + if_exprt( + cond_5_expr, + buff0_used_5_expr, + buff0_used_3_expr)))))); // buff1_used - assignment(goto_program, target, source_location, vars.w_buff1_used, if_exprt( - delay_expr, - buff1_used_expr, + assignment( + goto_program, + target, + source_location, + vars.w_buff1_used, if_exprt( - cond_1_expr, - buff1_used_1_expr, + delay_expr, + buff1_used_expr, if_exprt( - cond_267_expr, - buff1_used_267_expr, + cond_1_expr, + buff1_used_1_expr, if_exprt( - cond_4_expr, - buff1_used_4_expr, + cond_267_expr, + buff1_used_267_expr, if_exprt( - cond_5_expr, - buff1_used_5_expr, - buff1_used_3_expr - ) - ) - ) - ) - )); + cond_4_expr, + buff1_used_4_expr, + if_exprt( + cond_5_expr, + buff1_used_5_expr, + buff1_used_3_expr)))))); // buff0_thd - assignment(goto_program, target, source_location, - vars.r_buff0_thds[current_thread], if_exprt( + assignment( + goto_program, + target, + source_location, + vars.r_buff0_thds[current_thread], + if_exprt( delay_expr, buff0_thd_expr, if_exprt( @@ -1012,16 +1024,14 @@ void shared_bufferst::nondet_flush( if_exprt( cond_5_expr, buff0_thd_5_expr, - buff0_thd_3_expr - ) - ) - ) - ) - ) - ); + buff0_thd_3_expr)))))); // buff1_thd - assignment(goto_program, target, source_location, - vars.r_buff1_thds[current_thread], if_exprt( + assignment( + goto_program, + target, + source_location, + vars.r_buff1_thds[current_thread], + if_exprt( delay_expr, buff1_thd_expr, if_exprt( @@ -1036,13 +1046,7 @@ void shared_bufferst::nondet_flush( if_exprt( cond_5_expr, buff1_thd_5_expr, - buff1_thd_3_expr - ) - ) - ) - ) - ) - ); + buff1_thd_3_expr)))))); } } catch (std::string s) @@ -1127,8 +1131,8 @@ bool shared_bufferst::is_buffered_in_general( } else { - typedef std::multimap::iterator m_itt; - std::pair ran=cycles_loc.equal_range(identifier); + typedef std::multimap::iterator m_itt; + std::pair ran=cycles_loc.equal_range(identifier); for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++) if(ran_it->second==source_location) return true; // not to instrument @@ -1171,15 +1175,15 @@ void shared_bufferst::affected_by_delay( #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) forall_rw_set_w_entries(w_it, rw_set) forall_rw_set_r_entries(r_it, rw_set) { message.debug() <<"debug: "<second.object) <<" reads from "<second.object) <second.symbol_expr,true)) - //shouldn't it be true? false => overapprox + if(is_buffered_in_general(ns, r_it->second.symbol_expr, true)) + // shouldn't it be true? false => overapprox affected_by_delay_set.insert(w_it->second.object); } } @@ -1201,16 +1205,16 @@ Function: weak_memory_cfg void shared_bufferst::cfg_visitort::weak_memory( value_setst &value_sets, - const irep_idt& function, - memory_modelt model -) + const irep_idt &function, + memory_modelt model) { - shared_buffers.message.debug() << "visit function "<second.symbol_expr,false)) - past_writes.insert(w_it->second.object); - - goto_programt::instructiont original_instruction; - original_instruction.swap(instruction); - const source_locationt &source_location= - original_instruction.source_location; + ); // NOLINT(whitespace/parens) - // ATOMIC_BEGIN: we make the whole thing atomic - instruction.make_atomic_begin(); - instruction.source_location=source_location; - i_it++; + if(rw_set.empty()) + continue; - // we first perform (non-deterministically) up to 2 writes for - // stuff that is potentially read - forall_rw_set_r_entries(e_it, rw_set) - { - // flush read -- do nothing in this implementation - shared_buffers.flush_read( - goto_program, i_it, source_location, e_it->second.object); - - if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr,false)) - shared_buffers.nondet_flush( - goto_program, i_it, source_location, e_it->second.object, - current_thread, - (model==TSO || model==PSO || model==RMO)); - } + // add all the written values (which are not instrumentations) + // in a set + forall_rw_set_w_entries(w_it, rw_set) + if(shared_buffers.is_buffered(ns, w_it->second.symbol_expr, false)) + past_writes.insert(w_it->second.object); + + goto_programt::instructiont original_instruction; + original_instruction.swap(instruction); + const source_locationt &source_location= + original_instruction.source_location; + + // ATOMIC_BEGIN: we make the whole thing atomic + instruction.make_atomic_begin(); + instruction.source_location=source_location; + i_it++; + + // we first perform (non-deterministically) up to 2 writes for + // stuff that is potentially read + forall_rw_set_r_entries(e_it, rw_set) + { + // flush read -- do nothing in this implementation + shared_buffers.flush_read( + goto_program, i_it, source_location, e_it->second.object); + + if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr, false)) + shared_buffers.nondet_flush( + goto_program, i_it, source_location, e_it->second.object, + current_thread, + (model==TSO || model==PSO || model==RMO)); + } - // Now perform the write(s). - forall_rw_set_w_entries(e_it, rw_set) + // Now perform the write(s). + forall_rw_set_w_entries(e_it, rw_set) + { + // if one of the previous read was to buffer, then delays the read + if(model==RMO || model==Power) { - // if one of the previous read was to buffer, then delays the read - if(model==RMO || model==Power) forall_rw_set_r_entries(r_it, rw_set) - if(shared_buffers.is_buffered(ns, r_it->second.symbol_expr,true)) + if(shared_buffers.is_buffered(ns, r_it->second.symbol_expr, true)) { shared_buffers.delay_read( goto_program, i_it, source_location, r_it->second.object, e_it->second.object); } + } - if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr,true)) - { - shared_buffers.write( - goto_program, i_it, source_location, - e_it->second.object,original_instruction, - current_thread); - } - else + if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr, true)) + { + shared_buffers.write( + goto_program, i_it, source_location, + e_it->second.object, original_instruction, + current_thread); + } + else + { + // unbuffered + if(model==RMO || model==Power) { - // unbuffered - if(model==RMO || model==Power) - forall_rw_set_r_entries(r_it, rw_set) - if(shared_buffers.affected_by_delay_set.find(r_it->second.object) - !=shared_buffers.affected_by_delay_set.end()) - { - shared_buffers.message.debug() << "second: " - << r_it->second.object << messaget::eom; - const varst &vars=(shared_buffers)(r_it->second.object); - - shared_buffers.message.debug() << "writer " - <second.object - <<" reads "<second.object<< messaget::eom; - - // TO FIX: how to deal with rhs including calls? - // if a read is delayed, use its alias instead of itself - // -- or not - symbol_exprt to_replace_expr = symbol_exprt( - r_it->second.object, vars.type); - symbol_exprt new_read_expr = symbol_exprt( - vars.read_delayed_var, - pointer_typet(vars.type)); - symbol_exprt read_delayed_expr = symbol_exprt( - vars.read_delayed, bool_typet()); - - // One extra non-deterministic choice needed - irep_idt choice1=shared_buffers.choice( - instruction.function, "1"); - const symbol_exprt choice1_expr=symbol_exprt(choice1, - bool_typet()); - const exprt nondet_bool_expr=side_effect_expr_nondett( - bool_typet()); - - // throw Boolean dice - shared_buffers.assignment(goto_program, i_it, source_location, - choice1, - nondet_bool_expr); - - exprt rhs = if_exprt( - read_delayed_expr, + forall_rw_set_r_entries(r_it, rw_set) + if(shared_buffers.affected_by_delay_set.find( + r_it->second.object)!= + shared_buffers.affected_by_delay_set.end()) + { + shared_buffers.message.debug() << "second: " + << r_it->second.object << messaget::eom; + const varst &vars=(shared_buffers)(r_it->second.object); + + shared_buffers.message.debug() << "writer " + <second.object + <<" reads "<second.object<< messaget::eom; + + // TO FIX: how to deal with rhs including calls? + // if a read is delayed, use its alias instead of itself + // -- or not + symbol_exprt to_replace_expr=symbol_exprt( + r_it->second.object, vars.type); + symbol_exprt new_read_expr=symbol_exprt( + vars.read_delayed_var, + pointer_typet(vars.type)); + symbol_exprt read_delayed_expr=symbol_exprt( + vars.read_delayed, bool_typet()); + + // One extra non-deterministic choice needed + irep_idt choice1=shared_buffers.choice( + instruction.function, "1"); + const symbol_exprt choice1_expr=symbol_exprt(choice1, + bool_typet()); + const exprt nondet_bool_expr=side_effect_expr_nondett( + bool_typet()); + + // throw Boolean dice + shared_buffers.assignment( + goto_program, + i_it, + source_location, + choice1, + nondet_bool_expr); + + exprt rhs= if_exprt( - choice1_expr, - dereference_exprt(new_read_expr,vars.type), - to_replace_expr), - to_replace_expr);//original_instruction.code.op1()); - - shared_buffers.assignment( - goto_program, i_it, source_location, - r_it->second.object, rhs); - } - - // normal assignment - shared_buffers.assignment( - goto_program, i_it, source_location, - e_it->second.object, original_instruction.code.op1()); + read_delayed_expr, + if_exprt( + choice1_expr, + dereference_exprt(new_read_expr, vars.type), + to_replace_expr), + to_replace_expr); // original_instruction.code.op1()); + + shared_buffers.assignment( + goto_program, i_it, source_location, + r_it->second.object, rhs); + } } + + // normal assignment + shared_buffers.assignment( + goto_program, i_it, source_location, + e_it->second.object, original_instruction.code.op1()); } + } - // if last writes was flushed to make the lhs reads the buffer but - // without affecting the memory, restore the previous memory value - // (buffer flush delay) - forall_rw_set_r_entries(e_it, rw_set) - if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr,false)) - { - shared_buffers.message.debug() << "flush restore: " - << e_it->second.object << messaget::eom; - const varst vars= (shared_buffers)(e_it->second.object); - const exprt delayed_expr=symbol_exprt(vars.flush_delayed, - bool_typet()); - const symbol_exprt mem_value_expr=symbol_exprt(vars.mem_tmp, - vars.type); - const exprt cond_expr=if_exprt(delayed_expr, mem_value_expr, - e_it->second.symbol_expr); - - shared_buffers.assignment( - goto_program, i_it, source_location, - e_it->second.object, cond_expr); - shared_buffers.assignment( - goto_program, i_it, source_location, - vars.flush_delayed, false_exprt()); - } + // if last writes was flushed to make the lhs reads the buffer but + // without affecting the memory, restore the previous memory value + // (buffer flush delay) + forall_rw_set_r_entries(e_it, rw_set) + if(shared_buffers.is_buffered(ns, e_it->second.symbol_expr, false)) + { + shared_buffers.message.debug() << "flush restore: " + << e_it->second.object << messaget::eom; + const varst vars= (shared_buffers)(e_it->second.object); + const exprt delayed_expr=symbol_exprt(vars.flush_delayed, + bool_typet()); + const symbol_exprt mem_value_expr=symbol_exprt(vars.mem_tmp, + vars.type); + const exprt cond_expr=if_exprt(delayed_expr, mem_value_expr, + e_it->second.symbol_expr); + + shared_buffers.assignment( + goto_program, i_it, source_location, + e_it->second.object, cond_expr); + shared_buffers.assignment( + goto_program, i_it, source_location, + vars.flush_delayed, false_exprt()); + } - // ATOMIC_END - i_it=goto_program.insert_before(i_it); - i_it->make_atomic_end(); - i_it->source_location=source_location; - i_it++; + // ATOMIC_END + i_it=goto_program.insert_before(i_it); + i_it->make_atomic_end(); + i_it->source_location=source_location; + i_it++; - i_it--; // the for loop already counts us up - } - catch (...) - { - shared_buffers.message.warning() << "Identifier not found" - << messaget::eom; - } + i_it--; // the for loop already counts us up + } + catch (...) + { + shared_buffers.message.warning() << "Identifier not found" + << messaget::eom; + } } - else if(is_fence(instruction, ns) || (instruction.is_other() - && instruction.code.get_statement()==ID_fence - && (instruction.code.get_bool("WRfence") - || instruction.code.get_bool("WWfence") - || instruction.code.get_bool("RWfence") - || instruction.code.get_bool("RRfence")))) + else if(is_fence(instruction, ns) || + (instruction.is_other() && + instruction.code.get_statement()==ID_fence && + (instruction.code.get_bool("WRfence") || + instruction.code.get_bool("WWfence") || + instruction.code.get_bool("RWfence") || + instruction.code.get_bool("RRfence")))) { goto_programt::instructiont original_instruction; original_instruction.swap(instruction); @@ -1434,7 +1450,7 @@ void shared_bufferst::cfg_visitort::weak_memory( } else if(instruction.is_function_call()) { - const exprt& fun = to_code_function_call(instruction.code).function(); + const exprt &fun=to_code_function_call(instruction.code).function(); weak_memory(value_sets, to_symbol_expr(fun).get_identifier(), model); } } diff --git a/src/goto-instrument/wmm/shared_buffers.h b/src/goto-instrument/wmm/shared_buffers.h index 05a1400e8e7..50e3c2ec4db 100644 --- a/src/goto-instrument/wmm/shared_buffers.h +++ b/src/goto-instrument/wmm/shared_buffers.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #ifndef CPROVER_GOTO_INSTRUMENT_WMM_SHARED_BUFFERS_H #define CPROVER_GOTO_INSTRUMENT_WMM_SHARED_BUFFERS_H @@ -20,7 +28,7 @@ class shared_bufferst { public: shared_bufferst(symbol_tablet &_symbol_table, unsigned _nb_threads, - messaget& _message): + messaget &_message): symbol_table(_symbol_table), nb_threads(_nb_threads+1), uniq(0), @@ -32,7 +40,7 @@ class shared_bufferst void set_cav11(memory_modelt model) { if(model!=TSO) - throw "Sorry, CAV11 only available for TSO"; + throw "sorry, CAV11 only available for TSO"; cav11 = true; } @@ -71,9 +79,9 @@ class shared_bufferst // variables in the cycles std::set cycles; // events instrumented: var->locations in the code - std::multimap cycles_loc; + std::multimap cycles_loc; // events in cycles: var->locations (for read instrumentations) - std::multimap cycles_r_loc; + std::multimap cycles_r_loc; const varst &operator()(const irep_idt &object); @@ -84,15 +92,13 @@ class shared_bufferst goto_programt::targett &t, const source_locationt &source_location, const irep_idt &read_object, - const irep_idt &write_object - ); + const irep_idt &write_object); void flush_read( goto_programt &goto_program, goto_programt::targett &t, const source_locationt &source_location, - const irep_idt &write_object - ); + const irep_idt &write_object); void write( goto_programt &goto_program, @@ -141,7 +147,8 @@ class shared_bufferst namespacet ns(symbol_table); const symbolt &symbol=ns.lookup(id); - if(symbol.is_thread_local) return false; + if(symbol.is_thread_local) + return false; if(has_prefix(id2string(id), CPROVER_PREFIX)) return false; @@ -172,8 +179,7 @@ class shared_bufferst symbol_tablet &symbol_table, goto_programt &goto_program, memory_modelt model, - goto_functionst &goto_functions - ); + goto_functionst &goto_functions); void affected_by_delay( symbol_tablet &symbol_table, @@ -183,9 +189,9 @@ class shared_bufferst class cfg_visitort { protected: - shared_bufferst& shared_buffers; - symbol_tablet& symbol_table; - goto_functionst& goto_functions; + shared_bufferst &shared_buffers; + symbol_tablet &symbol_table; + goto_functionst &goto_functions; /* for thread marking (dynamic) */ unsigned current_thread; @@ -196,8 +202,8 @@ class shared_bufferst std::set past_writes; public: - cfg_visitort(shared_bufferst& _shared, symbol_tablet& _symbol_table, - goto_functionst& _goto_functions) + cfg_visitort(shared_bufferst &_shared, symbol_tablet &_symbol_table, + goto_functionst &_goto_functions) :shared_buffers(_shared), symbol_table(_symbol_table), goto_functions(_goto_functions) { @@ -208,7 +214,7 @@ class shared_bufferst void weak_memory( value_setst &value_sets, - const irep_idt& function, + const irep_idt &function, memory_modelt model); }; @@ -234,7 +240,7 @@ class shared_bufferst bool cav11; /* message */ - messaget& message; + messaget &message; irep_idt add( const irep_idt &object, diff --git a/src/goto-instrument/wmm/weak_memory.cpp b/src/goto-instrument/wmm/weak_memory.cpp index 6d2c40ac59f..efe8a73ffaf 100644 --- a/src/goto-instrument/wmm/weak_memory.cpp +++ b/src/goto-instrument/wmm/weak_memory.cpp @@ -50,7 +50,7 @@ void introduce_temporaries( #ifdef LOCAL_MAY const goto_functionst::goto_functiont &goto_function, #endif - messaget& message) + messaget &message) { namespacet ns(symbol_table); unsigned tmp_counter=0; @@ -73,12 +73,14 @@ void introduce_temporaries( #ifdef LOCAL_MAY , local_may #endif - ); - if(rw_set.empty()) continue; + ); // NOLINT(whitespace/parens) + if(rw_set.empty()) + continue; symbolt new_symbol; new_symbol.base_name="$tmp_guard"; - new_symbol.name=id2string(function)+"$tmp_guard"+std::to_string(tmp_counter++); + new_symbol.name= + id2string(function)+"$tmp_guard"+std::to_string(tmp_counter++); new_symbol.type=bool_typet(); new_symbol.is_static_lifetime=true; new_symbol.is_thread_local=true; @@ -122,8 +124,8 @@ Function: weak_memory void weak_memory( memory_modelt model, - value_setst& value_sets, - symbol_tablet& symbol_table, + value_setst &value_sets, + symbol_tablet &symbol_table, goto_functionst &goto_functions, bool SCC, instrumentation_strategyt event_strategy, @@ -138,7 +140,7 @@ void weak_memory( bool render_function, bool cav11_option, bool hide_internals, - message_handlert& message_handler, + message_handlert &message_handler, bool ignore_arrays) { messaget message(message_handler); @@ -242,7 +244,7 @@ void weak_memory( shared_buffers.cycles_r_loc = instrumenter.id2cycloc; // places in the cycles // for reads delays - shared_buffers.affected_by_delay(symbol_table,value_sets,goto_functions); + shared_buffers.affected_by_delay(symbol_table, value_sets, goto_functions); for(std::set::iterator it= shared_buffers.affected_by_delay_set.begin(); @@ -254,11 +256,12 @@ void weak_memory( for(std::set::iterator it=shared_buffers.cycles.begin(); it!=shared_buffers.cycles.end(); it++) { - typedef std::multimap::iterator m_itt; - const std::pair ran= + typedef std::multimap::iterator m_itt; + const std::pair ran= shared_buffers.cycles_loc.equal_range(*it); for(m_itt ran_it=ran.first; ran_it!=ran.second; ran_it++) - message.result() << ((*it)==""?"fence":*it)<<", "<second<second << messaget::eom; } shared_bufferst::cfg_visitort visitor(shared_buffers, symbol_table, diff --git a/src/goto-instrument/wmm/weak_memory.h b/src/goto-instrument/wmm/weak_memory.h index a440a10bd82..4ca48b0447e 100644 --- a/src/goto-instrument/wmm/weak_memory.h +++ b/src/goto-instrument/wmm/weak_memory.h @@ -36,7 +36,7 @@ void weak_memory( bool render_function, bool cav11_option, bool hide_internals, - message_handlert& message, + message_handlert &message, bool ignore_arrays); void introduce_temporaries( @@ -47,6 +47,6 @@ void introduce_temporaries( #ifdef LOCAL_MAY const goto_functionst::goto_functiont &goto_function, #endif - messaget& message); + messaget &message); #endif // CPROVER_GOTO_INSTRUMENT_WMM_WEAK_MEMORY_H diff --git a/src/goto-instrument/wmm/wmm.h b/src/goto-instrument/wmm/wmm.h index 9fa924e8693..fd3cbcc4e45 100644 --- a/src/goto-instrument/wmm/wmm.h +++ b/src/goto-instrument/wmm/wmm.h @@ -11,7 +11,8 @@ Date: 2012 #ifndef CPROVER_GOTO_INSTRUMENT_WMM_WMM_H #define CPROVER_GOTO_INSTRUMENT_WMM_WMM_H -typedef enum { +typedef enum +{ Unknown=-1, TSO=0, PSO=1, @@ -19,7 +20,8 @@ typedef enum { Power=3 } memory_modelt; -typedef enum { +typedef enum +{ all=0, min_interference=1, read_first=2, @@ -28,7 +30,8 @@ typedef enum { one_event_per_cycle=5 } instrumentation_strategyt; -typedef enum { +typedef enum +{ arrays_only=0, all_loops=1, no_loop=2 diff --git a/src/goto-programs/builtin_functions.cpp b/src/goto-programs/builtin_functions.cpp index 2ee615aa4b4..615470b7f9e 100644 --- a/src/goto-programs/builtin_functions.cpp +++ b/src/goto-programs/builtin_functions.cpp @@ -232,7 +232,8 @@ void goto_convertt::do_printf( if(f_id==CPROVER_PREFIX "printf" || f_id=="printf") { - typet return_type=static_cast(function.type().find(ID_return_type)); + typet return_type= + static_cast(function.type().find(ID_return_type)); side_effect_exprt printf_code(ID_printf, return_type); printf_code.operands()=arguments; @@ -289,7 +290,8 @@ void goto_convertt::do_scanf( if(!get_string_constant(arguments[0], format_string)) { // use our model - format_token_listt token_list=parse_format_string(id2string(format_string)); + format_token_listt token_list= + parse_format_string(id2string(format_string)); std::size_t argument_number=1; @@ -313,7 +315,8 @@ void goto_convertt::do_scanf( to_array_type(type).size()=size; const symbolt &tmp_symbol= - new_tmp_symbol(type, "scanf_string", dest, function.source_location()); + new_tmp_symbol( + type, "scanf_string", dest, function.source_location()); exprt rhs= address_of_exprt( @@ -327,7 +330,8 @@ void goto_convertt::do_scanf( array_copy_statement.operands().resize(2); array_copy_statement.op0()=ptr; \ array_copy_statement.op1()=rhs; - array_copy_statement.add_source_location()=function.source_location(); + array_copy_statement.add_source_location()= + function.source_location(); copy(array_copy_statement, OTHER, dest); #else @@ -573,7 +577,8 @@ void goto_convertt::do_cpp_new( code_function_callt new_call; new_call.function()=new_symbol; - if(new_array) new_call.arguments().push_back(count); + if(new_array) + new_call.arguments().push_back(count); new_call.arguments().push_back(object_size); new_call.set("#type", lhs.type().subtype()); new_call.lhs()=tmp_symbol_expr; @@ -585,7 +590,8 @@ void goto_convertt::do_cpp_new( { // call __placement_new exprt new_symbol= - ns.lookup(new_array?"__placement_new_array":"__placement_new").symbol_expr(); + ns.lookup( + new_array?"__placement_new_array":"__placement_new").symbol_expr(); const code_typet &code_type= to_code_type(new_symbol.type()); @@ -602,7 +608,8 @@ void goto_convertt::do_cpp_new( code_function_callt new_call; new_call.function()=new_symbol; - if(new_array) new_call.arguments().push_back(count); + if(new_array) + new_call.arguments().push_back(count); new_call.arguments().push_back(object_size); new_call.arguments().push_back(rhs.op0()); // memory location new_call.set("#type", lhs.type().subtype()); @@ -655,7 +662,8 @@ void set_class_identifier( to_struct_type(ns.follow(expr.type())); const struct_typet::componentst &components=struct_type.components(); - if(components.empty()) return; + if(components.empty()) + return; assert(!expr.operands().empty()); if(components.front().get_name()=="@class_identifier") @@ -728,8 +736,10 @@ void goto_convertt::do_java_new( // zero-initialize the object dereference_exprt deref(lhs, object_type); - exprt zero_object=zero_initializer(object_type, location, ns, get_message_handler()); - set_class_identifier(to_struct_expr(zero_object), ns, to_symbol_type(object_type)); + exprt zero_object= + zero_initializer(object_type, location, ns, get_message_handler()); + set_class_identifier( + to_struct_expr(zero_object), ns, to_symbol_type(object_type)); goto_programt::targett t_i=dest.add_instruction(ASSIGN); t_i->code=code_assignt(deref, zero_object); t_i->source_location=location; @@ -800,13 +810,19 @@ void goto_convertt::do_java_new_array( // if it's an array, we need to set the length field dereference_exprt deref(lhs, object_type); - member_exprt length(deref, struct_type.components()[1].get_name(), struct_type.components()[1].type()); + member_exprt length( + deref, + struct_type.components()[1].get_name(), + struct_type.components()[1].type()); goto_programt::targett t_s=dest.add_instruction(ASSIGN); t_s->code=code_assignt(length, rhs.op0()); t_s->source_location=location; // we also need to allocate space for the data - member_exprt data(deref, struct_type.components()[2].get_name(), struct_type.components()[2].type()); + member_exprt data( + deref, + struct_type.components()[2].get_name(), + struct_type.components()[2].type()); side_effect_exprt data_cpp_new_expr(ID_cpp_new_array, data.type()); data_cpp_new_expr.set(ID_size, rhs.op0()); goto_programt::targett t_p=dest.add_instruction(ASSIGN); @@ -847,7 +863,8 @@ void goto_convertt::do_java_new_array( inc.op0()=tmp_i; inc.op1()=plus_exprt(tmp_i, from_integer(1, tmp_i.type())); - dereference_exprt deref_expr(plus_exprt(data, tmp_i), data.type().subtype()); + dereference_exprt deref_expr( + plus_exprt(data, tmp_i), data.type().subtype()); for_loop.init()=code_assignt(tmp_i, from_integer(0, tmp_i.type())); for_loop.cond()=binary_relation_exprt(tmp_i, ID_lt, rhs.op0()); @@ -1213,7 +1230,8 @@ void goto_convertt::do_function_call_symbol( throw 0; } } - else if(has_prefix(id2string(identifier), "java::java.lang.AssertionError.:")) + else if(has_prefix( + id2string(identifier), "java::java.lang.AssertionError.:")) { // insert function call anyway code_function_callt function_call; @@ -1237,7 +1255,8 @@ void goto_convertt::do_function_call_symbol( t->source_location=function.source_location(); t->source_location.set("user-provided", true); t->source_location.set_property_class(ID_assertion); - t->source_location.set_comment("assertion at "+function.source_location().as_string()); + t->source_location.set_comment( + "assertion at "+function.source_location().as_string()); } else if(identifier=="assert" && !ns.lookup(identifier).location.get_function().empty()) @@ -1255,7 +1274,8 @@ void goto_convertt::do_function_call_symbol( t->source_location=function.source_location(); t->source_location.set("user-provided", true); t->source_location.set_property_class(ID_assertion); - t->source_location.set_comment("assertion "+id2string(from_expr(ns, "", t->guard))); + t->source_location.set_comment( + "assertion "+id2string(from_expr(ns, "", t->guard))); // let's double-check the type of the argument if(t->guard.type().id()!=ID_bool) @@ -1341,7 +1361,8 @@ void goto_convertt::do_function_call_symbol( has_prefix(id2string(identifier), "__VERIFIER_nondet_")) { // make it a side effect if there is an LHS - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; exprt rhs; @@ -1368,7 +1389,8 @@ void goto_convertt::do_function_call_symbol( else if(has_prefix(id2string(identifier), CPROVER_PREFIX "uninterpreted_")) { // make it a side effect if there is an LHS - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; function_application_exprt rhs; rhs.type()=lhs.type(); @@ -1421,7 +1443,8 @@ void goto_convertt::do_function_call_symbol( // This has been seen in Solaris 11. // Signature: - // void __assert_c99(const char *desc, const char *file, int line, const char *func); + // void __assert_c99( + // const char *desc, const char *file, int line, const char *func); // _wassert is Windows. The arguments are // L"expression", L"file.c", line @@ -1809,7 +1832,8 @@ void goto_convertt::do_function_call_symbol( // These are type-polymorphic, which makes it hard to put // them into ansi-c/library. - // bool __sync_bool_compare_and_swap (type *ptr, type oldval, type newval, ...) + // bool __sync_bool_compare_and_swap( + // type *ptr, type oldval, type newval, ...) if(arguments.size()<3) { @@ -1868,7 +1892,8 @@ void goto_convertt::do_function_call_symbol( } else if(identifier=="__sync_val_compare_and_swap") { - // type __sync_val_compare_and_swap (type *ptr, type oldval, type newval, ...) + // type __sync_val_compare_and_swap( + // type *ptr, type oldval, type newval, ...) if(arguments.size()<3) { error().source_location=function.find_source_location(); diff --git a/src/goto-programs/cfg.h b/src/goto-programs/cfg.h index 319f8d3542f..2fc7522a67d 100644 --- a/src/goto-programs/cfg.h +++ b/src/goto-programs/cfg.h @@ -39,7 +39,7 @@ struct cfg_base_nodet:public graph_nodet, public T template -class cfg_baset:public graph< cfg_base_nodet > +class cfg_baset:public grapht< cfg_base_nodet > { public: typedef std::size_t entryt; @@ -47,16 +47,16 @@ class cfg_baset:public graph< cfg_base_nodet > struct entry_mapt: public std::map { - graph< cfg_base_nodet > & container; + grapht< cfg_base_nodet > &container; - explicit entry_mapt(graph< cfg_base_nodet > & _container): + explicit entry_mapt(grapht< cfg_base_nodet > &_container): container(_container) { } - entryt& operator[](const goto_programt::const_targett &t) + entryt &operator[](const goto_programt::const_targett &t) { - std::pair e=insert(std::make_pair(t, 0)); + std::pair e=insert(std::make_pair(t, 0)); if(e.second) e.first->second=container.add_node(); diff --git a/src/goto-programs/class_hierarchy.cpp b/src/goto-programs/class_hierarchy.cpp index 1988cae7471..1311a3e7fdc 100644 --- a/src/goto-programs/class_hierarchy.cpp +++ b/src/goto-programs/class_hierarchy.cpp @@ -42,7 +42,8 @@ void class_hierarchyt::operator()(const symbol_tablet &symbol_table) for(const auto &base : bases) { irep_idt parent=base.find(ID_type).get(ID_identifier); - if(parent.empty()) continue; + if(parent.empty()) + continue; class_map[parent].children.push_back(it->first); class_map[it->first].parents.push_back(parent); @@ -68,7 +69,8 @@ void class_hierarchyt::get_children_trans_rec( idst &dest) const { class_mapt::const_iterator it=class_map.find(c); - if(it==class_map.end()) return; + if(it==class_map.end()) + return; const entryt &entry=it->second; for(const auto &child : entry.children) @@ -96,7 +98,8 @@ void class_hierarchyt::get_parents_trans_rec( idst &dest) const { class_mapt::const_iterator it=class_map.find(c); - if(it==class_map.end()) return; + if(it==class_map.end()) + return; const entryt &entry=it->second; for(const auto &child : entry.parents) diff --git a/src/goto-programs/compute_called_functions.cpp b/src/goto-programs/compute_called_functions.cpp index 0f6940de9a1..0c1acc08d22 100644 --- a/src/goto-programs/compute_called_functions.cpp +++ b/src/goto-programs/compute_called_functions.cpp @@ -161,7 +161,6 @@ void compute_called_functions( } } } - } /*******************************************************************\ diff --git a/src/goto-programs/elf_reader.cpp b/src/goto-programs/elf_reader.cpp index bbb71ea442b..9a2212bfbfc 100644 --- a/src/goto-programs/elf_reader.cpp +++ b/src/goto-programs/elf_reader.cpp @@ -25,7 +25,9 @@ Function: elf_readert::elf_readert elf_readert::elf_readert(std::istream &_in):in(_in) { // read 32-bit header - in.read((char *)&elf32_header, sizeof(elf32_header)); + in.read( + reinterpret_cast(&elf32_header), + sizeof(elf32_header)); if(!in) throw "failed to read ELF header"; @@ -34,7 +36,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in) elf32_header.e_ident[1]!='E' || elf32_header.e_ident[2]!='L' || elf32_header.e_ident[3]!='F') - throw "ELF header malformed (magic)"; + throw "ELF header malformed (magic)"; // NOLINT(readability/throw) elf_class=(elf_classt)elf32_header.e_ident[4]; @@ -47,7 +49,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in) else if(ei_data==2) little_endian=false; else - throw "ELF32 header malformed (EI_DATA)"; + throw "ELF32 header malformed (EI_DATA)"; // NOLINT(readability/throw) if(elf32_header.e_version!=1) throw "unknown ELF32 version"; @@ -55,7 +57,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in) // get offset for section header if(elf32_header.e_shoff==0 || elf32_header.e_shnum==0) - throw "ELF32 without section header"; + throw "ELF32 without section header"; // NOLINT(readability/throw) elf32_section_header_table.resize(elf32_header.e_shnum); number_of_sections=elf32_header.e_shnum; @@ -67,13 +69,15 @@ elf_readert::elf_readert(std::istream &_in):in(_in) in.seekg(elf32_header.e_shoff+i*elf32_header.e_shentsize); // read section header - in.read((char *)&elf32_section_header_table[i], sizeof(Elf32_Shdr)); + in.read( + reinterpret_cast(&elf32_section_header_table[i]), + sizeof(Elf32_Shdr)); } // string table unsigned string_table_nr=elf32_header.e_shstrndx; if(string_table_nr>=elf32_section_header_table.size()) - throw "ELF32 without string table"; + throw "ELF32 without string table"; // NOLINT(readability/throw) string_table_offset=section_offset(string_table_nr); } @@ -81,7 +85,9 @@ elf_readert::elf_readert(std::istream &_in):in(_in) { // read 64-bit header in.seekg(0); - in.read((char *)&elf64_header, sizeof(elf64_header)); + in.read( + reinterpret_cast(&elf64_header), + sizeof(elf64_header)); char ei_data=elf64_header.e_ident[5]; @@ -90,7 +96,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in) else if(ei_data==2) little_endian=false; else - throw "ELF64 header malformed (EI_DATA)"; + throw "ELF64 header malformed (EI_DATA)"; // NOLINT(readability/throw) if(elf64_header.e_version!=1) throw "unknown ELF64 version"; @@ -98,7 +104,7 @@ elf_readert::elf_readert(std::istream &_in):in(_in) // get offset for section header if(elf64_header.e_shoff==0 || elf64_header.e_shnum==0) - throw "ELF64 without section header"; + throw "ELF64 without section header"; // NOLINT(readability/throw) elf64_section_header_table.resize(elf64_header.e_shnum); number_of_sections=elf64_header.e_shnum; @@ -110,13 +116,15 @@ elf_readert::elf_readert(std::istream &_in):in(_in) in.seekg(elf64_header.e_shoff+i*elf64_header.e_shentsize); // read section header - in.read((char *)&elf64_section_header_table[i], sizeof(Elf64_Shdr)); + in.read( + reinterpret_cast(&elf64_section_header_table[i]), + sizeof(Elf64_Shdr)); } // string table unsigned string_table_nr=elf64_header.e_shstrndx; if(string_table_nr>=elf64_section_header_table.size()) - throw "ELF64 without string table"; + throw "ELF64 without string table"; // NOLINT(readability/throw) string_table_offset=section_offset(string_table_nr); } @@ -144,7 +152,8 @@ std::string elf_readert::get_string(std::streampos index) const { char ch; in.read(&ch, 1); - if(ch==0) break; + if(ch==0) + break; result+=ch; } @@ -166,7 +175,8 @@ Function: elf_readert::has_section bool elf_readert::has_section(const std::string &name) const { for(unsigned i=0; i { }; +class format_token_listt:public std::list +{ +}; format_token_listt parse_format_string(const std::string &); diff --git a/src/goto-programs/goto_clean_expr.cpp b/src/goto-programs/goto_clean_expr.cpp index 45c37242883..9b5b44a44d9 100644 --- a/src/goto-programs/goto_clean_expr.cpp +++ b/src/goto-programs/goto_clean_expr.cpp @@ -164,9 +164,12 @@ void goto_convertt::rewrite_boolean(exprt &expr) exprt::operandst &ops=expr.operands(); // start with last one - for(int i=int(ops.size())-1; i>=0; i--) + for(exprt::operandst::reverse_iterator + it=ops.rbegin(); + it!=ops.rend(); + ++it) { - exprt &op=ops[i]; + exprt &op=*it; if(!op.is_boolean()) { @@ -216,7 +219,8 @@ void goto_convertt::clean_expr( // compound assignments // compound literals - if(!needs_cleaning(expr)) return; + if(!needs_cleaning(expr)) + return; if(expr.id()==ID_and || expr.id()==ID_or) { @@ -398,7 +402,8 @@ void goto_convertt::clean_expr( { // need to do separately to prevent that // the operands of expr get 'cleaned' - remove_statement_expression(to_side_effect_expr(expr), dest, result_is_used); + remove_statement_expression( + to_side_effect_expr(expr), dest, result_is_used); return; } else if(statement==ID_assign) @@ -429,7 +434,9 @@ void goto_convertt::clean_expr( else if(statement==ID_function_call) { if(to_side_effect_expr_function_call(expr).function().id()==ID_symbol && - to_symbol_expr(to_side_effect_expr_function_call(expr).function()).get_identifier()=="__noop") + to_symbol_expr( + to_side_effect_expr_function_call(expr). + function()).get_identifier()=="__noop") { // __noop needs special treatment, as arguments are not // evaluated diff --git a/src/goto-programs/goto_convert.cpp b/src/goto-programs/goto_convert.cpp index c3f413a8600..a3124f3b898 100644 --- a/src/goto-programs/goto_convert.cpp +++ b/src/goto-programs/goto_convert.cpp @@ -121,7 +121,7 @@ void goto_convertt::finish_gotos(goto_programt &dest) // We don't currently handle variables *entering* scope, which is illegal // for C++ non-pod types and impossible in Java in any case. auto goto_stack=g_it.second; - const auto& label_stack=l_it->second.second; + const auto &label_stack=l_it->second.second; bool stack_is_prefix=true; if(label_stack.size()>goto_stack.size()) stack_is_prefix=false; @@ -237,7 +237,7 @@ Function: goto_convertt::finish_guarded_gotos void goto_convertt::finish_guarded_gotos(goto_programt &dest) { - for(auto& gg : guarded_gotos) + for(auto &gg : guarded_gotos) { // Check if any destructor code has been inserted: bool destructor_present=false; @@ -470,7 +470,7 @@ void goto_convertt::convert_gcc_switch_case_range( goto_programt tmp; convert(to_code(code.op2()), tmp); - //goto_programt::targett target=tmp.instructions.begin(); + // goto_programt::targett target=tmp.instructions.begin(); dest.destructive_append(tmp); #if 0 @@ -1005,7 +1005,6 @@ void goto_convertt::convert_cpp_delete( if(code.get_statement()==ID_cpp_delete_array) { // build loop - } else if(code.get_statement()==ID_cpp_delete) { @@ -1294,7 +1293,8 @@ void goto_convertt::convert_while( z->source_location=source_location; goto_programt tmp_branch; - generate_conditional_branch(boolean_negate(cond), z, source_location, tmp_branch); + generate_conditional_branch( + boolean_negate(cond), z, source_location, tmp_branch); // do the v label goto_programt::targett v=tmp_branch.instructions.begin(); @@ -1570,7 +1570,8 @@ void goto_convertt::convert_break( } // need to process destructor stack - unwind_destructor_stack(code.source_location(), targets.break_stack_size, dest); + unwind_destructor_stack( + code.source_location(), targets.break_stack_size, dest); // add goto goto_programt::targett t=dest.add_instruction(); @@ -1684,7 +1685,8 @@ void goto_convertt::convert_continue( } // need to process destructor stack - unwind_destructor_stack(code.source_location(), targets.continue_stack_size, dest); + unwind_destructor_stack( + code.source_location(), targets.continue_stack_size, dest); // add goto goto_programt::targett t=dest.add_instruction(); @@ -1714,7 +1716,7 @@ void goto_convertt::convert_goto( t->code=code; // remember it to do target later - targets.gotos.push_back(std::make_pair(t,targets.destructor_stack)); + targets.gotos.push_back(std::make_pair(t, targets.destructor_stack)); } /*******************************************************************\ @@ -2277,7 +2279,8 @@ void goto_convertt::generate_ifthenelse( // The above conjunction deliberately excludes the instance // if(some) { label: goto somewhere; } // Don't perform the transformation here, as code might get inserted into - // the true case to perform destructors. This will be attempted in finish_guarded_gotos. + // the true case to perform destructors. + // This will be attempted in finish_guarded_gotos. is_guarded_goto=true; } @@ -2366,7 +2369,7 @@ void goto_convertt::generate_ifthenelse( // Note this depends on the fact that `instructions` is a std::list // and so goto-program-destructive-append preserves iterator validity. if(is_guarded_goto) - guarded_gotos.push_back({ + guarded_gotos.push_back({ // NOLINT(whitespace/braces) tmp_v.instructions.begin(), tmp_w.instructions.begin(), guard}); @@ -2398,7 +2401,8 @@ Function: goto_convertt::generate_conditional_branch static bool has_and_or(const exprt &expr) { forall_operands(it, expr) - if(has_and_or(*it)) return true; + if(has_and_or(*it)) + return true; if(expr.id()==ID_and || expr.id()==ID_or) return true; @@ -2573,7 +2577,7 @@ bool goto_convertt::get_string_constant( binary2integer(id2string(to_constant_expr(*it).get_value()), true)); if(i!=0) // to skip terminating 0 - result+=char(i); + result+=static_cast(i); } return value=result, false; @@ -2679,7 +2683,8 @@ symbolt &goto_convertt::new_tmp_symbol( new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name); new_symbol.type=type; new_symbol.location=source_location; - } while(symbol_table.move(new_symbol, symbol_ptr)); + } + while(symbol_table.move(new_symbol, symbol_ptr)); code_declt decl; decl.symbol()=symbol_ptr->symbol_expr(); diff --git a/src/goto-programs/goto_convert_class.h b/src/goto-programs/goto_convert_class.h index a0e3ac1fe16..feab8197046 100644 --- a/src/goto-programs/goto_convert_class.h +++ b/src/goto-programs/goto_convert_class.h @@ -90,17 +90,49 @@ class goto_convertt:public messaget static bool has_sideeffect(const exprt &expr); static bool has_function_call(const exprt &expr); - void remove_side_effect(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_assignment(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_pre(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_post(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_function_call(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_cpp_new(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_cpp_delete(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_malloc(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_temporary_object(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_statement_expression(side_effect_exprt &expr, goto_programt &dest, bool result_is_used); - void remove_gcc_conditional_expression(exprt &expr, goto_programt &dest); + void remove_side_effect( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_assignment( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_pre( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_post( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_function_call( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_cpp_new( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_cpp_delete( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_malloc( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_temporary_object( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_statement_expression( + side_effect_exprt &expr, + goto_programt &dest, + bool result_is_used); + void remove_gcc_conditional_expression( + exprt &expr, + goto_programt &dest); virtual void do_cpp_new( const exprt &lhs, @@ -187,7 +219,9 @@ class goto_convertt:public messaget void convert_gcc_local_label(const codet &code, goto_programt &dest); void convert_switch_case(const code_switch_caset &code, goto_programt &dest); void convert_gcc_switch_case_range(const codet &code, goto_programt &dest); - void convert_function_call(const code_function_callt &code, goto_programt &dest); + void convert_function_call( + const code_function_callt &code, + goto_programt &dest); void convert_specc_notify(const codet &code, goto_programt &dest); void convert_specc_wait(const codet &code, goto_programt &dest); void convert_specc_par(const codet &code, goto_programt &dest); @@ -210,7 +244,10 @@ class goto_convertt:public messaget void convert(const codet &code, goto_programt &dest); - void copy(const codet &code, goto_program_instruction_typet type, goto_programt &dest); + void copy( + const codet &code, + goto_program_instruction_typet type, + goto_programt &dest); // // exceptions @@ -237,8 +274,11 @@ class goto_convertt:public messaget void finish_computed_gotos(goto_programt &dest); void finish_guarded_gotos(goto_programt &dest); - typedef std::map > labelst; - typedef std::list > gotost; + typedef std::map> + labelst; + typedef std::list> + gotost; typedef std::list computed_gotost; typedef exprt::operandst caset; typedef std::list > casest; @@ -313,7 +353,6 @@ class goto_convertt:public messaget leave_target=_leave_target; leave_stack_size=destructor_stack.size(); } - } targets; struct break_continue_targetst @@ -419,7 +458,8 @@ class goto_convertt:public messaget std::size_t leave_stack_size; }; - struct guarded_gotot { + struct guarded_gotot + { goto_programt::targett ifiter; goto_programt::targett gotoiter; exprt guard; @@ -468,18 +508,66 @@ class goto_convertt:public messaget exprt get_constant(const exprt &expr); // some built-in functions - void do_atomic_begin (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_atomic_end (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_create_thread (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_array_set (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_array_equal (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_array_copy (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_printf (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_scanf (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_input (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_output (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_prob_coin (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); - void do_prob_uniform (const exprt &lhs, const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest); + void do_atomic_begin( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_atomic_end( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_create_thread( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_array_set( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_array_equal( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_array_copy( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_printf( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_scanf( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_input( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_output( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_prob_coin( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); + void do_prob_uniform( + const exprt &lhs, + const exprt &rhs, + const exprt::operandst &arguments, + goto_programt &dest); exprt get_array_argument(const exprt &src); }; diff --git a/src/goto-programs/goto_convert_exceptions.cpp b/src/goto-programs/goto_convert_exceptions.cpp index 54d72f9c224..8d04f3cca16 100644 --- a/src/goto-programs/goto_convert_exceptions.cpp +++ b/src/goto-programs/goto_convert_exceptions.cpp @@ -269,7 +269,8 @@ void goto_convertt::convert_CPROVER_throw( if(targets.throw_set) { // need to process destructor stack - unwind_destructor_stack(code.source_location(), targets.throw_stack_size, dest); + unwind_destructor_stack( + code.source_location(), targets.throw_stack_size, dest); // add goto goto_programt::targett t=dest.add_instruction(); diff --git a/src/goto-programs/goto_convert_function_call.cpp b/src/goto-programs/goto_convert_function_call.cpp index 9735f994297..6fe2b42bbc1 100644 --- a/src/goto-programs/goto_convert_function_call.cpp +++ b/src/goto-programs/goto_convert_function_call.cpp @@ -89,7 +89,8 @@ void goto_convertt::do_function_call( } else if(new_function.id()==ID_symbol) { - do_function_call_symbol(new_lhs, to_symbol_expr(new_function), new_arguments, dest); + do_function_call_symbol( + new_lhs, to_symbol_expr(new_function), new_arguments, dest); } else if(new_function.id()=="NULL-object") { diff --git a/src/goto-programs/goto_convert_functions.cpp b/src/goto-programs/goto_convert_functions.cpp index 8a92d50445c..b25d8870f09 100644 --- a/src/goto-programs/goto_convert_functions.cpp +++ b/src/goto-programs/goto_convert_functions.cpp @@ -216,7 +216,8 @@ void goto_convert_functionst::convert_function(const irep_idt &identifier) temporary_counter=0; f.type=to_code_type(symbol.type); - if(f.body_available()) return; // already converted + if(f.body_available()) + return; // already converted if(symbol.value.is_nil() || symbol.value.id()=="compiled") /* goto_inline may have removed the body */ diff --git a/src/goto-programs/goto_convert_new_switch_case.cpp b/src/goto-programs/goto_convert_new_switch_case.cpp index 063fc579ead..4a81a4176a2 100644 --- a/src/goto-programs/goto_convert_new_switch_case.cpp +++ b/src/goto-programs/goto_convert_new_switch_case.cpp @@ -384,14 +384,15 @@ void goto_convertt::convert_gcc_switch_case_range( if(code.operands().size()!=3) { err_location(code); - error() << "GCC's switch-case-range statement expected to have three operands" << eom; + error() << "GCC's switch-case-range statement expected to have " + << "three operands" << eom; throw 0; } goto_programt tmp; convert(to_code(code.op2()), tmp); - //goto_programt::targett target=tmp.instructions.begin(); + // goto_programt::targett target=tmp.instructions.begin(); dest.destructive_append(tmp); #if 0 @@ -919,7 +920,6 @@ void goto_convertt::convert_cpp_delete( if(code.get_statement()==ID_cpp_delete_array) { // build loop - } else if(code.get_statement()==ID_cpp_delete) { @@ -1170,7 +1170,8 @@ void goto_convertt::convert_while( z->source_location=source_location; goto_programt tmp_branch; - generate_conditional_branch(boolean_negate(cond), z, source_location, tmp_branch); + generate_conditional_branch( + boolean_negate(cond), z, source_location, tmp_branch); // do the v label goto_programt::targett v=tmp_branch.instructions.begin(); @@ -1455,7 +1456,8 @@ void goto_convertt::convert_break( } // need to process destructor stack - unwind_destructor_stack(code.source_location(), targets.break_stack_size, dest); + unwind_destructor_stack( + code.source_location(), targets.break_stack_size, dest); // add goto goto_programt::targett t=dest.add_instruction(); @@ -1569,7 +1571,8 @@ void goto_convertt::convert_continue( } // need to process destructor stack - unwind_destructor_stack(code.source_location(), targets.continue_stack_size, dest); + unwind_destructor_stack( + code.source_location(), targets.continue_stack_size, dest); // add goto goto_programt::targett t=dest.add_instruction(); @@ -2246,7 +2249,8 @@ Function: goto_convertt::generate_conditional_branch static bool has_and_or(const exprt &expr) { forall_operands(it, expr) - if(has_and_or(*it)) return true; + if(has_and_or(*it)) + return true; if(expr.id()==ID_and || expr.id()==ID_or) return true; @@ -2420,7 +2424,7 @@ const irep_idt goto_convertt::get_string_constant( binary2integer(id2string(to_constant_expr(*it).get_value()), true)); if(i!=0) // to skip terminating 0 - result+=char(i); + result+=static_cast(i); } return result; @@ -2503,7 +2507,8 @@ symbolt &goto_convertt::new_tmp_symbol( new_symbol.name=tmp_symbol_prefix+id2string(new_symbol.base_name); new_symbol.type=type; new_symbol.location=source_location; - } while(symbol_table.move(new_symbol, symbol_ptr)); + } + while(symbol_table.move(new_symbol, symbol_ptr)); tmp_symbols.push_back(symbol_ptr->name); diff --git a/src/goto-programs/goto_convert_side_effect.cpp b/src/goto-programs/goto_convert_side_effect.cpp index 6312e38f04b..f34ee9d03a0 100644 --- a/src/goto-programs/goto_convert_side_effect.cpp +++ b/src/goto-programs/goto_convert_side_effect.cpp @@ -828,7 +828,8 @@ void goto_convertt::remove_side_effect( else if(statement==ID_throw) { goto_programt::targett t=dest.add_instruction(THROW); - t->code=code_expressiont(side_effect_expr_throwt(expr.find(ID_exception_list))); + t->code= + code_expressiont(side_effect_expr_throwt(expr.find(ID_exception_list))); t->code.op0().operands().swap(expr.operands()); t->code.add_source_location()=expr.source_location(); t->source_location=expr.source_location(); diff --git a/src/goto-programs/goto_functions.cpp b/src/goto-programs/goto_functions.cpp index 3e3d7d966d8..d11868339b3 100644 --- a/src/goto-programs/goto_functions.cpp +++ b/src/goto-programs/goto_functions.cpp @@ -35,6 +35,7 @@ void get_local_identifiers( for(const auto ¶m : parameters) { const irep_idt &identifier=param.get_identifier(); - if(identifier!="") dest.insert(identifier); + if(identifier!="") + dest.insert(identifier); } } diff --git a/src/goto-programs/goto_functions.h b/src/goto-programs/goto_functions.h index 6abb68ea5a4..60c7fa90658 100644 --- a/src/goto-programs/goto_functions.h +++ b/src/goto-programs/goto_functions.h @@ -20,11 +20,13 @@ class goto_functionst:public goto_functions_templatet }; #define Forall_goto_functions(it, functions) \ - for(goto_functionst::function_mapt::iterator it=(functions).function_map.begin(); \ + for(goto_functionst::function_mapt::iterator \ + it=(functions).function_map.begin(); \ it!=(functions).function_map.end(); it++) #define forall_goto_functions(it, functions) \ - for(goto_functionst::function_mapt::const_iterator it=(functions).function_map.begin(); \ + for(goto_functionst::function_mapt::const_iterator \ + it=(functions).function_map.begin(); \ it!=(functions).function_map.end(); it++) void get_local_identifiers( diff --git a/src/goto-programs/goto_functions_template.h b/src/goto-programs/goto_functions_template.h index c0cc8c6c5b1..27757df4e87 100644 --- a/src/goto-programs/goto_functions_template.h +++ b/src/goto-programs/goto_functions_template.h @@ -27,22 +27,22 @@ class goto_function_templatet typedef std::vector parameter_identifierst; parameter_identifierst parameter_identifiers; - inline bool body_available() const + bool body_available() const { return !body.instructions.empty(); } - inline bool is_inlined() const + bool is_inlined() const { return type.get_bool(ID_C_inlined); } - inline bool is_hidden() const + bool is_hidden() const { return type.get_bool(ID_C_hide); } - inline void make_hidden() + void make_hidden() { type.set(ID_C_hide, true); } @@ -88,7 +88,7 @@ class goto_functions_templatet typedef std::map function_mapt; function_mapt function_map; - inline goto_functions_templatet() + goto_functions_templatet() { } @@ -98,7 +98,7 @@ class goto_functions_templatet assert(src.function_map.empty()); } - inline void clear() + void clear() { function_map.clear(); } @@ -126,7 +126,7 @@ class goto_functions_templatet return ID__start; } - inline void swap(goto_functions_templatet &other) + void swap(goto_functions_templatet &other) { function_map.swap(other.function_map); } @@ -136,7 +136,6 @@ class goto_functions_templatet for(const auto &fun : other.function_map) function_map[fun.first].copy_from(fun.second); } - }; /*******************************************************************\ @@ -154,7 +153,7 @@ Function: goto_functions_templatet::output template void goto_functions_templatet::output( const namespacet &ns, - std::ostream& out) const + std::ostream &out) const { for(const auto &fun : function_map) { diff --git a/src/goto-programs/goto_model.h b/src/goto-programs/goto_model.h index 3829d4936f2..ff7a671e074 100644 --- a/src/goto-programs/goto_model.h +++ b/src/goto-programs/goto_model.h @@ -22,7 +22,7 @@ class goto_modelt symbol_tablet symbol_table; goto_functionst goto_functions; - inline void clear() + void clear() { symbol_table.clear(); goto_functions.clear(); @@ -34,11 +34,11 @@ class goto_modelt goto_functions.output(ns, out); } - inline goto_modelt() + goto_modelt() { } - inline goto_modelt(goto_modelt &&other) + goto_modelt(goto_modelt &&other) { symbol_table.swap(other.symbol_table); goto_functions.swap(other.goto_functions); diff --git a/src/goto-programs/goto_program.cpp b/src/goto-programs/goto_program.cpp index f5e9999114d..c1b72dc7bbf 100644 --- a/src/goto-programs/goto_program.cpp +++ b/src/goto-programs/goto_program.cpp @@ -31,10 +31,10 @@ Function: goto_programt::output_instruction \*******************************************************************/ -std::ostream& goto_programt::output_instruction( +std::ostream &goto_programt::output_instruction( const class namespacet &ns, const irep_idt &identifier, - std::ostream& out, + std::ostream &out, instructionst::const_iterator it) const { return output_instruction(ns, identifier, out, *it); @@ -138,7 +138,8 @@ std::ostream &goto_programt::output_instruction( out << from_expr(ns, identifier, instruction.guard); const irep_idt &comment=instruction.source_location.get_comment(); - if(comment!="") out << " // " << comment; + if(comment!="") + out << " // " << comment; } out << '\n'; @@ -343,7 +344,9 @@ std::list expressions_read( } break; - default:; + default: + { + } } return dest; @@ -381,7 +384,9 @@ std::list expressions_written( dest.push_back(to_code_assign(instruction.code).lhs()); break; - default:; + default: + { + } } return dest; @@ -537,7 +542,8 @@ std::string as_string( gt_it!=i.targets.end(); gt_it++) { - if(gt_it!=i.targets.begin()) result+=", "; + if(gt_it!=i.targets.begin()) + result+=", "; result+=std::to_string((*gt_it)->target_number); } return result; @@ -561,7 +567,8 @@ std::string as_string( { const irep_idt &comment=i.source_location.get_comment(); - if(comment!="") result+=" /* "+id2string(comment)+" */"; + if(comment!="") + result+=" /* "+id2string(comment)+" */"; } return result; diff --git a/src/goto-programs/goto_program.h b/src/goto-programs/goto_program.h index e3c7c5528c6..06e2895529f 100644 --- a/src/goto-programs/goto_program.h +++ b/src/goto-programs/goto_program.h @@ -51,12 +51,14 @@ class goto_programt:public goto_program_templatet it=(program).instructions.begin(); \ it!=(program).instructions.end(); it++) -extern inline bool operator<(const goto_programt::const_targett i1, - const goto_programt::const_targett i2) +inline bool operator<( + const goto_programt::const_targett i1, + const goto_programt::const_targett i2) { return order_const_target(i1, i2); } +// NOLINTNEXTLINE(readability/identifiers) typedef struct const_target_hash_templatet const_target_hash; std::list objects_read(const goto_programt::instructiont &); diff --git a/src/goto-programs/goto_program_irep.cpp b/src/goto-programs/goto_program_irep.cpp index 2f9f491d58e..3ddc09e27a3 100644 --- a/src/goto-programs/goto_program_irep.cpp +++ b/src/goto-programs/goto_program_irep.cpp @@ -80,7 +80,8 @@ void convert( { instruction.code=static_cast(irep.find(ID_code)); instruction.function = irep.find(ID_function).id(); - instruction.source_location = static_cast(irep.find(ID_location)); + instruction.source_location= + static_cast(irep.find(ID_location)); instruction.type = static_cast( unsafe_string2unsigned(irep.find(ID_type).id_string())); instruction.guard = static_cast(irep.find(ID_guard)); @@ -105,7 +106,7 @@ Function: convert \*******************************************************************/ -void convert( const goto_programt &program, irept &irep ) +void convert(const goto_programt &program, irept &irep) { irep.id("goto-program"); irep.get_sub().reserve(program.instructions.size()); @@ -128,7 +129,7 @@ Function: convert \*******************************************************************/ -void convert( const irept &irep, goto_programt &program ) +void convert(const irept &irep, goto_programt &program) { assert(irep.id()=="goto-program"); @@ -138,7 +139,7 @@ void convert( const irept &irep, goto_programt &program ) // convert instructions back const irept::subt &subs = irep.get_sub(); - for (irept::subt::const_iterator it=subs.begin(); + for(irept::subt::const_iterator it=subs.begin(); it!=subs.end(); it++) { @@ -148,7 +149,7 @@ void convert( const irept &irep, goto_programt &program ) number_targets_list.push_back(std::list()); const irept &targets=it->find(ID_targets); const irept::subt &tsubs=targets.get_sub(); - for (const auto & tsub : tsubs) + for(const auto &tsub : tsubs) number_targets_list.back().push_back( unsafe_string2unsigned(tsub.id_string())); } @@ -166,16 +167,16 @@ void convert( const irept &irep, goto_programt &program ) for(const unsigned t : *nit) { goto_programt::targett fit=program.instructions.begin(); - for(;fit!=program.instructions.end();fit++) + for( ; fit!=program.instructions.end(); fit++) { - if (fit->location_number==t) + if(fit->location_number==t) { lit->targets.push_back(fit); break; } } - if (fit==program.instructions.end()) + if(fit==program.instructions.end()) { std::cout << "Warning: could not resolve target link " << "during irep->goto_program translation." << std::endl; diff --git a/src/goto-programs/goto_program_template.h b/src/goto-programs/goto_program_template.h index 94ef7c8a297..77161fcb4d8 100644 --- a/src/goto-programs/goto_program_template.h +++ b/src/goto-programs/goto_program_template.h @@ -23,27 +23,28 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -typedef enum { NO_INSTRUCTION_TYPE=0, - GOTO=1, // branch, possibly guarded - ASSUME=2, // non-failing guarded self loop - ASSERT=3, // assertions - OTHER=4, // anything else - SKIP=5, // just advance the PC - START_THREAD=6, // spawns an asynchronous thread - END_THREAD=7, // end the current thread - LOCATION=8, // semantically like SKIP - END_FUNCTION=9, // exit point of a function - ATOMIC_BEGIN=10, // marks a block without interleavings - ATOMIC_END=11, // end of a block without interleavings - RETURN=12, // set function return value (no control-flow change) - ASSIGN=13, // assignment lhs:=rhs - DECL=14, // declare a local variable - DEAD=15, // marks the end-of-live of a local variable - FUNCTION_CALL=16,// call a function - THROW=17, // throw an exception - CATCH=18 // catch an exception - } - goto_program_instruction_typet; +typedef enum +{ + NO_INSTRUCTION_TYPE=0, + GOTO=1, // branch, possibly guarded + ASSUME=2, // non-failing guarded self loop + ASSERT=3, // assertions + OTHER=4, // anything else + SKIP=5, // just advance the PC + START_THREAD=6, // spawns an asynchronous thread + END_THREAD=7, // end the current thread + LOCATION=8, // semantically like SKIP + END_FUNCTION=9, // exit point of a function + ATOMIC_BEGIN=10, // marks a block without interleavings + ATOMIC_END=11, // end of a block without interleavings + RETURN=12, // set function return value (no control-flow change) + ASSIGN=13, // assignment lhs:=rhs + DECL=14, // declare a local variable + DEAD=15, // marks the end-of-live of a local variable + FUNCTION_CALL=16, // call a function + THROW=17, // throw an exception + CATCH=18 // catch an exception +} goto_program_instruction_typet; std::ostream &operator<<(std::ostream &, goto_program_instruction_typet); @@ -59,7 +60,7 @@ class goto_program_templatet \param[in] src an empty goto program \remark Use copy_from to copy non-empty goto-programs */ - inline goto_program_templatet(const goto_program_templatet &src) + goto_program_templatet(const goto_program_templatet &src) { // DO NOT COPY ME! I HAVE POINTERS IN ME! assert(src.instructions.empty()); @@ -69,7 +70,7 @@ class goto_program_templatet \param[in] src an empty goto program \remark Use copy_from to copy non-empty goto-programs */ - inline goto_program_templatet &operator=(const goto_program_templatet &src) + goto_program_templatet &operator=(const goto_program_templatet &src) { // DO NOT COPY ME! I HAVE POINTERS IN ME! assert(src.instructions.empty()); @@ -99,22 +100,22 @@ class goto_program_templatet // The below will eventually become a single target only. //! the target for gotos and for start_thread nodes - typedef typename std::list::iterator targett; - typedef typename std::list::const_iterator const_targett; + typedef typename std::list::iterator targett; + typedef typename std::list::const_iterator const_targett; typedef std::list targetst; typedef std::list const_targetst; targetst targets; // for the usual case of a single target - inline targett get_target() const + targett get_target() const { assert(targets.size()==1); return targets.front(); } // for the usual case of a single target - inline void set_target(targett t) + void set_target(targett t) { targets.clear(); targets.push_back(t); @@ -128,11 +129,11 @@ class goto_program_templatet std::set incoming_edges; //! is this node a branch target? - inline bool is_target() const + bool is_target() const { return target_number!=nil_target; } //! clear the node - inline void clear(goto_program_instruction_typet _type) + void clear(goto_program_instruction_typet _type) { type=_type; targets.clear(); @@ -140,53 +141,58 @@ class goto_program_templatet code.make_nil(); } - inline void make_goto() { clear(GOTO); } - inline void make_return() { clear(RETURN); } - inline void make_function_call(const codeT &_code) { clear(FUNCTION_CALL); code=_code; } - inline void make_skip() { clear(SKIP); } - inline void make_throw() { clear(THROW); } - inline void make_catch() { clear(CATCH); } - inline void make_assertion(const guardT &g) { clear(ASSERT); guard=g; } - inline void make_assumption(const guardT &g) { clear(ASSUME); guard=g; } - inline void make_assignment() { clear(ASSIGN); } - inline void make_other(const codeT &_code) { clear(OTHER); code=_code; } - inline void make_decl() { clear(DECL); } - inline void make_dead() { clear(DEAD); } - inline void make_atomic_begin() { clear(ATOMIC_BEGIN); } - inline void make_atomic_end() { clear(ATOMIC_END); } - - inline void make_goto(targett _target) + void make_goto() { clear(GOTO); } + void make_return() { clear(RETURN); } + void make_skip() { clear(SKIP); } + void make_throw() { clear(THROW); } + void make_catch() { clear(CATCH); } + void make_assertion(const guardT &g) { clear(ASSERT); guard=g; } + void make_assumption(const guardT &g) { clear(ASSUME); guard=g; } + void make_assignment() { clear(ASSIGN); } + void make_other(const codeT &_code) { clear(OTHER); code=_code; } + void make_decl() { clear(DECL); } + void make_dead() { clear(DEAD); } + void make_atomic_begin() { clear(ATOMIC_BEGIN); } + void make_atomic_end() { clear(ATOMIC_END); } + + void make_goto(targett _target) { make_goto(); targets.push_back(_target); } - inline void make_goto(targett _target, const guardT &g) + void make_goto(targett _target, const guardT &g) { make_goto(_target); guard=g; } - inline bool is_goto () const { return type==GOTO; } - inline bool is_return () const { return type==RETURN; } - inline bool is_assign () const { return type==ASSIGN; } - inline bool is_function_call() const { return type==FUNCTION_CALL; } - inline bool is_throw () const { return type==THROW; } - inline bool is_catch () const { return type==CATCH; } - inline bool is_skip () const { return type==SKIP; } - inline bool is_location () const { return type==LOCATION; } - inline bool is_other () const { return type==OTHER; } - inline bool is_decl () const { return type==DECL; } - inline bool is_dead () const { return type==DEAD; } - inline bool is_assume () const { return type==ASSUME; } - inline bool is_assert () const { return type==ASSERT; } - inline bool is_atomic_begin () const { return type==ATOMIC_BEGIN; } - inline bool is_atomic_end () const { return type==ATOMIC_END; } - inline bool is_start_thread () const { return type==START_THREAD; } - inline bool is_end_thread () const { return type==END_THREAD; } - inline bool is_end_function () const { return type==END_FUNCTION; } - - inline instructiont(): + void make_function_call(const codeT &_code) + { + clear(FUNCTION_CALL); + code=_code; + } + + bool is_goto () const { return type==GOTO; } + bool is_return () const { return type==RETURN; } + bool is_assign () const { return type==ASSIGN; } + bool is_function_call() const { return type==FUNCTION_CALL; } + bool is_throw () const { return type==THROW; } + bool is_catch () const { return type==CATCH; } + bool is_skip () const { return type==SKIP; } + bool is_location () const { return type==LOCATION; } + bool is_other () const { return type==OTHER; } + bool is_decl () const { return type==DECL; } + bool is_dead () const { return type==DEAD; } + bool is_assume () const { return type==ASSUME; } + bool is_assert () const { return type==ASSERT; } + bool is_atomic_begin () const { return type==ATOMIC_BEGIN; } + bool is_atomic_end () const { return type==ATOMIC_END; } + bool is_start_thread () const { return type==START_THREAD; } + bool is_end_thread () const { return type==END_THREAD; } + bool is_end_function () const { return type==END_FUNCTION; } + + instructiont(): source_location(static_cast(get_nil_irep())), type(NO_INSTRUCTION_TYPE), guard(true_exprt()), @@ -195,7 +201,7 @@ class goto_program_templatet { } - inline instructiont(goto_program_instruction_typet _type): + explicit instructiont(goto_program_instruction_typet _type): source_location(static_cast(get_nil_irep())), type(_type), guard(true_exprt()), @@ -241,7 +247,8 @@ class goto_program_templatet //! Returns true if the instruction is a backwards branch. bool is_backwards_goto() const { - if(!is_goto()) return false; + if(!is_goto()) + return false; for(const auto &t : targets) if(t->location_number<=location_number) @@ -258,7 +265,7 @@ class goto_program_templatet } }; - typedef std::list instructionst; + typedef std::list instructionst; typedef typename instructionst::iterator targett; typedef typename instructionst::const_iterator const_targett; @@ -310,10 +317,13 @@ class goto_program_templatet //! Insertion that preserves jumps to "target". //! The program p is destroyed. - void insert_before_swap(targett target, goto_program_templatet &p) + void insert_before_swap( + targett target, + goto_program_templatet &p) { assert(target!=instructions.end()); - if(p.instructions.empty()) return; + if(p.instructions.empty()) + return; insert_before_swap(target, p.instructions.front()); targett next=target; next++; @@ -323,21 +333,21 @@ class goto_program_templatet //! Insertion before the given target //! \return newly inserted location - inline targett insert_before(targett target) + targett insert_before(targett target) { return instructions.insert(target, instructiont()); } - + //! Insertion before the given target //! \return newly inserted location - inline targett insert_before(const_targett target) + targett insert_before(const_targett target) { return instructions.insert(target, instructiont()); } //! Insertion after the given target //! \return newly inserted location - inline targett insert_after(targett target) + targett insert_after(targett target) { targett t=target; t++; @@ -345,7 +355,7 @@ class goto_program_templatet } //! Appends the given program, which is destroyed - inline void destructive_append(goto_program_templatet &p) + void destructive_append(goto_program_templatet &p) { instructions.splice(instructions.end(), p.instructions); @@ -354,29 +364,27 @@ class goto_program_templatet //! Inserts the given program at the given location. //! The program is destroyed. - inline void destructive_insert( + void destructive_insert( targett target, goto_program_templatet &p) { - instructions.splice(target, - p.instructions); + instructions.splice(target, p.instructions); // BUG: The iterators to p-instructions are invalidated! } //! Inserts the given program at the given location. //! The program is destroyed. - inline void destructive_insert( + void destructive_insert( const_targett target, goto_program_templatet &p) { - instructions.splice(target, - p.instructions); + instructions.splice(target, p.instructions); // BUG: The iterators to p-instructions are invalidated! } //! Adds an instruction at the end. //! \return The newly added instruction. - inline targett add_instruction() + targett add_instruction() { instructions.push_back(instructiont()); return --instructions.end(); @@ -384,7 +392,7 @@ class goto_program_templatet //! Adds an instruction of given type at the end. //! \return The newly added instruction. - inline targett add_instruction(goto_program_instruction_typet type) + targett add_instruction(goto_program_instruction_typet type) { instructions.push_back(instructiont(type)); return --instructions.end(); @@ -397,7 +405,7 @@ class goto_program_templatet std::ostream &out) const; //! Output goto-program to given stream - inline std::ostream &output(std::ostream &out) const + std::ostream &output(std::ostream &out) const { return output(namespacet(symbol_tablet()), "", out); } @@ -420,7 +428,7 @@ class goto_program_templatet } //! Compute location numbers - inline void compute_location_numbers() + void compute_location_numbers() { unsigned nr=0; compute_location_numbers(nr); @@ -433,14 +441,14 @@ class goto_program_templatet void update(); //! Human-readable loop name - inline static irep_idt loop_id(const_targett target) + static irep_idt loop_id(const_targett target) { return id2string(target->function)+"."+ std::to_string(target->loop_number); } //! Is the program empty? - inline bool empty() const + bool empty() const { return instructions.empty(); } @@ -455,13 +463,13 @@ class goto_program_templatet } //! Swap the goto program - inline void swap(goto_program_templatet &program) + void swap(goto_program_templatet &program) { program.instructions.swap(instructions); } //! Clear the goto program - inline void clear() + void clear() { instructions.clear(); } @@ -488,7 +496,8 @@ void goto_program_templatet::get_successors( targetst &successors) { successors.clear(); - if(target==instructions.end()) return; + if(target==instructions.end()) + return; targett next=target; next++; @@ -537,7 +546,8 @@ void goto_program_templatet::get_successors( const_targetst &successors) const { successors.clear(); - if(target==instructions.end()) return; + if(target==instructions.end()) + return; const_targett next=target; next++; @@ -588,10 +598,10 @@ void goto_program_templatet::update() } template -std::ostream& goto_program_templatet::output( +std::ostream &goto_program_templatet::output( const namespacet &ns, const irep_idt &identifier, - std::ostream& out) const + std::ostream &out) const { // output program @@ -626,7 +636,7 @@ void goto_program_templatet::compute_target_numbers() // number the targets properly unsigned cnt=0; - for(auto & i : instructions) + for(auto &i : instructions) { if(i.is_target()) { @@ -649,7 +659,6 @@ void goto_program_templatet::compute_target_numbers() } } } - } template @@ -743,7 +752,7 @@ inline bool order_const_target( template struct const_target_hash_templatet { - inline std::size_t operator()( + std::size_t operator()( const typename goto_program_templatet::const_targett t) const { return t->location_number; } }; diff --git a/src/goto-programs/goto_trace.cpp b/src/goto-programs/goto_trace.cpp index c05d6a4efdc..ad8bdcdfdd9 100644 --- a/src/goto-programs/goto_trace.cpp +++ b/src/goto-programs/goto_trace.cpp @@ -177,7 +177,10 @@ std::string trace_value_binary( forall_operands(it, expr) { - if(result=="") result="{ "; else result+=", "; + if(result=="") + result="{ "; + else + result+=", "; result+=trace_value_binary(*it, ns); } @@ -189,7 +192,8 @@ std::string trace_value_binary( forall_operands(it, expr) { - if(it!=expr.operands().begin()) result+=", "; + if(it!=expr.operands().begin()) + result+=", "; result+=trace_value_binary(*it, ns); } @@ -380,9 +384,11 @@ void show_goto_trace( // see if the full lhs is something clean if(is_index_member_symbol(step.full_lhs)) - trace_value(out, ns, step.lhs_object, step.full_lhs, step.full_lhs_value); + trace_value( + out, ns, step.lhs_object, step.full_lhs, step.full_lhs_value); else - trace_value(out, ns, step.lhs_object, step.lhs_object, step.lhs_object_value); + trace_value( + out, ns, step.lhs_object, step.lhs_object, step.lhs_object_value); } break; @@ -415,7 +421,8 @@ void show_goto_trace( l_it!=step.io_args.end(); l_it++) { - if(l_it!=step.io_args.begin()) out << ";"; + if(l_it!=step.io_args.begin()) + out << ";"; out << " " << from_expr(ns, "", *l_it); // the binary representation @@ -435,7 +442,8 @@ void show_goto_trace( l_it!=step.io_args.end(); l_it++) { - if(l_it!=step.io_args.begin()) out << ";"; + if(l_it!=step.io_args.begin()) + out << ";"; out << " " << from_expr(ns, "", *l_it); // the binary representation diff --git a/src/goto-programs/goto_trace.h b/src/goto-programs/goto_trace.h index fcaca39ba76..507d538ada0 100644 --- a/src/goto-programs/goto_trace.h +++ b/src/goto-programs/goto_trace.h @@ -131,7 +131,7 @@ class goto_tracet irep_idt mode; - inline void clear() + void clear() { mode.clear(); steps.clear(); @@ -143,13 +143,13 @@ class goto_tracet const class namespacet &ns, std::ostream &out) const; - inline void swap(goto_tracet &other) + void swap(goto_tracet &other) { other.steps.swap(steps); other.mode.swap(mode); } - inline void add_step(const goto_trace_stept &step) + void add_step(const goto_trace_stept &step) { steps.push_back(step); } @@ -158,10 +158,7 @@ class goto_tracet void trim_after(stepst::iterator s) { assert(s!=steps.end()); - s++; - for(; - s!=steps.end(); - s=steps.erase(s)); + steps.erase(++s, steps.end()); } }; diff --git a/src/goto-programs/graphml_witness.cpp b/src/goto-programs/graphml_witness.cpp index 664580ec397..8e95a03d853 100644 --- a/src/goto-programs/graphml_witness.cpp +++ b/src/goto-programs/graphml_witness.cpp @@ -415,7 +415,8 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation) const graphmlt::node_indext node=graphml.add_node(); graphml[node].node_name= - std::to_string(it->source.pc->location_number)+"."+std::to_string(step_nr); + std::to_string(it->source.pc->location_number)+"."+ + std::to_string(step_nr); graphml[node].file=source_location.get_file(); graphml[node].line=source_location.get_line(); graphml[node].thread_nr=it->source.thread_nr; diff --git a/src/goto-programs/graphml_witness.h b/src/goto-programs/graphml_witness.h index f8ed1a614d9..65a6b8e5406 100644 --- a/src/goto-programs/graphml_witness.h +++ b/src/goto-programs/graphml_witness.h @@ -26,7 +26,7 @@ class graphml_witnesst void operator()(const goto_tracet &goto_trace); void operator()(const symex_target_equationt &equation); - inline const graphmlt &graph() + const graphmlt &graph() { return graphml; } diff --git a/src/goto-programs/interpreter.cpp b/src/goto-programs/interpreter.cpp index c6f80260dbe..2b4841a7c22 100644 --- a/src/goto-programs/interpreter.cpp +++ b/src/goto-programs/interpreter.cpp @@ -53,7 +53,8 @@ void interpretert::operator()() { show_state(); command(); - if(!done) step(); + if(!done) + step(); } } @@ -81,7 +82,8 @@ void interpretert::show_state() << function->first << "'" << std::endl; } else - function->second.body.output_instruction(ns, function->first, std::cout, PC); + function->second.body.output_instruction( + ns, function->first, std::cout, PC); std::cout << std::endl; } @@ -175,7 +177,7 @@ void interpretert::step() case RETURN: if(call_stack.empty()) - throw "RETURN without call"; + throw "RETURN without call"; // NOLINT(readability/throw) if(PC->code.operands().size()==1 && call_stack.top().return_value_address!=0) @@ -197,20 +199,20 @@ void interpretert::step() break; case START_THREAD: - throw "START_THREAD not yet implemented"; + throw "START_THREAD not yet implemented"; // NOLINT(readability/throw) case END_THREAD: - throw "END_THREAD not yet implemented"; + throw "END_THREAD not yet implemented"; // NOLINT(readability/throw) break; case ATOMIC_BEGIN: - throw "ATOMIC_BEGIN not yet implemented"; + throw "ATOMIC_BEGIN not yet implemented"; // NOLINT(readability/throw) case ATOMIC_END: - throw "ATOMIC_END not yet implemented"; + throw "ATOMIC_END not yet implemented"; // NOLINT(readability/throw) case DEAD: - throw "DEAD not yet implemented"; + throw "DEAD not yet implemented"; // NOLINT(readability/throw) default: throw "encountered instruction with undefined instruction type"; @@ -465,7 +467,8 @@ void interpretert::execute_function_call() for(unsigned i=0; i=memory.size()) memory.resize(address+1); + if(address>=memory.size()) + memory.resize(address+1); memory[address].value=0; memory[address].identifier=id; memory[address].offset=i; diff --git a/src/goto-programs/interpreter_class.h b/src/goto-programs/interpreter_class.h index 9a3133e9f1c..14c429a1a86 100644 --- a/src/goto-programs/interpreter_class.h +++ b/src/goto-programs/interpreter_class.h @@ -1,8 +1,8 @@ /*******************************************************************\ - Class: interpretert +Module: Interpreter for GOTO Programs - Purpose: interpreter for GOTO programs +Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ @@ -29,8 +29,6 @@ class interpretert void operator()(); - friend class simplify_evaluatet; - protected: const symbol_tablet &symbol_table; const namespacet ns; @@ -96,7 +94,8 @@ class interpretert { std::vector v; evaluate(expr, v); - if(v.size()!=1) throw "invalid boolean value"; + if(v.size()!=1) + throw "invalid boolean value"; return v.front()!=0; } diff --git a/src/goto-programs/interpreter_evaluate.cpp b/src/goto-programs/interpreter_evaluate.cpp index 57c761ebc6a..a9d62740cc3 100644 --- a/src/goto-programs/interpreter_evaluate.cpp +++ b/src/goto-programs/interpreter_evaluate.cpp @@ -32,7 +32,7 @@ void interpretert::read( std::vector &dest) const { // copy memory region - for(unsigned i=0; itype().id()==ID_code) continue; + if(it->type().id()==ID_code) + continue; unsigned sub_size=get_size(it->type()); - if(sub_size==0) continue; + if(sub_size==0) + continue; std::vector tmp; evaluate(*it, tmp); @@ -262,14 +266,13 @@ void interpretert::evaluate( if(expr.type().id()==ID_fixedbv) { fixedbvt f; - f.spec=to_fixedbv_type(expr.type()); + f.spec=fixedbv_spect(to_fixedbv_type(expr.type())); f.from_integer(1); result=f.get_value(); } else if(expr.type().id()==ID_floatbv) { - ieee_floatt f; - f.spec=to_floatbv_type(expr.type()); + ieee_floatt f(to_floatbv_type(expr.type())); f.from_integer(1); result=f.pack(); } @@ -285,8 +288,8 @@ void interpretert::evaluate( if(expr.type().id()==ID_fixedbv) { fixedbvt f1, f2; - f1.spec=to_fixedbv_type(expr.type()); - f2.spec=to_fixedbv_type(it->type()); + f1.spec=fixedbv_spect(to_fixedbv_type(expr.type())); + f2.spec=fixedbv_spect(to_fixedbv_type(it->type())); f1.set_value(result); f2.set_value(tmp.front()); f1*=f2; @@ -294,9 +297,8 @@ void interpretert::evaluate( } else if(expr.type().id()==ID_floatbv) { - ieee_floatt f1, f2; - f1.spec=to_floatbv_type(expr.type()); - f2.spec=to_floatbv_type(it->type()); + ieee_floatt f1(to_floatbv_type(expr.type())); + ieee_floatt f2(to_floatbv_type(it->type())); f1.unpack(result); f2.unpack(tmp.front()); f1*=f2; diff --git a/src/goto-programs/json_goto_trace.cpp b/src/goto-programs/json_goto_trace.cpp index 4d4239ef182..da6590fe2de 100644 --- a/src/goto-programs/json_goto_trace.cpp +++ b/src/goto-programs/json_goto_trace.cpp @@ -207,7 +207,8 @@ void convert( json_objectt &json_location_only=dest_array.push_back().make_object(); json_location_only["stepType"]=json_stringt("location-only"); json_location_only["hidden"]=jsont::json_boolean(step.hidden); - json_location_only["thread"]=json_numbert(std::to_string(step.thread_nr)); + json_location_only["thread"]= + json_numbert(std::to_string(step.thread_nr)); json_location_only["sourceLocation"]=json_location; } } diff --git a/src/goto-programs/link_to_library.cpp b/src/goto-programs/link_to_library.cpp index 83ff6015f88..46cd45c36da 100644 --- a/src/goto-programs/link_to_library.cpp +++ b/src/goto-programs/link_to_library.cpp @@ -84,7 +84,8 @@ void link_to_library( } // done? - if(missing_functions.empty()) break; + if(missing_functions.empty()) + break; add_cprover_library(missing_functions, symbol_table, message_handler); @@ -96,6 +97,5 @@ void link_to_library( added_functions.insert(id); } - } } diff --git a/src/goto-programs/loop_ids.cpp b/src/goto-programs/loop_ids.cpp index e4e4a280a7a..4d3eedec739 100644 --- a/src/goto-programs/loop_ids.cpp +++ b/src/goto-programs/loop_ids.cpp @@ -88,7 +88,7 @@ void show_loop_ids( break; } case ui_message_handlert::JSON_UI: - assert(false); //use function below + assert(false); // use function below } } @@ -97,7 +97,7 @@ void show_loop_ids_json( const goto_programt &goto_program, json_arrayt &loops) { - assert(ui==ui_message_handlert::JSON_UI); //use function above + assert(ui==ui_message_handlert::JSON_UI); // use function above forall_goto_program_instructions(it, goto_program) { diff --git a/src/goto-programs/osx_fat_reader.cpp b/src/goto-programs/osx_fat_reader.cpp index da5cecb9ce3..aa9594ec203 100644 --- a/src/goto-programs/osx_fat_reader.cpp +++ b/src/goto-programs/osx_fat_reader.cpp @@ -59,22 +59,26 @@ osx_fat_readert::osx_fat_readert(std::ifstream &in) : has_gb_arch(false) { #ifdef __APPLE__ + // NOLINTNEXTLINE(readability/identifiers) struct fat_header fh; - in.read((char*)&fh, sizeof(struct fat_header)); + // NOLINTNEXTLINE(readability/identifiers) + in.read(reinterpret_cast(&fh), sizeof(struct fat_header)); if(!in) throw "failed to read OSX fat header"; - if(!is_osx_fat_magic((char*)&(fh.magic))) - throw "OSX fat header malformed (magic)"; + if(!is_osx_fat_magic(reinterpret_cast(&(fh.magic)))) + throw "OSX fat header malformed (magic)"; // NOLINT(readability/throw) assert(sizeof(fh.nfat_arch)==4); unsigned narch=__builtin_bswap32(fh.nfat_arch); for(unsigned i=0; !has_gb_arch && i(&fa), sizeof(struct fat_arch)); assert(sizeof(fa.cputype)==4 && sizeof(fa.cpusubtype)==4 && diff --git a/src/goto-programs/osx_fat_reader.h b/src/goto-programs/osx_fat_reader.h index 83c64de13ca..e164548607b 100644 --- a/src/goto-programs/osx_fat_reader.h +++ b/src/goto-programs/osx_fat_reader.h @@ -20,7 +20,7 @@ class osx_fat_readert public: explicit osx_fat_readert(std::ifstream &in); - inline bool has_gb() const { return has_gb_arch; } + bool has_gb() const { return has_gb_arch; } bool extract_gb( const std::string &source, diff --git a/src/goto-programs/parameter_assignments.cpp b/src/goto-programs/parameter_assignments.cpp index 0cb2332e692..2052bdb09d8 100644 --- a/src/goto-programs/parameter_assignments.cpp +++ b/src/goto-programs/parameter_assignments.cpp @@ -72,7 +72,8 @@ void parameter_assignmentst::do_function_calls( { irep_idt p_identifier=code_type.parameters()[nr].get_identifier(); - if(p_identifier.empty()) continue; + if(p_identifier.empty()) + continue; if(nrcode=code_assignt(lhs, rhs); t->function=i_it->function; } diff --git a/src/goto-programs/pointer_arithmetic.h b/src/goto-programs/pointer_arithmetic.h index 646223dc99c..4e59e78ff52 100644 --- a/src/goto-programs/pointer_arithmetic.h +++ b/src/goto-programs/pointer_arithmetic.h @@ -15,7 +15,7 @@ struct pointer_arithmetict { exprt pointer, offset; - pointer_arithmetict(const exprt &src); + explicit pointer_arithmetict(const exprt &src); protected: void read(const exprt &src); diff --git a/src/goto-programs/read_bin_goto_object.cpp b/src/goto-programs/read_bin_goto_object.cpp index 653adadd46d..9c92b403cf1 100644 --- a/src/goto-programs/read_bin_goto_object.cpp +++ b/src/goto-programs/read_bin_goto_object.cpp @@ -57,23 +57,23 @@ bool read_bin_goto_object_v3( std::size_t flags=irepconverter.read_gb_word(in); - sym.is_weak = (flags & (1 << 16))!=0; - sym.is_type = (flags & (1 << 15))!=0; - sym.is_property = (flags & (1 << 14))!=0; - sym.is_macro = (flags & (1 << 13))!=0; - sym.is_exported = (flags & (1 << 12))!=0; - sym.is_input = (flags & (1 << 11))!=0; - sym.is_output = (flags & (1 << 10))!=0; - sym.is_state_var = (flags & (1 << 9))!=0; - sym.is_parameter = (flags & (1 << 8))!=0; - sym.is_auxiliary = (flags & (1 << 7))!=0; - //sym.binding = (flags & (1 << 6))!=0; - sym.is_lvalue = (flags & (1 << 5))!=0; - sym.is_static_lifetime = (flags & (1 << 4))!=0; - sym.is_thread_local = (flags & (1 << 3))!=0; - sym.is_file_local = (flags & (1 << 2))!=0; - sym.is_extern = (flags & (1 << 1))!=0; - sym.is_volatile = (flags & 1)!=0; + sym.is_weak = (flags &(1 << 16))!=0; + sym.is_type = (flags &(1 << 15))!=0; + sym.is_property = (flags &(1 << 14))!=0; + sym.is_macro = (flags &(1 << 13))!=0; + sym.is_exported = (flags &(1 << 12))!=0; + sym.is_input = (flags &(1 << 11))!=0; + sym.is_output = (flags &(1 << 10))!=0; + sym.is_state_var = (flags &(1 << 9))!=0; + sym.is_parameter = (flags &(1 << 8))!=0; + sym.is_auxiliary = (flags &(1 << 7))!=0; + // sym.binding = (flags &(1 << 6))!=0; + sym.is_lvalue = (flags &(1 << 5))!=0; + sym.is_static_lifetime = (flags &(1 << 4))!=0; + sym.is_thread_local = (flags &(1 << 3))!=0; + sym.is_file_local = (flags &(1 << 2))!=0; + sym.is_extern = (flags &(1 << 1))!=0; + sym.is_volatile = (flags &1)!=0; if(!sym.is_type && sym.type.id()==ID_code) { @@ -116,8 +116,9 @@ bool read_bin_goto_object_v3( irepconverter.read_string_ref(in); // former event instruction.target_number = irepconverter.read_gb_word(in); if(instruction.is_target() && - rev_target_map.insert(rev_target_map.end(), - std::make_pair(instruction.target_number, itarget))->second!=itarget) + rev_target_map.insert( + rev_target_map.end(), + std::make_pair(instruction.target_number, itarget))->second!=itarget) assert(false); std::size_t t_count = irepconverter.read_gb_word(in); // # of targets @@ -131,7 +132,8 @@ bool read_bin_goto_object_v3( { irep_idt label=irepconverter.read_string_ref(in); instruction.labels.push_back(label); - if(label=="__CPROVER_HIDE") hidden=true; + if(label=="__CPROVER_HIDE") + hidden=true; // The above info is normally in the type of the goto_functiont object, // which should likely be stored in the binary. } @@ -157,7 +159,8 @@ bool read_bin_goto_object_v3( f.body.update(); - if(hidden) f.make_hidden(); + if(hidden) + f.make_hidden(); } functions.compute_location_numbers(); @@ -193,7 +196,9 @@ bool read_bin_goto_object( hdr[2]=in.get(); if(hdr[0]=='G' && hdr[1]=='B' && hdr[2]=='F') - ; + { + // OK! + } else { hdr[3]=in.get(); @@ -204,16 +209,18 @@ bool read_bin_goto_object( else if(hdr[0]==0x7f && hdr[1]=='E' && hdr[2]=='L' && hdr[3]=='F') { if(filename!="") - message.error() << - "Sorry, but I can't read ELF binary `" << filename << "'" << messaget::eom; + message.error() << "Sorry, but I can't read ELF binary `" + << filename << "'" << messaget::eom; else - message.error() << "Sorry, but I can't read ELF binaries" << messaget::eom; + message.error() << "Sorry, but I can't read ELF binaries" + << messaget::eom; return true; } else { - message.error() << "`" << filename << "' is not a goto-binary" << messaget::eom; + message.error() << "`" << filename << "' is not a goto-binary" + << messaget::eom; return true; } } @@ -221,7 +228,7 @@ bool read_bin_goto_object( irep_serializationt::ireps_containert ic; irep_serializationt irepconverter(ic); - //symbol_serializationt symbolconverter(ic); + // symbol_serializationt symbolconverter(ic); { std::size_t version=irepconverter.read_gb_word(in); diff --git a/src/goto-programs/read_goto_binary.cpp b/src/goto-programs/read_goto_binary.cpp index 9ae9ed5a29a..b5919d93eee 100644 --- a/src/goto-programs/read_goto_binary.cpp +++ b/src/goto-programs/read_goto_binary.cpp @@ -141,7 +141,8 @@ bool read_goto_binary( std::ifstream temp_in(tempname, std::ios::binary); if(!temp_in) - messaget(message_handler).error() << "failed to read temp binary" << messaget::eom; + messaget(message_handler).error() << "failed to read temp binary" + << messaget::eom; const bool read_err=read_bin_goto_object( temp_in, filename, symbol_table, goto_functions, message_handler); temp_in.close(); @@ -191,7 +192,8 @@ bool is_goto_binary(const std::string &filename) std::ifstream in(filename, std::ios::binary); #endif - if(!in) return false; + if(!in) + return false; // We accept two forms: // 1. goto binaries, marked with 0x7f GBF @@ -214,7 +216,8 @@ bool is_goto_binary(const std::string &filename) { in.seekg(0); elf_readert elf_reader(in); - if(elf_reader.has_section("goto-cc")) return true; + if(elf_reader.has_section("goto-cc")) + return true; } catch(...) @@ -229,7 +232,8 @@ bool is_goto_binary(const std::string &filename) { in.seekg(0); osx_fat_readert osx_fat_reader(in); - if(osx_fat_reader.has_gb()) return true; + if(osx_fat_reader.has_gb()) + return true; } catch(...) diff --git a/src/goto-programs/remove_asm.cpp b/src/goto-programs/remove_asm.cpp index 11cc5ce94a1..a77d1e0e418 100644 --- a/src/goto-programs/remove_asm.cpp +++ b/src/goto-programs/remove_asm.cpp @@ -143,7 +143,7 @@ void remove_asmt::process_instruction( const irep_idt &i_str= to_string_constant(code.op0()).get_value(); - //std::cout << "DOING " << i_str << std::endl; + // std::cout << "DOING " << i_str << std::endl; std::istringstream str(id2string(i_str)); assembler_parser.clear(); @@ -156,7 +156,8 @@ void remove_asmt::process_instruction( for(const auto &instruction : assembler_parser.instructions) { - if(instruction.empty()) continue; + if(instruction.empty()) + continue; #if 0 std::cout << "A ********************\n"; diff --git a/src/goto-programs/remove_function_pointers.cpp b/src/goto-programs/remove_function_pointers.cpp index 1baca8d11d5..b5dac445fda 100644 --- a/src/goto-programs/remove_function_pointers.cpp +++ b/src/goto-programs/remove_function_pointers.cpp @@ -12,7 +12,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include -#include #include #include @@ -65,8 +64,9 @@ class remove_function_pointerst const typet &function_type); void fix_argument_types(code_function_callt &function_call); - void fix_return_type(code_function_callt &function_call, - goto_programt &dest); + void fix_return_type( + code_function_callt &function_call, + goto_programt &dest); symbolt &new_tmp_symbol(); @@ -78,7 +78,6 @@ class remove_function_pointerst for(const auto &s : symbol_table.symbols) compute_address_taken_functions(s.second.value, address_taken); } - }; /*******************************************************************\ @@ -130,9 +129,12 @@ symbolt &remove_function_pointerst::new_tmp_symbol() do { - new_symbol.base_name="tmp_return_val$"+std::to_string(++temporary_counter); - new_symbol.name="remove_function_pointers::"+id2string(new_symbol.base_name); - } while(symbol_table.move(new_symbol, symbol_ptr)); + new_symbol.base_name= + "tmp_return_val$"+std::to_string(++temporary_counter); + new_symbol.name= + "remove_function_pointers::"+id2string(new_symbol.base_name); + } + while(symbol_table.move(new_symbol, symbol_ptr)); return *symbol_ptr; } @@ -153,7 +155,8 @@ bool remove_function_pointerst::arg_is_type_compatible( const typet &call_type, const typet &function_type) { - if(type_eq(call_type, function_type, ns)) return true; + if(type_eq(call_type, function_type, ns)) + return true; // any integer-vs-enum-vs-pointer is ok if(call_type.id()==ID_signedbv || @@ -296,7 +299,8 @@ void remove_function_pointerst::fix_return_type( goto_programt &dest) { // are we returning anything at all? - if(function_call.lhs().is_nil()) return; + if(function_call.lhs().is_nil()) + return; const code_typet &code_type= to_code_type(ns.follow(function_call.function().type())); @@ -460,8 +464,10 @@ void remove_function_pointerst::remove_function_pointer( irep_idt comment=it->source_location.get_comment(); it->source_location=target->source_location; it->function=target->function; - if(!property_class.empty()) it->source_location.set_property_class(property_class); - if(!comment.empty()) it->source_location.set_comment(comment); + if(!property_class.empty()) + it->source_location.set_property_class(property_class); + if(!comment.empty()) + it->source_location.set_comment(comment); } goto_programt::targett next_target=target; diff --git a/src/goto-programs/remove_returns.cpp b/src/goto-programs/remove_returns.cpp index ce1ced18c37..b3afbf967fc 100644 --- a/src/goto-programs/remove_returns.cpp +++ b/src/goto-programs/remove_returns.cpp @@ -84,7 +84,8 @@ void remove_returnst::replace_returns( auxiliary_symbolt new_symbol; new_symbol.is_static_lifetime=true; new_symbol.module=function_symbol.module; - new_symbol.base_name=id2string(function_symbol.base_name)+RETURN_VALUE_SUFFIX; + new_symbol.base_name= + id2string(function_symbol.base_name)+RETURN_VALUE_SUFFIX; new_symbol.name=id2string(function_symbol.name)+RETURN_VALUE_SUFFIX; new_symbol.mode=function_symbol.mode; new_symbol.type=return_type; @@ -147,7 +148,8 @@ void remove_returnst::do_function_calls( // Do we return anything? if(old_type.return_type()!=empty_typet()) { - // replace "lhs=f(...)" by "f(...); lhs=f#return_value; DEAD f#return_value;" + // replace "lhs=f(...)" by + // "f(...); lhs=f#return_value; DEAD f#return_value;" assert(function_call.function().id()==ID_symbol); const irep_idt function_id= @@ -158,10 +160,13 @@ void remove_returnst::do_function_calls( f_it=goto_functions.function_map.find(function_id); if(f_it==goto_functions.function_map.end()) - throw "failed to find function `"+id2string(function_id)+"' in function map"; + throw + "failed to find function `"+id2string(function_id)+ + "' in function map"; // fix the type - to_code_type(function_call.function().type()).return_type()=empty_typet(); + to_code_type(function_call.function().type()).return_type()= + empty_typet(); if(function_call.lhs().is_not_nil()) { @@ -171,7 +176,8 @@ void remove_returnst::do_function_calls( { symbol_exprt return_value; return_value.type()=function_call.lhs().type(); - return_value.set_identifier(id2string(function_id)+RETURN_VALUE_SUFFIX); + return_value.set_identifier( + id2string(function_id)+RETURN_VALUE_SUFFIX); rhs=return_value; } else diff --git a/src/goto-programs/remove_skip.cpp b/src/goto-programs/remove_skip.cpp index cb903fd0e0c..dedeb8aca2a 100644 --- a/src/goto-programs/remove_skip.cpp +++ b/src/goto-programs/remove_skip.cpp @@ -33,7 +33,8 @@ static bool is_skip(goto_programt::instructionst::iterator it) if(it->is_goto()) { - if(it->guard.is_false()) return true; + if(it->guard.is_false()) + return true; if(it->targets.size()!=1) return false; @@ -49,7 +50,8 @@ static bool is_skip(goto_programt::instructionst::iterator it) if(it->is_other()) { - if(it->code.is_nil()) return true; + if(it->code.is_nil()) + return true; const irep_idt &statement=it->code.get_statement(); @@ -97,7 +99,8 @@ void remove_skip(goto_programt &goto_program) old_size=goto_program.instructions.size(); // maps deleted instructions to their replacement - typedef std::map new_targetst; + typedef std::map + new_targetst; new_targetst new_targets; // remove skip statements diff --git a/src/goto-programs/remove_unused_functions.cpp b/src/goto-programs/remove_unused_functions.cpp index 75b33c63095..860af2e1d73 100644 --- a/src/goto-programs/remove_unused_functions.cpp +++ b/src/goto-programs/remove_unused_functions.cpp @@ -28,7 +28,8 @@ void remove_unused_functions( { std::set used_functions; std::list unused_functions; - find_used_functions(goto_functionst::entry_point(), functions, used_functions); + find_used_functions( + goto_functionst::entry_point(), functions, used_functions); for(goto_functionst::function_mapt::iterator it= functions.function_map.begin(); @@ -82,7 +83,8 @@ void find_used_functions( if(f_it!=functions.function_map.end()) { - forall_goto_program_instructions(it, f_it->second.body){ + forall_goto_program_instructions(it, f_it->second.body) + { if(it->type==FUNCTION_CALL) { const code_function_callt &call = diff --git a/src/goto-programs/remove_virtual_functions.cpp b/src/goto-programs/remove_virtual_functions.cpp index da9cce5039f..4b950593aed 100644 --- a/src/goto-programs/remove_virtual_functions.cpp +++ b/src/goto-programs/remove_virtual_functions.cpp @@ -46,7 +46,7 @@ class remove_virtual_functionst { public: functiont() {} - explicit functiont(const irep_idt& _class_id) : + explicit functiont(const irep_idt &_class_id) : class_id(_class_id) {} @@ -260,7 +260,7 @@ void remove_virtual_functionst::get_child_functions_rec( if(findit==class_hierarchy.class_map.end()) return; - for(const auto & child : findit->second.children) + for(const auto &child : findit->second.children) { exprt method=get_method(child, component_name); functiont function(child); diff --git a/src/goto-programs/set_properties.cpp b/src/goto-programs/set_properties.cpp index 4f345e5eab0..fc79d4dcfe7 100644 --- a/src/goto-programs/set_properties.cpp +++ b/src/goto-programs/set_properties.cpp @@ -33,7 +33,8 @@ void set_properties( it!=goto_program.instructions.end(); it++) { - if(!it->is_assert()) continue; + if(!it->is_assert()) + continue; irep_idt property_id=it->source_location.get_property_id(); @@ -85,14 +86,16 @@ void label_properties( it!=goto_program.instructions.end(); it++) { - if(!it->is_assert()) continue; + if(!it->is_assert()) + continue; irep_idt function=it->source_location.get_function(); std::string prefix=id2string(function); if(it->source_location.get_property_class()!="") { - if(prefix!="") prefix+="."; + if(prefix!="") + prefix+="."; std::string class_infix= id2string(it->source_location.get_property_class()); @@ -103,7 +106,8 @@ void label_properties( prefix+=class_infix; } - if(prefix!="") prefix+="."; + if(prefix!="") + prefix+="."; unsigned &count=property_counters[prefix]; @@ -248,7 +252,8 @@ void make_assertions_false( i_it!=goto_program.instructions.end(); i_it++) { - if(!i_it->is_assert()) continue; + if(!i_it->is_assert()) + continue; i_it->guard=false_exprt(); } } diff --git a/src/goto-programs/show_properties.cpp b/src/goto-programs/show_properties.cpp index 6deddc286da..c7a6bdedf3f 100644 --- a/src/goto-programs/show_properties.cpp +++ b/src/goto-programs/show_properties.cpp @@ -45,7 +45,6 @@ void show_properties( const source_locationt &source_location=ins.source_location; const irep_idt &comment=source_location.get_comment(); - //const irep_idt &function=location.get_function(); const irep_idt &property_class=source_location.get_property_class(); const irep_idt description= (comment==""?"assertion":comment); @@ -56,27 +55,10 @@ void show_properties( { case ui_message_handlert::XML_UI: { - #if 0 - xmlt xml_claim("claim"); // this will go away, use below - xml_claim.new_element("number").data=id2string(property_id); // will go away - xml_claim.new_element("name").data=id2string(property_id); // will go away - xml_claim.set_attribute("name", id2string(property_id)); // use this one - - xmlt &l=xml_claim.new_element(); - l=xml(it.source_location); - - xml_claim.new_element("description").data=id2string(description); - xml_claim.new_element("property").data=id2string(property_class); - xml_claim.new_element("expression").data=from_expr(ns, identifier, it.guard); - xml_claim.new_element("source").data=""; - - std::cout << xml_claim << std::endl; - #endif - // use me instead xmlt xml_property("property"); - xml_property.set_attribute("name", id2string(property_id)); // use this one - xml_property.set_attribute("class", id2string(property_class)); // use this one + xml_property.set_attribute("name", id2string(property_id)); + xml_property.set_attribute("class", id2string(property_class)); xmlt &property_l=xml_property.new_element(); property_l=xml(source_location); @@ -137,7 +119,7 @@ void show_properties_json( const source_locationt &source_location=ins.source_location; const irep_idt &comment=source_location.get_comment(); - //const irep_idt &function=location.get_function(); + // const irep_idt &function=location.get_function(); const irep_idt &property_class=source_location.get_property_class(); const irep_idt description= (comment==""?"assertion":comment); diff --git a/src/goto-programs/show_symbol_table.cpp b/src/goto-programs/show_symbol_table.cpp index 2df672e3bdb..955a444695a 100644 --- a/src/goto-programs/show_symbol_table.cpp +++ b/src/goto-programs/show_symbol_table.cpp @@ -68,7 +68,8 @@ void show_symbol_table_plain( else { ptr=get_language_from_mode(symbol.mode); - if(ptr==NULL) throw "symbol "+id2string(symbol.name)+" has unknown mode"; + if(ptr==NULL) + throw "symbol "+id2string(symbol.name)+" has unknown mode"; } std::unique_ptr p(ptr); @@ -89,22 +90,38 @@ void show_symbol_table_plain( out << "Value.......: " << value_str << '\n'; out << "Flags.......:"; - if(symbol.is_lvalue) out << " lvalue"; - if(symbol.is_static_lifetime) out << " static_lifetime"; - if(symbol.is_thread_local) out << " thread_local"; - if(symbol.is_file_local) out << " file_local"; - if(symbol.is_type) out << " type"; - if(symbol.is_extern) out << " extern"; - if(symbol.is_input) out << " input"; - if(symbol.is_output) out << " output"; - if(symbol.is_macro) out << " macro"; - if(symbol.is_parameter) out << " parameter"; - if(symbol.is_auxiliary) out << " auxiliary"; - if(symbol.is_weak) out << " weak"; - if(symbol.is_property) out << " property"; - if(symbol.is_state_var) out << " state_var"; - if(symbol.is_exported) out << " exported"; - if(symbol.is_volatile) out << " volatile"; + if(symbol.is_lvalue) + out << " lvalue"; + if(symbol.is_static_lifetime) + out << " static_lifetime"; + if(symbol.is_thread_local) + out << " thread_local"; + if(symbol.is_file_local) + out << " file_local"; + if(symbol.is_type) + out << " type"; + if(symbol.is_extern) + out << " extern"; + if(symbol.is_input) + out << " input"; + if(symbol.is_output) + out << " output"; + if(symbol.is_macro) + out << " macro"; + if(symbol.is_parameter) + out << " parameter"; + if(symbol.is_auxiliary) + out << " auxiliary"; + if(symbol.is_weak) + out << " weak"; + if(symbol.is_property) + out << " property"; + if(symbol.is_state_var) + out << " state_var"; + if(symbol.is_exported) + out << " exported"; + if(symbol.is_volatile) + out << " volatile"; out << '\n'; out << "Location....: " << symbol.location << '\n'; diff --git a/src/goto-programs/slice_global_inits.cpp b/src/goto-programs/slice_global_inits.cpp index ecaf6939af1..5e58888d366 100644 --- a/src/goto-programs/slice_global_inits.cpp +++ b/src/goto-programs/slice_global_inits.cpp @@ -72,7 +72,8 @@ void slice_global_inits( if(functions_reached.find(callee)==functions_reached.end()) worklist.push_back(callee); } - } while(!worklist.empty()); + } + while(!worklist.empty()); const irep_idt initialize=CPROVER_PREFIX "initialize"; functions_reached.erase(initialize); diff --git a/src/goto-programs/string_abstraction.cpp b/src/goto-programs/string_abstraction.cpp index a12b766eb1e..67abff95812 100644 --- a/src/goto-programs/string_abstraction.cpp +++ b/src/goto-programs/string_abstraction.cpp @@ -31,10 +31,13 @@ Function: string_abstractiont::build_wrap \*******************************************************************/ -bool string_abstractiont::build_wrap(const exprt &object, exprt &dest, bool write) +bool string_abstractiont::build_wrap( + const exprt &object, + exprt &dest, bool write) { // debugging - if(build(object, dest, write)) return true; + if(build(object, dest, write)) + return true; // extra consistency check // use @@ -261,7 +264,7 @@ Function: string_abstractiont::add_str_arguments \*******************************************************************/ void string_abstractiont::add_str_arguments( - const irep_idt & name, + const irep_idt &name, goto_functionst::goto_functiont &fct) { symbol_tablet::symbolst::iterator sym_entry=symbol_table.symbols.find(name); @@ -282,7 +285,8 @@ void string_abstractiont::add_str_arguments( continue; const irep_idt &identifier=it->get_identifier(); - if(identifier=="") continue; // ignore + if(identifier=="") + continue; // ignore add_argument(str_args, fct_symbol, abstract_type, id2string(it->get_base_name())+arg_suffix, @@ -294,7 +298,8 @@ void string_abstractiont::add_str_arguments( parameters.insert(parameters.end(), str_args.begin(), str_args.end()); code_typet::parameterst &symb_parameters= to_code_type(fct_symbol.type).parameters(); - symb_parameters.insert(symb_parameters.end(), str_args.begin(), str_args.end()); + symb_parameters.insert( + symb_parameters.end(), str_args.begin(), str_args.end()); } /*******************************************************************\ @@ -356,7 +361,8 @@ void string_abstractiont::abstract(goto_programt &dest) Forall_goto_program_instructions(it, dest) it=abstract(dest, it); - if(locals.empty()) return; + if(locals.empty()) + return; // go over it again for the newly added locals declare_define_locals(dest); @@ -405,7 +411,8 @@ void string_abstractiont::declare_define_locals(goto_programt &dest) goto_programt tmp; make_decl_and_def(tmp, ref_instr, l.second, l.first); - if(has_decl) ++ref_instr; + if(has_decl) + ++ref_instr; dest.insert_before_swap(ref_instr, tmp); } } @@ -509,10 +516,10 @@ exprt string_abstractiont::make_val_or_dummy_rec(goto_programt &dest, continue; const typet &eff_sub_type=ns.follow(it2->type()); - if(eff_sub_type.id() == ID_pointer || - eff_sub_type.id() == ID_array || - eff_sub_type.id() == ID_struct || - eff_sub_type.id() == ID_union) + if(eff_sub_type.id()==ID_pointer || + eff_sub_type.id()==ID_array || + eff_sub_type.id()==ID_struct || + eff_sub_type.id()==ID_union) { symbol_exprt sym_expr=add_dummy_symbol_and_value( dest, ref_instr, symbol, it2->get_name(), @@ -598,7 +605,8 @@ symbol_exprt string_abstractiont::add_dummy_symbol_and_value( make_type(new_symbol.value.op2(), build_type(SIZE)); } else - new_symbol.value=make_val_or_dummy_rec(dest, ref_instr, new_symbol, source_type); + new_symbol.value= + make_val_or_dummy_rec(dest, ref_instr, new_symbol, source_type); if(new_symbol.value.is_not_nil()) { @@ -743,7 +751,8 @@ void string_abstractiont::abstract_function_call( it2++, it1++) { const typet &abstract_type=build_abstraction_type(it2->type()); - if(abstract_type.is_nil()) continue; + if(abstract_type.is_nil()) + continue; if(it1==arguments.end()) { @@ -874,7 +883,8 @@ exprt string_abstractiont::build( } exprt str_struct; - if(build_wrap(pointer, str_struct, write)) assert(false); + if(build_wrap(pointer, str_struct, write)) + assert(false); exprt result=member(str_struct, what); @@ -903,7 +913,7 @@ Function: string_abstractiont::build_abstraction_type \*******************************************************************/ -const typet& string_abstractiont::build_abstraction_type(const typet &type) +const typet &string_abstractiont::build_abstraction_type(const typet &type) { const typet &eff_type=ns.follow(type); abstraction_types_mapt::const_iterator map_entry= @@ -934,7 +944,7 @@ Function: string_abstractiont::build_abstraction_type_rec \*******************************************************************/ -const typet& string_abstractiont::build_abstraction_type_rec(const typet &type, +const typet &string_abstractiont::build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known) { const typet &eff_type=ns.follow(type); @@ -952,11 +962,11 @@ const typet& string_abstractiont::build_abstraction_type_rec(const typet &type, { // char* or void* or char[] if(is_char_type(eff_type.subtype()) || - eff_type.subtype().id() == ID_empty) + eff_type.subtype().id()==ID_empty) map_entry.first->second=pointer_typet(string_struct); else { - const typet& subt=build_abstraction_type_rec(eff_type.subtype(), known); + const typet &subt=build_abstraction_type_rec(eff_type.subtype(), known); if(!subt.is_nil()) { if(eff_type.id()==ID_array) @@ -975,9 +985,12 @@ const typet& string_abstractiont::build_abstraction_type_rec(const typet &type, struct_union_typet::componentst new_comp; for(const auto &comp : struct_union_type.components()) { - if(comp.get_anonymous()) continue; + if(comp.get_anonymous()) + continue; typet subt=build_abstraction_type_rec(comp.type(), known); - if(subt.is_nil()) continue; // also precludes structs with pointers to the same datatype + if(subt.is_nil()) + // also precludes structs with pointers to the same datatype + continue; new_comp.push_back(struct_union_typet::componentt()); new_comp.back().set_name(comp.get_name()); @@ -1010,7 +1023,8 @@ Function: string_abstractiont::build bool string_abstractiont::build(const exprt &object, exprt &dest, bool write) { const typet &abstract_type=build_abstraction_type(object.type()); - if(abstract_type.is_nil()) return true; + if(abstract_type.is_nil()) + return true; if(object.id()==ID_typecast) { @@ -1090,7 +1104,8 @@ bool string_abstractiont::build_if(const if_exprt &o_if, // recursive calls bool op1_err=build_wrap(o_if.true_case(), new_if.true_case(), write); bool op2_err=build_wrap(o_if.false_case(), new_if.false_case(), write); - if(op1_err && op2_err) return true; + if(op1_err && op2_err) + return true; // at least one of them gave proper results if(op1_err) { @@ -1127,12 +1142,14 @@ bool string_abstractiont::build_array(const array_exprt &object, assert(is_char_type(object.type().subtype())); // writing is invalid - if(write) return true; + if(write) + return true; const exprt &a_size=to_array_type(object.type()).size(); mp_integer size; // don't do anything, if we cannot determine the size - if (to_integer(a_size, size)) return true; + if(to_integer(a_size, size)) + return true; assert(size==object.operands().size()); exprt::operandst::const_iterator it=object.operands().begin(); @@ -1169,9 +1186,11 @@ bool string_abstractiont::build_pointer(const exprt &object, return build_wrap(to_index_expr(a.object()).array(), dest, write); // writing is invalid - if(write) return true; + if(write) + return true; - if(build_wrap(a.object(), dest, write)) return true; + if(build_wrap(a.object(), dest, write)) + return true; dest=address_of_exprt(dest); return false; } @@ -1241,7 +1260,8 @@ exprt string_abstractiont::build_unknown(const typet &type, bool write) // create an uninitialized dummy symbol // because of a lack of contextual information we can't build a nice name // here, but moving that into locals should suffice for proper operation - irep_idt identifier="$tmp::nondet_str#str$"+std::to_string(++temporary_counter); + irep_idt identifier= + "$tmp::nondet_str#str$"+std::to_string(++temporary_counter); // ensure decl and initialization locals[identifier]=identifier; @@ -1324,8 +1344,9 @@ void string_abstractiont::build_new_symbol(const symbolt &symbol, new_symbol.module=symbol.module; new_symbol.base_name=id2string(symbol.base_name)+sym_suffix; new_symbol.mode=symbol.mode; - new_symbol.pretty_name=id2string( - symbol.pretty_name.empty()?symbol.base_name:symbol.pretty_name)+sym_suffix; + new_symbol.pretty_name= + id2string(symbol.pretty_name.empty()?symbol.base_name:symbol.pretty_name)+ + sym_suffix; new_symbol.is_static_lifetime=symbol.is_static_lifetime; new_symbol.is_thread_local=symbol.is_thread_local; @@ -1352,8 +1373,10 @@ Function: string_abstractiont::build_symbol_constant \*******************************************************************/ -bool string_abstractiont::build_symbol_constant(const mp_integer &zero_length, - const mp_integer &buf_size, exprt &dest) +bool string_abstractiont::build_symbol_constant( + const mp_integer &zero_length, + const mp_integer &buf_size, + exprt &dest) { irep_idt base="$string_constant_str_"+integer2string(zero_length) +"_"+integer2string(buf_size); @@ -1444,11 +1467,13 @@ goto_programt::targett string_abstractiont::abstract_pointer_assign( while(rhsp->id()==ID_typecast) rhsp=&(rhsp->op0()); - const typet& abstract_type=build_abstraction_type(lhs.type()); - if(abstract_type.is_nil()) return target; + const typet &abstract_type=build_abstraction_type(lhs.type()); + if(abstract_type.is_nil()) + return target; exprt new_lhs, new_rhs; - if(build_wrap(lhs, new_lhs, true)) return target; + if(build_wrap(lhs, new_lhs, true)) + return target; bool unknown=(abstract_type!=build_abstraction_type(rhsp->type()) || build_wrap(rhs, new_rhs, false)); @@ -1609,9 +1634,10 @@ Function: string_abstractiont::value_assignments \*******************************************************************/ goto_programt::targett string_abstractiont::value_assignments( - goto_programt &dest, - goto_programt::targett target, - const exprt& lhs, const exprt& rhs) + goto_programt &dest, + goto_programt::targett target, + const exprt &lhs, + const exprt &rhs) { if(rhs.id()==ID_if) return value_assignments_if(dest, target, lhs, to_if_expr(rhs)); @@ -1623,7 +1649,8 @@ goto_programt::targett string_abstractiont::value_assignments( const exprt &a_size=to_array_type(lhs.type()).size(); mp_integer size; // don't do anything, if we cannot determine the size - if (to_integer(a_size, size)) return target; + if(to_integer(a_size, size)) + return target; for(mp_integer i=0; icode); exprt &function=call.function(); - //const exprt &lhs=call.lhs(); + // const exprt &lhs=call.lhs(); if(function.id()==ID_symbol) { @@ -430,8 +463,9 @@ void string_instrumentationt::do_snprintf( assertion->source_location.set_property_class("string"); assertion->source_location.set_comment("snprintf buffer overflow"); - exprt bufsize = buffer_size(arguments[0]); - assertion->make_assertion(binary_relation_exprt(bufsize, ID_ge, arguments[1])); + exprt bufsize=buffer_size(arguments[0]); + assertion->make_assertion( + binary_relation_exprt(bufsize, ID_ge, arguments[1])); do_format_string_read(tmp, target, arguments, 2, 3, "snprintf"); @@ -515,7 +549,7 @@ void string_instrumentationt::do_format_string_read( unsigned argument_start_inx, const std::string &function_name) { - const exprt &format_arg = arguments[format_string_inx]; + const exprt &format_arg=arguments[format_string_inx]; if(format_arg.id()==ID_address_of && format_arg.op0().id()==ID_index && @@ -530,8 +564,8 @@ void string_instrumentationt::do_format_string_read( { if(token.type==format_tokent::STRING) { - const exprt &arg = arguments[argument_start_inx+args]; - const typet &arg_type = ns.follow(arg.type()); + const exprt &arg=arguments[argument_start_inx+args]; + const typet &arg_type=ns.follow(arg.type()); if(arg.id()!=ID_string_constant) // we don't need to check constants { @@ -577,7 +611,7 @@ void string_instrumentationt::do_format_string_read( for(unsigned i=2; isource_location=target->source_location; exprt lhs(ID_dereference, arg_type.subtype()); @@ -816,7 +851,8 @@ void string_instrumentationt::do_strchr( assertion->make_assertion(is_zero_string(arguments[0])); assertion->source_location=target->source_location; assertion->source_location.set_property_class("string"); - assertion->source_location.set_comment("zero-termination of string argument of strchr"); + assertion->source_location.set_comment( + "zero-termination of string argument of strchr"); target->make_skip(); dest.insert_before_swap(target, tmp); @@ -854,7 +890,8 @@ void string_instrumentationt::do_strrchr( assertion->make_assertion(is_zero_string(arguments[0])); assertion->source_location=target->source_location; assertion->source_location.set_property_class("string"); - assertion->source_location.set_comment("zero-termination of string argument of strrchr"); + assertion->source_location.set_comment( + "zero-termination of string argument of strrchr"); target->make_skip(); dest.insert_before_swap(target, tmp); @@ -892,13 +929,15 @@ void string_instrumentationt::do_strstr( assertion0->make_assertion(is_zero_string(arguments[0])); assertion0->source_location=target->source_location; assertion0->source_location.set_property_class("string"); - assertion0->source_location.set_comment("zero-termination of 1st string argument of strstr"); + assertion0->source_location.set_comment( + "zero-termination of 1st string argument of strstr"); goto_programt::targett assertion1=tmp.add_instruction(); assertion1->make_assertion(is_zero_string(arguments[1])); assertion1->source_location=target->source_location; assertion1->source_location.set_property_class("string"); - assertion1->source_location.set_comment("zero-termination of 2nd string argument of strstr"); + assertion1->source_location.set_comment( + "zero-termination of 2nd string argument of strstr"); target->make_skip(); dest.insert_before_swap(target, tmp); @@ -936,13 +975,15 @@ void string_instrumentationt::do_strtok( assertion0->make_assertion(is_zero_string(arguments[0])); assertion0->source_location=target->source_location; assertion0->source_location.set_property_class("string"); - assertion0->source_location.set_comment("zero-termination of 1st string argument of strtok"); + assertion0->source_location.set_comment( + "zero-termination of 1st string argument of strtok"); goto_programt::targett assertion1=tmp.add_instruction(); assertion1->make_assertion(is_zero_string(arguments[1])); assertion1->source_location=target->source_location; assertion1->source_location.set_property_class("string"); - assertion1->source_location.set_comment("zero-termination of 2nd string argument of strtok"); + assertion1->source_location.set_comment( + "zero-termination of 2nd string argument of strtok"); target->make_skip(); dest.insert_before_swap(target, tmp); @@ -1129,14 +1170,14 @@ void string_instrumentationt::invalidate_buffer( exprt cnt_bs, bufp; if(buf_type.id()==ID_pointer) - bufp = buffer; + bufp=buffer; else { index_exprt index; index.array()=buffer; index.index()=from_integer(0, index_type()); index.type()=buf_type.subtype(); - bufp = address_of_exprt(index); + bufp=address_of_exprt(index); } exprt deref(ID_dereference, buf_type.subtype()); @@ -1149,12 +1190,16 @@ void string_instrumentationt::invalidate_buffer( if(limit==0) check->guard= - binary_relation_exprt(cntr_sym.symbol_expr(), ID_ge, - buffer_size(bufp)); + binary_relation_exprt( + cntr_sym.symbol_expr(), + ID_ge, + buffer_size(bufp)); else check->guard= - binary_relation_exprt(cntr_sym.symbol_expr(), ID_gt, - from_integer(limit, unsigned_int_type())); + binary_relation_exprt( + cntr_sym.symbol_expr(), + ID_gt, + from_integer(limit, unsigned_int_type())); exprt nondet=side_effect_expr_nondett(buf_type.subtype()); invalidate->code=code_assignt(deref, nondet); diff --git a/src/goto-programs/vcd_goto_trace.cpp b/src/goto-programs/vcd_goto_trace.cpp index 76446cfd095..3fe1ebbb660 100644 --- a/src/goto-programs/vcd_goto_trace.cpp +++ b/src/goto-programs/vcd_goto_trace.cpp @@ -179,7 +179,9 @@ void output_vcd( } break; - default:; + default: + { + } } } } diff --git a/src/goto-programs/wp.cpp b/src/goto-programs/wp.cpp index 8b24655f304..7f10498810d 100644 --- a/src/goto-programs/wp.cpp +++ b/src/goto-programs/wp.cpp @@ -6,7 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#include +// #include #include #include diff --git a/src/goto-programs/write_goto_binary.cpp b/src/goto-programs/write_goto_binary.cpp index 021ba3e51bd..f5649e992d3 100644 --- a/src/goto-programs/write_goto_binary.cpp +++ b/src/goto-programs/write_goto_binary.cpp @@ -56,23 +56,23 @@ bool write_goto_binary_v3( write_gb_word(out, 0); // old: sym.ordering unsigned flags=0; - flags = (flags << 1) | (int)sym.is_weak; - flags = (flags << 1) | (int)sym.is_type; - flags = (flags << 1) | (int)sym.is_property; - flags = (flags << 1) | (int)sym.is_macro; - flags = (flags << 1) | (int)sym.is_exported; - flags = (flags << 1) | (int)sym.is_input; - flags = (flags << 1) | (int)sym.is_output; - flags = (flags << 1) | (int)sym.is_state_var; - flags = (flags << 1) | (int)sym.is_parameter; - flags = (flags << 1) | (int)sym.is_auxiliary; - flags = (flags << 1) | (int)false; // sym.binding; - flags = (flags << 1) | (int)sym.is_lvalue; - flags = (flags << 1) | (int)sym.is_static_lifetime; - flags = (flags << 1) | (int)sym.is_thread_local; - flags = (flags << 1) | (int)sym.is_file_local; - flags = (flags << 1) | (int)sym.is_extern; - flags = (flags << 1) | (int)sym.is_volatile; + flags = (flags << 1) | static_cast(sym.is_weak); + flags = (flags << 1) | static_cast(sym.is_type); + flags = (flags << 1) | static_cast(sym.is_property); + flags = (flags << 1) | static_cast(sym.is_macro); + flags = (flags << 1) | static_cast(sym.is_exported); + flags = (flags << 1) | static_cast(sym.is_input); + flags = (flags << 1) | static_cast(sym.is_output); + flags = (flags << 1) | static_cast(sym.is_state_var); + flags = (flags << 1) | static_cast(sym.is_parameter); + flags = (flags << 1) | static_cast(sym.is_auxiliary); + flags = (flags << 1) | static_cast(false); // sym.binding; + flags = (flags << 1) | static_cast(sym.is_lvalue); + flags = (flags << 1) | static_cast(sym.is_static_lifetime); + flags = (flags << 1) | static_cast(sym.is_thread_local); + flags = (flags << 1) | static_cast(sym.is_file_local); + flags = (flags << 1) | static_cast(sym.is_extern); + flags = (flags << 1) | static_cast(sym.is_volatile); write_gb_word(out, flags); } @@ -121,8 +121,8 @@ bool write_goto_binary_v3( } } - //irepconverter.output_map(f); - //irepconverter.output_string_map(f); + // irepconverter.output_map(f); + // irepconverter.output_string_map(f); return false; } @@ -166,7 +166,7 @@ bool write_goto_binary( irepconverter); default: - throw "Unknown goto binary version"; + throw "unknown goto binary version"; } return false; diff --git a/src/goto-programs/xml_goto_trace.cpp b/src/goto-programs/xml_goto_trace.cpp index b1a5e44fb51..6469b2a2132 100644 --- a/src/goto-programs/xml_goto_trace.cpp +++ b/src/goto-programs/xml_goto_trace.cpp @@ -128,8 +128,8 @@ void convert( xml_assignment.set_attribute("step_nr", std::to_string(step.step_nr)); xml_assignment.set_attribute("assignment_type", - step.assignment_type==goto_trace_stept::ACTUAL_PARAMETER?"actual_parameter": - "state"); + step.assignment_type==goto_trace_stept::ACTUAL_PARAMETER? + "actual_parameter":"state"); if(step.lhs_object_value.is_not_nil()) xml_assignment.new_element("value_expression"). @@ -197,7 +197,8 @@ void convert( const symbolt &symbol=ns.lookup(step.identifier); xmlt &xml_function=xml_call_return.new_element("function"); - xml_function.set_attribute("display_name", id2string(symbol.display_name())); + xml_function.set_attribute( + "display_name", id2string(symbol.display_name())); xml_function.set_attribute("identifier", id2string(step.identifier)); xml_function.new_element()=xml(symbol.location); @@ -215,8 +216,10 @@ void convert( xmlt &xml_location_only=dest.new_element("location-only"); xml_location_only.set_attribute_bool("hidden", step.hidden); - xml_location_only.set_attribute("thread", std::to_string(step.thread_nr)); - xml_location_only.set_attribute("step_nr", std::to_string(step.step_nr)); + xml_location_only.set_attribute( + "thread", std::to_string(step.thread_nr)); + xml_location_only.set_attribute( + "step_nr", std::to_string(step.step_nr)); xml_location_only.new_element().swap(xml_location); } diff --git a/src/goto-symex/build_goto_trace.cpp b/src/goto-symex/build_goto_trace.cpp index 82c724cf3c5..0e0a6f07dad 100644 --- a/src/goto-symex/build_goto_trace.cpp +++ b/src/goto-symex/build_goto_trace.cpp @@ -105,7 +105,6 @@ exprt build_full_lhs_rec( tmp.op0()=build_full_lhs_rec(prop_conv, ns, tmp.op0(), src_ssa.op0()); // re-write into big case-split - } return src_original; @@ -227,7 +226,8 @@ void build_goto_trace( goto_trace_step.pc=SSA_step.source.pc; goto_trace_step.comment=SSA_step.comment; if(SSA_step.ssa_lhs.is_not_nil()) - goto_trace_step.lhs_object=ssa_exprt(SSA_step.ssa_lhs.get_original_expr()); + goto_trace_step.lhs_object= + ssa_exprt(SSA_step.ssa_lhs.get_original_expr()); else goto_trace_step.lhs_object.make_nil(); goto_trace_step.type=SSA_step.type; @@ -321,13 +321,7 @@ void build_goto_trace( s_it1++) if(s_it1->is_assert() && !s_it1->cond_value) { - s_it1++; - - for(goto_tracet::stepst::iterator - s_it2=s_it1; - s_it2!=goto_trace.steps.end(); - s_it2=goto_trace.steps.erase(s_it2)); - + goto_trace.steps.erase(++s_it1, goto_trace.steps.end()); break; } } diff --git a/src/goto-symex/goto_symex.h b/src/goto-symex/goto_symex.h index d3e162b7925..de71fcc9d09 100644 --- a/src/goto-symex/goto_symex.h +++ b/src/goto-symex/goto_symex.h @@ -244,32 +244,77 @@ class goto_symext virtual void do_simplify(exprt &expr); - //virtual void symex_block(statet &state, const codet &code); + // virtual void symex_block(statet &state, const codet &code); void symex_assign_rec(statet &state, const code_assignt &code); virtual void symex_assign(statet &state, const code_assignt &code); typedef symex_targett::assignment_typet assignment_typet; - void symex_assign_rec(statet &state, const exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_symbol(statet &state, const ssa_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_typecast(statet &state, const typecast_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_array(statet &state, const index_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_struct_member(statet &state, const member_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_if(statet &state, const if_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); - void symex_assign_byte_extract(statet &state, const byte_extract_exprt &lhs, const exprt &full_lhs, const exprt &rhs, guardt &guard, assignment_typet assignment_type); + void symex_assign_rec( + statet &state, + const exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_symbol( + statet &state, + const ssa_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_typecast( + statet &state, + const typecast_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_array( + statet &state, + const index_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_struct_member( + statet &state, + const member_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_if( + statet &state, + const if_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); + void symex_assign_byte_extract( + statet &state, + const byte_extract_exprt &lhs, + const exprt &full_lhs, + const exprt &rhs, + guardt &guard, + assignment_typet assignment_type); static exprt add_to_lhs(const exprt &lhs, const exprt &what); - virtual void symex_gcc_builtin_va_arg_next(statet &state, const exprt &lhs, const side_effect_exprt &code); - virtual void symex_malloc (statet &state, const exprt &lhs, const side_effect_exprt &code); - virtual void symex_cpp_delete (statet &state, const codet &code); - virtual void symex_cpp_new (statet &state, const exprt &lhs, const side_effect_exprt &code); - virtual void symex_fkt (statet &state, const code_function_callt &code); - virtual void symex_macro (statet &state, const code_function_callt &code); - virtual void symex_trace (statet &state, const code_function_callt &code); - virtual void symex_printf (statet &state, const exprt &lhs, const exprt &rhs); - virtual void symex_input (statet &state, const codet &code); - virtual void symex_output (statet &state, const codet &code); + virtual void symex_gcc_builtin_va_arg_next( + statet &state, const exprt &lhs, const side_effect_exprt &code); + virtual void symex_malloc( + statet &state, const exprt &lhs, const side_effect_exprt &code); + virtual void symex_cpp_delete(statet &state, const codet &code); + virtual void symex_cpp_new( + statet &state, const exprt &lhs, const side_effect_exprt &code); + virtual void symex_fkt(statet &state, const code_function_callt &code); + virtual void symex_macro(statet &state, const code_function_callt &code); + virtual void symex_trace(statet &state, const code_function_callt &code); + virtual void symex_printf(statet &state, const exprt &lhs, const exprt &rhs); + virtual void symex_input(statet &state, const codet &code); + virtual void symex_output(statet &state, const codet &code); static unsigned nondet_count; static unsigned dynamic_counter; diff --git a/src/goto-symex/goto_symex_state.cpp b/src/goto-symex/goto_symex_state.cpp index c283daca345..e1a8938d823 100644 --- a/src/goto-symex/goto_symex_state.cpp +++ b/src/goto-symex/goto_symex_state.cpp @@ -132,7 +132,8 @@ void goto_symex_statet::level1t::operator()(ssa_exprt &ssa_expr) const irep_idt l0_name=ssa_expr.get_l1_object_identifier(); current_namest::const_iterator it=current_names.find(l0_name); - if(it==current_names.end()) return; + if(it==current_names.end()) + return; // rename! ssa_expr.set_level_1(it->second.second); @@ -316,18 +317,23 @@ static bool check_renaming(const typet &type) static bool check_renaming_l1(const exprt &expr) { - if(check_renaming(expr.type())) return true; + if(check_renaming(expr.type())) + return true; if(expr.id()==ID_symbol) { - if(!expr.get_bool(ID_C_SSA_symbol)) return expr.type().id()!=ID_code; - if(!to_ssa_expr(expr).get_level_2().empty()) return true; - if(to_ssa_expr(expr).get_original_expr().type()!=expr.type()) return true; + if(!expr.get_bool(ID_C_SSA_symbol)) + return expr.type().id()!=ID_code; + if(!to_ssa_expr(expr).get_level_2().empty()) + return true; + if(to_ssa_expr(expr).get_original_expr().type()!=expr.type()) + return true; } else { forall_operands(it, expr) - if(check_renaming_l1(*it)) return true; + if(check_renaming_l1(*it)) + return true; } return false; @@ -335,7 +341,8 @@ static bool check_renaming_l1(const exprt &expr) static bool check_renaming(const exprt &expr) { - if(check_renaming(expr.type())) return true; + if(check_renaming(expr.type())) + return true; if(expr.id()==ID_address_of && expr.op0().id()==ID_symbol) @@ -346,14 +353,18 @@ static bool check_renaming(const exprt &expr) check_renaming(expr.op0().op1()); else if(expr.id()==ID_symbol) { - if(!expr.get_bool(ID_C_SSA_symbol)) return expr.type().id()!=ID_code; - if(to_ssa_expr(expr).get_level_2().empty()) return true; - if(to_ssa_expr(expr).get_original_expr().type()!=expr.type()) return true; + if(!expr.get_bool(ID_C_SSA_symbol)) + return expr.type().id()!=ID_code; + if(to_ssa_expr(expr).get_level_2().empty()) + return true; + if(to_ssa_expr(expr).get_original_expr().type()!=expr.type()) + return true; } else { forall_operands(it, expr) - if(check_renaming(*it)) return true; + if(check_renaming(*it)) + return true; } return false; @@ -507,14 +518,17 @@ void goto_symex_statet::set_ssa_indices( break; case L1: - if(!ssa_expr.get_level_2().empty()) return; - if(!ssa_expr.get_level_1().empty()) return; + if(!ssa_expr.get_level_2().empty()) + return; + if(!ssa_expr.get_level_1().empty()) + return; level0(ssa_expr, ns, source.thread_nr); level1(ssa_expr); break; case L2: - if(!ssa_expr.get_level_2().empty()) return; + if(!ssa_expr.get_level_2().empty()) + return; level0(ssa_expr, ns, source.thread_nr); level1(ssa_expr); ssa_expr.set_level_2(level2.current_count(ssa_expr.get_identifier())); @@ -621,7 +635,8 @@ void goto_symex_statet::rename( expr.type()=to_with_expr(expr).old().type(); else if(expr.id()==ID_if) { - assert(to_if_expr(expr).true_case().type()==to_if_expr(expr).false_case().type()); + assert(to_if_expr(expr).true_case().type()== + to_if_expr(expr).false_case().type()); expr.type()=to_if_expr(expr).true_case().type(); } } diff --git a/src/goto-symex/goto_symex_state.h b/src/goto-symex/goto_symex_state.h index 9915926578c..5439af37e05 100644 --- a/src/goto-symex/goto_symex_state.h +++ b/src/goto-symex/goto_symex_state.h @@ -140,7 +140,6 @@ class goto_symex_statet { values.erase(identifier); } - } propagation; typedef enum { L0=0, L1=1, L2=2 } levelt; @@ -204,7 +203,8 @@ class goto_symex_statet } // the below replicate levelt2 member functions - void level2_get_variables(std::unordered_set &vars) const + void level2_get_variables( + std::unordered_set &vars) const { for(level2t::current_namest::const_iterator it=level2_current_names.begin(); @@ -223,7 +223,8 @@ class goto_symex_statet // gotos typedef std::list goto_state_listt; - typedef std::map goto_state_mapt; + typedef std::map + goto_state_mapt; // stack frames -- these are used for function calls and // for exceptions @@ -273,40 +274,42 @@ class goto_symex_statet typedef std::vector call_stackt; - inline call_stackt &call_stack() + call_stackt &call_stack() { assert(source.thread_nr > a_s_r_entryt; - typedef std::unordered_map read_in_atomic_sectiont; + typedef std::unordered_map + read_in_atomic_sectiont; typedef std::list a_s_w_entryt; - typedef std::unordered_map written_in_atomic_sectiont; + typedef std::unordered_map + written_in_atomic_sectiont; read_in_atomic_sectiont read_in_atomic_section; written_in_atomic_sectiont written_in_atomic_section; diff --git a/src/goto-symex/memory_model_pso.h b/src/goto-symex/memory_model_pso.h index bc66f0e2aa2..386a035bdcb 100644 --- a/src/goto-symex/memory_model_pso.h +++ b/src/goto-symex/memory_model_pso.h @@ -14,7 +14,7 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk class memory_model_psot:public memory_model_tsot { public: - inline explicit memory_model_psot(const namespacet &_ns): + explicit memory_model_psot(const namespacet &_ns): memory_model_tsot(_ns) { } diff --git a/src/goto-symex/memory_model_sc.cpp b/src/goto-symex/memory_model_sc.cpp index c90a4cb813a..7c131269802 100644 --- a/src/goto-symex/memory_model_sc.cpp +++ b/src/goto-symex/memory_model_sc.cpp @@ -137,7 +137,8 @@ void memory_model_sct::thread_spawn( { per_thread_mapt::const_iterator next_thread= per_thread_map.find(++next_thread_id); - if(next_thread==per_thread_map.end()) continue; + if(next_thread==per_thread_map.end()) + continue; // add a constraint for all events, // considering regression/cbmc-concurrency/pthread_create_tso1 @@ -175,7 +176,8 @@ void memory_model_sct::thread_spawn( { per_thread_mapt::const_iterator next_thread= per_thread_map.find(++next_thread_id); - if(next_thread==per_thread_map.end()) continue; + if(next_thread==per_thread_map.end()) + continue; // For SC and several weaker memory models a memory barrier // at the beginning of a thread can simply be ignored, because @@ -187,7 +189,8 @@ void memory_model_sct::thread_spawn( n_it!=next_thread->second.end() && (*n_it)->is_memory_barrier(); ++n_it) - ; + { + } if(n_it!=next_thread->second.end()) add_constraint( @@ -419,7 +422,6 @@ void memory_model_sct::from_read(symex_target_equationt &equation) add_constraint(equation, cond, "fr", r->source); } - } } } diff --git a/src/goto-symex/memory_model_sc.h b/src/goto-symex/memory_model_sc.h index 9d665f86f8d..66709ae22be 100644 --- a/src/goto-symex/memory_model_sc.h +++ b/src/goto-symex/memory_model_sc.h @@ -14,7 +14,7 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk class memory_model_sct:public memory_model_baset { public: - inline explicit memory_model_sct(const namespacet &_ns): + explicit memory_model_sct(const namespacet &_ns): memory_model_baset(_ns) { } diff --git a/src/goto-symex/memory_model_tso.h b/src/goto-symex/memory_model_tso.h index 6cd2639acef..11de873e02a 100644 --- a/src/goto-symex/memory_model_tso.h +++ b/src/goto-symex/memory_model_tso.h @@ -14,7 +14,7 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk class memory_model_tsot:public memory_model_sct { public: - inline explicit memory_model_tsot(const namespacet &_ns): + explicit memory_model_tsot(const namespacet &_ns): memory_model_sct(_ns) { } diff --git a/src/goto-symex/partial_order_concurrency.cpp b/src/goto-symex/partial_order_concurrency.cpp index f5168745788..7ec03afab34 100644 --- a/src/goto-symex/partial_order_concurrency.cpp +++ b/src/goto-symex/partial_order_concurrency.cpp @@ -82,7 +82,8 @@ void partial_order_concurrencyt::add_init_writes( const irep_idt &a=address(e_it); - if(init_done.find(a)!=init_done.end()) continue; + if(init_done.find(a)!=init_done.end()) + continue; if(spawn_seen || e_it->is_shared_read() || @@ -159,7 +160,8 @@ void partial_order_concurrencyt::build_event_lists( a_it++) { const a_rect &a_rec=a_it->second; - if(a_rec.reads.empty()) continue; + if(a_rec.reads.empty()) + continue; statistics() << "Shared " << a_it->first << ": " << a_rec.reads.size() << "R/" @@ -265,11 +267,13 @@ Function: partial_order_concurrencyt::before exprt partial_order_concurrencyt::before( event_it e1, event_it e2, unsigned axioms) { - const axiomt axiom_bits[]={ + const axiomt axiom_bits[]= + { AX_SC_PER_LOCATION, AX_NO_THINAIR, AX_OBSERVATION, - AX_PROPAGATION }; + AX_PROPAGATION + }; exprt::operandst ops; ops.reserve(sizeof(axiom_bits)/sizeof(axiomt)); @@ -278,7 +282,8 @@ exprt partial_order_concurrencyt::before( { const axiomt ax=axiom_bits[i]; - if((axioms & ax)==0) continue; + if((axioms &ax)==0) + continue; if(e1->atomic_section_id!=0 && e1->atomic_section_id==e2->atomic_section_id) diff --git a/src/goto-symex/partial_order_concurrency.h b/src/goto-symex/partial_order_concurrency.h index 425b31618b0..c18c8925d42 100644 --- a/src/goto-symex/partial_order_concurrency.h +++ b/src/goto-symex/partial_order_concurrency.h @@ -24,7 +24,8 @@ class partial_order_concurrencyt:public messaget typedef eventst::const_iterator event_it; // the name of a clock variable for a shared read/write - typedef enum { + typedef enum + { AX_SC_PER_LOCATION=1, AX_NO_THINAIR=2, AX_OBSERVATION=4, @@ -63,7 +64,7 @@ class partial_order_concurrencyt:public messaget } // produces an address ID for an event - inline irep_idt address(event_it event) const + irep_idt address(event_it event) const { ssa_exprt tmp=event->ssa_lhs; tmp.remove_level_2(); @@ -85,7 +86,6 @@ class partial_order_concurrencyt:public messaget // the partial order constraint for two events exprt before(event_it e1, event_it e2, unsigned axioms); virtual exprt before(event_it e1, event_it e2)=0; - }; #if 0 @@ -104,6 +104,7 @@ class numbered_evtst public: typedef std::vector ordered_evtst; + // NOLINTNEXTLINE(readability/identifiers) typedef ordered_evtst::const_iterator const_iterator; typedef std::map ordered_evts_mapt; @@ -190,7 +191,8 @@ class partial_order_concurrencyt { public: // the is-acyclic checks - typedef enum { + typedef enum + { AC_UNIPROC=0, AC_THINAIR=1, AC_GHB=2, @@ -256,7 +258,7 @@ class partial_order_concurrencyt const std::string &po_name, const evtt &n1, const evtt &n2, - const exprt& cond); + const exprt &cond); void add_partial_order_constraint( const acyclict check, const std::string &po_name, @@ -266,17 +268,17 @@ class partial_order_concurrencyt const evtt &n2, const unsigned n2_step, const evtt::event_dirt n2_o_d, - const exprt& cond); + const exprt &cond); const evtt* first_of(const evtt &e1, const evtt &e2) const; - const numbered_evtst& get_thread(const evtt &e) const; - const numbered_per_thread_evtst& get_all_threads() const + const numbered_evtst &get_thread(const evtt &e) const; + const numbered_per_thread_evtst &get_all_threads() const { return per_thread_evt_no; } - const namespacet& get_ns() const { return ns; } - messaget& get_message() { return message; } + const namespacet &get_ns() const { return ns; } + messaget &get_message() { return message; } std::map num_concurrency_constraints; private: @@ -301,16 +303,18 @@ class partial_order_concurrencyt // map between events and (symbolic) integers typet node_type; std::map barrier_id; - inline symbol_exprt node_symbol( + symbol_exprt node_symbol( const evtt &evt, const std::string &prefix) const; - std::vector > atomic_section_bounds[AC_N_AXIOMS]; + std::vector> + atomic_section_bounds[AC_N_AXIOMS]; std::list acyclic_constraints[AC_N_AXIOMS]; static std::string check_to_string(const acyclict check); // map point-wise order to a single Boolean symbol - typedef std::pair > evt_dir_pairt; + typedef std::pair> + evt_dir_pairt; typedef std::map, symbol_exprt> pointwise_mapt; pointwise_mapt edge_cache[AC_N_AXIOMS]; @@ -353,7 +357,7 @@ class partial_order_concurrencyt void print_graph( const adj_matrixt &graph, const std::string &edge_label, - namespacet const& ns) const; + namespacet const &ns) const; }; #endif diff --git a/src/goto-symex/postcondition.cpp b/src/goto-symex/postcondition.cpp index d290a6335b6..c93aa52a407 100644 --- a/src/goto-symex/postcondition.cpp +++ b/src/goto-symex/postcondition.cpp @@ -81,7 +81,8 @@ void postcondition( { postconditiont postcondition(ns, value_set, *it, s); postcondition.compute(dest); - if(dest.is_false()) return; + if(dest.is_false()) + return; } } diff --git a/src/goto-symex/precondition.cpp b/src/goto-symex/precondition.cpp index 4c392e57d94..15cc3e180a2 100644 --- a/src/goto-symex/precondition.cpp +++ b/src/goto-symex/precondition.cpp @@ -84,7 +84,8 @@ void precondition( { preconditiont precondition(ns, value_sets, target, *it, s); precondition.compute(dest); - if(dest.is_false()) return; + if(dest.is_false()) + return; } } diff --git a/src/goto-symex/slice.cpp b/src/goto-symex/slice.cpp index 5e2594c656d..ab377e2d9c9 100644 --- a/src/goto-symex/slice.cpp +++ b/src/goto-symex/slice.cpp @@ -386,8 +386,10 @@ void simple_slice(symex_target_equationt &equation) last_assertion; if(s_it!=equation.SSA_steps.end()) + { for(s_it++; s_it!=equation.SSA_steps.end(); s_it++) s_it->ignore=true; + } } diff --git a/src/goto-symex/slice_by_trace.cpp b/src/goto-symex/slice_by_trace.cpp index 922f66b3eb5..096edf8ae38 100644 --- a/src/goto-symex/slice_by_trace.cpp +++ b/src/goto-symex/slice_by_trace.cpp @@ -33,70 +33,78 @@ Function: slice_by_trace \*******************************************************************/ -void symex_slice_by_tracet::slice_by_trace(std::string trace_files, - symex_target_equationt &equation) +void symex_slice_by_tracet::slice_by_trace( + std::string trace_files, + symex_target_equationt &equation) { std::cout << "Slicing by trace..." << std::endl; - merge_identifier = "goto_symex::\\merge"; + merge_identifier="goto_symex::\\merge"; merge_symbol=symbol_exprt(typet(ID_bool)); merge_symbol.set_identifier(merge_identifier); std::vector trace_conditions; - size_t length = trace_files.length(); - for(size_t idx = 0; idx < length; idx++) { - const std::string::size_type next = trace_files.find(",", idx); - std::string filename = trace_files.substr(idx, next - idx); + size_t length=trace_files.length(); + for(size_t idx=0; idx < length; idx++) + { + const std::string::size_type next=trace_files.find(",", idx); + std::string filename=trace_files.substr(idx, next - idx); read_trace(filename); compute_ts_back(equation); - exprt t_copy (t[0]); + exprt t_copy(t[0]); trace_conditions.push_back(t_copy); - if(next == std::string::npos) break; - idx = next; + if(next==std::string::npos) + break; + idx=next; } exprt trace_condition; - if (trace_conditions.size() == 1) { - trace_condition = trace_conditions[0]; - } else { - trace_condition = exprt(ID_and, typet(ID_bool)); + if(trace_conditions.size()==1) + { + trace_condition=trace_conditions[0]; + } + else + { + trace_condition=exprt(ID_and, typet(ID_bool)); trace_condition.operands().reserve(trace_conditions.size()); - for (std::vector::iterator i = trace_conditions.begin(); - i != trace_conditions.end(); i++) { + for(std::vector::iterator i=trace_conditions.begin(); + i!=trace_conditions.end(); i++) + { trace_condition.move_to_operands(*i); } } simplify(trace_condition, ns); - std::set implications = implied_guards(trace_condition); + std::set implications=implied_guards(trace_condition); - for(std::set::iterator i = sliced_guards.begin(); i != + for(std::set::iterator i=sliced_guards.begin(); i != sliced_guards.end(); i++) { - exprt g_copy (*i); + exprt g_copy(*i); - if (g_copy.id() == ID_symbol || g_copy.id() == ID_not) + if(g_copy.id()==ID_symbol || g_copy.id() == ID_not) { g_copy.make_not(); simplify(g_copy, ns); implications.insert(g_copy); } - else if (g_copy.id() == ID_and) + else if(g_copy.id()==ID_and) { - exprt copy_last (g_copy.operands().back()); + exprt copy_last(g_copy.operands().back()); copy_last.make_not(); simplify(copy_last, ns); implications.insert(copy_last); } - else if (!(g_copy.id() == ID_constant)) { - throw "Guards should only be and, symbol, constant, or not."; + else if(!(g_copy.id()==ID_constant)) + { + throw "guards should only be and, symbol, constant, or `not'"; } } @@ -106,7 +114,7 @@ void symex_slice_by_tracet::slice_by_trace(std::string trace_files, t_guard.make_true(); symex_targett::sourcet empty_source; equation.SSA_steps.push_front(symex_target_equationt::SSA_stept()); - symex_target_equationt::SSA_stept &SSA_step = equation.SSA_steps.front(); + symex_target_equationt::SSA_stept &SSA_step=equation.SSA_steps.front(); SSA_step.guard=t_guard.as_expr(); SSA_step.ssa_lhs.make_nil(); @@ -135,8 +143,8 @@ void symex_slice_by_tracet::read_trace(std::string filename) { std::cout << "Reading trace from file " << filename << std::endl; std::ifstream file(filename); - if (file.fail()) - throw "Failed to read from trace file."; + if(file.fail()) + throw "failed to read from trace file"; // In case not the first trace read alphabet.clear(); @@ -145,30 +153,33 @@ void symex_slice_by_tracet::read_trace(std::string filename) t.clear(); std::string read_line; - bool done = false; - bool begin = true; - alphabet_parity = true; + bool done=false; + bool begin=true; + alphabet_parity=true; - while (!done && !file.eof ()) { + while(!done && !file.eof()) + { std::getline(file, read_line); - if (begin && (read_line == "!")) - alphabet_parity = false; + if(begin && (read_line=="!")) + alphabet_parity=false; else - done = parse_alphabet(read_line); + done=parse_alphabet(read_line); } - while (!file.eof ()) { - std::getline(file,read_line); + while(!file.eof()) + { + std::getline(file, read_line); parse_events(read_line); } - for (size_t i = 0; i < sigma.size(); i++) { - exprt f_e = static_cast(get_nil_irep()); + for(size_t i=0; i < sigma.size(); i++) + { + exprt f_e=static_cast(get_nil_irep()); f_e=false_exprt(); t.push_back(f_e); } - exprt t_e = static_cast(get_nil_irep()); + exprt t_e=static_cast(get_nil_irep()); t_e=true_exprt(); t.push_back(t_e); } @@ -185,15 +196,19 @@ Function: parse_alphabet \*******************************************************************/ -bool symex_slice_by_tracet::parse_alphabet(std::string read_line) { - if ((read_line == ":") || (read_line == ":exact") || - (read_line == ":suffix") || (read_line == ":exact-suffix") || - (read_line == ":prefix")) { - semantics = read_line; +bool symex_slice_by_tracet::parse_alphabet(std::string read_line) +{ + if((read_line==":") || (read_line == ":exact") || + (read_line==":suffix") || (read_line == ":exact-suffix") || + (read_line==":prefix")) + { + semantics=read_line; return true; - } else { + } + else + { std::cout << "Alphabet: "; - if (!alphabet_parity) + if(!alphabet_parity) std::cout << "!"; std::cout << read_line << std::endl; alphabet.insert(read_line); @@ -213,45 +228,51 @@ Function: parse_events \*******************************************************************/ -void symex_slice_by_tracet::parse_events(std::string read_line) { - if (read_line == "") +void symex_slice_by_tracet::parse_events(std::string read_line) +{ + if(read_line=="") return; - bool parity = strstr(read_line.c_str(),"!")==NULL; - bool universe = strstr(read_line.c_str(),"?")!=NULL; - bool has_values = strstr(read_line.c_str()," ")!=NULL; + bool parity=strstr(read_line.c_str(), "!")==NULL; + bool universe=strstr(read_line.c_str(), "?")!=NULL; + bool has_values=strstr(read_line.c_str(), " ")!=NULL; std::cout << "Trace: " << read_line << std::endl; std::vector value_v; - if (has_values) { - std::string::size_type sloc = read_line.find(" ",0); - std::string values = (read_line.substr(sloc, read_line.size()-1)); - size_t length = values.length(); - for(size_t idx = 0; idx < length; idx++) { - const std::string::size_type next = values.find(",", idx); - std::string value = values.substr(idx, next - idx); + if(has_values) + { + std::string::size_type sloc=read_line.find(" ", 0); + std::string values=(read_line.substr(sloc, read_line.size()-1)); + size_t length=values.length(); + for(size_t idx=0; idx < length; idx++) + { + const std::string::size_type next=values.find(",", idx); + std::string value=values.substr(idx, next - idx); value_v.push_back(value); - if(next == std::string::npos) break; - idx = next; + if(next==std::string::npos) + break; + idx=next; } - read_line = read_line.substr(0,sloc); + read_line=read_line.substr(0, sloc); } sigma_vals.push_back(value_v); - if (universe) - parity = false; - if (!parity) - read_line = read_line.substr(1,read_line.size()-1); + if(universe) + parity=false; + if(!parity) + read_line=read_line.substr(1, read_line.size()-1); std::set eis; - size_t vlength = read_line.length(); - for(size_t vidx = 0; vidx < vlength; vidx++) { - const std::string::size_type vnext = read_line.find(",", vidx); - std::string event = read_line.substr(vidx, vnext - vidx); + size_t vlength=read_line.length(); + for(size_t vidx=0; vidx < vlength; vidx++) + { + const std::string::size_type vnext=read_line.find(",", vidx); + std::string event=read_line.substr(vidx, vnext - vidx); eis.insert(event); - if ((!alphabet.empty()) && ((alphabet.count(event) != 0) != - alphabet_parity)) - throw ("Trace uses symbol not in alphabet: " + event); - if(vnext == std::string::npos) break; - vidx = vnext; + if((!alphabet.empty()) && + ((alphabet.count(event)!=0)!=alphabet_parity)) + throw "trace uses symbol not in alphabet: "+event; + if(vnext==std::string::npos) + break; + vidx=vnext; } - event_sett es = event_sett(eis, parity); + event_sett es=event_sett(eis, parity); sigma.push_back(es); } @@ -270,7 +291,7 @@ Function: compute_ts_back void symex_slice_by_tracet::compute_ts_back( symex_target_equationt &equation) { - size_t merge_count = 0; + size_t merge_count=0; for(symex_target_equationt::SSA_stepst::reverse_iterator i=equation.SSA_steps.rbegin(); @@ -281,108 +302,126 @@ void symex_slice_by_tracet::compute_ts_back( !i->io_args.empty() && i->io_args.front().id()=="trace_event") { - irep_idt event = i->io_args.front().get("event"); + irep_idt event=i->io_args.front().get("event"); - if (!alphabet.empty()) + if(!alphabet.empty()) { - bool present = (alphabet.count(event) != 0); - if (alphabet_parity != present) + bool present=(alphabet.count(event)!=0); + if(alphabet_parity!=present) continue; } - exprt guard = i->guard; + exprt guard=i->guard; #if 0 std::cout << "EVENT: " << event << std::endl; std::cout << "GUARD: " << from_expr(ns, "", guard) << std::endl; - for (size_t j = 0; j < t.size(); j++) { - std::cout << "t[" << j << "] = " << from_expr(ns, "", t[j]) << + for(size_t j=0; j < t.size(); j++) + { + std::cout << "t[" << j << "]=" << from_expr(ns, "", t[j]) << std::endl; } #endif - bool slice_this = (semantics != ":prefix"); + bool slice_this=(semantics!=":prefix"); std::vector merge; - for(size_t j = 0; j < t.size(); j++) { - if ((t[j].is_true()) || (t[j].is_false())) { + for(size_t j=0; j < t.size(); j++) + { + if((t[j].is_true()) || (t[j].is_false())) + { merge.push_back(t[j]); - } else { + } + else + { ssa_exprt merge_sym(merge_symbol); merge_sym.set_level_2(merge_count++); - exprt t_copy (t[j]); + exprt t_copy(t[j]); merge_map_back.push_back(t_copy); std::set empty_impls; merge_impl_cache_back.push_back - (std::pair >(false, empty_impls)); + (std::pair >(false, empty_impls)); merge.push_back(merge_sym); } } - for(size_t j = 0; j < t.size(); j++) { - exprt u_lhs = exprt(ID_and, typet(ID_bool)); - if ((j < sigma.size()) && (matches(sigma[j],event))) { + for(size_t j=0; j < t.size(); j++) + { + exprt u_lhs=exprt(ID_and, typet(ID_bool)); + if((j < sigma.size()) && (matches(sigma[j], event))) + { u_lhs.operands().reserve(2); u_lhs.copy_to_operands(guard); - if (!sigma_vals[j].empty()) { + if(!sigma_vals[j].empty()) + { std::list eq_conds; - std::list::iterator pvi = i->io_args.begin(); - for (std::vector::iterator k = sigma_vals[j].begin(); - k != sigma_vals[j].end(); k++) { - + std::list::iterator pvi=i->io_args.begin(); + for(std::vector::iterator k=sigma_vals[j].begin(); + k!=sigma_vals[j].end(); k++) + { exprt equal_cond=exprt(ID_equal, bool_typet()); equal_cond.operands().reserve(2); equal_cond.copy_to_operands(*pvi); // Should eventually change to handle non-bv types! - exprt constant_value=from_integer(unsafe_string2int(id2string(*k)), (*pvi).type()); + exprt constant_value= + from_integer(unsafe_string2int(id2string(*k)), (*pvi).type()); equal_cond.move_to_operands(constant_value); eq_conds.push_back(equal_cond); pvi++; } - exprt val_merge = exprt(ID_and, typet(ID_bool)); + exprt val_merge=exprt(ID_and, typet(ID_bool)); val_merge.operands().reserve(eq_conds.size()+1); val_merge.copy_to_operands(merge[j+1]); - for (std::list::iterator k = eq_conds.begin(); - k!= eq_conds.end(); k++) { + for(std::list::iterator k=eq_conds.begin(); + k!= eq_conds.end(); k++) + { val_merge.copy_to_operands(*k); } u_lhs.move_to_operands(val_merge); - } else { + } + else + { u_lhs.copy_to_operands(merge[j+1]); } simplify(u_lhs, ns); - if ((!u_lhs.is_false()) && implies_false(u_lhs)) + if((!u_lhs.is_false()) && implies_false(u_lhs)) u_lhs=false_exprt(); - if (!u_lhs.is_false()) - slice_this = false; - } else { + if(!u_lhs.is_false()) + slice_this=false; + } + else + { u_lhs=false_exprt(); } - exprt u_rhs = exprt (ID_and, typet(ID_bool)); - if ((semantics != ":suffix") || (j != 0)) { + exprt u_rhs=exprt(ID_and, typet(ID_bool)); + if((semantics!=":suffix") || (j != 0)) + { u_rhs.operands().reserve(2); u_rhs.copy_to_operands(guard); u_rhs.copy_to_operands(merge[j]); u_rhs.op0().make_not(); - } else { + } + else + { u_rhs.swap(merge[j]); } - exprt u_j = exprt (ID_or, typet(ID_bool)); + exprt u_j=exprt(ID_or, typet(ID_bool)); u_j.operands().reserve(2); u_j.copy_to_operands(u_lhs); u_j.copy_to_operands(u_rhs); simplify(u_j, ns); - t[j] = u_j; + t[j]=u_j; } - if (semantics == ":prefix") + if(semantics==":prefix") t[t.size()-1]=true_exprt(); - if (slice_this) { + if(slice_this) + { exprt guard_copy(guard); sliced_guards.insert(guard_copy); @@ -424,68 +463,72 @@ void symex_slice_by_tracet::slice_SSA_steps( symex_target_equationt &equation, std::set implications) { - //Some statistics for our benefit. - size_t conds_seen = 0; - size_t sliced_SSA_steps = 0; - size_t potential_SSA_steps = 0; - size_t sliced_conds = 0; - size_t trace_SSA_steps = 0; - size_t location_SSA_steps = 0; - size_t trace_loc_sliced = 0; + // Some statistics for our benefit. + size_t conds_seen=0; + size_t sliced_SSA_steps=0; + size_t potential_SSA_steps=0; + size_t sliced_conds=0; + size_t trace_SSA_steps=0; + size_t location_SSA_steps=0; + size_t trace_loc_sliced=0; for(symex_target_equationt::SSA_stepst::iterator it=equation.SSA_steps.begin(); it!=equation.SSA_steps.end(); it++) { - if (it->is_output()) + if(it->is_output()) trace_SSA_steps++; - if (it->is_location()) + if(it->is_location()) location_SSA_steps++; - bool sliced_SSA_step = false; + bool sliced_SSA_step=false; exprt guard=it->guard; simplify(guard, ns); - if (!guard.is_true()) + if(!guard.is_true()) potential_SSA_steps++; - //it->output(ns,std::cout); - //std::cout << "-----------------" << std::endl; + // it->output(ns,std::cout); + // std::cout << "-----------------" << std::endl; - if ((guard.id() == ID_symbol) || (guard.id() == ID_not)) + if((guard.id()==ID_symbol) || (guard.id() == ID_not)) { guard.make_not(); simplify(guard, ns); - if (implications.count(guard) != 0) { + if(implications.count(guard)!=0) + { it->cond_expr=true_exprt(); it->ssa_rhs=true_exprt(); it->guard=false_exprt(); sliced_SSA_steps++; - if (it->is_output() || it->is_location()) + if(it->is_output() || it->is_location()) trace_loc_sliced++; - sliced_SSA_step = true; + sliced_SSA_step=true; } } else if(guard.id()==ID_and) { - Forall_operands(git,guard) + Forall_operands(git, guard) { exprt neg_expr=*git; neg_expr.make_not(); simplify(neg_expr, ns); - if (implications.count(neg_expr) != 0) { + if(implications.count(neg_expr)!=0) + { it->cond_expr=true_exprt(); it->ssa_rhs=true_exprt(); it->guard=false_exprt(); sliced_SSA_steps++; - if (it->is_output() || it->is_location()) + if(it->is_output() || it->is_location()) trace_loc_sliced++; - sliced_SSA_step = true; + sliced_SSA_step=true; break; // Sliced, so no need to consider the rest } - } else if (guard.id() == ID_or) { + } + else if(guard.id()==ID_or) + { std::cout << "Guarded by an OR." << std::endl; } } @@ -495,25 +538,27 @@ void symex_slice_by_tracet::slice_SSA_steps( if(it->ssa_rhs.id()==ID_if) { conds_seen++; - exprt cond_copy (it->ssa_rhs.op0()); + exprt cond_copy(it->ssa_rhs.op0()); simplify(cond_copy, ns); - if (implications.count(cond_copy) != 0) { + if(implications.count(cond_copy)!=0) + { sliced_conds++; - exprt t_copy1 (it->ssa_rhs.op1()); - exprt t_copy2 (it->ssa_rhs.op1()); - it->ssa_rhs = t_copy1; + exprt t_copy1(it->ssa_rhs.op1()); + exprt t_copy2(it->ssa_rhs.op1()); + it->ssa_rhs=t_copy1; it->cond_expr.op1().swap(t_copy2); } else { cond_copy.make_not(); simplify(cond_copy, ns); - if (implications.count(cond_copy) != 0) { + if(implications.count(cond_copy)!=0) + { sliced_conds++; - exprt f_copy1 (it->ssa_rhs.op2()); - exprt f_copy2 (it->ssa_rhs.op2()); - it->ssa_rhs = f_copy1; + exprt f_copy1(it->ssa_rhs.op2()); + exprt f_copy2(it->ssa_rhs.op2()); + it->ssa_rhs=f_copy1; it->cond_expr.op1().swap(f_copy2); } } @@ -527,7 +572,7 @@ void symex_slice_by_tracet::slice_SSA_steps( std::cout << " (" << ((sliced_SSA_steps + sliced_conds) - trace_loc_sliced) << " out of " - << (equation.SSA_steps.size() - trace_SSA_steps - location_SSA_steps) + << (equation.SSA_steps.size()-trace_SSA_steps-location_SSA_steps) << " non-trace, non-location SSA_steps)" << std::endl; } @@ -547,7 +592,7 @@ bool symex_slice_by_tracet::matches( event_sett s, irep_idt event) { - bool present = s.first.count(event) != 0; + bool present=s.first.count(event)!=0; return ((s.second && present) || (!s.second && !present)); } @@ -566,9 +611,10 @@ Function: assign_merges void symex_slice_by_tracet::assign_merges( symex_target_equationt &equation) { - size_t merge_count = (merge_map_back.size()) - 1; - for (std::vector::reverse_iterator i = merge_map_back.rbegin(); - i != merge_map_back.rend(); i++) { + size_t merge_count=(merge_map_back.size()) - 1; + for(std::vector::reverse_iterator i=merge_map_back.rbegin(); + i!=merge_map_back.rend(); i++) + { ssa_exprt merge_sym(merge_symbol); merge_sym.set_level_2(merge_count); merge_count--; @@ -579,7 +625,7 @@ void symex_slice_by_tracet::assign_merges( exprt merge_copy(*i); equation.SSA_steps.push_front(symex_target_equationt::SSA_stept()); - symex_target_equationt::SSA_stept &SSA_step = equation.SSA_steps.front(); + symex_target_equationt::SSA_stept &SSA_step=equation.SSA_steps.front(); SSA_step.guard=t_guard.as_expr(); SSA_step.ssa_lhs=merge_sym; @@ -608,13 +654,13 @@ std::set symex_slice_by_tracet::implied_guards(exprt e) { std::set s; - if (e.id() == ID_symbol) + if(e.id()==ID_symbol) { // Guard or merge const std::string &id_string=id2string(e.get(ID_identifier)); std::string::size_type merge_loc=id_string.find("merge#"); if(merge_loc==std::string::npos) { - exprt e_copy (e); + exprt e_copy(e); simplify(e_copy, ns); s.insert(e_copy); return s; @@ -622,52 +668,64 @@ std::set symex_slice_by_tracet::implied_guards(exprt e) else { int i=unsafe_string2int(id_string.substr(merge_loc+6)); - if (merge_impl_cache_back[i].first) + if(merge_impl_cache_back[i].first) { return merge_impl_cache_back[i].second; } else { - merge_impl_cache_back[i].first = true; - exprt merge_copy (merge_map_back[i]); - merge_impl_cache_back[i].second = implied_guards(merge_copy); + merge_impl_cache_back[i].first=true; + exprt merge_copy(merge_map_back[i]); + merge_impl_cache_back[i].second=implied_guards(merge_copy); return merge_impl_cache_back[i].second; } } - } else if (e.id() == ID_not) { // Definitely a guard + } + else if(e.id()==ID_not) + { // Definitely a guard exprt e_copy(e); simplify(e_copy, ns); s.insert(e_copy); return s; - } else if (e.id() == ID_and) { // Descend into and - Forall_operands(it,e) { - std::set r = implied_guards(*it); - for (std::set::iterator i = r.begin(); - i != r.end(); i++) { + } + else if(e.id()==ID_and) + { // Descend into and + Forall_operands(it, e) + { + std::set r=implied_guards(*it); + for(std::set::iterator i=r.begin(); + i!=r.end(); i++) + { s.insert(*i); } } return s; - } else if (e.id() == ID_or) { // Descend into or + } + else if(e.id()==ID_or) + { // Descend into or std::vector > rs; - Forall_operands(it,e) { + Forall_operands(it, e) + { rs.push_back(implied_guards(*it)); } - for (std::set::iterator i = rs.front().begin(); - i != rs.front().end();) { - for (std::vector >::iterator j = rs.begin(); - j != rs.end(); j++) { - if (j == rs.begin()) + for(std::set::iterator i=rs.front().begin(); + i!=rs.front().end();) + { + for(std::vector >::iterator j=rs.begin(); + j!=rs.end(); j++) + { + if(j==rs.begin()) j++; - std::set::iterator k = i; + std::set::iterator k=i; i++; - if (j->count(*k) == 0) { + if(j->count(*k)==0) + { rs.front().erase(k); break; } } } - s = rs.front(); + s=rs.front(); return s; } @@ -688,16 +746,16 @@ Function: symex_slice_by_tracet::implies_false bool symex_slice_by_tracet::implies_false(const exprt e) { - std::set imps = implied_guards(e); + std::set imps=implied_guards(e); for(std::set::iterator i=imps.begin(); i!=imps.end(); i++) { - exprt i_copy (*i); + exprt i_copy(*i); i_copy.make_not(); simplify(i_copy, ns); - if (imps.count(i_copy) != 0) + if(imps.count(i_copy)!=0) return true; } diff --git a/src/goto-symex/slice_by_trace.h b/src/goto-symex/slice_by_trace.h index 841f8bb1a47..8223e6589e1 100644 --- a/src/goto-symex/slice_by_trace.h +++ b/src/goto-symex/slice_by_trace.h @@ -14,12 +14,13 @@ Author: Alex Groce (agroce@gmail.com) class symex_slice_by_tracet { public: - symex_slice_by_tracet(const namespacet &_ns):ns(_ns) + explicit symex_slice_by_tracet(const namespacet &_ns):ns(_ns) { } - void slice_by_trace(std::string trace_files, - symex_target_equationt &equation); + void slice_by_trace( + std::string trace_files, + symex_target_equationt &equation); protected: const namespacet &ns; @@ -69,9 +70,9 @@ class symex_slice_by_tracet void assign_merges(symex_target_equationt &equation); - std::set implied_guards (exprt e); + std::set implied_guards(exprt e); - bool implies_false (exprt e); + bool implies_false(exprt e); }; #endif // CPROVER_GOTO_SYMEX_SLICE_BY_TRACE_H diff --git a/src/goto-symex/symex_assign.cpp b/src/goto-symex/symex_assign.cpp index b8200280648..795e1240f32 100644 --- a/src/goto-symex/symex_assign.cpp +++ b/src/goto-symex/symex_assign.cpp @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "goto_symex.h" #include "goto_symex_state.h" -//#define USE_UPDATE +// #define USE_UPDATE /*******************************************************************\ @@ -178,26 +178,33 @@ void goto_symext::symex_assign_rec( { if(lhs.id()==ID_symbol && lhs.get_bool(ID_C_SSA_symbol)) - symex_assign_symbol(state, to_ssa_expr(lhs), full_lhs, rhs, guard, assignment_type); + symex_assign_symbol( + state, to_ssa_expr(lhs), full_lhs, rhs, guard, assignment_type); else if(lhs.id()==ID_index) - symex_assign_array(state, to_index_expr(lhs), full_lhs, rhs, guard, assignment_type); + symex_assign_array( + state, to_index_expr(lhs), full_lhs, rhs, guard, assignment_type); else if(lhs.id()==ID_member) { const typet &type=ns.follow(to_member_expr(lhs).struct_op().type()); if(type.id()==ID_struct) - symex_assign_struct_member(state, to_member_expr(lhs), full_lhs, rhs, guard, assignment_type); + symex_assign_struct_member( + state, to_member_expr(lhs), full_lhs, rhs, guard, assignment_type); else if(type.id()==ID_union) { // should have been replaced by byte_extract throw "symex_assign_rec: unexpected assignment to union member"; } else - throw "symex_assign_rec: unexpected assignment to member of `"+type.id_string()+"'"; + throw + "symex_assign_rec: unexpected assignment to member of `"+ + type.id_string()+"'"; } else if(lhs.id()==ID_if) - symex_assign_if(state, to_if_expr(lhs), full_lhs, rhs, guard, assignment_type); + symex_assign_if( + state, to_if_expr(lhs), full_lhs, rhs, guard, assignment_type); else if(lhs.id()==ID_typecast) - symex_assign_typecast(state, to_typecast_expr(lhs), full_lhs, rhs, guard, assignment_type); + symex_assign_typecast( + state, to_typecast_expr(lhs), full_lhs, rhs, guard, assignment_type); else if(lhs.id()==ID_string_constant || lhs.id()=="NULL-object" || lhs.id()=="zero_string" || @@ -232,7 +239,8 @@ void goto_symext::symex_assign_rec( new_rhs.op1()=rhs; } - symex_assign_rec(state, lhs.op0(), full_lhs, new_rhs, guard, assignment_type); + symex_assign_rec( + state, lhs.op0(), full_lhs, new_rhs, guard, assignment_type); } else throw "assignment to `"+lhs.id_string()+"' not handled"; @@ -275,7 +283,12 @@ void goto_symext::symex_assign_symbol( do_simplify(ssa_rhs); ssa_exprt ssa_lhs=lhs; - state.assignment(ssa_lhs, ssa_rhs, ns, options.get_bool_option("simplify"), constant_propagation); + state.assignment( + ssa_lhs, + ssa_rhs, + ns, + options.get_bool_option("simplify"), + constant_propagation); exprt ssa_full_lhs=full_lhs; ssa_full_lhs=add_to_lhs(ssa_full_lhs, ssa_lhs); @@ -289,7 +302,8 @@ void goto_symext::symex_assign_symbol( // do the assignment const symbolt &symbol=ns.lookup(ssa_lhs.get_original_expr()); - if(symbol.is_auxiliary) assignment_type=symex_targett::HIDDEN; + if(symbol.is_auxiliary) + assignment_type=symex_targett::HIDDEN; target.assignment( tmp_guard.as_expr(), @@ -518,14 +532,16 @@ void goto_symext::symex_assign_if( if(!renamed_guard.is_false()) { guard.add(renamed_guard); - symex_assign_rec(state, lhs.true_case(), full_lhs, rhs, guard, assignment_type); + symex_assign_rec( + state, lhs.true_case(), full_lhs, rhs, guard, assignment_type); guard.swap(old_guard); } if(!renamed_guard.is_true()) { guard.add(not_exprt(renamed_guard)); - symex_assign_rec(state, lhs.false_case(), full_lhs, rhs, guard, assignment_type); + symex_assign_rec( + state, lhs.false_case(), full_lhs, rhs, guard, assignment_type); guard.swap(old_guard); } } diff --git a/src/goto-symex/symex_atomic_section.cpp b/src/goto-symex/symex_atomic_section.cpp index 40a47dcfb87..7f4e239f676 100644 --- a/src/goto-symex/symex_atomic_section.cpp +++ b/src/goto-symex/symex_atomic_section.cpp @@ -22,7 +22,8 @@ Function: goto_symext::symex_atomic_begin void goto_symext::symex_atomic_begin(statet &state) { - if(state.guard.is_false()) return; + if(state.guard.is_false()) + return; // we don't allow any nesting of atomic sections if(state.atomic_section_id!=0) @@ -53,10 +54,11 @@ Function: goto_symext::symex_atomic_end void goto_symext::symex_atomic_end(statet &state) { - if(state.guard.is_false()) return; + if(state.guard.is_false()) + return; if(state.atomic_section_id==0) - throw "ATOMIC_END unmatched"; + throw "ATOMIC_END unmatched"; // NOLINT(readability/throw) const unsigned atomic_section_id=state.atomic_section_id; state.atomic_section_id=0; diff --git a/src/goto-symex/symex_builtin_functions.cpp b/src/goto-symex/symex_builtin_functions.cpp index 92b269f9405..c5bdd32d0f2 100644 --- a/src/goto-symex/symex_builtin_functions.cpp +++ b/src/goto-symex/symex_builtin_functions.cpp @@ -51,7 +51,8 @@ inline static typet c_sizeof_type_rec(const exprt &expr) forall_operands(it, expr) { typet t=c_sizeof_type_rec(*it); - if(t.is_not_nil()) return t; + if(t.is_not_nil()) + return t; } } @@ -124,7 +125,8 @@ void goto_symext::symex_malloc( mp_integer elements=alloc_size/elem_size; if(elements*elem_size==alloc_size) - object_type=array_typet(tmp_type, from_integer(elements, tmp_size.type())); + object_type=array_typet( + tmp_type, from_integer(elements, tmp_size.type())); } } } @@ -143,7 +145,8 @@ void goto_symext::symex_malloc( symbolt size_symbol; - size_symbol.base_name="dynamic_object_size"+std::to_string(dynamic_counter); + size_symbol.base_name= + "dynamic_object_size"+std::to_string(dynamic_counter); size_symbol.name="symex_dynamic::"+id2string(size_symbol.base_name); size_symbol.is_lvalue=true; size_symbol.type=tmp_size.type(); @@ -486,7 +489,7 @@ void goto_symext::symex_cpp_new( else symbol.type=code.type().subtype(); - //symbol.type.set("#active", symbol_expr(active_symbol)); + // symbol.type.set("#active", symbol_expr(active_symbol)); symbol.type.set("#dynamic", true); new_symbol_table.add(symbol); @@ -526,7 +529,7 @@ void goto_symext::symex_cpp_delete( statet &state, const codet &code) { - //bool do_array=code.get(ID_statement)==ID_cpp_delete_array; + // bool do_array=code.get(ID_statement)==ID_cpp_delete_array; } /*******************************************************************\ @@ -546,18 +549,21 @@ void goto_symext::symex_trace( const code_function_callt &code) { if(code.arguments().size()<2) - throw "CBMC_trace expects at least two arguments"; + // NOLINTNEXTLINE(readability/throw) + throw "symex_trace expects at least two arguments"; int debug_thresh=unsafe_string2int(options.get_option("debug-level")); mp_integer debug_lvl; if(to_integer(code.arguments()[0], debug_lvl)) + // NOLINTNEXTLINE(readability/throw) throw "CBMC_trace expects constant as first argument"; if(code.arguments()[1].id()!="implicit_address_of" || code.arguments()[1].operands().size()!=1 || code.arguments()[1].op0().id()!=ID_string_constant) + // NOLINTNEXTLINE(readability/throw) throw "CBMC_trace expects string constant as second argument"; if(mp_integer(debug_thresh)>=debug_lvl) @@ -601,7 +607,10 @@ void goto_symext::symex_fkt( bool first=true; Forall_operands(it, fc) - if(first) first=false; else new_fc.move_to_operands(*it); + if(first) + first=false; + else + new_fc.move_to_operands(*it); new_fc.set(ID_identifier, fc.op0().get(ID_identifier)); diff --git a/src/goto-symex/symex_dereference.cpp b/src/goto-symex/symex_dereference.cpp index 2234f7d8eaa..1ef9ac69962 100644 --- a/src/goto-symex/symex_dereference.cpp +++ b/src/goto-symex/symex_dereference.cpp @@ -296,11 +296,14 @@ void goto_symext::dereference_rec( options, symex_dereference_state, language_mode); - + // std::cout << "**** " << from_expr(ns, "", tmp1) << std::endl; - exprt tmp2=dereference.dereference( - tmp1, guard, write?value_set_dereferencet::WRITE:value_set_dereferencet::READ); - //std::cout << "**** " << from_expr(ns, "", tmp2) << std::endl; + exprt tmp2= + dereference.dereference( + tmp1, + guard, + write?value_set_dereferencet::WRITE:value_set_dereferencet::READ); + // std::cout << "**** " << from_expr(ns, "", tmp2) << std::endl; expr.swap(tmp2); diff --git a/src/goto-symex/symex_function_call.cpp b/src/goto-symex/symex_function_call.cpp index bbc16a394ec..00636ae339b 100644 --- a/src/goto-symex/symex_function_call.cpp +++ b/src/goto-symex/symex_function_call.cpp @@ -161,13 +161,15 @@ void goto_symext::parameter_assignments( // These are va_arg arguments; their types may differ from call to call unsigned va_count=0; const symbolt *va_sym=0; - while(!ns.lookup(id2string(function_identifier)+"::va_arg"+std::to_string(va_count), - va_sym)) + while(!ns.lookup( + id2string(function_identifier)+"::va_arg"+std::to_string(va_count), + va_sym)) ++va_count; for( ; it1!=arguments.end(); it1++, va_count++) { - irep_idt id=id2string(function_identifier)+"::va_arg"+std::to_string(va_count); + irep_idt id= + id2string(function_identifier)+"::va_arg"+std::to_string(va_count); // add to symbol table symbolt symbol; @@ -547,10 +549,11 @@ void goto_symext::return_assignment(statet &state) if(!base_type_eq(assignment.lhs().type(), assignment.rhs().type(), ns)) - throw "goto_symext::return_assignment type mismatch at "+ - instruction.source_location.as_string()+":\n"+ - "assignment.lhs().type():\n"+assignment.lhs().type().pretty()+"\n"+ - "assignment.rhs().type():\n"+assignment.rhs().type().pretty(); + throw + "goto_symext::return_assignment type mismatch at "+ + instruction.source_location.as_string()+":\n"+ + "assignment.lhs().type():\n"+assignment.lhs().type().pretty()+"\n"+ + "assignment.rhs().type():\n"+assignment.rhs().type().pretty(); symex_assign_rec(state, assignment); } diff --git a/src/goto-symex/symex_goto.cpp b/src/goto-symex/symex_goto.cpp index 8f45e513e4b..74c7b3c775d 100644 --- a/src/goto-symex/symex_goto.cpp +++ b/src/goto-symex/symex_goto.cpp @@ -194,7 +194,8 @@ void goto_symext::symex_step_goto(statet &state, bool taken) dereference(guard, state, false); state.rename(guard, ns); - if(!taken) guard.make_not(); + if(!taken) + guard.make_not(); state.guard.guard_expr(guard); do_simplify(guard); @@ -237,7 +238,7 @@ void goto_symext::merge_gotos(statet &state) // check atomic section if(state.atomic_section_id!=goto_state.atomic_section_id) - throw "Atomic sections differ across branches"; + throw "atomic sections differ across branches"; // do SSA phi functions phi_function(goto_state, state); @@ -346,7 +347,8 @@ void goto_symext::phi_function( if(p_it!=goto_state.propagation.values.end()) goto_state_rhs=p_it->second; else - to_ssa_expr(goto_state_rhs).set_level_2(goto_state.level2_current_count(l1_identifier)); + to_ssa_expr(goto_state_rhs).set_level_2( + goto_state.level2_current_count(l1_identifier)); } { @@ -356,7 +358,8 @@ void goto_symext::phi_function( if(p_it!=dest_state.propagation.values.end()) dest_state_rhs=p_it->second; else - to_ssa_expr(dest_state_rhs).set_level_2(dest_state.level2.current_count(l1_identifier)); + to_ssa_expr(dest_state_rhs).set_level_2( + dest_state.level2.current_count(l1_identifier)); } exprt rhs; diff --git a/src/goto-symex/symex_main.cpp b/src/goto-symex/symex_main.cpp index 4bcde13a0af..2cb7ac09290 100644 --- a/src/goto-symex/symex_main.cpp +++ b/src/goto-symex/symex_main.cpp @@ -65,7 +65,8 @@ void goto_symext::vcc( // now try simplifier on it do_simplify(expr); - if(expr.is_true()) return; + if(expr.is_true()) + return; state.guard.guard_expr(expr); @@ -91,7 +92,8 @@ void goto_symext::symex_assume(statet &state, const exprt &cond) do_simplify(simplified_cond); - if(simplified_cond.is_true()) return; + if(simplified_cond.is_true()) + return; if(state.threads.size()==1) { @@ -179,7 +181,7 @@ void goto_symext::operator()( state.source.thread_nr+1type << std::endl; - std::cout << "Location: " << state.source.pc->source_location << std::endl; - std::cout << "Guard: " << from_expr(ns, "", state.guard.as_expr()) << std::endl; - std::cout << "Code: " << from_expr(ns, "", state.source.pc->code) << std::endl; + std::cout << "\ninstruction type is " << state.source.pc->type << '\n'; + std::cout << "Location: " << state.source.pc->source_location << '\n'; + std::cout << "Guard: " << from_expr(ns, "", state.guard.as_expr()) << '\n'; + std::cout << "Code: " << from_expr(ns, "", state.source.pc->code) << '\n'; #endif assert(!state.threads.empty()); @@ -313,7 +315,8 @@ void goto_symext::symex_step( if(!state.guard.is_false()) { std::string msg=id2string(state.source.pc->source_location.get_comment()); - if(msg=="") msg="assertion"; + if(msg=="") + msg="assertion"; exprt tmp(instruction.guard); clean_expr(tmp, state, false); vcc(tmp, msg, state); diff --git a/src/goto-symex/symex_start_thread.cpp b/src/goto-symex/symex_start_thread.cpp index c7f0340496a..eb4687a1fb9 100644 --- a/src/goto-symex/symex_start_thread.cpp +++ b/src/goto-symex/symex_start_thread.cpp @@ -24,7 +24,8 @@ Function: goto_symext::symex_start_thread void goto_symext::symex_start_thread(statet &state) { - if(state.guard.is_false()) return; + if(state.guard.is_false()) + return; // we don't allow spawning threads out of atomic sections // this would require amendments to ordering constraints @@ -45,7 +46,7 @@ void goto_symext::symex_start_thread(statet &state) // put into thread vector std::size_t t=state.threads.size(); state.threads.push_back(statet::threadt()); - //statet::threadt &cur_thread=state.threads[state.source.thread_nr]; + // statet::threadt &cur_thread=state.threads[state.source.thread_nr]; statet::threadt &new_thread=state.threads.back(); new_thread.pc=thread_target; new_thread.guard=state.guard; @@ -92,7 +93,8 @@ void goto_symext::symex_start_thread(statet &state) guardt guard; const bool record_events=state.record_events; state.record_events=false; - symex_assign_symbol(state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); + symex_assign_symbol( + state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); state.record_events=record_events; } @@ -119,6 +121,7 @@ void goto_symext::symex_start_thread(statet &state) rhs=zero_initializer(symbol.type, symbol.location, ns); guardt guard; - symex_assign_symbol(state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); + symex_assign_symbol( + state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); } } diff --git a/src/goto-symex/symex_target.cpp b/src/goto-symex/symex_target.cpp index b0fc0a248ed..808ec3d2004 100644 --- a/src/goto-symex/symex_target.cpp +++ b/src/goto-symex/symex_target.cpp @@ -20,7 +20,9 @@ Function: operator < \*******************************************************************/ -bool operator < (const symex_targett::sourcet &a, const symex_targett::sourcet &b) +bool operator<( + const symex_targett::sourcet &a, + const symex_targett::sourcet &b) { if(a.thread_nr==b.thread_nr) return a.pc < b.pc; diff --git a/src/goto-symex/symex_target.h b/src/goto-symex/symex_target.h index 6f33b97046e..e3b94fc15b6 100644 --- a/src/goto-symex/symex_target.h +++ b/src/goto-symex/symex_target.h @@ -51,7 +51,8 @@ class symex_targett } }; - typedef enum { + typedef enum + { STATE, HIDDEN, VISIBLE_ACTUAL_PARAMETER, HIDDEN_ACTUAL_PARAMETER, PHI, GUARD } assignment_typet; diff --git a/src/goto-symex/symex_target_equation.cpp b/src/goto-symex/symex_target_equation.cpp index 66b9a87e9af..3cf9612e556 100644 --- a/src/goto-symex/symex_target_equation.cpp +++ b/src/goto-symex/symex_target_equation.cpp @@ -619,7 +619,7 @@ Function: symex_target_equationt::convert \*******************************************************************/ void symex_target_equationt::convert( - prop_convt &prop_conv) + prop_convt &prop_conv) { convert_guards(prop_conv); convert_assignments(prop_conv); @@ -981,11 +981,16 @@ void symex_target_equationt::SSA_stept::output( switch(type) { - case goto_trace_stept::ASSERT: out << "ASSERT " << from_expr(ns, "", cond_expr) << std::endl; break; - case goto_trace_stept::ASSUME: out << "ASSUME " << from_expr(ns, "", cond_expr) << std::endl; break; - case goto_trace_stept::LOCATION: out << "LOCATION" << std::endl; break; - case goto_trace_stept::INPUT: out << "INPUT" << std::endl; break; - case goto_trace_stept::OUTPUT: out << "OUTPUT" << std::endl; break; + case goto_trace_stept::ASSERT: + out << "ASSERT " << from_expr(ns, "", cond_expr) << std::endl; break; + case goto_trace_stept::ASSUME: + out << "ASSUME " << from_expr(ns, "", cond_expr) << std::endl; break; + case goto_trace_stept::LOCATION: + out << "LOCATION" << std::endl; break; + case goto_trace_stept::INPUT: + out << "INPUT" << std::endl; break; + case goto_trace_stept::OUTPUT: + out << "OUTPUT" << std::endl; break; case goto_trace_stept::DECL: out << "DECL" << std::endl; @@ -1002,23 +1007,36 @@ void symex_target_equationt::SSA_stept::output( case HIDDEN_ACTUAL_PARAMETER: out << "HIDDEN_ACTUAL_PARAMETER"; break; case PHI: out << "PHI"; break; case GUARD: out << "GUARD"; break; - default:; + default: + { + } } out << ")" << std::endl; break; - case goto_trace_stept::DEAD: out << "DEAD" << std::endl; break; - case goto_trace_stept::FUNCTION_CALL: out << "FUNCTION_CALL" << std::endl; break; - case goto_trace_stept::FUNCTION_RETURN: out << "FUNCTION_RETURN" << std::endl; break; - case goto_trace_stept::CONSTRAINT: out << "CONSTRAINT" << std::endl; break; - case goto_trace_stept::SHARED_READ: out << "SHARED READ" << std::endl; break; - case goto_trace_stept::SHARED_WRITE: out << "SHARED WRITE" << std::endl; break; - case goto_trace_stept::ATOMIC_BEGIN: out << "ATOMIC_BEGIN" << std::endl; break; - case goto_trace_stept::ATOMIC_END: out << "AUTOMIC_END" << std::endl; break; - case goto_trace_stept::SPAWN: out << "SPAWN" << std::endl; break; - case goto_trace_stept::MEMORY_BARRIER: out << "MEMORY_BARRIER" << std::endl; break; - case goto_trace_stept::GOTO: out << "IF " << from_expr(ns, "", cond_expr) << " GOTO" << std::endl; break; + case goto_trace_stept::DEAD: + out << "DEAD" << std::endl; break; + case goto_trace_stept::FUNCTION_CALL: + out << "FUNCTION_CALL" << std::endl; break; + case goto_trace_stept::FUNCTION_RETURN: + out << "FUNCTION_RETURN" << std::endl; break; + case goto_trace_stept::CONSTRAINT: + out << "CONSTRAINT" << std::endl; break; + case goto_trace_stept::SHARED_READ: + out << "SHARED READ" << std::endl; break; + case goto_trace_stept::SHARED_WRITE: + out << "SHARED WRITE" << std::endl; break; + case goto_trace_stept::ATOMIC_BEGIN: + out << "ATOMIC_BEGIN" << std::endl; break; + case goto_trace_stept::ATOMIC_END: + out << "AUTOMIC_END" << std::endl; break; + case goto_trace_stept::SPAWN: + out << "SPAWN" << std::endl; break; + case goto_trace_stept::MEMORY_BARRIER: + out << "MEMORY_BARRIER" << std::endl; break; + case goto_trace_stept::GOTO: + out << "IF " << from_expr(ns, "", cond_expr) << " GOTO" << std::endl; break; default: assert(false); } diff --git a/src/goto-symex/symex_target_equation.h b/src/goto-symex/symex_target_equation.h index 6fe33428f82..855b44ee0bb 100644 --- a/src/goto-symex/symex_target_equation.h +++ b/src/goto-symex/symex_target_equation.h @@ -172,19 +172,28 @@ class symex_target_equationt:public symex_targett bool is_assert() const { return type==goto_trace_stept::ASSERT; } bool is_assume() const { return type==goto_trace_stept::ASSUME; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_assignment() const { return type==goto_trace_stept::ASSIGNMENT; } bool is_goto() const { return type==goto_trace_stept::GOTO; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_constraint() const { return type==goto_trace_stept::CONSTRAINT; } bool is_location() const { return type==goto_trace_stept::LOCATION; } bool is_output() const { return type==goto_trace_stept::OUTPUT; } bool is_decl() const { return type==goto_trace_stept::DECL; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_function_call() const { return type==goto_trace_stept::FUNCTION_CALL; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_function_return() const { return type==goto_trace_stept::FUNCTION_RETURN; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_shared_read() const { return type==goto_trace_stept::SHARED_READ; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_shared_write() const { return type==goto_trace_stept::SHARED_WRITE; } bool is_spawn() const { return type==goto_trace_stept::SPAWN; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_memory_barrier() const { return type==goto_trace_stept::MEMORY_BARRIER; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_atomic_begin() const { return type==goto_trace_stept::ATOMIC_BEGIN; } + // NOLINTNEXTLINE(whitespace/line_length) bool is_atomic_end() const { return type==goto_trace_stept::ATOMIC_END; } // we may choose to hide @@ -247,7 +256,8 @@ class symex_target_equationt:public symex_targett for(SSA_stepst::const_iterator it=SSA_steps.begin(); it!=SSA_steps.end(); it++) - if(it->is_assert()) i++; + if(it->is_assert()) + i++; return i; } @@ -257,7 +267,8 @@ class symex_target_equationt:public symex_targett for(SSA_stepst::const_iterator it=SSA_steps.begin(); it!=SSA_steps.end(); it++) - if(it->ignore) i++; + if(it->ignore) + i++; return i; } @@ -301,14 +312,18 @@ class symex_target_equationt:public symex_targett void merge_ireps(SSA_stept &SSA_step); }; -extern inline bool operator<( +inline bool operator<( const symex_target_equationt::SSA_stepst::const_iterator a, const symex_target_equationt::SSA_stepst::const_iterator b) { return &(*a)<&(*b); } -std::ostream &operator<<(std::ostream &out, const symex_target_equationt::SSA_stept &step); -std::ostream &operator<<(std::ostream &out, const symex_target_equationt &equation); +std::ostream &operator<<( + std::ostream &out, + const symex_target_equationt::SSA_stept &step); +std::ostream &operator<<( + std::ostream &out, + const symex_target_equationt &equation); #endif // CPROVER_GOTO_SYMEX_SYMEX_TARGET_EQUATION_H diff --git a/src/goto-symex/symex_throw.cpp b/src/goto-symex/symex_throw.cpp index d363caffc71..e5091c566f2 100644 --- a/src/goto-symex/symex_throw.cpp +++ b/src/goto-symex/symex_throw.cpp @@ -38,7 +38,8 @@ void goto_symext::symex_throw(statet &state) { const goto_symex_statet::framet &frame=*s_it; - if(frame.catch_map.empty()) continue; + if(frame.catch_map.empty()) + continue; for(irept::subt::const_iterator e_it=exceptions_thrown.begin(); diff --git a/src/java_bytecode/bytecode_info.cpp b/src/java_bytecode/bytecode_info.cpp index b58a9076aee..556e208129c 100644 --- a/src/java_bytecode/bytecode_info.cpp +++ b/src/java_bytecode/bytecode_info.cpp @@ -1,215 +1,222 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + // http://docs.oracle.com/javase/specs/jvms/se8/html/ // http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings #include "bytecode_info.h" -struct bytecode_infot const bytecode_info[]= { - -{ "aaload", 0x32, ' ', 2, 1, ' ' }, // arrayref, index → value; load onto the stack a reference from an array -{ "aastore", 0x53, ' ', 3, 0, ' ' }, // arrayref, index, value →; store into a reference in an array -{ "aconst_null", 0x01, ' ', 0, 1, 'a' }, // → null; push a null reference onto the stack -{ "aload", 0x19, 'v', 0, 1, 'a' }, // → objectref; load a reference onto the stack from a local variable #index -{ "aload_0", 0x2a, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 0 -{ "aload_1", 0x2b, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 1 -{ "aload_2", 0x2c, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 2 -{ "aload_3", 0x2d, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 3 -{ "anewarray", 0xbd, 'C', 1, 1, 'a' }, // count → arrayref; create a new array of references of length count and component type identified by the class reference index (indexbyte1 << 8 + indexbyte2) in the constant pool -{ "areturn", 0xb0, ' ', 1, 0, ' ' }, // objectref → [empty]; return a reference from a method -{ "arraylength", 0xbe, ' ', 1, 1, 'i' }, // arrayref → length; get the length of an array -{ "astore", 0x3a, 'v', 1, 0, ' ' }, // objectref →; store a reference into a local variable #index -{ "astore_0", 0x4b, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 0 -{ "astore_1", 0x4c, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 1 -{ "astore_2", 0x4d, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 2 -{ "astore_3", 0x4e, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 3 -{ "athrow", 0xbf, ' ', 1, 1, ' ' }, // objectref → [empty], objectref; throws an error or exception (notice that the rest of the stack is cleared, leaving only a reference to the Throwable) -{ "baload", 0x33, ' ', 2, 1, 'b' }, // arrayref, index → value; load a byte or Boolean value from an array -{ "bastore", 0x54, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a byte or Boolean value into an array -{ "bipush", 0x10, 'b', 0, 1, 'i' }, // → value; push a byte onto the stack as an integer value -{ "caload", 0x34, ' ', 2, 1, 'c' }, // arrayref, index → value; load a char from an array -{ "castore", 0x55, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a char into an array -{ "checkcast", 0xc0, 'C', 1, 1, 'a' }, // objectref → objectref; checks whether an objectref is of a certain type, the class reference of which is in the constant pool at index (indexbyte1 << 8 + indexbyte2) -{ "dadd", 0x63, ' ', 2, 1, 'd' }, // value1, value2 → result; add two doubles -{ "daload", 0x31, ' ', 2, 1, 'd' }, // arrayref, index → value; load a double from an array -{ "dastore", 0x52, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a double into an array -{ "dcmpg", 0x98, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two doubles -{ "dcmpl", 0x97, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two doubles -{ "dconst_0", 0x0e, ' ', 0, 1, 'd' }, // → 0.0; push the constant 0.0 onto the stack -{ "dconst_1", 0x0f, ' ', 0, 1, 'd' }, // → 1.0; push the constant 1.0 onto the stack -{ "ddiv", 0x6f, ' ', 2, 1, 'd' }, // value1, value2 → result; divide two doubles -{ "dload", 0x18, 'v', 0, 1, 'd' }, // → value; load a double value from a local variable #index -{ "dload_0", 0x26, ' ', 0, 1, 'd' }, // → value; load a double from local variable 0 -{ "dload_1", 0x27, ' ', 0, 1, 'd' }, // → value; load a double from local variable 1 -{ "dload_2", 0x28, ' ', 0, 1, 'd' }, // → value; load a double from local variable 2 -{ "dload_3", 0x29, ' ', 0, 1, 'd' }, // → value; load a double from local variable 3 -{ "dmul", 0x6b, ' ', 2, 1, 'd' }, // value1, value2 → result; multiply two doubles -{ "dneg", 0x77, ' ', 1, 1, 'd' }, // value → result; negate a double -{ "drem", 0x73, ' ', 2, 1, 'd' }, // value1, value2 → result; get the remainder from a division between two doubles -{ "dreturn", 0xaf, ' ', 1, 0, ' ' }, // value → [empty]; return a double from a method -{ "dstore", 0x39, 'v', 1, 0, ' ' }, // value →; store a double value into a local variable #index -{ "dstore_0", 0x47, ' ', 1, 0, ' ' }, // value →; store a double into local variable 0 -{ "dstore_1", 0x48, ' ', 1, 0, ' ' }, // value →; store a double into local variable 1 -{ "dstore_2", 0x49, ' ', 1, 0, ' ' }, // value →; store a double into local variable 2 -{ "dstore_3", 0x4a, ' ', 1, 0, ' ' }, // value →; store a double into local variable 3 -{ "dsub", 0x67, ' ', 2, 1, 'd' }, // value1, value2 → result; subtract a double from another -{ "dup", 0x59, ' ', 1, 2, ' ' }, // value → value, value; duplicate the value on top of the stack -{ "dup_x1", 0x5a, ' ', 2, 3, ' ' }, // value2, value1 → value1, value2, value1; insert a copy of the top value into the stack two values from the top. value1 and value2 must not be of the type double or long. -{ "dup_x2", 0x5b, ' ', 3, 4, ' ' }, // value3, value2, value1 → value1, value3, value2, value1; insert a copy of the top value into the stack two (if value2 is double or long it takes up the entry of value3, too) or three values (if value2 is neither double nor long) from the top -{ "dup2", 0x5c, ' ', 0, 0, ' ' }, // {value2, value1} → {value2, value; value2, value1} }, // duplicate top two stack words -{ "dup2_x1", 0x5d, ' ', 0, 0, ' ' }, // value3, {value2, value1} → {value2, value; value3, {value2, value1} }, // duplicate two words and insert beneath third word (see explanation above) -{ "dup2_x2", 0x5e, ' ', 0, 0, ' ' }, // {value4, value; value2, value1} → {value2, value1}, {value4, value3}, {value2, value1} }, // duplicate two words and insert beneath fourth word -{ "fadd", 0x62, ' ', 2, 1, 'f' }, // value1, value2 → result; add two floats -{ "faload", 0x30, ' ', 2, 1, 'f' }, // arrayref, index → value; load a float from an array -{ "fastore", 0x51, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a float in an array -{ "fcmpg", 0x96, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two floats -{ "fcmpl", 0x95, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two floats -{ "fconst_0", 0x0b, ' ', 0, 1, 'f' }, // → 0.0f; push 0.0f on the stack -{ "fconst_1", 0x0c, ' ', 0, 1, 'f' }, // → 1.0f; push 1.0f on the stack -{ "fconst_2", 0x0d, ' ', 0, 1, 'f' }, // → 2.0f; push 2.0f on the stack -{ "fdiv", 0x6e, ' ', 2, 1, 'f' }, // value1, value2 → result; divide two floats -{ "fload", 0x17, 'v', 0, 1, 'f' }, // → value; load a float value from a local variable #index -{ "fload_0", 0x22, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 0 -{ "fload_1", 0x23, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 1 -{ "fload_2", 0x24, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 2 -{ "fload_3", 0x25, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 3 -{ "fmul", 0x6a, ' ', 2, 1, 'f' }, // value1, value2 → result; multiply two floats -{ "fneg", 0x76, ' ', 1, 1, 'f' }, // value → result; negate a float -{ "frem", 0x72, ' ', 2, 1, 'f' }, // value1, value2 → result; get the remainder from a division between two floats -{ "freturn", 0xae, ' ', 1, 0, ' ' }, // value → [empty]; return a float -{ "fstore", 0x38, 'v', 1, 0, ' ' }, // value →; store a float value into a local variable #index -{ "fstore_0", 0x43, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 0 -{ "fstore_1", 0x44, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 1 -{ "fstore_2", 0x45, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 2 -{ "fstore_3", 0x46, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 3 -{ "fsub", 0x66, ' ', 2, 1, 'f' }, // value1, value2 → result; subtract two floats -{ "getfield", 0xb4, 'C', 1, 1, ' ' }, // objectref → value; get a field value of an object objectref, where the field is identified by field reference in the constant pool index (index1 << 8 + index2) -{ "getstatic", 0xb2, 'C', 0, 1, ' ' }, // → value; get a static field value of a class, where the field is identified by field reference in the constant pool index (index1 << 8 + index2) -{ "goto", 0xa7, 'o', 0, 0, ' ' }, // [no change]; goes to another instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "goto_w", 0xc8, 'O', 0, 0, ' ' }, // [no change]; goes to another instruction at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) -{ "i2l", 0x85, ' ', 1, 1, 'l' }, // value → result; convert an int into a long -{ "i2f", 0x86, ' ', 1, 1, 'f' }, // value → result; convert an int into a float -{ "i2d", 0x87, ' ', 1, 1, 'd' }, // value → result; convert an int into a double -{ "l2i", 0x88, ' ', 1, 1, 'i' }, // value → result; convert a long to a int -{ "l2f", 0x89, ' ', 1, 1, 'f' }, // value → result; convert a long to a float -{ "l2d", 0x8a, ' ', 1, 1, 'd' }, // value → result; convert a long to a double -{ "f2i", 0x8b, ' ', 1, 1, 'i' }, // value → result; convert a float to an int -{ "f2l", 0x8c, ' ', 1, 1, 'l' }, // value → result; convert a float to a long -{ "f2d", 0x8d, ' ', 1, 1, 'd' }, // value → result; convert a float to a double -{ "d2i", 0x8e, ' ', 1, 1, 'i' }, // value → result; convert a double to an int -{ "d2l", 0x8f, ' ', 1, 1, 'l' }, // value → result; convert a double to a long -{ "d2f", 0x90, ' ', 1, 1, 'f' }, // value → result; convert a double to a float -{ "i2b", 0x91, ' ', 1, 1, 'b' }, // value → result; convert an int into a byte -{ "i2c", 0x92, ' ', 1, 1, 'c' }, // value → result; convert an int into a character -{ "i2s", 0x93, ' ', 1, 1, 's' }, // value → result; convert an int into a short -{ "iadd", 0x60, ' ', 2, 1, 'i' }, // value1, value2 → result; add two ints -{ "iaload", 0x2e, ' ', 2, 1, 'i' }, // arrayref, index → value; load an int from an array -{ "iand", 0x7e, ' ', 2, 1, 'i' }, // value1, value2 → result; perform a bitwise and on two integers -{ "iastore", 0x4f, ' ', 3, 0, ' ' }, // arrayref, index, value →; store an int into an array -{ "iconst_m1", 0x02, ' ', 0, 1, 'i' }, // → -1; load the int value -1 onto the stack -{ "iconst_0", 0x03, ' ', 0, 1, 'i' }, // → 0; load the int value 0 onto the stack -{ "iconst_1", 0x04, ' ', 0, 1, 'i' }, // → 1; load the int value 1 onto the stack -{ "iconst_2", 0x05, ' ', 0, 1, 'i' }, // → 2; load the int value 2 onto the stack -{ "iconst_3", 0x06, ' ', 0, 1, 'i' }, // → 3; load the int value 3 onto the stack -{ "iconst_4", 0x07, ' ', 0, 1, 'i' }, // → 4; load the int value 4 onto the stack -{ "iconst_5", 0x08, ' ', 0, 1, 'i' }, // → 5; load the int value 5 onto the stack -{ "idiv", 0x6c, ' ', 2, 1, 'i' }, // value1, value2 → result; divide two integers -{ "if_acmpeq", 0xa5, 'o', 2, 0, ' ' }, // value1, value2 →; if references are equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_acmpne", 0xa6, 'o', 2, 0, ' ' }, // value1, value2 →; if references are not equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmpeq", 0x9f, 'o', 2, 0, ' ' }, // value1, value2 →; if ints are equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmpne", 0xa0, 'o', 2, 0, ' ' }, // value1, value2 →; if ints are not equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmplt", 0xa1, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is less than value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmpge", 0xa2, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is greater than or equal to value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmpgt", 0xa3, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is greater than value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "if_icmple", 0xa4, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is less than or equal to value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifeq", 0x99, 'o', 1, 0, ' ' }, // value →; if value is 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifne", 0x9a, 'o', 1, 0, ' ' }, // value →; if value is not 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "iflt", 0x9b, 'o', 1, 0, ' ' }, // value →; if value is less than 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifge", 0x9c, 'o', 1, 0, ' ' }, // value →; if value is greater than or equal to 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifgt", 0x9d, 'o', 1, 0, ' ' }, // value →; if value is greater than 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifle", 0x9e, 'o', 1, 0, ' ' }, // value →; if value is less than or equal to 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifnonnull", 0xc7, 'o', 1, 0, ' ' }, // value →; if value is not null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "ifnull", 0xc6, 'o', 1, 0, ' ' }, // value →; if value is null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) -{ "iinc", 0x84, 'V', 0, 0, ' ' }, // [No change]; increment local variable #index by signed byte const -{ "iload", 0x15, 'v', 0, 1, 'i' }, // → value; load an int value from a local variable #index -{ "iload_0", 0x1a, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 0 -{ "iload_1", 0x1b, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 1 -{ "iload_2", 0x1c, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 2 -{ "iload_3", 0x1d, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 3 -{ "imul", 0x68, ' ', 2, 1, 'i' }, // value1, value2 → result; multiply two integers -{ "ineg", 0x74, ' ', 1, 1, 'i' }, // value → result; negate int -{ "instanceof", 0xc1, 'C', 1, 1, ' ' }, // objectref → result; determines if an object objectref is of a given type, identified by class reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "invokedynamic", 0xba, 'I', 0, 0, ' ' }, // [arg1, [arg2 ...]] →; invokes a dynamic method identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "invokeinterface",0xb9, 'I', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invokes an interface method on object objectref, where the interface method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "invokespecial", 0xb7, 'C', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invoke instance method on object objectref, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "invokestatic", 0xb8, 'C', 0, 0, ' ' }, // [arg1, arg2, ...] →; invoke a static method, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "invokevirtual", 0xb6, 'C', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invoke virtual method on object objectref, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "ior", 0x80, ' ', 2, 1, 'i' }, // value1, value2 → result; bitwise int or -{ "irem", 0x70, ' ', 2, 1, 'i' }, // value1, value2 → result; logical int remainder -{ "ireturn", 0xac, ' ', 1, 0, ' ' }, // value → [empty]; return an integer from a method -{ "ishl", 0x78, ' ', 2, 1, 'i' }, // value1, value2 → result; int shift left -{ "ishr", 0x7a, ' ', 2, 1, 'i' }, // value1, value2 → result; int arithmetic shift right -{ "istore", 0x36, 'v', 1, 0, ' ' }, // value →; store int value into variable #index -{ "istore_0", 0x3b, ' ', 1, 0, ' ' }, // value →; store int value into variable 0 -{ "istore_1", 0x3c, ' ', 1, 0, ' ' }, // value →; store int value into variable 1 -{ "istore_2", 0x3d, ' ', 1, 0, ' ' }, // value →; store int value into variable 2 -{ "istore_3", 0x3e, ' ', 1, 0, ' ' }, // value →; store int value into variable 3 -{ "isub", 0x64, ' ', 2, 1, 'i' }, // value1, value2 → result; int subtract -{ "iushr", 0x7c, ' ', 2, 1, 'i' }, // value1, value2 → result; int logical shift right -{ "ixor", 0x82, ' ', 2, 1, 'i' }, // value1, value2 → result; int xor -{ "jsr", 0xa8, 'o', 0, 1, 'a' }, // → address; jump to subroutine at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) and place the return address on the stack -{ "jsr_w", 0xc9, 'O', 0, 1, 'a' }, // → address; jump to subroutine at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) and place the return address on the stack -{ "ladd", 0x61, ' ', 2, 1, 'l' }, // value1, value2 → result; add two longs -{ "laload", 0x2f, ' ', 2, 1, 'l' }, // arrayref, index → value; load a long from an array -{ "land", 0x7f, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise and of two longs -{ "lastore", 0x50, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a long to an array -{ "lcmp", 0x94, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two long values -{ "lconst_0", 0x09, ' ', 0, 1, 'l' }, // → 0L; push the long 0 onto the stack -{ "lconst_1", 0x0a, ' ', 0, 1, 'l' }, // → 1L; push the long 1 onto the stack -{ "ldc", 0x12, 'c', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (String, int or float) onto the stack -{ "ldc_w", 0x13, 'C', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (String, int or float) onto the stack (wide index is constructed as indexbyte1 << 8 + indexbyte2) -{ "ldc2_w", 0x14, 'C', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (double or long) onto the stack (wide index is constructed as indexbyte1 << 8 + indexbyte2) -{ "ldiv", 0x6d, ' ', 2, 1, 'l' }, // value1, value2 → result; divide two longs -{ "lload", 0x16, 'v', 0, 1, 'l' }, // → value; load a long value from a local variable #index -{ "lload_0", 0x1e, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 0 -{ "lload_1", 0x1f, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 1 -{ "lload_2", 0x20, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 2 -{ "lload_3", 0x21, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 3 -{ "lmul", 0x69, ' ', 2, 1, 'l' }, // value1, value2 → result; multiply two longs -{ "lneg", 0x75, ' ', 1, 1, 'l' }, // value → result; negate a long -{ "lookupswitch", 0xab, 'L', 1, 0, ' ' }, // key →; a target address is looked up from a table using a key and execution continues from the instruction at that address -{ "lor", 0x81, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise or of two longs -{ "lrem", 0x71, ' ', 2, 1, 'l' }, // value1, value2 → result; remainder of division of two longs -{ "lreturn", 0xad, ' ', 1, 0, ' ' }, // value → [empty]; return a long value -{ "lshl", 0x79, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift left of a long value1 by value2 positions -{ "lshr", 0x7b, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift right of a long value1 by value2 positions -{ "lstore", 0x37, 'v', 1, 0, ' ' }, // value →; store a long value in a local variable #index -{ "lstore_0", 0x3f, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 0 -{ "lstore_1", 0x40, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 1 -{ "lstore_2", 0x41, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 2 -{ "lstore_3", 0x42, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 3 -{ "lsub", 0x65, ' ', 2, 1, 'l' }, // value1, value2 → result; subtract two longs -{ "lushr", 0x7d, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift right of a long value1 by value2 positions, unsigned -{ "lxor", 0x83, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise exclusive or of two longs -{ "monitorenter", 0xc2, ' ', 1, 0, ' ' }, // objectref →; enter monitor for object ("grab the lock" - start of synchronized() section) -{ "monitorexit", 0xc3, ' ', 1, 0, ' ' }, // objectref →; exit monitor for object ("release the lock" - end of synchronized() section) -{ "multianewarray", 0xc5, 'm', 0, 1, 'a' }, // count1, [count2,...] → arrayref; create a new array of dimensions dimensions with elements of type identified by class reference in constant pool index (indexbyte1 << 8 + indexbyte2); the sizes of each dimension is identified by count1, [count2, etc.] -{ "new", 0xbb, 'C', 0, 1, 'a' }, // → objectref; create new object of type identified by class reference in constant pool index (indexbyte1 << 8 + indexbyte2) -{ "newarray", 0xbc, 't', 1, 1, 'a' }, // count → arrayref; create new array with count elements of primitive type identified by atype -{ "nop", 0x00, ' ', 0, 0, ' ' }, // [No change]; perform no operation -{ "pop", 0x57, ' ', 1, 0, ' ' }, // value →; discard the top value on the stack -{ "pop2", 0x58, ' ', 1, 0, ' ' }, // {value2, value1} →; discard the top two values on the stack (or one value, if it is a double or long) -{ "putfield", 0xb5, 'C', 2, 0, ' ' }, // objectref, value →; set field to value in an object objectref, where the field is identified by a field reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "putstatic", 0xb3, 'C', 1, 0, ' ' }, // value →; set static field to value in a class, where the field is identified by a field reference index in constant pool (indexbyte1 << 8 + indexbyte2) -{ "ret", 0xa9, 'v', 0, 0, ' ' }, // [No change]; continue execution from address taken from a local variable #index (the asymmetry with jsr is intentional) -{ "return", 0xb1, ' ', 0, 0, ' ' }, // → [empty]; return void from method -{ "saload", 0x35, ' ', 2, 1, 's' }, // arrayref, index → value; load short from array -{ "sastore", 0x56, ' ', 3, 0, 's' }, // arrayref, index, value →; store short to array -{ "sipush", 0x11, 's', 0, 1, 's' }, // → value; push a short onto the stack -{ "swap", 0x5f, ' ', 2, 2, ' ' }, // value2, value1 → value1, value2; swaps two top words on the stack (note that value1 and value2 must not be double or long) -{ "tableswitch", 0xaa, 'T', 1, 0, ' ' }, // index →; continue execution from an address in the table at offset index -{ "breakpoint", 0xca, ' ', 0, 0, ' ' }, // ; reserved for breakpoints in Java debuggers; should not appear in any class file -{ "impdep1", 0xfe, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file -{ "impdep2", 0xff, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file -{ "wide", 0xc4, ' ', 0, 0, ' ' }, // modifier for others +struct bytecode_infot const bytecode_info[]= +{ +{ "aaload", 0x32, ' ', 2, 1, ' ' }, // arrayref, index → value; load onto the stack a reference from an array NOLINT(*) +{ "aastore", 0x53, ' ', 3, 0, ' ' }, // arrayref, index, value →; store into a reference in an array NOLINT(*) +{ "aconst_null", 0x01, ' ', 0, 1, 'a' }, // → null; push a null reference onto the stack NOLINT(*) +{ "aload", 0x19, 'v', 0, 1, 'a' }, // → objectref; load a reference onto the stack from a local variable #index NOLINT(*) +{ "aload_0", 0x2a, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 0 NOLINT(*) +{ "aload_1", 0x2b, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 1 NOLINT(*) +{ "aload_2", 0x2c, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 2 NOLINT(*) +{ "aload_3", 0x2d, ' ', 0, 1, 'a' }, // → objectref; load a reference onto the stack from local variable 3 NOLINT(*) +{ "anewarray", 0xbd, 'C', 1, 1, 'a' }, // count → arrayref; create a new array of references of length count and component type identified by the class reference index (indexbyte1 << 8 + indexbyte2) in the constant pool NOLINT(*) +{ "areturn", 0xb0, ' ', 1, 0, ' ' }, // objectref → [empty]; return a reference from a method NOLINT(*) +{ "arraylength", 0xbe, ' ', 1, 1, 'i' }, // arrayref → length; get the length of an array NOLINT(*) +{ "astore", 0x3a, 'v', 1, 0, ' ' }, // objectref →; store a reference into a local variable #index NOLINT(*) +{ "astore_0", 0x4b, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 0 NOLINT(*) +{ "astore_1", 0x4c, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 1 NOLINT(*) +{ "astore_2", 0x4d, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 2 NOLINT(*) +{ "astore_3", 0x4e, ' ', 1, 0, ' ' }, // objectref →; store a reference into local variable 3 NOLINT(*) +{ "athrow", 0xbf, ' ', 1, 1, ' ' }, // objectref → [empty], objectref; throws an error or exception (notice that the rest of the stack is cleared, leaving only a reference to the Throwable) NOLINT(*) +{ "baload", 0x33, ' ', 2, 1, 'b' }, // arrayref, index → value; load a byte or Boolean value from an array NOLINT(*) +{ "bastore", 0x54, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a byte or Boolean value into an array NOLINT(*) +{ "bipush", 0x10, 'b', 0, 1, 'i' }, // → value; push a byte onto the stack as an integer value NOLINT(*) +{ "caload", 0x34, ' ', 2, 1, 'c' }, // arrayref, index → value; load a char from an array NOLINT(*) +{ "castore", 0x55, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a char into an array NOLINT(*) +{ "checkcast", 0xc0, 'C', 1, 1, 'a' }, // objectref → objectref; checks whether an objectref is of a certain type, the class reference of which is in the constant pool at index (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "dadd", 0x63, ' ', 2, 1, 'd' }, // value1, value2 → result; add two doubles NOLINT(*) +{ "daload", 0x31, ' ', 2, 1, 'd' }, // arrayref, index → value; load a double from an array NOLINT(*) +{ "dastore", 0x52, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a double into an array NOLINT(*) +{ "dcmpg", 0x98, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two doubles NOLINT(*) +{ "dcmpl", 0x97, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two doubles NOLINT(*) +{ "dconst_0", 0x0e, ' ', 0, 1, 'd' }, // → 0.0; push the constant 0.0 onto the stack NOLINT(*) +{ "dconst_1", 0x0f, ' ', 0, 1, 'd' }, // → 1.0; push the constant 1.0 onto the stack NOLINT(*) +{ "ddiv", 0x6f, ' ', 2, 1, 'd' }, // value1, value2 → result; divide two doubles NOLINT(*) +{ "dload", 0x18, 'v', 0, 1, 'd' }, // → value; load a double value from a local variable #index NOLINT(*) +{ "dload_0", 0x26, ' ', 0, 1, 'd' }, // → value; load a double from local variable 0 NOLINT(*) +{ "dload_1", 0x27, ' ', 0, 1, 'd' }, // → value; load a double from local variable 1 NOLINT(*) +{ "dload_2", 0x28, ' ', 0, 1, 'd' }, // → value; load a double from local variable 2 NOLINT(*) +{ "dload_3", 0x29, ' ', 0, 1, 'd' }, // → value; load a double from local variable 3 NOLINT(*) +{ "dmul", 0x6b, ' ', 2, 1, 'd' }, // value1, value2 → result; multiply two doubles NOLINT(*) +{ "dneg", 0x77, ' ', 1, 1, 'd' }, // value → result; negate a double NOLINT(*) +{ "drem", 0x73, ' ', 2, 1, 'd' }, // value1, value2 → result; get the remainder from a division between two doubles NOLINT(*) +{ "dreturn", 0xaf, ' ', 1, 0, ' ' }, // value → [empty]; return a double from a method NOLINT(*) +{ "dstore", 0x39, 'v', 1, 0, ' ' }, // value →; store a double value into a local variable #index NOLINT(*) +{ "dstore_0", 0x47, ' ', 1, 0, ' ' }, // value →; store a double into local variable 0 NOLINT(*) +{ "dstore_1", 0x48, ' ', 1, 0, ' ' }, // value →; store a double into local variable 1 NOLINT(*) +{ "dstore_2", 0x49, ' ', 1, 0, ' ' }, // value →; store a double into local variable 2 NOLINT(*) +{ "dstore_3", 0x4a, ' ', 1, 0, ' ' }, // value →; store a double into local variable 3 NOLINT(*) +{ "dsub", 0x67, ' ', 2, 1, 'd' }, // value1, value2 → result; subtract a double from another NOLINT(*) +{ "dup", 0x59, ' ', 1, 2, ' ' }, // value → value, value; duplicate the value on top of the stack NOLINT(*) +{ "dup_x1", 0x5a, ' ', 2, 3, ' ' }, // value2, value1 → value1, value2, value1; insert a copy of the top value into the stack two values from the top. value1 and value2 must not be of the type double or long. NOLINT(*) +{ "dup_x2", 0x5b, ' ', 3, 4, ' ' }, // value3, value2, value1 → value1, value3, value2, value1; insert a copy of the top value into the stack two (if value2 is double or long it takes up the entry of value3, too) or three values (if value2 is neither double nor long) from the top NOLINT(*) +{ "dup2", 0x5c, ' ', 0, 0, ' ' }, // {value2, value1} → {value2, value; value2, value1} }, // duplicate top two stack words NOLINT(*) +{ "dup2_x1", 0x5d, ' ', 0, 0, ' ' }, // value3, {value2, value1} → {value2, value; value3, {value2, value1} }, // duplicate two words and insert beneath third word (see explanation above) NOLINT(*) +{ "dup2_x2", 0x5e, ' ', 0, 0, ' ' }, // {value4, value; value2, value1} → {value2, value1}, {value4, value3}, {value2, value1} }, // duplicate two words and insert beneath fourth word NOLINT(*) +{ "fadd", 0x62, ' ', 2, 1, 'f' }, // value1, value2 → result; add two floats NOLINT(*) +{ "faload", 0x30, ' ', 2, 1, 'f' }, // arrayref, index → value; load a float from an array NOLINT(*) +{ "fastore", 0x51, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a float in an array NOLINT(*) +{ "fcmpg", 0x96, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two floats NOLINT(*) +{ "fcmpl", 0x95, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two floats NOLINT(*) +{ "fconst_0", 0x0b, ' ', 0, 1, 'f' }, // → 0.0f; push 0.0f on the stack NOLINT(*) +{ "fconst_1", 0x0c, ' ', 0, 1, 'f' }, // → 1.0f; push 1.0f on the stack NOLINT(*) +{ "fconst_2", 0x0d, ' ', 0, 1, 'f' }, // → 2.0f; push 2.0f on the stack NOLINT(*) +{ "fdiv", 0x6e, ' ', 2, 1, 'f' }, // value1, value2 → result; divide two floats NOLINT(*) +{ "fload", 0x17, 'v', 0, 1, 'f' }, // → value; load a float value from a local variable #index NOLINT(*) +{ "fload_0", 0x22, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 0 NOLINT(*) +{ "fload_1", 0x23, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 1 NOLINT(*) +{ "fload_2", 0x24, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 2 NOLINT(*) +{ "fload_3", 0x25, ' ', 0, 1, 'f' }, // → value; load a float value from local variable 3 NOLINT(*) +{ "fmul", 0x6a, ' ', 2, 1, 'f' }, // value1, value2 → result; multiply two floats NOLINT(*) +{ "fneg", 0x76, ' ', 1, 1, 'f' }, // value → result; negate a float NOLINT(*) +{ "frem", 0x72, ' ', 2, 1, 'f' }, // value1, value2 → result; get the remainder from a division between two floats NOLINT(*) +{ "freturn", 0xae, ' ', 1, 0, ' ' }, // value → [empty]; return a float NOLINT(*) +{ "fstore", 0x38, 'v', 1, 0, ' ' }, // value →; store a float value into a local variable #index NOLINT(*) +{ "fstore_0", 0x43, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 0 NOLINT(*) +{ "fstore_1", 0x44, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 1 NOLINT(*) +{ "fstore_2", 0x45, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 2 NOLINT(*) +{ "fstore_3", 0x46, ' ', 1, 0, ' ' }, // value →; store a float value into local variable 3 NOLINT(*) +{ "fsub", 0x66, ' ', 2, 1, 'f' }, // value1, value2 → result; subtract two floats NOLINT(*) +{ "getfield", 0xb4, 'C', 1, 1, ' ' }, // objectref → value; get a field value of an object objectref, where the field is identified by field reference in the constant pool index (index1 << 8 + index2) NOLINT(*) +{ "getstatic", 0xb2, 'C', 0, 1, ' ' }, // → value; get a static field value of a class, where the field is identified by field reference in the constant pool index (index1 << 8 + index2) NOLINT(*) +{ "goto", 0xa7, 'o', 0, 0, ' ' }, // [no change]; goes to another instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "goto_w", 0xc8, 'O', 0, 0, ' ' }, // [no change]; goes to another instruction at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) NOLINT(*) +{ "i2l", 0x85, ' ', 1, 1, 'l' }, // value → result; convert an int into a long NOLINT(*) +{ "i2f", 0x86, ' ', 1, 1, 'f' }, // value → result; convert an int into a float NOLINT(*) +{ "i2d", 0x87, ' ', 1, 1, 'd' }, // value → result; convert an int into a double NOLINT(*) +{ "l2i", 0x88, ' ', 1, 1, 'i' }, // value → result; convert a long to a int NOLINT(*) +{ "l2f", 0x89, ' ', 1, 1, 'f' }, // value → result; convert a long to a float NOLINT(*) +{ "l2d", 0x8a, ' ', 1, 1, 'd' }, // value → result; convert a long to a double NOLINT(*) +{ "f2i", 0x8b, ' ', 1, 1, 'i' }, // value → result; convert a float to an int NOLINT(*) +{ "f2l", 0x8c, ' ', 1, 1, 'l' }, // value → result; convert a float to a long NOLINT(*) +{ "f2d", 0x8d, ' ', 1, 1, 'd' }, // value → result; convert a float to a double NOLINT(*) +{ "d2i", 0x8e, ' ', 1, 1, 'i' }, // value → result; convert a double to an int NOLINT(*) +{ "d2l", 0x8f, ' ', 1, 1, 'l' }, // value → result; convert a double to a long NOLINT(*) +{ "d2f", 0x90, ' ', 1, 1, 'f' }, // value → result; convert a double to a float NOLINT(*) +{ "i2b", 0x91, ' ', 1, 1, 'b' }, // value → result; convert an int into a byte NOLINT(*) +{ "i2c", 0x92, ' ', 1, 1, 'c' }, // value → result; convert an int into a character NOLINT(*) +{ "i2s", 0x93, ' ', 1, 1, 's' }, // value → result; convert an int into a short NOLINT(*) +{ "iadd", 0x60, ' ', 2, 1, 'i' }, // value1, value2 → result; add two ints NOLINT(*) +{ "iaload", 0x2e, ' ', 2, 1, 'i' }, // arrayref, index → value; load an int from an array NOLINT(*) +{ "iand", 0x7e, ' ', 2, 1, 'i' }, // value1, value2 → result; perform a bitwise and on two integers NOLINT(*) +{ "iastore", 0x4f, ' ', 3, 0, ' ' }, // arrayref, index, value →; store an int into an array NOLINT(*) +{ "iconst_m1", 0x02, ' ', 0, 1, 'i' }, // → -1; load the int value -1 onto the stack NOLINT(*) +{ "iconst_0", 0x03, ' ', 0, 1, 'i' }, // → 0; load the int value 0 onto the stack NOLINT(*) +{ "iconst_1", 0x04, ' ', 0, 1, 'i' }, // → 1; load the int value 1 onto the stack NOLINT(*) +{ "iconst_2", 0x05, ' ', 0, 1, 'i' }, // → 2; load the int value 2 onto the stack NOLINT(*) +{ "iconst_3", 0x06, ' ', 0, 1, 'i' }, // → 3; load the int value 3 onto the stack NOLINT(*) +{ "iconst_4", 0x07, ' ', 0, 1, 'i' }, // → 4; load the int value 4 onto the stack NOLINT(*) +{ "iconst_5", 0x08, ' ', 0, 1, 'i' }, // → 5; load the int value 5 onto the stack NOLINT(*) +{ "idiv", 0x6c, ' ', 2, 1, 'i' }, // value1, value2 → result; divide two integers NOLINT(*) +{ "if_acmpeq", 0xa5, 'o', 2, 0, ' ' }, // value1, value2 →; if references are equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_acmpne", 0xa6, 'o', 2, 0, ' ' }, // value1, value2 →; if references are not equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmpeq", 0x9f, 'o', 2, 0, ' ' }, // value1, value2 →; if ints are equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmpne", 0xa0, 'o', 2, 0, ' ' }, // value1, value2 →; if ints are not equal, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmplt", 0xa1, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is less than value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmpge", 0xa2, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is greater than or equal to value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmpgt", 0xa3, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is greater than value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "if_icmple", 0xa4, 'o', 2, 0, ' ' }, // value1, value2 →; if value1 is less than or equal to value2, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifeq", 0x99, 'o', 1, 0, ' ' }, // value →; if value is 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifne", 0x9a, 'o', 1, 0, ' ' }, // value →; if value is not 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "iflt", 0x9b, 'o', 1, 0, ' ' }, // value →; if value is less than 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifge", 0x9c, 'o', 1, 0, ' ' }, // value →; if value is greater than or equal to 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifgt", 0x9d, 'o', 1, 0, ' ' }, // value →; if value is greater than 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifle", 0x9e, 'o', 1, 0, ' ' }, // value →; if value is less than or equal to 0, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifnonnull", 0xc7, 'o', 1, 0, ' ' }, // value →; if value is not null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "ifnull", 0xc6, 'o', 1, 0, ' ' }, // value →; if value is null, branch to instruction at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) NOLINT(*) +{ "iinc", 0x84, 'V', 0, 0, ' ' }, // [No change]; increment local variable #index by signed byte const NOLINT(*) +{ "iload", 0x15, 'v', 0, 1, 'i' }, // → value; load an int value from a local variable #index NOLINT(*) +{ "iload_0", 0x1a, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 0 NOLINT(*) +{ "iload_1", 0x1b, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 1 NOLINT(*) +{ "iload_2", 0x1c, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 2 NOLINT(*) +{ "iload_3", 0x1d, ' ', 0, 1, 'i' }, // → value; load an int value from local variable 3 NOLINT(*) +{ "imul", 0x68, ' ', 2, 1, 'i' }, // value1, value2 → result; multiply two integers NOLINT(*) +{ "ineg", 0x74, ' ', 1, 1, 'i' }, // value → result; negate int NOLINT(*) +{ "instanceof", 0xc1, 'C', 1, 1, ' ' }, // objectref → result; determines if an object objectref is of a given type, identified by class reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "invokedynamic", 0xba, 'I', 0, 0, ' ' }, // [arg1, [arg2 ...]] →; invokes a dynamic method identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "invokeinterface", 0xb9, 'I', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invokes an interface method on object objectref, where the interface method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "invokespecial", 0xb7, 'C', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invoke instance method on object objectref, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "invokestatic", 0xb8, 'C', 0, 0, ' ' }, // [arg1, arg2, ...] →; invoke a static method, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "invokevirtual", 0xb6, 'C', 0, 0, ' ' }, // objectref, [arg1, arg2, ...] →; invoke virtual method on object objectref, where the method is identified by method reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "ior", 0x80, ' ', 2, 1, 'i' }, // value1, value2 → result; bitwise int or NOLINT(*) +{ "irem", 0x70, ' ', 2, 1, 'i' }, // value1, value2 → result; logical int remainder NOLINT(*) +{ "ireturn", 0xac, ' ', 1, 0, ' ' }, // value → [empty]; return an integer from a method NOLINT(*) +{ "ishl", 0x78, ' ', 2, 1, 'i' }, // value1, value2 → result; int shift left NOLINT(*) +{ "ishr", 0x7a, ' ', 2, 1, 'i' }, // value1, value2 → result; int arithmetic shift right NOLINT(*) +{ "istore", 0x36, 'v', 1, 0, ' ' }, // value →; store int value into variable #index NOLINT(*) +{ "istore_0", 0x3b, ' ', 1, 0, ' ' }, // value →; store int value into variable 0 NOLINT(*) +{ "istore_1", 0x3c, ' ', 1, 0, ' ' }, // value →; store int value into variable 1 NOLINT(*) +{ "istore_2", 0x3d, ' ', 1, 0, ' ' }, // value →; store int value into variable 2 NOLINT(*) +{ "istore_3", 0x3e, ' ', 1, 0, ' ' }, // value →; store int value into variable 3 NOLINT(*) +{ "isub", 0x64, ' ', 2, 1, 'i' }, // value1, value2 → result; int subtract NOLINT(*) +{ "iushr", 0x7c, ' ', 2, 1, 'i' }, // value1, value2 → result; int logical shift right NOLINT(*) +{ "ixor", 0x82, ' ', 2, 1, 'i' }, // value1, value2 → result; int xor NOLINT(*) +{ "jsr", 0xa8, 'o', 0, 1, 'a' }, // → address; jump to subroutine at branchoffset (signed short constructed from unsigned bytes branchbyte1 << 8 + branchbyte2) and place the return address on the stack NOLINT(*) +{ "jsr_w", 0xc9, 'O', 0, 1, 'a' }, // → address; jump to subroutine at branchoffset (signed int constructed from unsigned bytes branchbyte1 << 24 + branchbyte2 << 16 + branchbyte3 << 8 + branchbyte4) and place the return address on the stack NOLINT(*) +{ "ladd", 0x61, ' ', 2, 1, 'l' }, // value1, value2 → result; add two longs NOLINT(*) +{ "laload", 0x2f, ' ', 2, 1, 'l' }, // arrayref, index → value; load a long from an array NOLINT(*) +{ "land", 0x7f, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise and of two longs NOLINT(*) +{ "lastore", 0x50, ' ', 3, 0, ' ' }, // arrayref, index, value →; store a long to an array NOLINT(*) +{ "lcmp", 0x94, ' ', 2, 1, 'i' }, // value1, value2 → result; compare two long values NOLINT(*) +{ "lconst_0", 0x09, ' ', 0, 1, 'l' }, // → 0L; push the long 0 onto the stack NOLINT(*) +{ "lconst_1", 0x0a, ' ', 0, 1, 'l' }, // → 1L; push the long 1 onto the stack NOLINT(*) +{ "ldc", 0x12, 'c', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (String, int or float) onto the stack NOLINT(*) +{ "ldc_w", 0x13, 'C', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (String, int or float) onto the stack (wide index is constructed as indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "ldc2_w", 0x14, 'C', 0, 1, ' ' }, // → value; push a constant #index from a constant pool (double or long) onto the stack (wide index is constructed as indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "ldiv", 0x6d, ' ', 2, 1, 'l' }, // value1, value2 → result; divide two longs NOLINT(*) +{ "lload", 0x16, 'v', 0, 1, 'l' }, // → value; load a long value from a local variable #index NOLINT(*) +{ "lload_0", 0x1e, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 0 NOLINT(*) +{ "lload_1", 0x1f, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 1 NOLINT(*) +{ "lload_2", 0x20, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 2 NOLINT(*) +{ "lload_3", 0x21, ' ', 0, 1, 'l' }, // → value; load a long value from a local variable 3 NOLINT(*) +{ "lmul", 0x69, ' ', 2, 1, 'l' }, // value1, value2 → result; multiply two longs NOLINT(*) +{ "lneg", 0x75, ' ', 1, 1, 'l' }, // value → result; negate a long NOLINT(*) +{ "lookupswitch", 0xab, 'L', 1, 0, ' ' }, // key →; a target address is looked up from a table using a key and execution continues from the instruction at that address NOLINT(*) +{ "lor", 0x81, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise or of two longs NOLINT(*) +{ "lrem", 0x71, ' ', 2, 1, 'l' }, // value1, value2 → result; remainder of division of two longs NOLINT(*) +{ "lreturn", 0xad, ' ', 1, 0, ' ' }, // value → [empty]; return a long value NOLINT(*) +{ "lshl", 0x79, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift left of a long value1 by value2 positions NOLINT(*) +{ "lshr", 0x7b, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift right of a long value1 by value2 positions NOLINT(*) +{ "lstore", 0x37, 'v', 1, 0, ' ' }, // value →; store a long value in a local variable #index NOLINT(*) +{ "lstore_0", 0x3f, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 0 NOLINT(*) +{ "lstore_1", 0x40, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 1 NOLINT(*) +{ "lstore_2", 0x41, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 2 NOLINT(*) +{ "lstore_3", 0x42, ' ', 1, 0, ' ' }, // value →; store a long value in a local variable 3 NOLINT(*) +{ "lsub", 0x65, ' ', 2, 1, 'l' }, // value1, value2 → result; subtract two longs NOLINT(*) +{ "lushr", 0x7d, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise shift right of a long value1 by value2 positions, unsigned NOLINT(*) +{ "lxor", 0x83, ' ', 2, 1, 'l' }, // value1, value2 → result; bitwise exclusive or of two longs NOLINT(*) +{ "monitorenter", 0xc2, ' ', 1, 0, ' ' }, // objectref →; enter monitor for object ("grab the lock" - start of synchronized() section) NOLINT(*) +{ "monitorexit", 0xc3, ' ', 1, 0, ' ' }, // objectref →; exit monitor for object ("release the lock" - end of synchronized() section) NOLINT(*) +{ "multianewarray", 0xc5, 'm', 0, 1, 'a' }, // count1, [count2,...] → arrayref; create a new array of dimensions dimensions with elements of type identified by class reference in constant pool index (indexbyte1 << 8 + indexbyte2); the sizes of each dimension is identified by count1, [count2, etc.] NOLINT(*) +{ "new", 0xbb, 'C', 0, 1, 'a' }, // → objectref; create new object of type identified by class reference in constant pool index (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "newarray", 0xbc, 't', 1, 1, 'a' }, // count → arrayref; create new array with count elements of primitive type identified by atype NOLINT(*) +{ "nop", 0x00, ' ', 0, 0, ' ' }, // [No change]; perform no operation NOLINT(*) +{ "pop", 0x57, ' ', 1, 0, ' ' }, // value →; discard the top value on the stack NOLINT(*) +{ "pop2", 0x58, ' ', 1, 0, ' ' }, // {value2, value1} →; discard the top two values on the stack (or one value, if it is a double or long) NOLINT(*) +{ "putfield", 0xb5, 'C', 2, 0, ' ' }, // objectref, value →; set field to value in an object objectref, where the field is identified by a field reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "putstatic", 0xb3, 'C', 1, 0, ' ' }, // value →; set static field to value in a class, where the field is identified by a field reference index in constant pool (indexbyte1 << 8 + indexbyte2) NOLINT(*) +{ "ret", 0xa9, 'v', 0, 0, ' ' }, // [No change]; continue execution from address taken from a local variable #index (the asymmetry with jsr is intentional) NOLINT(*) +{ "return", 0xb1, ' ', 0, 0, ' ' }, // → [empty]; return void from method NOLINT(*) +{ "saload", 0x35, ' ', 2, 1, 's' }, // arrayref, index → value; load short from array NOLINT(*) +{ "sastore", 0x56, ' ', 3, 0, 's' }, // arrayref, index, value →; store short to array NOLINT(*) +{ "sipush", 0x11, 's', 0, 1, 's' }, // → value; push a short onto the stack NOLINT(*) +{ "swap", 0x5f, ' ', 2, 2, ' ' }, // value2, value1 → value1, value2; swaps two top words on the stack (note that value1 and value2 must not be double or long) NOLINT(*) +{ "tableswitch", 0xaa, 'T', 1, 0, ' ' }, // index →; continue execution from an address in the table at offset index NOLINT(*) +{ "breakpoint", 0xca, ' ', 0, 0, ' ' }, // ; reserved for breakpoints in Java debuggers; should not appear in any class file NOLINT(*) +{ "impdep1", 0xfe, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file NOLINT(*) +{ "impdep2", 0xff, ' ', 0, 0, ' ' }, // ; reserved for implementation-dependent operations within debuggers; should not appear in any class file NOLINT(*) +{ "wide", 0xc4, ' ', 0, 0, ' ' }, // modifier for others NOLINT(*) { 0, 0 } - }; diff --git a/src/java_bytecode/bytecode_info.h b/src/java_bytecode/bytecode_info.h index 9822710e719..e378c0a18c8 100644 --- a/src/java_bytecode/bytecode_info.h +++ b/src/java_bytecode/bytecode_info.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #ifndef CPROVER_JAVA_BYTECODE_BYTECODE_INFO_H #define CPROVER_JAVA_BYTECODE_BYTECODE_INFO_H @@ -43,13 +51,13 @@ struct bytecode_infot extern struct bytecode_infot const bytecode_info[]; -typedef uint8_t u1; -typedef uint16_t u2; -typedef uint32_t u4; -typedef uint64_t u8; -typedef int8_t s1; -typedef int16_t s2; -typedef int32_t s4; -typedef int64_t s8; +typedef uint8_t u1; // NOLINT(readability/identifiers) +typedef uint16_t u2; // NOLINT(readability/identifiers) +typedef uint32_t u4; // NOLINT(readability/identifiers) +typedef uint64_t u8; // NOLINT(readability/identifiers) +typedef int8_t s1; // NOLINT(readability/identifiers) +typedef int16_t s2; // NOLINT(readability/identifiers) +typedef int32_t s4; // NOLINT(readability/identifiers) +typedef int64_t s8; // NOLINT(readability/identifiers) #endif // CPROVER_JAVA_BYTECODE_BYTECODE_INFO_H diff --git a/src/java_bytecode/jar_file.cpp b/src/java_bytecode/jar_file.cpp index 5e59aadc12e..09c18a9cb4c 100644 --- a/src/java_bytecode/jar_file.cpp +++ b/src/java_bytecode/jar_file.cpp @@ -31,6 +31,7 @@ void jar_filet::open(const std::string &filename) { #ifdef HAVE_LIBZIP if(zip!=nullptr) + // NOLINTNEXTLINE(readability/identifiers) zip_close(static_cast(zip)); int zip_error; @@ -39,6 +40,7 @@ void jar_filet::open(const std::string &filename) if(zip!=nullptr) { std::size_t number_of_files= + // NOLINTNEXTLINE(readability/identifiers) zip_get_num_entries(static_cast(zip), 0); index.reserve(number_of_files); @@ -46,6 +48,7 @@ void jar_filet::open(const std::string &filename) for(std::size_t i=0; i(zip), i, 0); index.push_back(file_name); } @@ -71,6 +74,7 @@ jar_filet::~jar_filet() { #ifdef HAVE_LIBZIP if(zip!=nullptr) + // NOLINTNEXTLINE(readability/identifiers) zip_close(static_cast(zip)); #endif } @@ -99,12 +103,16 @@ std::string jar_filet::get_entry(std::size_t i) std::string dest; #ifdef HAVE_LIBZIP - struct zip_file *zip_file= - zip_fopen_index(static_cast(zip), i, 0); + void *zip_e=zip; // zip is both a type and a non-type + // NOLINTNEXTLINE(readability/identifiers) + struct zip *zip_p=static_cast(zip_e); + + // NOLINTNEXTLINE(readability/identifiers) + struct zip_file *zip_file=zip_fopen_index(zip_p, i, 0); if(zip_file==NULL) { - zip_close(static_cast(zip)); + zip_close(zip_p); zip=nullptr; return std::string(""); // error } @@ -117,7 +125,8 @@ std::string jar_filet::get_entry(std::size_t i) int bytes_read= zip_fread(zip_file, buffer.data(), ZIP_READ_SIZE); assert(bytes_read<=ZIP_READ_SIZE); - if(bytes_read<=0) break; + if(bytes_read<=0) + break; dest.insert(dest.end(), buffer.begin(), buffer.begin()+bytes_read); } @@ -167,7 +176,8 @@ jar_filet::manifestt jar_filet::get_manifest() while(std::getline(in, line)) { std::size_t pos=line.find(':'); - if(pos==std::string::npos) continue; + if(pos==std::string::npos) + continue; std::string key=line.substr(0, pos); // skip spaces diff --git a/src/java_bytecode/jar_file.h b/src/java_bytecode/jar_file.h index 881d8090227..a128a2fcc37 100644 --- a/src/java_bytecode/jar_file.h +++ b/src/java_bytecode/jar_file.h @@ -18,7 +18,7 @@ class jar_filet public: jar_filet():zip(nullptr) { } - inline explicit jar_filet(const std::string &file_name):zip(nullptr) + explicit jar_filet(const std::string &file_name):zip(nullptr) { open(file_name); } @@ -28,7 +28,7 @@ class jar_filet void open(const std::string &); // Test for error; 'true' means we are good. - inline explicit operator bool() const { return zip!=nullptr; } + explicit operator bool() const { return zip!=nullptr; } typedef std::vector indext; indext index; diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index f9cb121091b..54412747708 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -12,7 +12,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include #include #include #include @@ -36,26 +35,31 @@ Author: Daniel Kroening, kroening@kroening.com class patternt { public: - explicit inline patternt(const char *_p):p(_p) + explicit patternt(const char *_p):p(_p) { } // match with '?' - friend bool operator==(const irep_idt &what, const patternt &pattern) + bool operator==(const irep_idt &what) const { for(std::size_t i=0; isecond; diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 43f51269aab..8c0e708a530 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -86,7 +86,7 @@ class java_bytecode_convert_methodt:public messaget protected: typedef std::vector variablest; - expanding_vector variables; + expanding_vectort variables; std::set used_local_names; bool method_has_this; diff --git a/src/java_bytecode/java_bytecode_internal_additions.h b/src/java_bytecode/java_bytecode_internal_additions.h index 099a7484cad..34c47f89414 100644 --- a/src/java_bytecode/java_bytecode_internal_additions.h +++ b/src/java_bytecode/java_bytecode_internal_additions.h @@ -6,6 +6,11 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ +#ifndef CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INTERNAL_ADDITIONS_H +#define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INTERNAL_ADDITIONS_H + #include void java_internal_additions(symbol_tablet &dest); + +#endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INTERNAL_ADDITIONS_H diff --git a/src/java_bytecode/java_bytecode_parse_tree.h b/src/java_bytecode/java_bytecode_parse_tree.h index 69e4aee7f1f..4784f930beb 100644 --- a/src/java_bytecode/java_bytecode_parse_tree.h +++ b/src/java_bytecode/java_bytecode_parse_tree.h @@ -60,7 +60,7 @@ class java_bytecode_parse_treet virtual void output(std::ostream &out) const = 0; - inline membert(): + membert(): is_public(false), is_protected(false), is_private(false), is_static(false), is_final(false) { @@ -147,7 +147,7 @@ class java_bytecode_parse_treet virtual void output(std::ostream &out) const; - inline methodt(): + methodt(): is_native(false), is_abstract(false), is_synchronized(false) @@ -179,13 +179,13 @@ class java_bytecode_parse_treet methodst methods; annotationst annotations; - inline fieldt &add_field() + fieldt &add_field() { fields.push_back(fieldt()); return fields.back(); } - inline methodt &add_method() + methodt &add_method() { methods.push_back(methodt()); return methods.back(); @@ -212,7 +212,7 @@ class java_bytecode_parse_treet bool loading_successful; - inline java_bytecode_parse_treet():loading_successful(false) + java_bytecode_parse_treet():loading_successful(false) { } }; diff --git a/src/java_bytecode/java_bytecode_vtable.cpp b/src/java_bytecode/java_bytecode_vtable.cpp index be0cf2a15b8..d70225d9beb 100644 --- a/src/java_bytecode/java_bytecode_vtable.cpp +++ b/src/java_bytecode/java_bytecode_vtable.cpp @@ -16,27 +16,38 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -const char ID_virtual_name[] = "virtual_name"; +#include "java_bytecode_vtable.h" -class is_virtual_name_equalt { +const char ID_virtual_name[]="virtual_name"; + +class is_virtual_name_equalt +{ const irep_idt &virtual_name; public: - is_virtual_name_equalt(const class_typet::methodt &method) : - virtual_name(method.get(ID_virtual_name)) { + explicit is_virtual_name_equalt(const class_typet::methodt &method): + virtual_name(method.get(ID_virtual_name)) + { } - bool operator()(const class_typet::methodt &method) const { - return virtual_name == method.get(ID_virtual_name); + + bool operator()(const class_typet::methodt &method) const + { + return virtual_name==method.get(ID_virtual_name); } }; -class is_name_equalt { +class is_name_equalt +{ const irep_idt &name; + public: - is_name_equalt(const irep_idt &name) : - name(name) { + explicit is_name_equalt(const irep_idt &name): + name(name) + { } - bool operator()(const class_typet::componentt &component) const { - return name == component.get_name(); + + bool operator()(const class_typet::componentt &component) const + { + return name==component.get_name(); } }; @@ -49,10 +60,13 @@ class java_bytecode_vtable_factoryt public: bool has_error; - java_bytecode_vtable_factoryt(symbol_tablet &symbol_table, - const std::string &module) : - symbol_table(symbol_table), module(module), ns(symbol_table), has_error( - false) + java_bytecode_vtable_factoryt( + symbol_tablet &symbol_table, + const std::string &module): + symbol_table(symbol_table), + module(module), + ns(symbol_table), + has_error(false) { } @@ -67,23 +81,23 @@ class java_bytecode_vtable_factoryt const std::string &class_name=id2string(class_type.get(ID_name)); const std::string &base_class_name=id2string(class_type.get(ID_base_name)); const symbolt &type_symbol(get_vt_type_symbol(class_type)); - result.name = vtnamest::get_table(class_name); - result.base_name = vtnamest::get_table_base(base_class_name); - result.pretty_name = result.base_name; - result.mode = type_symbol.mode; - result.module = module; - result.location = type_symbol.location; - result.type = symbol_typet(type_symbol.name); - result.is_lvalue = true; - result.is_state_var = true; - result.is_static_lifetime = true; + result.name=vtnamest::get_table(class_name); + result.base_name=vtnamest::get_table_base(base_class_name); + result.pretty_name=result.base_name; + result.mode=type_symbol.mode; + result.module=module; + result.location=type_symbol.location; + result.type=symbol_typet(type_symbol.name); + result.is_lvalue=true; + result.is_state_var=true; + result.is_static_lifetime=true; } bool has_component(const class_typet &vtable_type, const irep_idt &ifc_name) { const class_typet::componentst &comps(vtable_type.components()); const is_name_equalt pred(ifc_name); - return std::find_if(comps.begin(), comps.end(), pred) != comps.end(); + return std::find_if(comps.begin(), comps.end(), pred)!=comps.end(); } void add_vtable_entry(struct_exprt &vtable_value, @@ -94,16 +108,17 @@ class java_bytecode_vtable_factoryt const is_virtual_name_equalt pred(implementation); const class_typet::methodst::const_iterator ifc_method( std::find_if(methods.begin(), methods.end(), pred)); - assert(methods.end() != ifc_method); + assert(methods.end()!=ifc_method); symbolt &vtable_type_symbol(get_vt_type_symbol(implementor)); class_typet &vtable_type(to_class_type(vtable_type_symbol.type)); const irep_idt &ifc_name(ifc_method->get_name()); - if (has_component(vtable_type, ifc_name)) return; + if(has_component(vtable_type, ifc_name)) + return; struct_typet::componentt entry_component; entry_component.set_name(ifc_name); entry_component.set_base_name(ifc_method->get_base_name()); - entry_component.type() = pointer_typet(implementation.type()); + entry_component.type()=pointer_typet(implementation.type()); vtable_type.components().push_back(entry_component); const irep_idt &impl_name(implementation.get_name()); @@ -127,12 +142,13 @@ class java_bytecode_vtable_factoryt const typet &type(static_cast(base.find(ID_type))); const symbol_typet &symbol_type(to_symbol_type(type)); const irep_idt &base_class_name(symbol_type.get_identifier()); - if (!symbol_table.has_symbol(base_class_name)) return false; + if(!symbol_table.has_symbol(base_class_name)) + return false; const symbolt &base_class_symbol(ns.lookup(base_class_name)); const class_typet &base_class_type(to_class_type(base_class_symbol.type)); const class_typet::methodst &methods(base_class_type.methods()); const is_virtual_name_equalt pred(method); - return std::find_if(methods.begin(), methods.end(), pred) != methods.end(); + return std::find_if(methods.begin(), methods.end(), pred)!=methods.end(); } void extract_types( @@ -141,9 +157,10 @@ class java_bytecode_vtable_factoryt const class_typet::methodt &method) { for(irept::subt::const_iterator it=types.begin(); - it != types.end(); ++it) + it!=types.end(); ++it) { - if (!has_method(*it, method)) continue; + if(!has_method(*it, method)) + continue; result.push_back(get_class_type(*it)); } } @@ -159,10 +176,11 @@ class java_bytecode_vtable_factoryt const class_typet &class_type, const class_typet::methodt &method) { - if (!is_virtual(method)) return; + if(!is_virtual(method)) + return; std::vector bases; extract_types(bases, class_type.bases(), method); - //extract_types(bases, class_type.find(ID_interfaces).get_sub(), method); + // extract_types(bases, class_type.find(ID_interfaces).get_sub(), method); for(const std::vector::value_type &b : bases) add_vtable_entry(vtable_value, b, class_type, method); } @@ -170,21 +188,24 @@ class java_bytecode_vtable_factoryt void create_vtable_entry(struct_exprt &vtable_value, const class_typet &class_type, const class_typet::methodt &method) { - if (!is_virtual(method)) return; + if(!is_virtual(method)) + return; add_vtable_entry(vtable_value, class_type, class_type, method); } void set_vtable_value(symbolt &vtable_symbol, const class_typet &class_type, - struct_exprt &vtable_value) { + struct_exprt &vtable_value) + { const std::string &class_name(id2string(class_type.get(ID_name))); const irep_idt vttype(vtnamest::get_type(class_name)); - vtable_value.type() = symbol_typet(vttype); - vtable_symbol.value = vtable_value; + vtable_value.type()=symbol_typet(vttype); + vtable_symbol.value=vtable_value; } bool is_class_with_vt(const symbolt &symbol) { - if (!symbol.is_type || ID_struct != symbol.type.id()) return false; + if(!symbol.is_type || ID_struct!=symbol.type.id()) + return false; const class_typet &class_type(to_class_type(symbol.type)); const std::string &class_name(id2string(class_type.get(ID_name))); return symbol_table.has_symbol(vtnamest::get_type(class_name)); @@ -192,18 +213,20 @@ class java_bytecode_vtable_factoryt void operator()(const irep_idt &symbol_name) { - const symbolt &symbol = symbol_table.lookup(symbol_name); - if (!is_class_with_vt(symbol)) return; + const symbolt &symbol=symbol_table.lookup(symbol_name); + if(!is_class_with_vt(symbol)) + return; const class_typet &class_type(to_class_type(symbol.type)); const std::string &class_name(id2string(symbol_name)); - if (symbol_table.has_symbol(vtnamest::get_table(class_name))) return; + if(symbol_table.has_symbol(vtnamest::get_table(class_name))) + return; symbolt vtable_symbol; create_vtable_symbol(vtable_symbol, class_type); const class_typet::methodst &methods(class_type.methods()); struct_exprt vtable_value; - for (const class_typet::methodst::value_type &m : methods) + for(const class_typet::methodst::value_type &m : methods) create_base_vtable_entries(vtable_value, class_type, m); - for (const class_typet::methodst::value_type &m : methods) + for(const class_typet::methodst::value_type &m : methods) create_vtable_entry(vtable_value, class_type, m); set_vtable_value(vtable_symbol, class_type, vtable_value); assert(!symbol_table.add(vtable_symbol)); @@ -238,29 +261,28 @@ bool java_bytecode_vtable( return factory.has_error; } -namespace +static void create_vtable_type( + const irep_idt &vt_name, + symbol_tablet &symbol_table, + const symbolt &class_symbol) { - -void create_vtable_type(const irep_idt &vt_name, symbol_tablet &symbol_table, - const symbolt &class_symbol) { symbolt vt_symb_type; - vt_symb_type.name = vt_name; - vt_symb_type.base_name = vtnamest::get_type_base( + vt_symb_type.name=vt_name; + vt_symb_type.base_name=vtnamest::get_type_base( id2string(class_symbol.base_name)); - vt_symb_type.pretty_name = vt_symb_type.base_name; - vt_symb_type.mode = class_symbol.mode; - vt_symb_type.module = class_symbol.module; - vt_symb_type.location = class_symbol.location; - vt_symb_type.type = struct_typet(); + vt_symb_type.pretty_name=vt_symb_type.base_name; + vt_symb_type.mode=class_symbol.mode; + vt_symb_type.module=class_symbol.module; + vt_symb_type.location=class_symbol.location; + vt_symb_type.type=struct_typet(); vt_symb_type.type.set(ID_name, vt_symb_type.name); - vt_symb_type.is_type = true; + vt_symb_type.is_type=true; assert(!symbol_table.add(vt_symb_type)); } -const char ID_isvtptr[] = "is_vtptr"; -const char ID_vtable_pointer[] = "@vtable_pointer"; +#define ID_vtable_pointer "@vtable_pointer" -void add_vtable_pointer_member( +static void add_vtable_pointer_member( const irep_idt &vt_name, symbolt &class_symbol) { @@ -270,14 +292,12 @@ void add_vtable_pointer_member( comp.set_name(ID_vtable_pointer); comp.set_base_name(ID_vtable_pointer); comp.set_pretty_name(ID_vtable_pointer); - comp.set(ID_isvtptr, true); + comp.set("is_vtptr", true); struct_typet &class_type=to_struct_type(class_symbol.type); class_type.components().push_back(comp); } -} - /******************************************************************* Function: create_vtable_symbol @@ -317,8 +337,9 @@ bool has_vtable_info( const symbol_tablet &symbol_table, const symbolt &class_symbol) { - return symbol_table.has_symbol(vtnamest::get_type(id2string(class_symbol.name))) - && to_struct_union_type(class_symbol.type).has_component(ID_vtable_pointer); + return + symbol_table.has_symbol(vtnamest::get_type(id2string(class_symbol.name))) && + to_struct_union_type(class_symbol.type).has_component(ID_vtable_pointer); } /******************************************************************* @@ -341,10 +362,6 @@ void create_vtable_pointer(symbolt &class_symbol) add_vtable_pointer_member(vttype, class_symbol); } -namespace { -const char NAME_SEP = '.'; -} - /******************************************************************* Function: get_virtual_name @@ -360,39 +377,33 @@ const char NAME_SEP = '.'; void set_virtual_name(class_typet::methodt &method) { const std::string &name(id2string(method.get(ID_name))); - const std::string::size_type vname_start(name.find_last_of(NAME_SEP) + 1); + const std::string::size_type vname_start(name.find_last_of('.') + 1); std::string virtual_name(name.substr(vname_start)); method.set(ID_virtual_name, virtual_name); } -namespace { - -exprt get_ref( +static exprt get_ref( const exprt &this_obj, const symbol_typet &target_type) { const typet &type(this_obj.type()); const irep_idt &type_id(type.id()); - if(ID_symbol == type_id) + if(ID_symbol==type_id) return get_ref(address_of_exprt(this_obj), target_type); - assert(ID_pointer == type_id); + assert(ID_pointer==type_id); const typecast_exprt cast(this_obj, pointer_typet(target_type)); return dereference_exprt(cast, target_type); } -const char JAVA_NS[] = "java::"; -const size_t JAVA_NS_LENGTH(6); -const char CLS_MTD_SEP(':'); -const char NSEP('.'); - -std::string get_full_class_name(const std::string &name) { - const bool has_prefix(name.find(JAVA_NS) != std::string::npos); - const std::string::size_type offset(has_prefix ? JAVA_NS_LENGTH : 0); - const std::string::size_type end(name.find_first_of(CLS_MTD_SEP, offset)); - const std::string::size_type last_sep(name.rfind(NSEP, end)); +static std::string get_full_class_name(const std::string &name) +{ + const bool has_prefix(name.find("java::")!=std::string::npos); + const std::string::size_type offset= + has_prefix ? std::string("java::").size() : 0; + const std::string::size_type end(name.find_first_of(':', offset)); + const std::string::size_type last_sep(name.rfind('.', end)); return name.substr(0, last_sep); } -} /******************************************************************* @@ -414,7 +425,8 @@ exprt make_vtable_function( const std::string class_id(get_full_class_name(id2string(func_name))); // TODO: Handle unavailable models! - if (class_id.find("java.") != std::string::npos) { + if(class_id.find("java.")!=std::string::npos) + { // When translating a single java_bytecode_parse_treet, we don't know // which classes will eventually be available yet. If we could provide // access to the class loader here, we know which classes have been diff --git a/src/java_bytecode/java_class_loader.h b/src/java_bytecode/java_class_loader.h index d3fcdd62810..4d67b3e7164 100644 --- a/src/java_bytecode/java_class_loader.h +++ b/src/java_bytecode/java_class_loader.h @@ -28,7 +28,7 @@ class java_class_loadert:public messaget static std::string file_to_class_name(const std::string &); static std::string class_name_to_file(const irep_idt &); - inline void add_jar_file(const std::string &f) + void add_jar_file(const std::string &f) { jar_files.push_back(f); } diff --git a/src/java_bytecode/java_entry_point.cpp b/src/java_bytecode/java_entry_point.cpp index d4d40beff3b..dcc3dead0a8 100644 --- a/src/java_bytecode/java_entry_point.cpp +++ b/src/java_bytecode/java_entry_point.cpp @@ -21,6 +21,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include + #include #include @@ -219,7 +220,7 @@ exprt::operandst java_build_arguments( to_code_type(function.type).return_type().id()==ID_empty && (!to_code_type(function.type).has_this()) && parameters.size()==1 && - full_eq(parameters[0].type(), string_array_type); + parameters[0].type().full_eq(string_array_type); is_main=(named_main && has_correct_type); } diff --git a/src/java_bytecode/java_local_variable_table.cpp b/src/java_bytecode/java_local_variable_table.cpp index 3cfb5030136..33e8a39f5db 100644 --- a/src/java_bytecode/java_local_variable_table.cpp +++ b/src/java_bytecode/java_local_variable_table.cpp @@ -22,7 +22,7 @@ struct procedure_local_cfg_baset< T, java_bytecode_convert_methodt::method_with_amapt, unsigned> : - public graph > + public grapht > { typedef java_bytecode_convert_methodt::method_with_amapt method_with_amapt; typedef std::map entry_mapt; @@ -412,7 +412,7 @@ Function: get_common_dominator \*******************************************************************/ static unsigned get_common_dominator( - const std::set& merge_vars, + const std::set &merge_vars, const java_cfg_dominatorst &dominator_analysis) { assert(!merge_vars.empty()); diff --git a/src/java_bytecode/java_types.cpp b/src/java_bytecode/java_types.cpp index de89fc0e209..735a2a0dbfb 100644 --- a/src/java_bytecode/java_types.cpp +++ b/src/java_bytecode/java_types.cpp @@ -345,7 +345,8 @@ typet java_type_from_string(const std::string &src) case '(': // function type { std::size_t e_pos=src.rfind(')'); - if(e_pos==std::string::npos) return nil_typet(); + if(e_pos==std::string::npos) + return nil_typet(); code_typet result; @@ -387,9 +388,11 @@ typet java_type_from_string(const std::string &src) { // If this is a reference array, we generate a plain array[reference] // with void* members, but note the real type in ID_C_element_type. - if(src.size()<=1) return nil_typet(); + if(src.size()<=1) + return nil_typet(); char subtype_letter=src[1]; - const typet subtype=java_type_from_string(src.substr(1, std::string::npos)); + const typet subtype= + java_type_from_string(src.substr(1, std::string::npos)); if(subtype_letter=='L' || // [L denotes a reference array of some sort. subtype_letter=='[') // Array-of-arrays subtype_letter='A'; @@ -411,11 +414,13 @@ typet java_type_from_string(const std::string &src) case 'L': { // ends on ; - if(src[src.size()-1]!=';') return nil_typet(); + if(src[src.size()-1]!=';') + return nil_typet(); std::string class_name=src.substr(1, src.size()-2); for(unsigned i=0; isecond); + symbol_tablet::symbolst::const_iterator s_it= + symbol_table.symbols.find(it->second); - if(s_it==symbol_table.symbols.end()) continue; + if(s_it==symbol_table.symbols.end()) + continue; if(s_it->second.type.id()==ID_code) matches.push_back(it->second); @@ -119,7 +121,8 @@ bool jsil_entry_point( main_symbol=ID_main; // look it up - symbol_tablet::symbolst::const_iterator s_it=symbol_table.symbols.find(main_symbol); + symbol_tablet::symbolst::const_iterator s_it= + symbol_table.symbols.find(main_symbol); if(s_it==symbol_table.symbols.end()) { diff --git a/src/jsil/jsil_internal_additions.h b/src/jsil/jsil_internal_additions.h index 6b2a4b6b0d9..f57cc098189 100644 --- a/src/jsil/jsil_internal_additions.h +++ b/src/jsil/jsil_internal_additions.h @@ -6,6 +6,11 @@ Author: Michael Tautschnig, tautschn@amazon.com \*******************************************************************/ +#ifndef CPROVER_JSIL_JSIL_INTERNAL_ADDITIONS_H +#define CPROVER_JSIL_JSIL_INTERNAL_ADDITIONS_H + class symbol_tablet; void jsil_internal_additions(symbol_tablet &dest); + +#endif // CPROVER_JSIL_JSIL_INTERNAL_ADDITIONS_H diff --git a/src/jsil/jsil_language.cpp b/src/jsil/jsil_language.cpp index cf7867437c4..6c022e65069 100644 --- a/src/jsil/jsil_language.cpp +++ b/src/jsil/jsil_language.cpp @@ -167,7 +167,6 @@ Function: jsil_languaget::final bool jsil_languaget::final(symbol_tablet &symbol_table) { - if(jsil_entry_point( symbol_table, get_message_handler())) diff --git a/src/jsil/jsil_typecheck.cpp b/src/jsil/jsil_typecheck.cpp index f8a9cfeb34e..38a1b94e6be 100644 --- a/src/jsil/jsil_typecheck.cpp +++ b/src/jsil/jsil_typecheck.cpp @@ -87,7 +87,7 @@ void jsil_typecheckt::update_expr_type(exprt &expr, const typet &type) const irep_idt &id=to_symbol_expr(expr).get_identifier(); if(!symbol_table.has_symbol(id)) - throw "Unexpected symbol: "+id2string(id); + throw "unexpected symbol: "+id2string(id); symbolt &s=symbol_table.lookup(id); if(s.type.id().empty() || s.type.is_nil()) @@ -258,16 +258,16 @@ void jsil_typecheckt::typecheck_expr_main(exprt &expr) throw 0; } else if(expr.id()==ID_symbol) - typecheck_symbol_expr(to_symbol_expr (expr)); + typecheck_symbol_expr(to_symbol_expr(expr)); else if(expr.id()==ID_constant) { } else { // expressions are expected not to have type set just yet - assert(expr.type().is_nil()||expr.type().id().empty()); + assert(expr.type().is_nil() || expr.type().id().empty()); - if (expr.id()==ID_null || + if(expr.id()==ID_null || expr.id()=="undefined" || expr.id()==ID_empty) typecheck_expr_constant(expr); @@ -306,7 +306,8 @@ void jsil_typecheckt::typecheck_expr_main(exprt &expr) typecheck_expr_unary_num(expr); expr.type()=floatbv_typet(); } - else if(expr.id()=="num_to_string") { + else if(expr.id()=="num_to_string") + { typecheck_expr_unary_num(expr); expr.type()=string_typet(); } @@ -518,7 +519,7 @@ void jsil_typecheckt::typecheck_expr_index(exprt &expr) make_type_compatible(expr.op1(), string_typet(), true); // special case for function identifiers - if (expr.op1().id()=="fid" || expr.op1().id()=="constructid") + if(expr.op1().id()=="fid" || expr.op1().id()=="constructid") expr.type()=code_typet(); else expr.type()=jsil_value_type(); @@ -783,7 +784,7 @@ void jsil_typecheckt::typecheck_exp_binary_equal(exprt &expr) throw 0; } - // operands can be of any types + // operands can be of any types expr.type()=bool_typet(); } @@ -1141,7 +1142,8 @@ void jsil_typecheckt::typecheck_function_call( for(std::size_t i=0; i=call.arguments().size()) break; + if(i>=call.arguments().size()) + break; const typet ¶m_type=codet.parameters()[i].type(); @@ -1285,7 +1287,7 @@ void jsil_typecheckt::typecheck_non_type_symbol(symbolt &symbol) // Do nothing } else - throw "Non type symbol value expected code, but got "+ + throw "non-type symbol value expected code, but got "+ symbol.value.pretty(); } diff --git a/src/jsil/jsil_typecheck.h b/src/jsil/jsil_typecheck.h index f515147a297..68988a80273 100644 --- a/src/jsil/jsil_typecheck.h +++ b/src/jsil/jsil_typecheck.h @@ -51,9 +51,9 @@ class jsil_typecheckt:public typecheckt // prefix to variables which is set in typecheck_declaration irep_idt proc_name; - void update_expr_type (exprt &expr, const typet &type); + void update_expr_type(exprt &expr, const typet &type); void make_type_compatible(exprt &expr, const typet &type, bool must); - void typecheck_type_symbol(symbolt &symbol) {}; + void typecheck_type_symbol(symbolt &symbol) {} void typecheck_non_type_symbol(symbolt &symbol); void typecheck_symbol_expr(symbol_exprt &symbol_expr); void typecheck_expr_side_effect_throw(side_effect_expr_throwt &expr); @@ -83,7 +83,7 @@ class jsil_typecheckt:public typecheckt void typecheck_block(codet &code); void typecheck_ifthenelse(code_ifthenelset &code); void typecheck_assign(code_assignt &code); - void typecheck_try_catch (code_try_catcht &code); + void typecheck_try_catch(code_try_catcht &code); void typecheck_type(typet &type); irep_idt add_prefix(const irep_idt &ds); diff --git a/src/jsil/jsil_types.cpp b/src/jsil/jsil_types.cpp index c9d96f4d64b..ffccfd16bbe 100644 --- a/src/jsil/jsil_types.cpp +++ b/src/jsil/jsil_types.cpp @@ -24,7 +24,7 @@ Function: jsil_any_type typet jsil_any_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_empty_type(), jsil_reference_type(), jsil_value_type() @@ -45,7 +45,7 @@ Function: jsil_value_or_empty_type typet jsil_value_or_empty_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_value_type(), jsil_empty_type() }); @@ -65,7 +65,7 @@ Function: jsil_value_or_reference_type typet jsil_value_or_reference_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_value_type(), jsil_reference_type() }); @@ -85,7 +85,7 @@ Function: jsil_value_type typet jsil_value_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_undefined_type(), jsil_null_type(), jsil_prim_type(), @@ -107,7 +107,7 @@ Function: jsil_prim_type typet jsil_prim_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) floatbv_typet(), string_typet(), bool_typet() @@ -128,7 +128,7 @@ Function: jsil_reference_type typet jsil_reference_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_member_reference_type(), jsil_variable_reference_type() }); @@ -182,7 +182,7 @@ Function: jsil_object_type typet jsil_object_type() { - return jsil_union_typet({ + return jsil_union_typet({ // NOLINT(whitespace/braces) jsil_user_object_type(), jsil_builtin_object_type() }); @@ -449,7 +449,7 @@ jsil_union_typet jsil_union_typet::intersect_with( auto &elements2=other.components(); jsil_union_typet result; auto &elements=result.components(); - elements.resize(std::min(elements1.size(),elements2.size())); + elements.resize(std::min(elements1.size(), elements2.size())); std::vector::iterator it=std::set_intersection( elements1.begin(), elements1.end(), elements2.begin(), elements2.end(), @@ -516,7 +516,7 @@ Function: jsil_union_typet::to_type() \*******************************************************************/ -const typet& jsil_union_typet::to_type() const +const typet &jsil_union_typet::to_type() const { auto &elements=components(); if(elements.size()==1) diff --git a/src/jsil/jsil_types.h b/src/jsil/jsil_types.h index d76f73873d4..b27be7f3219 100644 --- a/src/jsil/jsil_types.h +++ b/src/jsil/jsil_types.h @@ -35,21 +35,21 @@ typet jsil_union(const typet &type1, const typet &type2); class jsil_builtin_code_typet:public code_typet { public: - explicit inline jsil_builtin_code_typet(code_typet &code): + explicit jsil_builtin_code_typet(code_typet &code): code_typet(code) { set("jsil_builtin_proceduret", true); } }; -extern inline jsil_builtin_code_typet &to_jsil_builtin_code_type( +inline jsil_builtin_code_typet &to_jsil_builtin_code_type( code_typet &code) { assert(code.get_bool("jsil_builtin_proceduret")); return static_cast(code); } -extern inline bool is_jsil_builtin_code_type(const typet &type) +inline bool is_jsil_builtin_code_type(const typet &type) { return type.id()==ID_code && type.get_bool("jsil_builtin_proceduret"); @@ -58,21 +58,21 @@ extern inline bool is_jsil_builtin_code_type(const typet &type) class jsil_spec_code_typet:public code_typet { public: - explicit inline jsil_spec_code_typet(code_typet &code): + explicit jsil_spec_code_typet(code_typet &code): code_typet(code) { set("jsil_spec_proceduret", true); } }; -extern inline jsil_spec_code_typet &to_jsil_spec_code_type( +inline jsil_spec_code_typet &to_jsil_spec_code_type( code_typet &code) { assert(code.get_bool("jsil_spec_proceduret")); return static_cast(code); } -extern inline bool is_jsil_spec_code_type(const typet &type) +inline bool is_jsil_spec_code_type(const typet &type) { return type.id()==ID_code && type.get_bool("jsil_spec_proceduret"); @@ -81,9 +81,9 @@ extern inline bool is_jsil_spec_code_type(const typet &type) class jsil_union_typet:public union_typet { public: - inline jsil_union_typet():union_typet() { } + jsil_union_typet():union_typet() { } - explicit inline jsil_union_typet(const typet &type) + explicit jsil_union_typet(const typet &type) :jsil_union_typet(std::vector({type})) { } explicit jsil_union_typet(const std::vector &types); @@ -94,17 +94,16 @@ class jsil_union_typet:public union_typet bool is_subtype(const jsil_union_typet &other) const; - const typet& to_type() const; + const typet &to_type() const; }; -extern inline jsil_union_typet &to_jsil_union_type(typet &type) +inline jsil_union_typet &to_jsil_union_type(typet &type) { assert(type.id()==ID_union); return static_cast(type); } -extern inline const jsil_union_typet &to_jsil_union_type( - const typet &type) +inline const jsil_union_typet &to_jsil_union_type(const typet &type) { assert(type.id()==ID_union); return static_cast(type); diff --git a/src/json/json_parser.cpp b/src/json/json_parser.cpp index 4bc8a2b5d38..04c6d7dbfde 100644 --- a/src/json/json_parser.cpp +++ b/src/json/json_parser.cpp @@ -68,7 +68,8 @@ bool parse_json( { std::ifstream in(filename); - if(!in) return true; + if(!in) + return true; return parse_json(in, filename, message_handler, dest); } diff --git a/src/json/json_parser.h b/src/json/json_parser.h index 6d26b77802c..2983d2542a5 100644 --- a/src/json/json_parser.h +++ b/src/json/json_parser.h @@ -23,19 +23,19 @@ class json_parsert:public parsert typedef std::stack > stackt; stackt stack; - inline jsont &top() { return stack.top(); } + jsont &top() { return stack.top(); } virtual bool parse() override { return yyjsonparse()!=0; } - inline void push(const jsont &x) + void push(const jsont &x) { stack.push(x); } - inline void pop(jsont &dest) + void pop(jsont &dest) { assert(!stack.empty()); dest.swap(stack.top()); diff --git a/src/langapi/language_ui.cpp b/src/langapi/language_ui.cpp index 3775c3c6125..8640d735631 100644 --- a/src/langapi/language_ui.cpp +++ b/src/langapi/language_ui.cpp @@ -278,7 +278,8 @@ void language_uit::show_symbol_table_plain( else { ptr=get_language_from_mode(symbol.mode); - if(ptr==NULL) throw "symbol "+id2string(symbol.name)+" has unknown mode"; + if(ptr==NULL) + throw "symbol "+id2string(symbol.name)+" has unknown mode"; } std::unique_ptr p(ptr); @@ -305,22 +306,38 @@ void language_uit::show_symbol_table_plain( out << "Value.......: " << value_str << '\n'; out << "Flags.......:"; - if(symbol.is_lvalue) out << " lvalue"; - if(symbol.is_static_lifetime) out << " static_lifetime"; - if(symbol.is_thread_local) out << " thread_local"; - if(symbol.is_file_local) out << " file_local"; - if(symbol.is_type) out << " type"; - if(symbol.is_extern) out << " extern"; - if(symbol.is_input) out << " input"; - if(symbol.is_output) out << " output"; - if(symbol.is_macro) out << " macro"; - if(symbol.is_parameter) out << " parameter"; - if(symbol.is_auxiliary) out << " auxiliary"; - if(symbol.is_weak) out << " weak"; - if(symbol.is_property) out << " property"; - if(symbol.is_state_var) out << " state_var"; - if(symbol.is_exported) out << " exported"; - if(symbol.is_volatile) out << " volatile"; + if(symbol.is_lvalue) + out << " lvalue"; + if(symbol.is_static_lifetime) + out << " static_lifetime"; + if(symbol.is_thread_local) + out << " thread_local"; + if(symbol.is_file_local) + out << " file_local"; + if(symbol.is_type) + out << " type"; + if(symbol.is_extern) + out << " extern"; + if(symbol.is_input) + out << " input"; + if(symbol.is_output) + out << " output"; + if(symbol.is_macro) + out << " macro"; + if(symbol.is_parameter) + out << " parameter"; + if(symbol.is_auxiliary) + out << " auxiliary"; + if(symbol.is_weak) + out << " weak"; + if(symbol.is_property) + out << " property"; + if(symbol.is_state_var) + out << " state_var"; + if(symbol.is_exported) + out << " exported"; + if(symbol.is_volatile) + out << " volatile"; out << '\n'; out << "Location....: " << symbol.location << '\n'; diff --git a/src/langapi/mode.cpp b/src/langapi/mode.cpp index e18c657afcf..525a9519afd 100644 --- a/src/langapi/mode.cpp +++ b/src/langapi/mode.cpp @@ -88,12 +88,14 @@ languaget *get_language_from_filename(const std::string &filename) { std::size_t ext_pos=filename.rfind('.'); - if(ext_pos==std::string::npos) return NULL; + if(ext_pos==std::string::npos) + return NULL; std::string extension= std::string(filename, ext_pos+1, std::string::npos); - if(extension=="") return NULL; + if(extension=="") + return NULL; for(languagest::const_iterator l_it=languages.begin(); diff --git a/src/linking/linking.cpp b/src/linking/linking.cpp index 3ff4d09de22..b66c0591b4b 100644 --- a/src/linking/linking.cpp +++ b/src/linking/linking.cpp @@ -114,7 +114,8 @@ std::string linkingt::type_to_string_verbose( std::string result=followed.id_string(); const std::string &tag=followed.get_string(ID_tag); - if(tag!="") result+=" "+tag; + if(tag!="") + result+=" "+tag; result+=" {\n"; const struct_union_typet::componentst &components= @@ -225,6 +226,7 @@ void linkingt::detailed_conflict_report_rec( msg+=std::to_string(components2.size())+')'; } else + { for(std::size_t i=0; i id_sett; bool needs_renaming_type( diff --git a/src/linking/remove_internal_symbols.cpp b/src/linking/remove_internal_symbols.cpp index 88d2c435642..f3dd5cf5e68 100644 --- a/src/linking/remove_internal_symbols.cpp +++ b/src/linking/remove_internal_symbols.cpp @@ -51,7 +51,8 @@ void get_symbols_rec( irep_idt id=it->get_identifier(); const symbolt *s; // identifiers for prototypes need not exist - if(!ns.lookup(id, s)) new_symbols.insert(id); + if(!ns.lookup(id, s)) + new_symbols.insert(id); } } diff --git a/src/linking/static_lifetime_init.cpp b/src/linking/static_lifetime_init.cpp index 8e7d475766c..29f5005d685 100644 --- a/src/linking/static_lifetime_init.cpp +++ b/src/linking/static_lifetime_init.cpp @@ -45,7 +45,8 @@ bool static_lifetime_init( symbol_tablet::symbolst::iterator s_it= symbol_table.symbols.find(INITIALIZE_FUNCTION); - if(s_it==symbol_table.symbols.end()) return false; + if(s_it==symbol_table.symbols.end()) + return false; symbolt &init_symbol=s_it->second; @@ -71,9 +72,11 @@ bool static_lifetime_init( const irep_idt &identifier=symbol.name; - if(!symbol.is_static_lifetime) continue; + if(!symbol.is_static_lifetime) + continue; - if(symbol.is_type || symbol.is_macro) continue; + if(symbol.is_type || symbol.is_macro) + continue; // special values if(identifier==CPROVER_PREFIX "constant_infinity_uint" || @@ -131,14 +134,12 @@ bool static_lifetime_init( if(symbol.value.is_nil()) { - try { namespacet ns(symbol_table); rhs=zero_initializer(symbol.type, symbol.location, ns, message_handler); assert(rhs.is_not_nil()); } - catch(...) { return true; diff --git a/src/linking/zero_initializer.cpp b/src/linking/zero_initializer.cpp index 071cb34aa27..9e96c48480b 100644 --- a/src/linking/zero_initializer.cpp +++ b/src/linking/zero_initializer.cpp @@ -220,7 +220,8 @@ exprt zero_initializert::zero_initializer_rec( value.copy_to_operands(code_value); } else - value.copy_to_operands(zero_initializer_rec(it->type(), source_location)); + value.copy_to_operands( + zero_initializer_rec(it->type(), source_location)); } value.add_source_location()=source_location; @@ -246,7 +247,8 @@ exprt zero_initializert::zero_initializer_rec( it++) { // skip methods - if(it->type().id()==ID_code) continue; + if(it->type().id()==ID_code) + continue; mp_integer bits=pointer_offset_bits(it->type(), ns); diff --git a/src/memory-models/mm2cpp.cpp b/src/memory-models/mm2cpp.cpp index 838ed6133d4..bc3eb0d9e18 100644 --- a/src/memory-models/mm2cpp.cpp +++ b/src/memory-models/mm2cpp.cpp @@ -15,7 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com class mm2cppt { public: - inline mm2cppt(std::ostream &_out):out(_out) + explicit mm2cppt(std::ostream &_out):out(_out) { } diff --git a/src/musketeer/cycles_visitor.cpp b/src/musketeer/cycles_visitor.cpp index 267cade2ecd..c5fc1402311 100644 --- a/src/musketeer/cycles_visitor.cpp +++ b/src/musketeer/cycles_visitor.cpp @@ -30,11 +30,11 @@ class instrumentert; \*******************************************************************/ /* po^+ /\ U{C_1, ..., C_n} \/ delays */ -void cycles_visitort::po_edges(std::set& edges) +void cycles_visitort::po_edges(std::set &edges) { - instrumentert& instrumenter=fence_inserter.instrumenter; + instrumentert &instrumenter=fence_inserter.instrumenter; - event_grapht& egraph=instrumenter.egraph; + event_grapht &egraph=instrumenter.egraph; for(std::set::iterator C_j=instrumenter.set_of_cycles.begin(); @@ -161,9 +161,13 @@ void cycles_visitort::po_edges(std::set& edges) event_grapht::critical_cyclet::const_iterator C_k_it=C_k->begin(); for(; C_j_it!=C_j->end(); ++C_j_it) { - for(; C_k_it!=C_k->end() - && !egraph.are_po_ordered(*C_j_it,*C_k_it) - && !egraph.are_po_ordered(*C_k_it,*C_j_it); ++C_k_it); + for( ; + C_k_it!=C_k->end() && + !egraph.are_po_ordered(*C_j_it, *C_k_it) && + !egraph.are_po_ordered(*C_k_it, *C_j_it); + ++C_k_it) + { + } if(C_k_it!=C_k->end()) break; @@ -174,8 +178,8 @@ void cycles_visitort::po_edges(std::set& edges) #endif /* computes the largest pos+ in C_j */ - std::map m_begin; - std::map m_end; + std::map m_begin; + std::map m_end; std::set m_threads; unsigned previous_thread=0; @@ -197,8 +201,8 @@ void cycles_visitort::po_edges(std::set& edges) } /* computes the largest pos+ in C_k */ - std::map k_begin; - std::map k_end; + std::map k_begin; + std::map k_end; std::set k_threads; previous_thread=0; @@ -229,18 +233,18 @@ void cycles_visitort::po_edges(std::set& edges) const event_idt c=*k_begin[*it]; const event_idt d=*k_end[*it]; - if(egraph.are_po_ordered(b,c)) + if(egraph.are_po_ordered(b, c)) continue; - else if (egraph.are_po_ordered(d,a)) + else if(egraph.are_po_ordered(d, a)) continue; - else if (egraph.are_po_ordered(a,c) && egraph.are_po_ordered(b,d)) - fence_inserter.add_edge(edget(c,b)); - else if (egraph.are_po_ordered(a,c) && egraph.are_po_ordered(d,b)) - fence_inserter.add_edge(edget(c,d)); - else if (egraph.are_po_ordered(c,a) && egraph.are_po_ordered(b,d)) - fence_inserter.add_edge(edget(a,b)); - else if (egraph.are_po_ordered(c,a) && egraph.are_po_ordered(d,b)) - fence_inserter.add_edge(edget(a,d)); + else if(egraph.are_po_ordered(a, c) && egraph.are_po_ordered(b, d)) + fence_inserter.add_edge(edget(c, b)); + else if(egraph.are_po_ordered(a, c) && egraph.are_po_ordered(d, b)) + fence_inserter.add_edge(edget(c, d)); + else if(egraph.are_po_ordered(c, a) && egraph.are_po_ordered(b, d)) + fence_inserter.add_edge(edget(a, b)); + else if(egraph.are_po_ordered(c, a) && egraph.are_po_ordered(d, b)) + fence_inserter.add_edge(edget(a, d)); } } #else @@ -263,10 +267,10 @@ void cycles_visitort::po_edges(std::set& edges) /* C_j /\ po^+ /\ poWR */ void cycles_visitort::powr_constraint( - const event_grapht::critical_cyclet& C_j, - std::set& edges) + const event_grapht::critical_cyclet &C_j, + std::set &edges) { - event_grapht& graph=fence_inserter.instrumenter.egraph; + event_grapht &graph=fence_inserter.instrumenter.egraph; for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) @@ -294,10 +298,10 @@ void cycles_visitort::powr_constraint( /* C_j /\ po^+ /\ poWW */ void cycles_visitort::poww_constraint( - const event_grapht::critical_cyclet& C_j, - std::set& edges) + const event_grapht::critical_cyclet &C_j, + std::set &edges) { - event_grapht& graph=fence_inserter.instrumenter.egraph; + event_grapht &graph=fence_inserter.instrumenter.egraph; for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) @@ -325,10 +329,10 @@ void cycles_visitort::poww_constraint( /* C_j /\ po^+ /\ poRW */ void cycles_visitort::porw_constraint( - const event_grapht::critical_cyclet& C_j, - std::set& edges) + const event_grapht::critical_cyclet &C_j, + std::set &edges) { - event_grapht& graph=fence_inserter.instrumenter.egraph; + event_grapht &graph=fence_inserter.instrumenter.egraph; for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) @@ -356,10 +360,10 @@ void cycles_visitort::porw_constraint( /* C_j /\ po^+ /\ poRR */ void cycles_visitort::porr_constraint( - const event_grapht::critical_cyclet& C_j, - std::set& edges) + const event_grapht::critical_cyclet &C_j, + std::set &edges) { - event_grapht& graph=fence_inserter.instrumenter.egraph; + event_grapht &graph=fence_inserter.instrumenter.egraph; for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) @@ -387,10 +391,10 @@ void cycles_visitort::porr_constraint( /* C_j /\ comWR */ void cycles_visitort::com_constraint( - const event_grapht::critical_cyclet& C_j, - std::set& edges) + const event_grapht::critical_cyclet &C_j, + std::set &edges) { - event_grapht& egraph=fence_inserter.instrumenter.egraph; + event_grapht &egraph=fence_inserter.instrumenter.egraph; for(std::set::const_iterator it=C_j.unsafe_pairs.begin(); it!=C_j.unsafe_pairs.end(); @@ -404,7 +408,7 @@ void cycles_visitort::com_constraint( } #if 0 - event_grapht& egraph=instrumenter.egraph; + event_grapht &egraph=instrumenter.egraph; std::list::const_iterator e_it=C_j.begin(); std::list::const_iterator next_it=e_it; @@ -412,8 +416,8 @@ void cycles_visitort::com_constraint( ++next_it; for(; next_it!=C_j.end() && e_it!=C_j.end(); ++e_it, ++next_it) { - const abstract_eventt& e1=egraph[*e_it]; - const abstract_eventt& e2=egraph[*next_it]; + const abstract_eventt &e1=egraph[*e_it]; + const abstract_eventt &e2=egraph[*next_it]; if(e1.operation==abstract_eventt::Write && e2.operation==abstract_eventt::Read @@ -427,8 +431,8 @@ void cycles_visitort::com_constraint( assert(e_it!=C_j.end()); next_it=C_j.begin(); - const abstract_eventt& e1=egraph[*e_it]; - const abstract_eventt& e2=egraph[*next_it]; + const abstract_eventt &e1=egraph[*e_it]; + const abstract_eventt &e2=egraph[*next_it]; if(e1.operation==abstract_eventt::Write && e2.operation==abstract_eventt::Read diff --git a/src/musketeer/cycles_visitor.h b/src/musketeer/cycles_visitor.h index 33bd1e5bbb7..f125b511668 100644 --- a/src/musketeer/cycles_visitor.h +++ b/src/musketeer/cycles_visitor.h @@ -20,28 +20,28 @@ class cycles_visitort protected: typedef event_grapht::critical_cyclet::delayt edget; - fence_insertert& fence_inserter; + fence_insertert &fence_inserter; public: - cycles_visitort(fence_insertert& _fi) + explicit cycles_visitort(fence_insertert &_fi) : fence_inserter(_fi) {} /* computes po^+ edges in U{C_1, ..., C_j} */ - void po_edges(std::set& edges); + void po_edges(std::set &edges); /* computes pairs that will be protected for the TSO/PSO/RMO/Power/ARM by the constraints */ - void powr_constraint(const event_grapht::critical_cyclet& C_j, - std::set& edges); - void poww_constraint(const event_grapht::critical_cyclet& C_j, - std::set& edges); - void porw_constraint(const event_grapht::critical_cyclet& C_j, - std::set& edges); - void porr_constraint(const event_grapht::critical_cyclet& C_j, - std::set& edges); - void com_constraint(const event_grapht::critical_cyclet& C_j, - std::set& edges); + void powr_constraint(const event_grapht::critical_cyclet &C_j, + std::set &edges); + void poww_constraint(const event_grapht::critical_cyclet &C_j, + std::set &edges); + void porw_constraint(const event_grapht::critical_cyclet &C_j, + std::set &edges); + void porr_constraint(const event_grapht::critical_cyclet &C_j, + std::set &edges); + void com_constraint(const event_grapht::critical_cyclet &C_j, + std::set &edges); }; #endif // CPROVER_MUSKETEER_CYCLES_VISITOR_H diff --git a/src/musketeer/fence_assert.cpp b/src/musketeer/fence_assert.cpp index 77b4c61484f..06bea8537fc 100644 --- a/src/musketeer/fence_assert.cpp +++ b/src/musketeer/fence_assert.cpp @@ -22,7 +22,7 @@ Author: Vincent Nimal \*******************************************************************/ bool fence_assert_insertert::find_assert( - const event_grapht::critical_cyclet& cycle) const + const event_grapht::critical_cyclet &cycle) const { /* TODO */ return true; diff --git a/src/musketeer/fence_assert.h b/src/musketeer/fence_assert.h index c8e20c5a57b..7e18e1f8e56 100644 --- a/src/musketeer/fence_assert.h +++ b/src/musketeer/fence_assert.h @@ -18,7 +18,7 @@ Author: Vincent Nimal class instrumentert; -class fence_assert_insertert : public fence_insertert +class fence_assert_insertert:public fence_insertert { protected: std::set selected_cycles; diff --git a/src/musketeer/fence_inserter.cpp b/src/musketeer/fence_inserter.cpp index 5b00949d11b..dc1de9fb037 100644 --- a/src/musketeer/fence_inserter.cpp +++ b/src/musketeer/fence_inserter.cpp @@ -33,8 +33,10 @@ Function: fence_insertert::fence_cost \*******************************************************************/ -unsigned fence_insertert::fence_cost(fence_typet f) const { - switch(f) { +unsigned fence_insertert::fence_cost(fence_typet f) const +{ + switch(f) + { case Fence: return 3; case Lwfence: @@ -62,7 +64,8 @@ Function: fence_insertert::compute \*******************************************************************/ -void fence_insertert::compute() { +void fence_insertert::compute() +{ compute_fence_options(); instrumenter.message.status() << "Preprocessing" << messaget::eom; preprocess(); @@ -120,19 +123,20 @@ void fence_insertert::preprocess() cycles_visitor.porr_constraint(*C_j, new_rr_set); porr_constraints.push_back(new_rr_set); - if(model==Power || model==Unknown) { + if(model==Power || model==Unknown) + { std::set new_comset; cycles_visitor.com_constraint(*C_j, new_comset); com_constraints.push_back(new_comset); } - assert(powr_constraints.size() == poww_constraints.size()); - assert(poww_constraints.size() == porw_constraints.size()); - assert(porw_constraints.size() == porr_constraints.size()); + assert(powr_constraints.size()==poww_constraints.size()); + assert(poww_constraints.size()==porw_constraints.size()); + assert(porw_constraints.size()==porr_constraints.size()); } // Note: not true if filters - //assert(non_powr_constraints.size() == instrumenter.set_of_cycles.size()); + // assert(non_powr_constraints.size()==instrumenter.set_of_cycles.size()); // NEW /* first, powr constraints: for all C_j */ @@ -148,7 +152,7 @@ void fence_insertert::preprocess() ++e_c_it) { std::set pt_set; - assert(map_to_e.find(*e_c_it) != map_to_e.end()); + assert(map_to_e.find(*e_c_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_c_it)->second, pt_set); } } @@ -166,7 +170,7 @@ void fence_insertert::preprocess() ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); } } @@ -184,7 +188,7 @@ void fence_insertert::preprocess() ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); } } @@ -202,7 +206,7 @@ void fence_insertert::preprocess() ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); } } @@ -222,8 +226,8 @@ void fence_insertert::preprocess() ++e_c_it) { std::set ct_set; - assert( invisible_var.map_to_e.find(*e_c_it) - != invisible_var.map_to_e.end()); + assert(invisible_var.map_to_e.find(*e_c_it)!= + invisible_var.map_to_e.end()); const_graph_visitor.CT(invisible_var.map_to_e.find(*e_c_it)->second, ct_set); @@ -247,21 +251,22 @@ Function: fence_insertert::mip_set_var \*******************************************************************/ -void inline fence_insertert::mip_set_var(ilpt& ilp, - unsigned& i) +void inline fence_insertert::mip_set_var( + ilpt &ilp, + unsigned &i) { #ifdef HAVE_GLPK glp_add_cols(ilp.lp, unique*fence_options); - //unsigned i=1; + // unsigned i=1; for(; i<=unique*fence_options; i+=fence_options) { - const bool has_cost = 1; //(po_plus.find(i)==po_plus.end()); - /* has_cost == 0 => invisible variable */ + const bool has_cost=1; // (po_plus.find(i)==po_plus.end()); + /* has_cost==0 => invisible variable */ assert(has_cost); // not useful for this problem /* computes the sum of the frequencies of the cycles in which this event appears, if requested */ - float freq_sum = 0; + float freq_sum=0; if(with_freq) { assert(instrumenter.set_of_cycles.size()==freq_table.size()); @@ -272,20 +277,24 @@ void inline fence_insertert::mip_set_var(ilpt& ilp, ++C_j) { /* filters */ - if(filter_cycles(C_j->id)) continue; + if(filter_cycles(C_j->id)) + continue; /* if(C_j->find( col_to_var(i) )!=C_j->end()) */ std::list::const_iterator it; - for(it = C_j->begin(); it!=C_j->end() && col_to_var(i)!=*it; ++it); + for(it=C_j->begin(); it!=C_j->end() && col_to_var(i)!=*it; ++it) + { + } if(it!=C_j->end()) freq_sum += freq_table[C_j->id]; } } else - freq_sum = 1; + freq_sum=1; - if(model==Power || model==Unknown) { + if(model==Power || model==Unknown) + { /* dp variable for e */ const std::string name_dp="dp_"+std::to_string(i); glp_set_col_name(ilp.lp, i, name_dp.c_str()); @@ -306,7 +315,8 @@ void inline fence_insertert::mip_set_var(ilpt& ilp, const std::string name_br="br_"+std::to_string(i); glp_set_col_name(ilp.lp, i+2, name_br.c_str()); glp_set_col_bnds(ilp.lp, i+2, GLP_LO, 0.0, 0.0); - glp_set_obj_coef(ilp.lp, i+2, (has_cost?fence_cost(Branching):0)*freq_sum); + glp_set_obj_coef( + ilp.lp, i+2, (has_cost?fence_cost(Branching):0)*freq_sum); glp_set_col_kind(ilp.lp, i+2, GLP_BV); /* cf variable for e */ @@ -317,7 +327,8 @@ void inline fence_insertert::mip_set_var(ilpt& ilp, glp_set_col_kind(ilp.lp, i+3, GLP_BV); #endif - if(model==Power) { + if(model==Power) + { /* lwf variable for e */ const std::string name_lwf="lwf_"+std::to_string(i); glp_set_col_name(ilp.lp, i+2/*4*/, name_lwf.c_str()); @@ -327,7 +338,8 @@ void inline fence_insertert::mip_set_var(ilpt& ilp, glp_set_col_kind(ilp.lp, i+2/*4*/, GLP_BV); } } - else { + else + { /* fence variable for e */ const std::string name_f="f_"+std::to_string(i); glp_set_col_name(ilp.lp, i, name_f.c_str()); @@ -337,8 +349,7 @@ void inline fence_insertert::mip_set_var(ilpt& ilp, } } #else - throw "Sorry, musketeer requires glpk; please recompile\ - musketeer with glpk."; + throw "sorry, musketeer requires glpk; please recompile musketeer with glpk"; #endif } @@ -354,7 +365,7 @@ Function: fence_insertert::mip_set_cst \*******************************************************************/ -void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) +void inline fence_insertert::mip_set_cst(ilpt &ilp, unsigned &i) { #ifdef HAVE_GLPK glp_add_rows(ilp.lp, constraints_number); @@ -364,7 +375,7 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) for( std::list >::const_iterator c_wr_it = powr_constraints.begin(); - c_wr_it != powr_constraints.end(); + c_wr_it!=powr_constraints.end(); ++c_wr_it) { /* for all e */ @@ -378,11 +389,10 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) } /* then the poww: for all C_j */ - for( - std::list >::const_iterator c_ww_it = - poww_constraints.begin(); - c_ww_it != poww_constraints.end(); - ++c_ww_it) + for(std::list >::const_iterator + c_ww_it=poww_constraints.begin(); + c_ww_it!=poww_constraints.end(); + ++c_ww_it) { /* for all e */ for(std::size_t j=1; j<=c_ww_it->size(); ++j) @@ -395,11 +405,10 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) } /* then the porw: for all C_j */ - for( - std::list >::const_iterator c_rw_it = - porw_constraints.begin(); - c_rw_it != porw_constraints.end(); - ++c_rw_it) + for(std::list >::const_iterator + c_rw_it=porw_constraints.begin(); + c_rw_it!=porw_constraints.end(); + ++c_rw_it) { /* for all e */ for(std::size_t j=1; j<=c_rw_it->size(); ++j) @@ -415,7 +424,7 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) for( std::list >::const_iterator c_rr_it = porr_constraints.begin(); - c_rr_it != porr_constraints.end(); + c_rr_it!=porr_constraints.end(); ++c_rr_it) { /* for all e */ @@ -428,12 +437,12 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) } } - if(model==Power || model==Unknown) { - for( - std::list >::const_iterator c_it = - com_constraints.begin(); - c_it != com_constraints.end(); - ++c_it) + if(model==Power || model==Unknown) + { + for(std::list >::const_iterator + c_it=com_constraints.begin(); + c_it!=com_constraints.end(); + ++c_it) { /* for all e */ for(std::size_t j=1; j<=c_it->size(); ++j) @@ -446,8 +455,7 @@ void inline fence_insertert::mip_set_cst(ilpt& ilp, unsigned& i) } } #else - throw "Sorry, musketeer requires glpk; please recompile\ - musketeer with glpk."; + throw "sorry, musketeer requires glpk; please recompile musketeer with glpk"; #endif } @@ -463,8 +471,11 @@ Function: fence_insertert::mip_fill_matrix \*******************************************************************/ -void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, - unsigned const_constraints_number, unsigned const_unique) +void inline fence_insertert::mip_fill_matrix( + ilpt &ilp, + unsigned &i, + unsigned const_constraints_number, + unsigned const_unique) { #ifdef HAVE_GLPK unsigned col=1; @@ -484,7 +495,7 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, ++e_c_it) { std::set pt_set; - assert(map_to_e.find(*e_c_it) != map_to_e.end()); + assert(map_to_e.find(*e_c_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_c_it)->second, pt_set); /* sum_e' f_e' */ for(col=1; col<=unique*fence_options; ++col) @@ -493,16 +504,18 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, assert(col<=const_unique*fence_options); ilp.imat[i]=row; ilp.jmat[i]=col; - if(model==Power || model==Unknown) { + if(model==Power || model==Unknown) + { if(pt_set.find(col_to_var(col))!=pt_set.end() && col_to_fence(col)==Fence) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; } - else { - if(pt_set.find(col_to_var(col))!=pt_set.end() - && col_to_fence(col)==Fence) + else + { + if(pt_set.find(col_to_var(col))!=pt_set.end() && + col_to_fence(col)==Fence) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; @@ -526,7 +539,7 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); /* sum_e' (f_e' + lwf_e') */ for(col=1; col<=unique*fence_options; ++col) @@ -535,16 +548,18 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, assert(col<=const_unique*fence_options); ilp.imat[i]=row; ilp.jmat[i]=col; - if(model==Power) { - if(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Lwfence || col_to_fence(col)==Fence)) + if(model==Power) + { + if(pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Lwfence || col_to_fence(col)==Fence)) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; } - else { - if(pt_set.find(col_to_var(col))!=pt_set.end() - && col_to_fence(col)==Fence) + else + { + if(pt_set.find(col_to_var(col))!=pt_set.end() && + col_to_fence(col)==Fence) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; @@ -568,7 +583,7 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); /* dp_e + sum_e' (f_e' + lwf_e' + br_e') */ for(col=1; col<=unique*fence_options; ++col) @@ -577,40 +592,41 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, assert(col<=const_unique*fence_options); ilp.imat[i]=row; ilp.jmat[i]=col; - if(model==Power) { - if(col==var_fence_to_col(Dp, *e_nc_it) - ||(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Lwfence - || col_to_fence(col)==Fence + if(model==Power) + { + if(col==var_fence_to_col(Dp, *e_nc_it) || + (pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Lwfence || + col_to_fence(col)==Fence #if 0 || col_to_fence(col)==Branching #endif - )) - ) + ))) // NOLINT(whitespace/parens) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; } - else if (model==Unknown) { - if(col==var_fence_to_col(Dp, *e_nc_it) - ||(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Fence + else if(model==Unknown) + { + if(col==var_fence_to_col(Dp, *e_nc_it) || + (pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Fence #if 0 || col_to_fence(col)==Branching #endif - )) - ) + ))) // NOLINT(whitespace/parens) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; } - else { - if(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Fence + else + { + if(pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Fence #if 0 || col_to_fence(col)==Branching #endif - )) + )) // NOLINT(whitespace/parens) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; @@ -623,18 +639,18 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, /* then, porr constraints: for all C_j */ for(std::list >::const_iterator - e_i=porr_constraints.begin(); - e_i!=porr_constraints.end(); - ++e_i) + e_i=porr_constraints.begin(); + e_i!=porr_constraints.end(); + ++e_i) { /* for all e */ for(std::set::const_iterator - e_nc_it=e_i->begin(); - e_nc_it!=e_i->end(); - ++e_nc_it) + e_nc_it=e_i->begin(); + e_nc_it!=e_i->end(); + ++e_nc_it) { std::set pt_set; - assert(map_to_e.find(*e_nc_it) != map_to_e.end()); + assert(map_to_e.find(*e_nc_it)!=map_to_e.end()); const_graph_visitor.PT(map_to_e.find(*e_nc_it)->second, pt_set); // uncomment for cf #if 0 @@ -648,14 +664,13 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, assert(col<=const_unique*fence_options); ilp.imat[i]=row; ilp.jmat[i]=col; - if(model==Power) { - if(col==var_fence_to_col(Dp, *e_nc_it) - ||(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Lwfence - || col_to_fence(col)==Fence - )) + if(model==Power) + { + if(col==var_fence_to_col(Dp, *e_nc_it) || + (pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Lwfence || col_to_fence(col)==Fence)) #if 0 - ||(it_set.find(col_to_var(col))!=it_set.end() + || (it_set.find(col_to_var(col))!=it_set.end() && col_to_fence(col)==Ctlfence) #endif ) @@ -663,13 +678,13 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, else ilp.vmat[i]=0.0; } - else if (model==Unknown) { - if(col==var_fence_to_col(Dp, *e_nc_it) - ||(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Fence - )) + else if(model==Unknown) + { + if(col==var_fence_to_col(Dp, *e_nc_it) || + (pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Fence)) #if 0 - ||(it_set.find(col_to_var(col))!=it_set.end() + || (it_set.find(col_to_var(col))!=it_set.end() && col_to_fence(col)==Ctlfence) #endif ) @@ -677,10 +692,10 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, else ilp.vmat[i]=0.0; } - else { - if(pt_set.find(col_to_var(col))!=pt_set.end() - && (col_to_fence(col)==Fence - )) + else + { + if(pt_set.find(col_to_var(col))!=pt_set.end() && + (col_to_fence(col)==Fence)) ilp.vmat[i]=1.0; else ilp.vmat[i]=0.0; @@ -708,8 +723,8 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, unsigned possibilities_met=0; std::set ct_set; - assert( invisible_var.map_to_e.find(*e_c_it) - != invisible_var.map_to_e.end()); + assert(invisible_var.map_to_e.find(*e_c_it)!= + invisible_var.map_to_e.end()); const_graph_visitor.CT(invisible_var.map_to_e.find(*e_c_it)->second, ct_set); @@ -729,10 +744,10 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, assert(col<=const_unique*fence_options); ilp.imat[i]=row; ilp.jmat[i]=col; - if( (ct_set.find(col_to_var(col))!=ct_set.end() - && col_to_fence(col)==Fence) - || (ct_not_powr_set.find(col_to_var(col))!=ct_not_powr_set.end() - && col_to_fence(col)==Lwfence) ) + if((ct_set.find(col_to_var(col))!=ct_set.end() && + col_to_fence(col)==Fence) || + (ct_not_powr_set.find(col_to_var(col))!=ct_not_powr_set.end() && + col_to_fence(col)==Lwfence)) { ilp.vmat[i]=1.0; ++possibilities_met; @@ -749,8 +764,7 @@ void inline fence_insertert::mip_fill_matrix(ilpt& ilp, unsigned& i, instrumenter.message.debug() << "3: " << i << " row: " << row << messaget::eom; #else - throw "Sorry, musketeer requires glpk; please recompile\ - musketeer with glpk."; + throw "sorry, musketeer requires glpk; please recompile musketeer with glpk"; #endif } @@ -766,7 +780,8 @@ Function: fence_insertert::solve() \*******************************************************************/ -void fence_insertert::solve() { +void fence_insertert::solve() +{ #ifdef HAVE_GLPK ilpt ilp; @@ -775,7 +790,7 @@ void fence_insertert::solve() { << messaget::eom; /* sets the variables and coefficients */ - //nb of po+ considered * types of fences (_e) + // nb of po+ considered * types of fences (_e) unsigned i=1; mip_set_var(ilp, i); @@ -788,7 +803,9 @@ void fence_insertert::solve() { const std::size_t const_constraints_number=constraints_number; const event_idt const_unique=unique; - const std::size_t mat_size=const_unique*fence_options*const_constraints_number; + const std::size_t mat_size= + // NOLINTNEXTLINE(whitespace/operators) + const_unique*fence_options*const_constraints_number; instrumenter.message.statistics() << "size of the system: " << mat_size << messaget::eom; instrumenter.message.statistics() << "# of constraints: " @@ -808,7 +825,7 @@ void fence_insertert::solve() { instrumenter.message.statistics() << "i: " << i << " mat_size: " << mat_size << messaget::eom; - //assert(i-1==mat_size); + // assert(i-1==mat_size); #ifdef DEBUG for(i=1; i<=mat_size; ++i) @@ -824,7 +841,8 @@ void fence_insertert::solve() { #endif /* checks optimality */ - switch(glp_mip_status(ilp.lp)) { + switch(glp_mip_status(ilp.lp)) + { case GLP_OPT: instrumenter.message.result() << "Optimal solution found" << messaget::eom; @@ -833,8 +851,10 @@ void fence_insertert::solve() { instrumenter.message.result() << "Solution undefined" << messaget::eom; assert(0); case GLP_FEAS: - instrumenter.message.result() << "Solution feasible, yet not proven \ - optimal, due to early termination" << messaget::eom; + instrumenter.message.result() << "Solution feasible, " + << "yet not proven optimal, " + << "due to early termination" + << messaget::eom; break; case GLP_NOFEAS: instrumenter.message.result() @@ -842,7 +862,7 @@ void fence_insertert::solve() { assert(0); } - event_grapht& egraph=instrumenter.egraph; + event_grapht &egraph=instrumenter.egraph; /* loads results (x_i) */ instrumenter.message.statistics() << "minimal cost: " @@ -853,19 +873,19 @@ void fence_insertert::solve() { { /* insert that fence */ assert(map_to_e.find(col_to_var(j))!=map_to_e.end()); - const edget& delay = map_to_e.find(col_to_var(j))->second; + const edget &delay=map_to_e.find(col_to_var(j))->second; instrumenter.message.statistics() << delay.first << " -> " << delay.second << " : " << to_string(col_to_fence(j)) << messaget::eom; instrumenter.message.statistics() << "(between " << egraph[delay.first].source_location << " and " << egraph[delay.second].source_location << messaget::eom; - fenced_edges.insert(std::pair(delay, col_to_fence(j))); + fenced_edges.insert( + std::pair(delay, col_to_fence(j))); } } #else - throw "Sorry, musketeer requires glpk; please recompile\ - musketeer with glpk."; + throw "sorry, musketeer requires glpk; please recompile musketeer with glpk"; #endif } @@ -881,7 +901,8 @@ Function: fence_insertert::import_freq \*******************************************************************/ -void fence_insertert::import_freq() { +void fence_insertert::import_freq() +{ /* TODO */ } @@ -901,12 +922,12 @@ void fence_insertert::print_to_file() { /* removes redundant (due to several call to the same fenced function) */ std::set non_redundant_display; - for(std::map::const_iterator it=fenced_edges.begin(); + for(std::map::const_iterator it=fenced_edges.begin(); it!=fenced_edges.end(); ++it) { std::ostringstream s; - const abstract_eventt& first=instrumenter.egraph[it->first.first]; + const abstract_eventt &first=instrumenter.egraph[it->first.first]; s << to_string(it->second) << "|" << first.source_location.get_file() << "|" << first.source_location.get_line() << "|" @@ -935,35 +956,35 @@ Function: fence_insertert::print_to_file_2 \*******************************************************************/ - /* prints final results */ - void fence_insertert::print_to_file_2() +/* prints final results */ +void fence_insertert::print_to_file_2() +{ + /* removes redundant (due to several call to the same fenced function) */ + std::set non_redundant_display; + for(std::map::const_iterator it=fenced_edges.begin(); + it!=fenced_edges.end(); + ++it) { - /* removes redundant (due to several call to the same fenced function) */ - std::set non_redundant_display; - for(std::map::const_iterator it=fenced_edges.begin(); - it!=fenced_edges.end(); - ++it) - { - std::ostringstream s; - const abstract_eventt& first=instrumenter.egraph[it->first.first]; - const abstract_eventt& second=instrumenter.egraph[it->first.second]; - - s << to_string(it->second) << "|" << first.source_location.get_file() - << "|" << first.source_location.get_line() << "|" - << second.source_location.get_file() - << "|" << second.source_location.get_line() << std::endl; - non_redundant_display.insert(s.str()); - } + std::ostringstream s; + const abstract_eventt &first=instrumenter.egraph[it->first.first]; + const abstract_eventt &second=instrumenter.egraph[it->first.second]; - std::ofstream results; - results.open("results.txt"); - for(std::set::const_iterator it=non_redundant_display.begin(); - it!=non_redundant_display.end(); - ++it) - results << *it; - results.close(); + s << to_string(it->second) << "|" << first.source_location.get_file() + << "|" << first.source_location.get_line() << "|" + << second.source_location.get_file() + << "|" << second.source_location.get_line() << std::endl; + non_redundant_display.insert(s.str()); } + std::ofstream results; + results.open("results.txt"); + for(std::set::const_iterator it=non_redundant_display.begin(); + it!=non_redundant_display.end(); + ++it) + results << *it; + results.close(); +} + /*******************************************************************\ Function: fence_insertert::print_to_file_3 @@ -977,44 +998,46 @@ Function: fence_insertert::print_to_file_3 \*******************************************************************/ /* prints final results */ - void fence_insertert::print_to_file_3() +void fence_insertert::print_to_file_3() +{ + /* removes redundant (due to several call to the same fenced function) */ + std::set non_redundant_display; + for(std::map::const_iterator it=fenced_edges.begin(); + it!=fenced_edges.end(); + ++it) { - /* removes redundant (due to several call to the same fenced function) */ - std::set non_redundant_display; - for(std::map::const_iterator it=fenced_edges.begin(); - it!=fenced_edges.end(); - ++it) - { - std::ostringstream s; - const abstract_eventt& first=instrumenter.egraph[it->first.first]; - const abstract_eventt& second=instrumenter.egraph[it->first.second]; + std::ostringstream s; + const abstract_eventt &first=instrumenter.egraph[it->first.first]; + const abstract_eventt &second=instrumenter.egraph[it->first.second]; - try { - s << to_string(it->second) << "|" << first.source_location.get_file() - << "|" << first.source_location.get_function() << "|" - << first.source_location.get_line() << "|" << first.variable << "|" - << second.source_location.get_file() << "|" - << second.source_location.get_function() << "|" - << second.source_location.get_line() - << "|" << second.variable << std::endl; - non_redundant_display.insert(s.str()); - } - catch (std::string s) { - instrumenter.message.warning() - << "Couldn't retrieve symbols of variables " << first.variable - << " and " << second.variable << " due to " << s << messaget::eom; - } + try + { + s << to_string(it->second) << "|" << first.source_location.get_file() + << "|" << first.source_location.get_function() << "|" + << first.source_location.get_line() << "|" << first.variable << "|" + << second.source_location.get_file() << "|" + << second.source_location.get_function() << "|" + << second.source_location.get_line() + << "|" << second.variable << std::endl; + non_redundant_display.insert(s.str()); + } + catch(std::string s) + { + instrumenter.message.warning() + << "Couldn't retrieve symbols of variables " << first.variable + << " and " << second.variable << " due to " << s << messaget::eom; } - - std::ofstream results; - results.open("results.txt"); - for(std::set::const_iterator it=non_redundant_display.begin(); - it!=non_redundant_display.end(); - ++it) - results << *it; - results.close(); } + std::ofstream results; + results.open("results.txt"); + for(std::set::const_iterator it=non_redundant_display.begin(); + it!=non_redundant_display.end(); + ++it) + results << *it; + results.close(); +} + /*******************************************************************\ Function: fence_insertert::print_to_file_4 @@ -1027,20 +1050,21 @@ Function: fence_insertert::print_to_file_4 \*******************************************************************/ - /* prints final results */ - void fence_insertert::print_to_file_4() - { - /* removes redundant (due to several call to the same fenced function) */ - std::set non_redundant_display; - for(std::map::const_iterator it=fenced_edges.begin(); +/* prints final results */ +void fence_insertert::print_to_file_4() +{ + /* removes redundant (due to several call to the same fenced function) */ + std::set non_redundant_display; + for(std::map::const_iterator it=fenced_edges.begin(); it!=fenced_edges.end(); ++it) - { - std::ostringstream s; - const abstract_eventt& first=instrumenter.egraph[it->first.first]; - const abstract_eventt& second=instrumenter.egraph[it->first.second]; + { + std::ostringstream s; + const abstract_eventt &first=instrumenter.egraph[it->first.first]; + const abstract_eventt &second=instrumenter.egraph[it->first.second]; - try { + try + { s << to_string(it->second) << "|" << first.source_location.get_file() << "|" << first.source_location.get_function() << "|" << first.source_location.get_line() @@ -1052,23 +1076,24 @@ Function: fence_insertert::print_to_file_4 << "|" << second.variable << "|" << get_type(second.variable).get("#c_type") << std::endl; non_redundant_display.insert(s.str()); - } - catch (std::string s) { - instrumenter.message.warning() - << "Couldn't retrieve types of variables " << first.variable - << " and " << second.variable << " due to " << s << messaget::eom; - } } - - std::ofstream results; - results.open("results.txt"); - for(std::set::const_iterator it=non_redundant_display.begin(); - it!=non_redundant_display.end(); - ++it) - results << *it; - results.close(); + catch (std::string s) + { + instrumenter.message.warning() + << "Couldn't retrieve types of variables " << first.variable + << " and " << second.variable << " due to " << s << messaget::eom; + } } + std::ofstream results; + results.open("results.txt"); + for(std::set::const_iterator it=non_redundant_display.begin(); + it!=non_redundant_display.end(); + ++it) + results << *it; + results.close(); +} + /*******************************************************************\ Function: fence_insertert::to_string @@ -1081,15 +1106,17 @@ Function: fence_insertert::to_string \*******************************************************************/ -std::string fence_insertert::to_string(fence_typet f) const { - switch(f) { +std::string fence_insertert::to_string(fence_typet f) const +{ + switch(f) + { case Fence: return "fence"; case Lwfence: return "lwfence"; case Dp: return "dp"; case Branching: return "branching"; case Ctlfence: return "ctlfence"; } - assert (0); + assert(0); } /*******************************************************************\ @@ -1124,7 +1151,8 @@ Function: fence_insertert::col_to_fence inline fence_insertert::fence_typet fence_insertert::col_to_fence(unsigned u) const { - switch(u%fence_options) { + switch(u%fence_options) + { case 0: return Fence; case 1: return Dp; case 2: return Lwfence; @@ -1149,7 +1177,8 @@ Function: fence_insertert::var_fence_to_col inline unsigned fence_insertert::var_fence_to_col(fence_typet f, unsigned var) const { - switch(f) { + switch(f) + { case Fence: return var*fence_options; case Dp: return (var-1)*fence_options+1; case Lwfence: return (var-1)*fence_options+2; @@ -1173,17 +1202,18 @@ Function: fence_insertert::compute_fence_options void fence_insertert::compute_fence_options() { - switch(model) { + switch(model) + { case TSO: case PSO: case RMO: - fence_options = 1; // 2: f, br + fence_options=1; // 2: f, br break; case Power: - fence_options = 3; // 5: f, lwf, dp, cf, br + fence_options=3; // 5: f, lwf, dp, cf, br break; case Unknown: /* including ARM */ - fence_options = 2; // 4: f, dp, cf, br + fence_options=2; // 4: f, dp, cf, br break; } } @@ -1200,16 +1230,17 @@ Function: fence_insertert::print_vars \*******************************************************************/ -void fence_insertert::print_vars() const { +void fence_insertert::print_vars() const +{ instrumenter.message.statistics() << "---- pos/pos+ (visible) variables ----" << messaget::eom; - for(std::map::const_iterator it=map_from_e.begin(); + for(std::map::const_iterator it=map_from_e.begin(); it!=map_from_e.end(); ++it) instrumenter.message.statistics() << it->first.first << "," << it->first.second << messaget::eom; instrumenter.message.statistics() << "---- cmp (invisible) variables ----" << messaget::eom; - for(std::map::const_iterator it= + for(std::map::const_iterator it= invisible_var.map_from_e.begin(); it!=invisible_var.map_from_e.end(); ++it) instrumenter.message.statistics() << it->first.first << "," @@ -1230,15 +1261,18 @@ Function: fence_insertert::get_type \*******************************************************************/ -typet fence_insertert::get_type(const irep_idt& id) { +typet fence_insertert::get_type(const irep_idt &id) +{ std::string copy=id2string(id); /* if we picked an array, removes [] that rw_set added */ if(copy.find("[]")!=std::string::npos) copy=copy.substr(0, copy.find_last_of("[]")-1); - try { + try + { return instrumenter.ns.lookup(copy).type; } - catch (...) { + catch(...) + { std::list fields; std::string current; @@ -1249,11 +1283,13 @@ typet fence_insertert::get_type(const irep_idt& id) { { next=it; ++next; - if(! (*it=='.' || (next!=copy.end() && *it=='-' && *next=='>')) ) { + if(!(*it=='.' || (next!=copy.end() && *it=='-' && *next=='>'))) + { current+=*it; instrumenter.message.debug() << current << messaget::eom; } - else { + else + { fields.push_back(current); current.clear(); if(*it!='.') @@ -1282,20 +1318,24 @@ Function: fence_insertert::type_component \*******************************************************************/ -typet fence_insertert::type_component(std::list::const_iterator it, - std::list::const_iterator end, const typet& type) +typet fence_insertert::type_component( + std::list::const_iterator it, + std::list::const_iterator end, + const typet &type) { if(it==end) return type; - if(type.id()==ID_struct) { - const struct_union_typet& str=to_struct_union_type(type); + if(type.id()==ID_struct) + { + const struct_union_typet &str=to_struct_union_type(type); typet comp_type=str.component_type(*it); ++it; return type_component(it, end, comp_type); } - if(type.id()==ID_symbol) { + if(type.id()==ID_symbol) + { return type; } diff --git a/src/musketeer/fence_inserter.h b/src/musketeer/fence_inserter.h index 630066b5c6e..eaabff176ff 100644 --- a/src/musketeer/fence_inserter.h +++ b/src/musketeer/fence_inserter.h @@ -62,11 +62,13 @@ class fence_insertert instrumentert &instrumenter; /* normal variables used almost everytime */ - std::map& map_to_e; - std::map& map_from_e; - inline event_idt add_edge(const edget& e) { return var.add_edge(e); } - inline event_idt add_invisible_edge(const edget& e) { - return invisible_var.add_edge(e);} + std::map &map_to_e; + std::map &map_from_e; + event_idt add_edge(const edget &e) { return var.add_edge(e); } + event_idt add_invisible_edge(const edget &e) + { + return invisible_var.add_edge(e); + } /* number of contraints */ std::size_t constraints_number; @@ -76,7 +78,7 @@ class fence_insertert const_graph_visitort const_graph_visitor; protected: - event_idt& unique; + event_idt &unique; unsigned fence_options; /* MIP variables to edges in po^+/\C */ @@ -86,9 +88,12 @@ class fence_insertert mip_vart invisible_var; /* MIP matrix construction */ - void mip_set_var(ilpt& ilp, unsigned& i); - void mip_set_cst(ilpt& ilp, unsigned& i); - void mip_fill_matrix(ilpt& ilp, unsigned& i, unsigned const_constraints_number, + void mip_set_var(ilpt &ilp, unsigned &i); + void mip_set_cst(ilpt &ilp, unsigned &i); + void mip_fill_matrix( + ilpt &ilp, + unsigned &i, + unsigned const_constraints_number, unsigned const_unique); /* preprocessing (necessary as glpk static) and solving */ @@ -165,7 +170,7 @@ class fence_insertert void print_to_file_4(); /* TODO: to be replaced eventually by ns.lookup and basename */ - static std::string remove_extra(const irep_idt& id) + static std::string remove_extra(const irep_idt &id) { const std::string copy=id2string(id); return remove_extra(copy); diff --git a/src/musketeer/fence_shared.cpp b/src/musketeer/fence_shared.cpp index 9e3a3c580f1..61d3651baf1 100644 --- a/src/musketeer/fence_shared.cpp +++ b/src/musketeer/fence_shared.cpp @@ -15,14 +15,13 @@ Author: Vincent Nimal #include #include -#include #include #include #include #include #include -//#include +// #include #include "fence_shared.h" @@ -30,18 +29,20 @@ Author: Vincent Nimal #include #endif -#define OUTPUT(s,fence,file,line,id,type) s< writes; std::list reads; } fenced_edges; @@ -62,10 +63,16 @@ class simple_insertiont { { std::ostringstream s; - if(it->source_location().as_string().empty()) continue; + if(it->source_location().as_string().empty()) + continue; - OUTPUT(s, "fence", it->source_location().get_file(), it->source_location().get_line(), - ns.lookup(it->get_identifier()).base_name, "Write"); + OUTPUT( + s, + "fence", + it->source_location().get_file(), + it->source_location().get_line(), + ns.lookup(it->get_identifier()).base_name, + "Write"); non_redundant_display.insert(s.str()); } @@ -75,10 +82,16 @@ class simple_insertiont { { std::ostringstream s; - if(it->source_location().as_string().empty()) continue; + if(it->source_location().as_string().empty()) + continue; - OUTPUT(s, "fence", it->source_location().get_file(), it->source_location().get_line(), - ns.lookup(it->get_identifier()).base_name, "Read"); + OUTPUT( + s, + "fence", + it->source_location().get_file(), + it->source_location().get_line(), + ns.lookup(it->get_identifier()).base_name, + "Read"); non_redundant_display.insert(s.str()); } @@ -92,18 +105,19 @@ class simple_insertiont { } public: - explicit simple_insertiont ( - messaget& _message, - value_setst& _value_sets, - const symbol_tablet& _symbol_table, - const goto_functionst& _goto_functions) + explicit simple_insertiont( + messaget &_message, + value_setst &_value_sets, + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions) :message(_message), value_sets(_value_sets), symbol_table(_symbol_table), ns(_symbol_table), goto_functions(_goto_functions) {} virtual ~simple_insertiont() {} - void do_it() { + void do_it() + { compute(); print_to_file(); } @@ -116,12 +130,12 @@ class fence_all_sharedt:public simple_insertiont void compute(); public: - fence_all_sharedt ( - messaget& _message, - value_setst& _value_sets, - const symbol_tablet& _symbol_table, - const goto_functionst& _goto_functions) - :simple_insertiont(_message, _value_sets,_symbol_table,_goto_functions) + fence_all_sharedt( + messaget &_message, + value_setst &_value_sets, + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions) + :simple_insertiont(_message, _value_sets, _symbol_table, _goto_functions) {} }; @@ -131,18 +145,18 @@ class fence_all_shared_aegt:public fence_all_sharedt protected: void compute(); std::set visited_functions; - void fence_all_shared_aeg_explore(const goto_programt& code + void fence_all_shared_aeg_explore(const goto_programt &code #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif -); + ); // NOLINT(whitespace/parens) public: - fence_all_shared_aegt ( - messaget& _message, - value_setst& _value_sets, - const symbol_tablet& _symbol_table, - const goto_functionst& _goto_functions) + fence_all_shared_aegt( + messaget &_message, + value_setst &_value_sets, + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions) :fence_all_sharedt(_message, _value_sets, _symbol_table, _goto_functions) {} }; @@ -152,14 +166,14 @@ class fence_volatilet:public simple_insertiont { protected: void compute(); - bool is_volatile(const typet& src) const; + bool is_volatile(const typet &src) const; public: - fence_volatilet ( - messaget& _message, - value_setst& _value_sets, - const symbol_tablet& _symbol_table, - const goto_functionst& _goto_functions) + fence_volatilet( + messaget &_message, + value_setst &_value_sets, + const symbol_tablet &_symbol_table, + const goto_functionst &_goto_functions) :simple_insertiont(_message, _value_sets, _symbol_table, _goto_functions) {} }; @@ -178,11 +192,13 @@ Function: is_volatile \*******************************************************************/ -bool fence_volatilet::is_volatile (const typet &src) const +bool fence_volatilet::is_volatile(const typet &src) const { - if(src.get_bool(ID_C_volatile)) return true; + if(src.get_bool(ID_C_volatile)) + return true; -// std::cout << "type: " << src << " has sub: " << src.subtypes().empty() /*src.has_subtypes()*/ << std::endl; +// std::cout << "type: " << src << " has sub: " +// << src.subtypes().empty() /*src.has_subtypes()*/ << std::endl; if(src.id()==ID_symbol) { symbol_tablet::symbolst::const_iterator s_it= @@ -206,7 +222,7 @@ bool fence_volatilet::is_volatile (const typet &src) const it!=src.subtypes().end(); ++it) { - //std::cout << *it << std::endl; + // std::cout << *it << std::endl; vol|=is_volatile(*it); if(vol) break; @@ -239,28 +255,32 @@ void fence_volatilet::compute() local_may_aliast local_may(f_it->second); #endif - forall_goto_program_instructions(i_it, f_it->second.body) { + forall_goto_program_instructions(i_it, f_it->second.body) + { rw_set_loct rw_set(ns, value_sets, i_it #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) forall_rw_set_w_entries(w_it, rw_set) { if(has_prefix(id2string(w_it->second.object), CPROVER_PREFIX)) continue; - try { + try + { message.debug() << "debug: " << id2string(w_it->second.object) << messaget::eom; - const symbolt& var=ns.lookup(w_it->second.object); + const symbolt &var=ns.lookup(w_it->second.object); if(is_volatile(var.type)) { message.debug() << "volatile: " << id2string(w_it->second.object) << messaget::eom; fenced_edges.writes.push_front(w_it->second.symbol_expr); } - } catch (std::string s) { + } + catch(std::string s) + { message.warning() << "failed to find" << s << messaget::eom; continue; @@ -275,8 +295,9 @@ void fence_volatilet::compute() { message.debug() << "debug: " << id2string(r_it->second.object) << messaget::eom; - const symbolt& var=ns.lookup(r_it->second.object); + const symbolt &var=ns.lookup(r_it->second.object); #if 0 + // NOLINTNEXTLINE(readability/braces) if(var.is_volatile && !var.is_thread_local) #endif if(is_volatile(var.type)) @@ -319,102 +340,109 @@ void fence_all_sharedt::compute() local_may_aliast local_may(f_it->second); #endif - forall_goto_program_instructions(i_it, f_it->second.body) { - if(i_it->is_function_call()) - continue; + forall_goto_program_instructions(i_it, f_it->second.body) + { + if(i_it->is_function_call()) + continue; - rw_set_with_trackt rw_set(ns, value_sets, i_it + rw_set_with_trackt rw_set(ns, value_sets, i_it #ifdef LOCAL_MAY - , local_may + , local_may #endif - ); - forall_rw_set_w_entries(w_it, rw_set) - { - if(has_prefix(id2string(w_it->second.object), CPROVER_PREFIX)) - continue; + ); // NOLINT(whitespace/parens) + forall_rw_set_w_entries(w_it, rw_set) + { + if(has_prefix(id2string(w_it->second.object), CPROVER_PREFIX)) + continue; - try { - const symbolt& var=ns.lookup(w_it->second.object); - message.debug() << "debug: " - << id2string(w_it->second.object) << " shared: " << var.is_shared() - << " loc: " << w_it->second.symbol_expr.source_location() - << messaget::eom; - if(var.is_shared()) + try + { + const symbolt &var=ns.lookup(w_it->second.object); + message.debug() << "debug: " + << id2string(w_it->second.object) << " shared: " << var.is_shared() + << " loc: " << w_it->second.symbol_expr.source_location() + << messaget::eom; + if(var.is_shared()) + { + /* this variable has perhaps been discovered after dereferencing + a pointer. We want to report this pointer */ + std::map &ref= + rw_set.dereferenced_from; + if(ref.find(w_it->second.object)!=ref.end()) { - /* this variable has perhaps been discovered after dereferencing - a pointer. We want to report this pointer */ - std::map& ref= - rw_set.dereferenced_from; - if(ref.find(w_it->second.object)!=ref.end()) - { - const irep_idt from=ref[w_it->second.object]; - const rw_set_baset::entryt& entry= ( - rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? - rw_set.r_entries[from] : - rw_set.w_entries[from] - ); - message.debug() << "shared: (through " - << id2string(w_it->second.object) << ") " << entry.object - << messaget::eom; - fenced_edges.writes.push_front(entry.symbol_expr); - } - else { - message.debug() << "shared: " - << id2string(w_it->second.object) << " -> " - << w_it->second.object << messaget::eom; - fenced_edges.writes.push_front(w_it->second.symbol_expr); - } + const irep_idt from=ref[w_it->second.object]; + const rw_set_baset::entryt &entry= + rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? + rw_set.r_entries[from] : + rw_set.w_entries[from]; + message.debug() << "shared: (through " + << id2string(w_it->second.object) << ") " << entry.object + << messaget::eom; + fenced_edges.writes.push_front(entry.symbol_expr); + } + else + { + message.debug() << "shared: " + << id2string(w_it->second.object) << " -> " + << w_it->second.object << messaget::eom; + fenced_edges.writes.push_front(w_it->second.symbol_expr); } - } catch (std::string s) { - message.warning() << "failed to find" << s - << messaget::eom; - continue; } } - forall_rw_set_r_entries(r_it, rw_set) + catch(std::string s) { - if(has_prefix(id2string(r_it->second.object), CPROVER_PREFIX)) - continue; + message.warning() << "failed to find" << s + << messaget::eom; + continue; + } + } + forall_rw_set_r_entries(r_it, rw_set) + { + if(has_prefix(id2string(r_it->second.object), CPROVER_PREFIX)) + continue; - try { - const symbolt& var=ns.lookup(r_it->second.object); - message.debug() << "debug: " - << id2string(r_it->second.object) << " shared: " - << var.is_shared() << " loc: " - << r_it->second.symbol_expr.source_location() << messaget::eom; - if(var.is_shared()) + try + { + const symbolt &var=ns.lookup(r_it->second.object); + message.debug() << "debug: " + << id2string(r_it->second.object) << " shared: " + << var.is_shared() << " loc: " + << r_it->second.symbol_expr.source_location() << messaget::eom; + if(var.is_shared()) + { + /* this variable has perhaps been discovered after dereferencing + a pointer. We want to report this pointer */ + std::map& + ref=rw_set.dereferenced_from; + if(ref.find(r_it->second.object)!=ref.end()) { - /* this variable has perhaps been discovered after dereferencing - a pointer. We want to report this pointer */ - std::map& - ref=rw_set.dereferenced_from; - if(ref.find(r_it->second.object)!=ref.end()) - { - const irep_idt from=ref[r_it->second.object]; - const rw_set_baset::entryt& entry=( - rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? - rw_set.r_entries[from] : - rw_set.w_entries[from] - ); - - message.debug() << "shared: (through " - << id2string(r_it->second.object) << ") " << entry.object - << messaget::eom; - fenced_edges.reads.push_front(entry.symbol_expr); - } - else { - message.debug() << "shared: " - << id2string(r_it->second.object) << " -> " - << r_it->second.object << messaget::eom; - fenced_edges.reads.push_front(r_it->second.symbol_expr); - } + const irep_idt from=ref[r_it->second.object]; + const rw_set_baset::entryt &entry= + rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? + rw_set.r_entries[from] : + rw_set.w_entries[from]; + + message.debug() << "shared: (through " + << id2string(r_it->second.object) << ") " << entry.object + << messaget::eom; + fenced_edges.reads.push_front(entry.symbol_expr); + } + else + { + message.debug() << "shared: " + << id2string(r_it->second.object) << " -> " + << r_it->second.object << messaget::eom; + fenced_edges.reads.push_front(r_it->second.symbol_expr); } - } catch (std::string s) { - message.warning() << "failed to find" << s - << messaget::eom; - continue; } - } + } + catch(std::string s) + { + message.warning() << "failed to find" << s + << messaget::eom; + continue; + } + } } } } @@ -435,7 +463,7 @@ void fence_all_shared_aegt::compute() { message.status() << "--------" << messaget::eom; - const goto_functionst::goto_functiont& main= + const goto_functionst::goto_functiont &main= goto_functions.function_map.find(goto_functionst::entry_point())->second; #ifdef LOCAL_MAY local_may_aliast local_may(main); @@ -445,33 +473,37 @@ void fence_all_shared_aegt::compute() #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) } -void fence_all_shared_aegt::fence_all_shared_aeg_explore(const goto_programt& code +void fence_all_shared_aegt::fence_all_shared_aeg_explore( + const goto_programt &code #ifdef LOCAL_MAY - , local_may_aliast& local_may + , local_may_aliast &local_may #endif ) { - forall_goto_program_instructions(i_it, code) { + forall_goto_program_instructions(i_it, code) + { if(i_it->is_function_call()) { - const exprt& fun=to_code_function_call(i_it->code).function(); + const exprt &fun=to_code_function_call(i_it->code).function(); - if(fun.id()!=goto_functionst::entry_point()) continue; + if(fun.id()!=goto_functionst::entry_point()) + continue; - const irep_idt& fun_id=to_symbol_expr(fun).get_identifier(); + const irep_idt &fun_id=to_symbol_expr(fun).get_identifier(); if(visited_functions.find(fun_id)!=visited_functions.end()) continue; visited_functions.insert(fun_id); - fence_all_shared_aeg_explore(goto_functions.function_map.find(fun_id)->second.body + fence_all_shared_aeg_explore( + goto_functions.function_map.find(fun_id)->second.body #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) visited_functions.erase(fun_id); } @@ -479,14 +511,15 @@ void fence_all_shared_aegt::fence_all_shared_aeg_explore(const goto_programt& co #ifdef LOCAL_MAY , local_may #endif - ); + ); // NOLINT(whitespace/parens) forall_rw_set_w_entries(w_it, rw_set) { if(has_prefix(id2string(w_it->second.object), CPROVER_PREFIX)) continue; - try { - const symbolt& var=ns.lookup(w_it->second.object); + try + { + const symbolt &var=ns.lookup(w_it->second.object); message.debug() << "debug: " << id2string(w_it->second.object) << " shared: " << var.is_shared() << " loc: " @@ -500,25 +533,27 @@ void fence_all_shared_aegt::fence_all_shared_aeg_explore(const goto_programt& co if(ref.find(w_it->second.object)!=ref.end()) { const irep_idt from=ref[w_it->second.object]; - const rw_set_baset::entryt& entry=( + const rw_set_baset::entryt &entry= rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? rw_set.r_entries[from] : - rw_set.w_entries[from] - ); + rw_set.w_entries[from]; message.debug() << "shared: (through " << id2string(w_it->second.object) << ") " << entry.object << messaget::eom; fenced_edges.writes.push_front(entry.symbol_expr); } - else { + else + { message.debug() << "shared: " << id2string(w_it->second.object) << " -> " << w_it->second.object << messaget::eom; fenced_edges.writes.push_front(w_it->second.symbol_expr); } } - } catch (std::string s) { + } + catch(std::string s) + { message.warning() << "failed to find" << s << messaget::eom; continue; @@ -529,8 +564,9 @@ void fence_all_shared_aegt::fence_all_shared_aeg_explore(const goto_programt& co if(has_prefix(id2string(r_it->second.object), CPROVER_PREFIX)) continue; - try { - const symbolt& var=ns.lookup(r_it->second.object); + try + { + const symbolt &var=ns.lookup(r_it->second.object); message.debug() << "debug: " << id2string(r_it->second.object) << " shared: " <second.object)!=ref.end()) { const irep_idt from=ref[r_it->second.object]; - const rw_set_baset::entryt& entry=( + const rw_set_baset::entryt &entry= rw_set.set_reads.find(from)!=rw_set.set_reads.end() ? rw_set.r_entries[from] : - rw_set.w_entries[from] - ); + rw_set.w_entries[from]; message.debug() << "shared: (through " << id2string(r_it->second.object) << ") " << entry.object << messaget::eom; fenced_edges.reads.push_front(entry.symbol_expr); } - else { + else + { message.debug() << "shared: " << id2string(r_it->second.object) << " -> " << r_it->second.object << messaget::eom; fenced_edges.reads.push_front(r_it->second.symbol_expr); } } - } catch (std::string s) { + } + catch(std::string s) + { message.warning() << "failed to find" << s << messaget::eom; continue; @@ -584,7 +622,7 @@ void fence_all_shared_aegt::fence_all_shared_aeg_explore(const goto_programt& co \*******************************************************************/ void fence_all_shared( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions) @@ -608,7 +646,7 @@ void fence_all_shared( \*******************************************************************/ void fence_all_shared_aeg( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions) @@ -632,7 +670,7 @@ void fence_all_shared_aeg( \*******************************************************************/ void fence_volatile( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions) diff --git a/src/musketeer/fence_shared.h b/src/musketeer/fence_shared.h index 0b0d38c7bbd..ecfb5ff4746 100644 --- a/src/musketeer/fence_shared.h +++ b/src/musketeer/fence_shared.h @@ -18,21 +18,21 @@ class message_handlert; /* finds all the shared variables (including static, global and dynamic) */ void fence_all_shared( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions); /* finds all the shared variables (including static, global and dynamic) */ void fence_all_shared_aeg( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions); /* finds all the volatile-declared variables */ void fence_volatile( - message_handlert& message_handler, + message_handlert &message_handler, value_setst &value_sets, symbol_tablet &symbol_table, goto_functionst &goto_functions); diff --git a/src/musketeer/fence_user_def.cpp b/src/musketeer/fence_user_def.cpp index c9fcf931f8c..f543efa7e97 100644 --- a/src/musketeer/fence_user_def.cpp +++ b/src/musketeer/fence_user_def.cpp @@ -22,7 +22,7 @@ Author: Vincent Nimal \*******************************************************************/ bool fence_user_def_insertert::contains_user_def( - const event_grapht::critical_cyclet& cycle) const + const event_grapht::critical_cyclet &cycle) const { /* DEPRECATED: user-inserted fences now detected at cycle collection */ #if 0 diff --git a/src/musketeer/fence_user_def.h b/src/musketeer/fence_user_def.h index e8ed32022d3..1f95a4c84cf 100644 --- a/src/musketeer/fence_user_def.h +++ b/src/musketeer/fence_user_def.h @@ -18,7 +18,7 @@ Author: Vincent Nimal class instrumentert; -class fence_user_def_insertert : public fence_insertert +class fence_user_def_insertert:public fence_insertert { protected: std::set selected_cycles; @@ -29,18 +29,20 @@ class fence_user_def_insertert : public fence_insertert virtual void process_cycles_selection(); // overload for base class - virtual bool filter_cycles (unsigned cycles_id) const + virtual bool filter_cycles(unsigned cycles_id) const { return selected_cycles.find(cycles_id)==selected_cycles.end(); } public: - explicit fence_user_def_insertert(instrumentert &instr) - :fence_insertert(instr) { + explicit fence_user_def_insertert(instrumentert &instr): + fence_insertert(instr) + { } - fence_user_def_insertert(instrumentert &instr, memory_modelt _model) - :fence_insertert(instr, _model) { + fence_user_def_insertert(instrumentert &instr, memory_modelt _model): + fence_insertert(instr, _model) + { } }; diff --git a/src/musketeer/fencer.cpp b/src/musketeer/fencer.cpp index 71587267e8f..a787ce06393 100644 --- a/src/musketeer/fencer.cpp +++ b/src/musketeer/fencer.cpp @@ -50,7 +50,7 @@ void fence_weak_memory( bool hide_internals, bool print_graph, infer_modet mode, - message_handlert& message_handler, + message_handlert &message_handler, bool ignore_arrays) { messaget message(message_handler); @@ -78,7 +78,7 @@ void fence_weak_memory( // collects cycles, directly or by SCCs if(input_max_var!=0 || input_max_po_trans!=0) - instrumenter.set_parameters_collection(input_max_var,input_max_po_trans, + instrumenter.set_parameters_collection(input_max_var, input_max_po_trans, ignore_arrays); else instrumenter.set_parameters_collection(max_thds, 0, ignore_arrays); @@ -140,7 +140,8 @@ void fence_weak_memory( instrumenter.cfg_cycles_filter(); /* selects method, infers fences then outputs them */ - switch(mode) { + switch(mode) + { case INFER: { fence_insertert fence_inserter(instrumenter, model); diff --git a/src/musketeer/fencer.h b/src/musketeer/fencer.h index 1c3b236eb4f..cc28d439497 100644 --- a/src/musketeer/fencer.h +++ b/src/musketeer/fencer.h @@ -39,7 +39,7 @@ void fence_weak_memory( bool hide_internals, bool print_graph, infer_modet mode, - message_handlert& message_handler, + message_handlert &message_handler, bool ignore_arrays); #endif // CPROVER_MUSKETEER_FENCER_H diff --git a/src/musketeer/graph_visitor.cpp b/src/musketeer/graph_visitor.cpp index e503a65170d..d7f94938819 100644 --- a/src/musketeer/graph_visitor.cpp +++ b/src/musketeer/graph_visitor.cpp @@ -31,22 +31,25 @@ void const_graph_visitort::graph_explore( std::list &old_path, std::set &edges) { - if(next == end) { + if(next==end) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { /* it should be a po_s, and not a po_s^+ */ - assert(egraph.has_po_edge(*it,*next_it)); - edges.insert(fence_inserter.add_edge(edget(*it,*next_it))); + assert(egraph.has_po_edge(*it, *next_it)); + edges.insert(fence_inserter.add_edge(edget(*it, *next_it))); } } - else if(egraph.po_out(next).size()==0) { + else if(egraph.po_out(next).size()==0) + { /* this path is not connecting a to b => return */ } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(next).begin(); next_it!=egraph.po_out(next).end(); @@ -76,27 +79,30 @@ void const_graph_visitort::graph_explore( \*******************************************************************/ void const_graph_visitort::const_graph_explore( - event_grapht& egraph, + event_grapht &egraph, event_idt next, event_idt end, - std::list& old_path) + std::list &old_path) { - if(next == end) { + if(next==end) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { /* it should be a po_s, and not a po_s^+ */ - assert(egraph.has_po_edge(*it,*next_it)); - fence_inserter.add_edge(edget(*it,*next_it)); + assert(egraph.has_po_edge(*it, *next_it)); + fence_inserter.add_edge(edget(*it, *next_it)); } } - else if(egraph.po_out(next).size()==0) { + else if(egraph.po_out(next).size()==0) + { /* this path is not connecting a to b => return */ } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(next).begin(); next_it!=egraph.po_out(next).end(); @@ -126,17 +132,19 @@ void const_graph_visitort::const_graph_explore( \*******************************************************************/ void const_graph_visitort::graph_explore_BC( - event_grapht& egraph, + event_grapht &egraph, event_idt next, - std::list& old_path, - std::set& edges, + std::list &old_path, + std::set &edges, bool porw) { /* TODO: restricts to C_1 U ... U C_n for perf improvement */ - assert(old_path.size() > 0); + assert(old_path.size()>0); - fence_inserter.instrumenter.message.debug() << "(BC) explore " << old_path.front() - << " --...--> " << next << messaget::eom; + fence_inserter.instrumenter.message.debug() << "(BC) explore " + << old_path.front() + << " --...--> " << next + << messaget::eom; if(visited_nodes.find(next)!=visited_nodes.end()) return; @@ -154,22 +162,25 @@ void const_graph_visitort::graph_explore_BC( break; } - if(egraph.po_out(next).size()==0 || no_other_pos) { + if(egraph.po_out(next).size()==0 || no_other_pos) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { - const abstract_eventt& e1=egraph[*it]; - const abstract_eventt& e2=egraph[*next_it]; - if(!porw || (e1.operation==abstract_eventt::Read - && e2.operation==abstract_eventt::Write)) - edges.insert(fence_inserter.add_edge(edget(*it,*next_it))); + const abstract_eventt &e1=egraph[*it]; + const abstract_eventt &e2=egraph[*next_it]; + if(!porw || + (e1.operation==abstract_eventt::Read && + e2.operation==abstract_eventt::Write)) + edges.insert(fence_inserter.add_edge(edget(*it, *next_it))); } assert(it!=old_path.end()); } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(next).begin(); next_it!=egraph.po_out(next).end(); @@ -195,9 +206,9 @@ void const_graph_visitort::graph_explore_BC( \*******************************************************************/ void const_graph_visitort::const_graph_explore_BC( - event_grapht& egraph, + event_grapht &egraph, event_idt next, - std::list& old_path) + std::list &old_path) { /* TODO: restricts to C_1 U ... U C_n */ assert(old_path.size() > 0); @@ -218,23 +229,25 @@ void const_graph_visitort::const_graph_explore_BC( break; } - if(egraph.po_out(next).size()==0 || no_other_pos) { + if(egraph.po_out(next).size()==0 || no_other_pos) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { - const abstract_eventt& e1=egraph[*it]; - const abstract_eventt& e2=egraph[*next_it]; + const abstract_eventt &e1=egraph[*it]; + const abstract_eventt &e2=egraph[*next_it]; if((e1.operation==abstract_eventt::Read && e2.operation==abstract_eventt::Write)) - fence_inserter.add_edge(edget(*it,*next_it)); + fence_inserter.add_edge(edget(*it, *next_it)); } // NEW assert(it!=old_path.end()); } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(next).begin(); next_it!=egraph.po_out(next).end(); @@ -260,10 +273,10 @@ void const_graph_visitort::const_graph_explore_BC( \*******************************************************************/ void const_graph_visitort::graph_explore_AC( - event_grapht& egraph, + event_grapht &egraph, event_idt next, - std::list& old_path, - std::set& edges, + std::list &old_path, + std::set &edges, bool porw) { /* TODO: restricts to C_1 U ... U C_n */ @@ -288,22 +301,25 @@ void const_graph_visitort::graph_explore_AC( break; } - if(egraph.po_in(next).size()==0 || no_other_pos) { + if(egraph.po_in(next).size()==0 || no_other_pos) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { - const abstract_eventt& e1=egraph[*next_it]; - const abstract_eventt& e2=egraph[*it]; - if(!porw || (e1.operation==abstract_eventt::Read - && e2.operation==abstract_eventt::Write)) - edges.insert(fence_inserter.add_edge(edget(*next_it,*it))); + const abstract_eventt &e1=egraph[*next_it]; + const abstract_eventt &e2=egraph[*it]; + if(!porw || + (e1.operation==abstract_eventt::Read && + e2.operation==abstract_eventt::Write)) + edges.insert(fence_inserter.add_edge(edget(*next_it, *it))); } assert(it!=old_path.end()); } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_in(next).begin(); next_it!=egraph.po_in(next).end(); @@ -329,9 +345,9 @@ void const_graph_visitort::graph_explore_AC( \*******************************************************************/ void const_graph_visitort::const_graph_explore_AC( - event_grapht& egraph, + event_grapht &egraph, event_idt next, - std::list& old_path) + std::list &old_path) { /* TODO: restricts to C_1 U ... U C_n */ assert(old_path.size() > 0); @@ -353,23 +369,25 @@ void const_graph_visitort::const_graph_explore_AC( } /* if beginning of the thread */ - if(egraph.po_in(next).size()==0 || no_other_pos) { + if(egraph.po_in(next).size()==0 || no_other_pos) + { /* inserts all the pos collected from old_path in edges */ std::list::const_iterator it=old_path.begin(); std::list::const_iterator next_it=it; ++next_it; - for(;next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) + for( ; next_it!=old_path.end() && it!=old_path.end(); ++it, ++next_it) { - const abstract_eventt& e1=egraph[*next_it]; - const abstract_eventt& e2=egraph[*it]; - if((e1.operation==abstract_eventt::Read - && e2.operation==abstract_eventt::Write)) - fence_inserter.add_edge(edget(*next_it,*it)); + const abstract_eventt &e1=egraph[*next_it]; + const abstract_eventt &e2=egraph[*it]; + if(e1.operation==abstract_eventt::Read && + e2.operation==abstract_eventt::Write) + fence_inserter.add_edge(edget(*next_it, *it)); } // NEW assert(it!=old_path.end()); } - else { + else + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_in(next).begin(); next_it!=egraph.po_in(next).end(); @@ -395,19 +413,19 @@ void const_graph_visitort::const_graph_explore_AC( \*******************************************************************/ void const_graph_visitort::PT( - const edget& e, - std::set& edges) + const edget &e, + std::set &edges) { visited_nodes.clear(); // if(!e.is_po) /* e is in po^+\po */ is_po is a flag set manually, do not // use it for checks!! - const wmm_grapht::edgest& list_po_out= + const wmm_grapht::edgest &list_po_out= fence_inserter.instrumenter.egraph.po_out(e.first); if(list_po_out.find(e.second)==list_po_out.end()) { #ifdef BTWN1 - event_grapht& egraph=fence_inserter.instrumenter.egraph; + event_grapht &egraph=fence_inserter.instrumenter.egraph; /* all the pos inbetween */ for(wmm_grapht::edgest::const_iterator @@ -428,7 +446,7 @@ void const_graph_visitort::PT( check whether e.first-po-> edge.first /\ edge.second-po->e.second, using egraph.are_po_ordered. */ #else - throw "BTWN definition not selected!"; + throw "BTWN definition not selected!"; // NOLINT(readability/throw) #endif } else @@ -449,14 +467,14 @@ void const_graph_visitort::PT( \*******************************************************************/ void const_graph_visitort::CT( - const edget& edge, - std::set& edges) + const edget &edge, + std::set &edges) { - event_grapht& egraph=fence_inserter.instrumenter.egraph; + event_grapht &egraph=fence_inserter.instrumenter.egraph; /* the edge can be in the reversed order (back-edge) */ - const abstract_eventt& test_first=egraph[edge.first]; - const abstract_eventt& test_second=egraph[edge.second]; + const abstract_eventt &test_first=egraph[edge.first]; + const abstract_eventt &test_second=egraph[edge.second]; assert(test_first.operation!=test_second.operation); const event_idt first= @@ -468,7 +486,8 @@ void const_graph_visitort::CT( visited_nodes.clear(); /* if one event only on this thread of the cycle, discard */ - if(egraph.po_in(first).size() > 0) + if(!egraph.po_in(first).empty()) + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_in(first).begin(); next_it!=egraph.po_in(first).end(); @@ -479,8 +498,10 @@ void const_graph_visitort::CT( new_path.push_back(next_it->first); graph_explore_AC(egraph, next_it->first, new_path, edges); } + } - if(egraph.po_out(second).size() > 0) + if(!egraph.po_out(second).empty()) + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(second).begin(); next_it!=egraph.po_out(second).end(); @@ -491,6 +512,7 @@ void const_graph_visitort::CT( new_path.push_back(next_it->first); graph_explore_BC(egraph, next_it->first, new_path, edges); } + } } /*******************************************************************\ @@ -506,14 +528,14 @@ void const_graph_visitort::CT( \*******************************************************************/ void const_graph_visitort::CT_not_powr( - const edget& edge, - std::set& edges) + const edget &edge, + std::set &edges) { - event_grapht& egraph=fence_inserter.instrumenter.egraph; + event_grapht &egraph=fence_inserter.instrumenter.egraph; /* the edge can be in the reversed order (back-edge) */ - const abstract_eventt& test_first=egraph[edge.first]; - const abstract_eventt& test_second=egraph[edge.second]; + const abstract_eventt &test_first=egraph[edge.first]; + const abstract_eventt &test_second=egraph[edge.second]; assert(test_first.operation!=test_second.operation); const event_idt first= @@ -524,7 +546,8 @@ void const_graph_visitort::CT_not_powr( /* TODO: AC + restricts to C_1 U ... U C_n */ visited_nodes.clear(); - if(egraph.po_in(first).size() > 0) + if(!egraph.po_in(first).empty()) + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_in(first).begin(); next_it!=egraph.po_in(first).end(); @@ -535,8 +558,10 @@ void const_graph_visitort::CT_not_powr( new_path.push_back(next_it->first); graph_explore_AC(egraph, next_it->first, new_path, edges, true); } + } - if(egraph.po_out(second).size() > 0) + if(!egraph.po_out(second).empty()) + { for(wmm_grapht::edgest::const_iterator next_it=egraph.po_out(second).begin(); next_it!=egraph.po_out(second).end(); @@ -547,4 +572,5 @@ void const_graph_visitort::CT_not_powr( new_path.push_back(next_it->first); graph_explore_BC(egraph, next_it->first, new_path, edges, true); } + } } diff --git a/src/musketeer/graph_visitor.h b/src/musketeer/graph_visitor.h index c75004d01d3..0574cae885f 100644 --- a/src/musketeer/graph_visitor.h +++ b/src/musketeer/graph_visitor.h @@ -21,50 +21,50 @@ class const_graph_visitort protected: typedef event_grapht::critical_cyclet::delayt edget; - fence_insertert& fence_inserter; + fence_insertert &fence_inserter; std::set visited_nodes; public: /* computes the PT (btwn), CT (cml) and IT (cntrl) */ - void PT(const edget& e, std::set& edges); - void CT(const edget& e, std::set& edges); - void CT_not_powr(const edget& e, std::set &edges); - void IT(const edget& e, std::set& edges); + void PT(const edget &e, std::set &edges); + void CT(const edget &e, std::set &edges); + void CT_not_powr(const edget &e, std::set &edges); + void IT(const edget &e, std::set &edges); void const_graph_explore( - event_grapht& graph, + event_grapht &graph, event_idt next, event_idt end, - std::list& old_path); - void graph_explore(event_grapht& graph, event_idt next, event_idt end, - std::list& old_path, std::set& edges); - void graph_explore_BC(event_grapht& egraph, event_idt next, - std::list& old_path, std::set& edges, bool porw); - void graph_explore_AC(event_grapht& egraph, event_idt next, - std::list& old_path, std::set& edges, bool porw); + std::list &old_path); + void graph_explore(event_grapht &graph, event_idt next, event_idt end, + std::list &old_path, std::set &edges); + void graph_explore_BC(event_grapht &egraph, event_idt next, + std::list &old_path, std::set &edges, bool porw); + void graph_explore_AC(event_grapht &egraph, event_idt next, + std::list &old_path, std::set &edges, bool porw); void graph_explore_BC( - event_grapht& egraph, event_idt next, - std::list& old_path, - std::set& edges) + event_grapht &egraph, event_idt next, + std::list &old_path, + std::set &edges) { graph_explore_BC(egraph, next, old_path, edges, false); } void graph_explore_AC( - event_grapht& egraph, + event_grapht &egraph, event_idt next, - std::list& old_path, - std::set& edges) + std::list &old_path, + std::set &edges) { graph_explore_AC(egraph, next, old_path, edges, false); } - void const_graph_explore_BC(event_grapht& egraph, event_idt next, - std::list& old_path); - void const_graph_explore_AC(event_grapht& egraph, event_idt next, - std::list& old_path); + void const_graph_explore_BC(event_grapht &egraph, event_idt next, + std::list &old_path); + void const_graph_explore_AC(event_grapht &egraph, event_idt next, + std::list &old_path); - const_graph_visitort(fence_insertert& _fence_inserter) + explicit const_graph_visitort(fence_insertert &_fence_inserter) : fence_inserter(_fence_inserter) {} }; diff --git a/src/musketeer/ilp.h b/src/musketeer/ilp.h index 8e8a0283458..cecc47fb0a8 100644 --- a/src/musketeer/ilp.h +++ b/src/musketeer/ilp.h @@ -20,9 +20,11 @@ class ilpt { protected: template - class my_vectort: public std::vector { + class my_vectort: public std::vector + { public: - T* to_array() { + T *to_array() + { /* NOTE: not valid if T==bool */ return &(*this)[0]; } @@ -32,13 +34,14 @@ class ilpt unsigned matrix_size; public: - glp_prob* lp; + glp_prob *lp; my_vectort imat; my_vectort jmat; my_vectort vmat; - ilpt () { + ilpt() + { glp_init_iocp(&parm); parm.msg_lev=GLP_MSG_OFF; parm.presolve=GLP_ON; @@ -48,18 +51,21 @@ class ilpt glp_set_obj_dir(lp, GLP_MIN); } - ~ilpt () { + ~ilpt() + { glp_delete_prob(lp); } - void set_size(unsigned mat_size) { + void set_size(unsigned mat_size) + { matrix_size=mat_size; imat.resize(mat_size+1); jmat.resize(mat_size+1); vmat.resize(mat_size+1); } - void solve() { + void solve() + { glp_load_matrix(lp, matrix_size, imat.to_array(), jmat.to_array(), vmat.to_array()); glp_intopt(lp, &parm); diff --git a/src/musketeer/infer_mode.h b/src/musketeer/infer_mode.h index f98aaa1c32a..426653a1622 100644 --- a/src/musketeer/infer_mode.h +++ b/src/musketeer/infer_mode.h @@ -9,7 +9,8 @@ #ifndef CPROVER_MUSKETEER_INFER_MODE_H #define CPROVER_MUSKETEER_INFER_MODE_H -typedef enum { +typedef enum +{ INFER=0, USER_DEF=1, USER_ASSERT=2 diff --git a/src/musketeer/musketeer_parse_options.cpp b/src/musketeer/musketeer_parse_options.cpp index 4912db95dd3..707ec50bd0b 100644 --- a/src/musketeer/musketeer_parse_options.cpp +++ b/src/musketeer/musketeer_parse_options.cpp @@ -65,7 +65,8 @@ void goto_fence_inserter_parse_optionst::set_verbosity() if(cmdline.isset("verbosity")) { v=unsafe_string2unsigned(cmdline.get_value("verbosity")); - if(v>10) v=10; + if(v>10) + v=10; } ui_message_handler.set_verbosity(v); @@ -121,7 +122,7 @@ int goto_fence_inserter_parse_optionst::doit() return 0; } - //help(); + // help(); return 0; } @@ -211,13 +212,15 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( || cmdline.isset("naive") || cmdline.isset("all-shared-aeg") ) { - if(cmdline.isset("remove-function-pointers")) { + if(cmdline.isset("remove-function-pointers")) + { status() << "remove soundly function pointers" << eom; remove_function_pointers(symbol_table, goto_functions, cmdline.isset("pointer-check")); } - if(cmdline.isset("async")) { + if(cmdline.isset("async")) + { status() << "Replace pthread_creates by __CPROVER_ASYNC_0:" << eom; replace_async(ns, goto_functions); goto_functions.update(); @@ -227,15 +230,16 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( status() << "Partial Inlining" << eom; goto_partial_inline(goto_functions, ns, ui_message_handler); - if( cmdline.isset("const-function-pointer-propagation") ) { + if(cmdline.isset("const-function-pointer-propagation")) + { /* propagate const pointers to functions */ status() << "Propagate Constant Function Pointers" << eom; propagate_const_function_pointers(symbol_table, goto_functions, get_message_handler()); } - //goto_functions.output(ns, std::cout); - //return; + // goto_functions.output(ns, std::cout); + // return; #if 0 status() << "Function Pointer Removal" << eom; remove_function_pointers(symbol_table, goto_functions, @@ -263,7 +267,8 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( remove_asm(symbol_table, goto_functions); goto_functions.update(); - if(cmdline.isset("all-shared")) { + if(cmdline.isset("all-shared")) + { status() << "Shared variables accesses detection" << eom; fence_all_shared(get_message_handler(), value_set_analysis, symbol_table, goto_functions); @@ -271,7 +276,8 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( // does not transform the goto-binary return; } - if(cmdline.isset("all-shared-aeg")) { + if(cmdline.isset("all-shared-aeg")) + { status() << "Shared variables accesses detection (CF)" << eom; fence_all_shared_aeg(get_message_handler(), value_set_analysis, symbol_table, goto_functions); @@ -279,7 +285,8 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( // does not transform the goto-binary return; } - else if(cmdline.isset("volatile")) { + else if(cmdline.isset("volatile")) + { status() << "Detection of variables declared volatile" << eom; fence_volatile(get_message_handler(), value_set_analysis, symbol_table, @@ -288,16 +295,17 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( // does not transform the goto-binary return; } - else if(cmdline.isset("pensieve") || cmdline.isset("naive")) { + else if(cmdline.isset("pensieve") || cmdline.isset("naive")) + { status() << "Delay-set analysis" << eom; - const unsigned unwind_loops = - ( cmdline.isset("unwind") ? - unsafe_string2unsigned(cmdline.get_value("unwind")) : 0 ); + const unsigned unwind_loops= + cmdline.isset("unwind") ? + unsafe_string2unsigned(cmdline.get_value("unwind")) : 0; - const unsigned max_po_trans = - ( cmdline.isset("max-po-trans") ? - unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0 ); + const unsigned max_po_trans= + cmdline.isset("max-po-trans") ? + unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0; fence_pensieve( value_set_analysis, @@ -339,16 +347,16 @@ void goto_fence_inserter_parse_optionst::instrument_goto_program( inst_strategy=all; const unsigned unwind_loops = - ( cmdline.isset("unwind") ? - unsafe_string2unsigned(cmdline.get_value("unwind")) : 0 ); + cmdline.isset("unwind") ? + unsafe_string2unsigned(cmdline.get_value("unwind")) : 0; const unsigned max_var = - ( cmdline.isset("max-var") ? - unsafe_string2unsigned(cmdline.get_value("max-var")) : 0 ); + cmdline.isset("max-var") ? + unsafe_string2unsigned(cmdline.get_value("max-var")) : 0; const unsigned max_po_trans = - ( cmdline.isset("max-po-trans") ? - unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0 ); + cmdline.isset("max-po-trans") ? + unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0; if(mm=="tso") { @@ -459,18 +467,23 @@ void goto_fence_inserter_parse_optionst::help() "\n" "Main options:\n" "\n" + // NOLINTNEXTLINE(whitespace/line_length) " --mm detects all the fences to insert for a weak\n" " memory model\n" "\n" "Alternative methods:\n" "\n" + // NOLINTNEXTLINE(whitespace/line_length) " --all-shared detects and fences all the accesses to shared\n" " variables (context insensitive)\n" + // NOLINTNEXTLINE(whitespace/line_length) " --all-shared-aeg detects all the accesses to shared variables\n" " (context sensitive)\n" + // NOLINTNEXTLINE(whitespace/line_length) " --volatile detects all the accesses to volatile variables\n" " --pensieve detects all the pairs to be delayed with\n" " Pensieve's criteria (context sensitive)\n" + // NOLINTNEXTLINE(whitespace/line_length) " --naive detects all the pairs to be delayed in a naive\n" " approach (context sensitive)\n" "\n" @@ -478,17 +491,23 @@ void goto_fence_inserter_parse_optionst::help() "\n" " --remove-function-pointers removes soundly function pointers based on\n" " their signatures\n" + // NOLINTNEXTLINE(whitespace/line_length) " --async replaces all the pthread_creates by CPROVER_ASYNC\n" " --const-function-pointer-propagation\n" + // NOLINTNEXTLINE(whitespace/line_length) " propagates the constant pointers to functions\n" + // NOLINTNEXTLINE(whitespace/line_length) " --scc detects cycles in parallel (one thread/SCC)\n" + // NOLINTNEXTLINE(whitespace/line_length) " --force-loop-duplication duplicates the bodies of all the loops, and not\n" " only those with arrays accesses\n" " --no-loop-duplication constructs back-edges for all the loops\n" + // NOLINTNEXTLINE(whitespace/line_length) " --no-dependencies ignores existing dependencies in the program\n" " --print-graph prints the AEG into graph.dot\n" " --max-po-var limits the number of variables per cycle\n" " --max-po-trans limits the size of pos^+ in terms of pos\n" + // NOLINTNEXTLINE(whitespace/line_length) " --ignore-arrays ignores cycles with multiple accesses to the\n" " same array\n" "\n"; diff --git a/src/musketeer/pensieve.cpp b/src/musketeer/pensieve.cpp index bea0fab3525..649182e1696 100644 --- a/src/musketeer/pensieve.cpp +++ b/src/musketeer/pensieve.cpp @@ -38,7 +38,7 @@ void fence_pensieve( bool render_file, bool render_function, bool naive_mode, - message_handlert& message_handler) + message_handlert &message_handler) { messaget message(message_handler); @@ -63,7 +63,7 @@ void fence_pensieve( message.status() << "Abstract event graph computed" << messaget::eom; if(input_max_po_trans!=0) - instrumenter.set_parameters_collection(0,input_max_po_trans); + instrumenter.set_parameters_collection(0, input_max_po_trans); else instrumenter.set_parameters_collection(max_thds); diff --git a/src/musketeer/pensieve.h b/src/musketeer/pensieve.h index f4010513e5e..298919f182f 100644 --- a/src/musketeer/pensieve.h +++ b/src/musketeer/pensieve.h @@ -27,6 +27,6 @@ void fence_pensieve( bool render_file, bool render_function, bool naive_mode, - message_handlert& message_handler); + message_handlert &message_handler); #endif // CPROVER_MUSKETEER_PENSIEVE_H diff --git a/src/musketeer/propagate_const_function_pointers.cpp b/src/musketeer/propagate_const_function_pointers.cpp index 253d601a056..0fb2f0aad18 100644 --- a/src/musketeer/propagate_const_function_pointers.cpp +++ b/src/musketeer/propagate_const_function_pointers.cpp @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: Constant Function Pointer Propagation + +Author: Vincent Nimal + +\*******************************************************************/ + #include #include #include @@ -12,12 +20,15 @@ #include #include -class const_function_pointer_propagationt { +#include "propagate_const_function_pointers.h" + +class const_function_pointer_propagationt +{ protected: - symbol_tablet& symbol_table; - goto_functionst& goto_functions; + symbol_tablet &symbol_table; + goto_functionst &goto_functions; const namespacet ns; - messaget& message; + messaget &message; std::unordered_map map_unique; @@ -33,15 +44,17 @@ class const_function_pointer_propagationt { /* stack of callsites: provides functions and location in the goto-program */ goto_programt::const_targetst callsite_stack; - bool resolve(const irep_idt& symb, - symbol_exprt& goto_function, - unsigned& stack_scope) + bool resolve( + const irep_idt &symb, + symbol_exprt &goto_function, + unsigned &stack_scope) { message.debug() << "I resolve " << symb << " with " << pointer_to_fun[symb].get_identifier() << messaget::eom; if(pointer_to_fun.find(symb)==pointer_to_fun.end()) return false; - else { + else + { goto_function=pointer_to_fun[symb]; stack_scope=pointer_to_stack[symb]; return true; @@ -53,72 +66,76 @@ class const_function_pointer_propagationt { Yes! Pure propagation of pointers only intra-proc. At call, arguments and pointed functions stored in the table -- no need to keep the match between two pointers inter-proc. */ - bool add(const irep_idt& symb, const symbol_exprt& goto_function) + bool add(const irep_idt &symb, const symbol_exprt &goto_function) { return add(symb, goto_function, callsite_stack.size()); } - bool add(const irep_idt& symb, - const symbol_exprt& goto_function, + bool add(const irep_idt &symb, + const symbol_exprt &goto_function, unsigned scope) { pointer_to_fun[symb]=goto_function; pointer_to_stack[symb]=scope; - const symbolt& function_symb=ns.lookup(goto_function.get_identifier()); + const symbolt &function_symb=ns.lookup(goto_function.get_identifier()); if(fun_id_to_invok.find(function_symb.base_name)==fun_id_to_invok.end()) fun_id_to_invok[function_symb.base_name]=scope; return true; } - bool remove(const irep_idt& symb) { - //assert(pointer_to_fun.find(symb)!=pointer_to_fun.end()); + bool remove(const irep_idt &symb) + { + assert(pointer_to_fun.find(symb)!=pointer_to_fun.end()); pointer_to_fun.erase(symb); return true; } - bool has(const irep_idt& symb) const { + bool has(const irep_idt &symb) const + { return pointer_to_fun.find(symb)!=pointer_to_fun.end(); } - symbol_exprt get(const irep_idt& symb) { + symbol_exprt get(const irep_idt &symb) + { return pointer_to_fun[symb]; } /* to keep track of the visited functions and avoid recursion */ std::set functions_met; - void propagate(const irep_idt& function); + void propagate(const irep_idt &function); - void dup_caller_and_inline_callee(const symbol_exprt& function, + void dup_caller_and_inline_callee(const symbol_exprt &function, unsigned stack_scope); /* to keep track of the constant function pointers passed as arguments */ class arg_stackt: public std::set { protected: - const_function_pointer_propagationt& cfpp; + const_function_pointer_propagationt &cfpp; public: - arg_stackt (const_function_pointer_propagationt& _cfpp) - :cfpp(_cfpp) + explicit arg_stackt(const_function_pointer_propagationt &_cfpp): + cfpp(_cfpp) {} - void add_args(const symbol_exprt& const_function, + void add_args(const symbol_exprt &const_function, goto_programt::instructionst::iterator it); void remove_args(); }; public: - const_function_pointer_propagationt(symbol_tablet& _symbol_table, - goto_functionst& _goto_functions, messaget& _message) + const_function_pointer_propagationt(symbol_tablet &_symbol_table, + goto_functionst &_goto_functions, messaget &_message) :symbol_table(_symbol_table), goto_functions(_goto_functions), ns(_symbol_table), message(_message) {} /* Note that it only propagates from MAIN, following the CFG, without resolving non-constant function pointers. */ - void propagate() { + void propagate() + { propagate(goto_functionst::entry_point()); } }; @@ -138,7 +155,7 @@ class const_function_pointer_propagationt { \*******************************************************************/ void const_function_pointer_propagationt::dup_caller_and_inline_callee( - const symbol_exprt& const_function, + const symbol_exprt &const_function, unsigned stack_scope) { assert(callsite_stack.size()>0); @@ -173,11 +190,13 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( if(current_call>stack_scope) { /* unique suffix */ - if(map_unique.find(function_id)!=map_unique.end()) { + if(map_unique.find(function_id)!=map_unique.end()) + { suffix+=std::to_string(map_unique[function_id]); ++map_unique[function_id]; } - else { + else + { map_unique[function_id]=0; suffix+=std::to_string(map_unique[function_id]); ++map_unique[function_id]; @@ -188,7 +207,7 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( << messaget::eom; const irep_idt function_new_id=id2string(function_id)+suffix; - goto_functionst::goto_functiont& function_dup= + goto_functionst::goto_functiont &function_dup= goto_functions.function_map[function_new_id]; function_dup.copy_from(goto_functions.function_map[function_id]); pfunction_dup=&function_dup; @@ -197,10 +216,11 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( it!=function_dup.body.instructions.end(); ++it) it->function=function_new_id; - assert(goto_functions.function_map[function_new_id].body.instructions.size()>0); + assert(goto_functions.function_map[function_new_id]. + body.instructions.size()>0); /* removes in definition the argument leading to the const_function */ - code_typet::parameterst& args=function_dup.type.parameters(); + code_typet::parameterst &args=function_dup.type.parameters(); for(code_typet::parameterst::iterator it=args.begin(); it!=args.end(); ++it) { @@ -210,7 +230,7 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( } /* updates the table of symbols */ - const symbolt& fun_symb=ns.lookup(function_id); + const symbolt &fun_symb=ns.lookup(function_id); symbolt dup_fun_symb; dup_fun_symb=fun_symb; dup_fun_symb.name=id2string(dup_fun_symb.name)+suffix; @@ -232,37 +252,43 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( << messaget::eom; /* sets the call to the previous newly duplicated function */ - goto_programt::instructionst& new_instructions= + goto_programt::instructionst &new_instructions= pfunction_dup->body.instructions; goto_programt::targett it=new_instructions.begin(); // beurk -- should use location_number or something unique per // instruction but shared between two copies of a same goto-program - for(; it->source_location!=(*callsite)->source_location - && it!=new_instructions.end(); ++it); + for( ; + it->source_location!=(*callsite)->source_location && + it!=new_instructions.end(); + ++it) + { + } assert(it->source_location==(*callsite)->source_location); - exprt& function_called=to_code_function_call(it->code).function(); + exprt &function_called=to_code_function_call(it->code).function(); assert(function_called.id()==ID_symbol); - symbol_exprt& symbol_fun_called=to_symbol_expr(function_called); + symbol_exprt &symbol_fun_called=to_symbol_expr(function_called); symbol_fun_called.set_identifier( id2string(symbol_fun_called.get_identifier())+last_suffix); /* removes the constant pointer from the arguments passed at call */ - code_function_callt::argumentst& args=to_code_function_call(it->code) + code_function_callt::argumentst &args=to_code_function_call(it->code) .arguments(); for(code_function_callt::argumentst::iterator arg_it=args.begin(); arg_it!=args.end(); ++arg_it) { - if(arg_it->id()==ID_symbol) { - const symbol_exprt& symb_arg=to_symbol_expr(*arg_it); + if(arg_it->id()==ID_symbol) + { + const symbol_exprt &symb_arg=to_symbol_expr(*arg_it); if(symb_arg.get_identifier()==const_function.get_identifier() || (pointer_to_fun.find(symb_arg.get_identifier()) !=pointer_to_fun.end() && pointer_to_fun[symb_arg.get_identifier()]==const_function) ) args.erase(arg_it); } - else if(arg_it->id()==ID_address_of) { - const address_of_exprt& add_arg=to_address_of_expr(*arg_it); + else if(arg_it->id()==ID_address_of) + { + const address_of_exprt &add_arg=to_address_of_expr(*arg_it); if(add_arg.object().id()==ID_symbol && to_symbol_expr(add_arg.object()).get_identifier() ==const_function.get_identifier()) @@ -272,18 +298,23 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( new_callsite_stack.push_back(it); } - else { + else + { message.debug() << "we first modify the first caller" << messaget::eom; /* initially, inlines the callee function in the duplicate of the last caller */ - goto_programt::instructionst& new_instructions= + goto_programt::instructionst &new_instructions= pfunction_dup->body.instructions; goto_programt::targett it=new_instructions.begin(); // beurk -- should use location_number or something unique per // instruction but shared between two copies of a same goto-program - for(; it->source_location!=(*callsite)->source_location - && it!=new_instructions.end(); ++it); + for( ; + it->source_location!=(*callsite)->source_location && + it!=new_instructions.end(); + ++it) + { + } message.debug() << "callsite targetted: " << (*callsite)->source_location << " function: " << const_function.get_identifier() << messaget::eom; @@ -300,7 +331,7 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( } /* and updates the call_stack and callsite_stack */ - //new_callsite_stack.splice(new_callsite_stack.end(), callsite_stack, + // new_callsite_stack.splice(new_callsite_stack.end(), callsite_stack, // callsite, callsite_stack.end()); for(goto_programt::const_targetst::const_iterator it=callsite; it!=callsite_stack.end(); ++it) @@ -324,12 +355,12 @@ void const_function_pointer_propagationt::dup_caller_and_inline_callee( \*******************************************************************/ void const_function_pointer_propagationt::arg_stackt::add_args( - const symbol_exprt& const_function, + const symbol_exprt &const_function, goto_programt::instructionst::iterator it) { /* if constant pointers passed as arguments, add the names of the parameters in the function definition to the map */ - const code_function_callt::argumentst& arg= + const code_function_callt::argumentst &arg= to_code_function_call(it->code).arguments(); /* retrieve the corresponding parameters expressions in the @@ -337,7 +368,7 @@ void const_function_pointer_propagationt::arg_stackt::add_args( assert(cfpp.goto_functions.function_map.find( const_function.get_identifier())!=cfpp.goto_functions.function_map.end()); - goto_functionst::goto_functiont& cor_function= + goto_functionst::goto_functiont &cor_function= cfpp.goto_functions.function_map[const_function.get_identifier()]; code_typet::parameterst::const_iterator cor_arg_it= @@ -352,16 +383,17 @@ void const_function_pointer_propagationt::arg_stackt::add_args( if(arg_it->id()!=ID_symbol && arg_it->id()!=ID_address_of) continue; - if(arg_it->id()==ID_address_of) { + if(arg_it->id()==ID_address_of) + { if(to_address_of_expr(*arg_it).object().id()!=ID_symbol) continue; - const exprt& arg_expr=to_address_of_expr(*arg_it).object(); + const exprt &arg_expr=to_address_of_expr(*arg_it).object(); assert(arg_expr.id()==ID_symbol); - const symbol_exprt& arg_symbol_expr=to_symbol_expr(arg_expr); + const symbol_exprt &arg_symbol_expr=to_symbol_expr(arg_expr); - //const symbolt& arg_symbol= - //cfpp.symbol_table.lookup(arg_symbol_expr.get_identifier()); + // const symbolt &arg_symbol= + // cfpp.symbol_table.lookup(arg_symbol_expr.get_identifier()); // debug for(std::unordered_map::const_iterator @@ -376,17 +408,19 @@ void const_function_pointer_propagationt::arg_stackt::add_args( cfpp.message.debug() << "SET: insert " << cor_arg_it->get_base_name() << messaget::eom; } - else { + else + { cfpp.message.debug() << "fun: " << const_function.get_identifier() << " - arg: (symb) " << cfpp.symbol_table .lookup(to_symbol_expr(*arg_it).get_identifier()).base_name << messaget::eom; - const symbol_exprt& arg_symbol_expr=to_symbol_expr(*arg_it); - const symbolt& arg_symbol= + const symbol_exprt &arg_symbol_expr=to_symbol_expr(*arg_it); + const symbolt &arg_symbol= cfpp.symbol_table.lookup(arg_symbol_expr.get_identifier()); - if(cfpp.has(arg_symbol.base_name)) { + if(cfpp.has(arg_symbol.base_name)) + { cfpp.add(cor_arg_it->get_base_name(), cfpp.get(arg_symbol.base_name), cfpp.fun_id_to_invok[arg_symbol.base_name]); insert(cor_arg_it->get_base_name()); @@ -409,9 +443,11 @@ void const_function_pointer_propagationt::arg_stackt::add_args( \*******************************************************************/ -void const_function_pointer_propagationt::arg_stackt::remove_args() { +void const_function_pointer_propagationt::arg_stackt::remove_args() +{ /* remove the parameter names */ - for(const_iterator arg_it=begin(); arg_it!=end(); ++arg_it) { + for(const_iterator arg_it=begin(); arg_it!=end(); ++arg_it) + { cfpp.remove(*arg_it); cfpp.message.debug() << "SET: remove " << *arg_it << messaget::eom; } @@ -430,62 +466,66 @@ void const_function_pointer_propagationt::arg_stackt::remove_args() { \*******************************************************************/ void const_function_pointer_propagationt::propagate( - const irep_idt& function_id) + const irep_idt &function_id) { - if(goto_functions.function_map.find(function_id) - ==goto_functions.function_map.end()) + if(goto_functions.function_map.find(function_id)== + goto_functions.function_map.end()) return; - goto_functionst::goto_functiont& function= + goto_functionst::goto_functiont &function= goto_functions.function_map[function_id]; if(functions_met.find(function_id)!=functions_met.end()) - return; + return; functions_met.insert(function_id); Forall_goto_program_instructions(it, function.body) { - if(it->is_assign()) { + if(it->is_assign()) + { /* is it an assignment of function pointer? */ - const code_assignt& assign=to_code_assign(it->code); - const exprt& lhs=assign.lhs(); - const exprt& rhs=assign.rhs(); + const code_assignt &assign=to_code_assign(it->code); + const exprt &lhs=assign.lhs(); + const exprt &rhs=assign.rhs(); /* rhs has to be an address to a function */ if(rhs.id()!=ID_address_of) continue; - const address_of_exprt& addr_rhs=to_address_of_expr(rhs); + const address_of_exprt &addr_rhs=to_address_of_expr(rhs); if(addr_rhs.object().id()!=ID_symbol || addr_rhs.object().type().id()!=ID_code) continue; - const symbol_exprt& symbol_rhs=to_symbol_expr(addr_rhs.object()); + const symbol_exprt &symbol_rhs=to_symbol_expr(addr_rhs.object()); /* lhs must be a pointer */ if(lhs.id()!=ID_symbol || lhs.type().id()!=ID_pointer) continue; - const symbol_exprt& symbol_expr_lhs=to_symbol_expr(lhs); - const symbolt& symbol_lhs= + const symbol_exprt &symbol_expr_lhs=to_symbol_expr(lhs); + const symbolt &symbol_lhs= symbol_table.lookup(symbol_expr_lhs.get_identifier()); add(symbol_lhs.base_name, symbol_rhs); } - else if(it->is_function_call()) { + else if(it->is_function_call()) + { callsite_stack.push_front(it); - const exprt& fun=to_code_function_call(it->code).function(); + const exprt &fun=to_code_function_call(it->code).function(); /* if it is a function pointer */ - if(fun.id()==ID_dereference) { - const exprt& fun_pointer=to_dereference_expr(fun).pointer(); - if(fun_pointer.id()!=ID_symbol) { + if(fun.id()==ID_dereference) + { + const exprt &fun_pointer=to_dereference_expr(fun).pointer(); + if(fun_pointer.id()!=ID_symbol) + { callsite_stack.pop_front(); continue; } - const symbol_exprt& fun_symbol_expr=to_symbol_expr(fun_pointer); - const symbolt& fun_symbol= + const symbol_exprt &fun_symbol_expr=to_symbol_expr(fun_pointer); + const symbolt &fun_symbol= symbol_table.lookup(fun_symbol_expr.get_identifier()); symbol_exprt const_function; unsigned stack_scope=0; @@ -511,17 +551,19 @@ void const_function_pointer_propagationt::propagate( /* restores the context */ callsite_stack.swap(context); } - else { + else + { /* no. Ignore it and leave it to the remove_function_pointers */ } } - else if(fun.id()==ID_symbol) { + else if(fun.id()==ID_symbol) + { message.debug() << "Propagates through " << to_symbol_expr(fun) .get_identifier() << messaget::eom; /* just propagate */ - const symbol_exprt& fun_symbol_expr=to_symbol_expr(fun); - const irep_idt& fun_id=fun_symbol_expr.get_identifier(); + const symbol_exprt &fun_symbol_expr=to_symbol_expr(fun); + const irep_idt &fun_id=fun_symbol_expr.get_identifier(); arg_stackt arg_stack(*this); arg_stack.add_args(fun_symbol_expr, it); @@ -533,7 +575,8 @@ void const_function_pointer_propagationt::propagate( callsite_stack.pop_front(); } - else if(it->is_end_function()) { + else if(it->is_end_function()) + { functions_met.erase(function_id); return; } @@ -555,9 +598,9 @@ void const_function_pointer_propagationt::propagate( \*******************************************************************/ void propagate_const_function_pointers( - symbol_tablet& symbol_table, - goto_functionst& goto_functions, - message_handlert& message_handler) + symbol_tablet &symbol_table, + goto_functionst &goto_functions, + message_handlert &message_handler) { messaget message(message_handler); const_function_pointer_propagationt propagation(symbol_table, diff --git a/src/musketeer/propagate_const_function_pointers.h b/src/musketeer/propagate_const_function_pointers.h index 7d518c5dec5..0749a1ac4bd 100644 --- a/src/musketeer/propagate_const_function_pointers.h +++ b/src/musketeer/propagate_const_function_pointers.h @@ -21,8 +21,8 @@ class message_handlert; functions-based exploration in remove_function_pointers. */ void propagate_const_function_pointers( - symbol_tablet& symbol_tables, - goto_functionst& goto_functions, - message_handlert& message_handler); + symbol_tablet &symbol_tables, + goto_functionst &goto_functions, + message_handlert &message_handler); #endif // CPROVER_MUSKETEER_PROPAGATE_CONST_FUNCTION_POINTERS_H diff --git a/src/musketeer/replace_async.h b/src/musketeer/replace_async.h index ade210725aa..6ef0b710860 100644 --- a/src/musketeer/replace_async.h +++ b/src/musketeer/replace_async.h @@ -23,7 +23,7 @@ void replace_async( { Forall_goto_functions(f_it, goto_functions) { - goto_programt& program=f_it->second.body; + goto_programt &program=f_it->second.body; Forall_goto_program_instructions(i_it, program) { @@ -41,13 +41,16 @@ void replace_async( assert(fct.arguments().size()>=4); code_function_callt new_call; /* takes the 3rd argument (pointer to the function to call) */ - const exprt& fct_name=fct.arguments()[2]; + const exprt &fct_name=fct.arguments()[2]; - if(fct_name.id()==ID_address_of) { + if(fct_name.id()==ID_address_of) + { /* pointer to function */ - new_call.function()=to_address_of_expr(fct.arguments()[2]).object(); + new_call.function()= + to_address_of_expr(fct.arguments()[2]).object(); } - else { + else + { /* other (e.g. local copy) */ new_call.function()=fct_name; } @@ -60,7 +63,8 @@ void replace_async( reproduce here the effects of the evaluation of this label */ i_it->labels.push_front("__CPROVER_ASYNC_0"); i_it->clear(START_THREAD); - /* CP_AC_0: f(); -> CP_AC_0: start_th; goto 2; 1: f(); end_th; 2: ... */ + /* CP_AC_0: f(); -> CP_AC_0: start_th; goto 2; + 1: f(); end_th; 2: ... */ goto_programt::targett goto2=program.insert_after(i_it); goto_programt::targett call=program.insert_after(goto2); diff --git a/src/path-symex/build_goto_trace.h b/src/path-symex/build_goto_trace.h index 67c9a2ad720..e6fd1a6d493 100644 --- a/src/path-symex/build_goto_trace.h +++ b/src/path-symex/build_goto_trace.h @@ -6,6 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ +// NOLINT(build/header_guard) as this file is also symlinked #ifndef CPROVER_PATH_SYMEX_BUILD_GOTO_TRACE_H #define CPROVER_PATH_SYMEX_BUILD_GOTO_TRACE_H diff --git a/src/path-symex/loc_ref.h b/src/path-symex/loc_ref.h index d11877683c2..9a8ea0dc341 100644 --- a/src/path-symex/loc_ref.h +++ b/src/path-symex/loc_ref.h @@ -16,24 +16,24 @@ class loc_reft public: unsigned loc_number; - inline loc_reft next_loc() const + loc_reft next_loc() const { loc_reft tmp=*this; tmp.increase(); return tmp; } - inline void increase() + void increase() { loc_number++; } - inline void decrease() + void decrease() { loc_number--; } - inline bool is_nil() const + bool is_nil() const { return loc_number==nil().loc_number; } @@ -47,35 +47,35 @@ class loc_reft return loc_reft(); } - inline loc_reft &operator++() // this is pre-increment + loc_reft &operator++() // this is pre-increment { increase(); return *this; } - inline loc_reft &operator--() // this is pre-decrement + loc_reft &operator--() // this is pre-decrement { decrease(); return *this; } -}; -static inline bool operator < (const loc_reft l1, const loc_reft l2) -{ - return l1.loc_number < l2.loc_number; -} + bool operator<(const loc_reft other) const + { + return loc_number function_mapt; function_mapt function_map; - locst(const namespacet &_ns); + explicit locst(const namespacet &_ns); void build(const goto_functionst &goto_functions); void output(std::ostream &out) const; - inline loct &operator[] (loc_reft l) + loct &operator[] (loc_reft l) { - assert(l.loc_number>=0 && l.loc_number < loc_vector.size()); + assert(l.loc_number>=0 && l.loc_number=0 && l.loc_number < loc_vector.size()); + assert(l.loc_number>=0 && l.loc_number +#include "path_symex.h" #include "path_symex_class.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -57,26 +58,31 @@ bool path_symext::propagate(const exprt &src) else if(src.id()==ID_plus) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_array) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_vector) { forall_operands(it, src) - if(!propagate(*it)) return false; + if(!propagate(*it)) + return false; return true; } else if(src.id()==ID_if) { const if_exprt &if_expr=to_if_expr(src); - if(!propagate(if_expr.true_case())) return false; - if(!propagate(if_expr.false_case())) return false; + if(!propagate(if_expr.true_case())) + return false; + if(!propagate(if_expr.false_case())) + return false; return true; } else if(src.id()==ID_array_of) @@ -173,7 +179,8 @@ inline static typet c_sizeof_type_rec(const exprt &expr) forall_operands(it, expr) { typet t=c_sizeof_type_rec(*it); - if(t.is_not_nil()) return t; + if(t.is_not_nil()) + return t; } } @@ -227,7 +234,8 @@ void path_symext::symex_malloc( mp_integer elements=alloc_size/elem_size; if(elements*elem_size==alloc_size) - object_type=array_typet(tmp_type, from_integer(elements, tmp_size.type())); + object_type= + array_typet(tmp_type, from_integer(elements, tmp_size.type())); } } } @@ -252,8 +260,6 @@ void path_symext::symex_malloc( size_symbol.type=tmp_size.type(); size_symbol.mode=ID_C; - //state.var_map(size_symbol.name, suffix, size_symbol.type); - assign(state, size_symbol.symbol_expr(), size); @@ -265,15 +271,14 @@ void path_symext::symex_malloc( // value symbolt value_symbol; - value_symbol.base_name="dynamic_object"+std::to_string(state.var_map.dynamic_count); + value_symbol.base_name= + "dynamic_object"+std::to_string(state.var_map.dynamic_count); value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name); value_symbol.is_lvalue=true; value_symbol.type=object_type; value_symbol.type.set("#dynamic", true); value_symbol.mode=ID_C; - //state.var_map(value_symbol.name, suffix, value_symbol.type); - address_of_exprt rhs; if(object_type.id()==ID_array) @@ -347,7 +352,7 @@ void path_symext::symex_va_arg_next( throw "va_arg_next expected to have one operand"; if(lhs.is_nil()) - return;// ignore + return; // ignore exprt tmp=state.read(code.op0()); // constant prop on va_arg parameter @@ -396,7 +401,7 @@ void path_symext::symex_va_arg_next( assign(state, lhs, rhs); } - + /*******************************************************************\ Function: path_symext::assign_rec @@ -415,11 +420,11 @@ void path_symext::assign_rec( const exprt &ssa_lhs, const exprt &ssa_rhs) { - //const typet &ssa_lhs_type=state.var_map.ns.follow(ssa_lhs.type()); + // const typet &ssa_lhs_type=state.var_map.ns.follow(ssa_lhs.type()); #ifdef DEBUG std::cout << "assign_rec: " << ssa_lhs.pretty() << std::endl; - //std::cout << "ssa_lhs_type: " << ssa_lhs_type.id() << std::endl; + // std::cout << "ssa_lhs_type: " << ssa_lhs_type.id() << std::endl; #endif if(ssa_lhs.id()==ID_symbol) @@ -476,7 +481,8 @@ void path_symext::assign_rec( state.record_step(); stept &step=*state.history; - if(!guard.empty()) step.guard=conjunction(guard); + if(!guard.empty()) + step.guard=conjunction(guard); step.full_lhs=ssa_lhs; step.ssa_lhs=new_lhs; step.ssa_rhs=ssa_rhs; @@ -609,7 +615,8 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(member_exprt(ssa_rhs, components[i].get_name(), components[i].type()), + simplify_expr( + member_exprt(ssa_rhs, components[i].get_name(), components[i].type()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -631,7 +638,10 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(index_exprt(ssa_rhs, from_integer(i, index_type()), array_type.subtype()), + simplify_expr( + index_exprt( + ssa_rhs, + from_integer(i, index_type()), array_type.subtype()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -648,7 +658,10 @@ void path_symext::assign_rec( { exprt new_rhs= ssa_rhs.is_nil()?ssa_rhs: - simplify_expr(index_exprt(ssa_rhs, from_integer(i, index_type()), vector_type.subtype()), + simplify_expr( + index_exprt( + ssa_rhs, + from_integer(i, index_type()), vector_type.subtype()), state.var_map.ns); assign_rec(state, guard, operands[i], new_rhs); } @@ -700,7 +713,8 @@ void path_symext::function_call_rec( state.locs.function_map.find(function_identifier); if(f_it==state.locs.function_map.end()) - throw "failed to find `"+id2string(function_identifier)+"' in function_map"; + throw + "failed to find `"+id2string(function_identifier)+"' in function_map"; const locst::function_entryt &function_entry=f_it->second; @@ -720,7 +734,8 @@ void path_symext::function_call_rec( } // push a frame on the call stack - path_symex_statet::threadt &thread=state.threads[state.get_current_thread()]; + path_symex_statet::threadt &thread= + state.threads[state.get_current_thread()]; thread.call_stack.push_back(path_symex_statet::framet()); thread.call_stack.back().current_function=function_identifier; thread.call_stack.back().return_location=thread.pc.next_loc(); @@ -730,7 +745,8 @@ void path_symext::function_call_rec( #if 0 for(loc_reft l=function_entry_point; ; ++l) { - if(locs[l].target->is_end_function()) break; + if(locs[l].target->is_end_function()) + break; if(locs[l].target->is_decl()) { // make sure we have the local in the var_map @@ -754,7 +770,7 @@ void path_symext::function_call_rec( const code_typet::parameterst &function_parameters=code_type.parameters(); const exprt::operandst &call_arguments=call.arguments(); - + // keep track when va arguments begin. std::size_t va_args_start_index=0; @@ -838,7 +854,8 @@ void path_symext::function_call_rec( path_symex_statet &false_state=further_states.back(); false_state.record_step(); false_state.history->guard=not_exprt(guard); - function_call_rec(further_states.back(), call, if_expr.false_case(), further_states); + function_call_rec( + further_states.back(), call, if_expr.false_case(), further_states); } // do the true-case in 'state' @@ -851,9 +868,11 @@ void path_symext::function_call_rec( else if(function.id()==ID_typecast) { // ignore - function_call_rec(state, call, to_typecast_expr(function).op(), further_states); + function_call_rec( + state, call, to_typecast_expr(function).op(), further_states); } else + // NOLINTNEXTLINE(readability/throw) throw "TODO: function_call "+function.id_string(); } @@ -1087,7 +1106,8 @@ void path_symext::operator()( // ordering of the following matters due to vector instability path_symex_statet::threadt &new_thread=state.add_thread(); - path_symex_statet::threadt &old_thread=state.threads[state.get_current_thread()]; + path_symex_statet::threadt &old_thread= + state.threads[state.get_current_thread()]; new_thread.pc=loc.branch_target; new_thread.local_vars=old_thread.local_vars; } @@ -1110,7 +1130,7 @@ void path_symext::operator()( case THROW: state.record_step(); - throw "THROW not yet implemented"; + throw "THROW not yet implemented"; // NOLINT(readability/throw) case ASSUME: state.record_step(); @@ -1149,7 +1169,7 @@ void path_symext::operator()( case ATOMIC_END: if(!state.inside_atomic_section) - throw "ATOMIC_END unmatched"; + throw "ATOMIC_END unmatched"; // NOLINT(readability/throw) state.record_step(); state.next_pc(); @@ -1163,7 +1183,8 @@ void path_symext::operator()( case FUNCTION_CALL: state.record_step(); - function_call(state, to_code_function_call(instruction.code), further_states); + function_call( + state, to_code_function_call(instruction.code), further_states); break; case OTHER: diff --git a/src/path-symex/path_symex.h b/src/path-symex/path_symex.h index a37777d5f22..731ea87608e 100644 --- a/src/path-symex/path_symex.h +++ b/src/path-symex/path_symex.h @@ -6,6 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ +// NOLINT(build/header_guard) as this file is also symlinked #ifndef CPROVER_PATH_SYMEX_PATH_SYMEX_H #define CPROVER_PATH_SYMEX_PATH_SYMEX_H diff --git a/src/path-symex/path_symex_class.h b/src/path-symex/path_symex_class.h index 2243e95518b..4eec3d4ff4c 100644 --- a/src/path-symex/path_symex_class.h +++ b/src/path-symex/path_symex_class.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com class path_symext { public: - inline path_symext() + path_symext() { } @@ -80,7 +80,7 @@ class path_symext const exprt &lhs, const exprt &rhs); - inline void assign( + void assign( path_symex_statet &state, const code_assignt &assignment) { diff --git a/src/path-symex/path_symex_history.h b/src/path-symex/path_symex_history.h index 95d10771091..3847138dc71 100644 --- a/src/path-symex/path_symex_history.h +++ b/src/path-symex/path_symex_history.h @@ -24,34 +24,34 @@ class path_symex_stept; class path_symex_step_reft { public: - explicit inline path_symex_step_reft( + explicit path_symex_step_reft( class path_symex_historyt &_history): index(std::numeric_limits::max()), history(&_history) { } - inline path_symex_step_reft(): + path_symex_step_reft(): index(std::numeric_limits::max()), history(0) { } - inline bool is_nil() const + bool is_nil() const { return index==std::numeric_limits::max(); } - inline path_symex_historyt &get_history() const + path_symex_historyt &get_history() const { assert(history!=0); return *history; } // pre-decrement - inline path_symex_step_reft &operator--(); + path_symex_step_reft &operator--(); - inline path_symex_stept &operator*() const { return get(); } - inline path_symex_stept *operator->() const { return &get(); } + path_symex_stept &operator*() const { return get(); } + path_symex_stept *operator->() const { return &get(); } void generate_successor(); @@ -63,7 +63,7 @@ class path_symex_step_reft std::size_t index; class path_symex_historyt *history; - inline path_symex_stept &get() const; + path_symex_stept &get() const; }; class decision_proceduret; @@ -72,21 +72,22 @@ class decision_proceduret; class path_symex_stept { public: - enum kindt { + enum kindt + { NON_BRANCH, BRANCH_TAKEN, BRANCH_NOT_TAKEN } branch; - inline bool is_branch_taken() const + bool is_branch_taken() const { return branch==BRANCH_TAKEN; } - inline bool is_branch_not_taken() const + bool is_branch_not_taken() const { return branch==BRANCH_NOT_TAKEN; } - inline bool is_branch() const + bool is_branch() const { return branch==BRANCH_TAKEN || branch==BRANCH_NOT_TAKEN; } @@ -121,7 +122,7 @@ class path_symex_stept }; // converts the full history -static inline decision_proceduret &operator << ( +inline decision_proceduret &operator<<( decision_proceduret &dest, path_symex_step_reft src) { @@ -142,7 +143,7 @@ class path_symex_historyt step_containert step_container; // TODO: consider typedefing path_symex_historyt - inline void clear() + void clear() { step_container.clear(); } diff --git a/src/path-symex/path_symex_state.cpp b/src/path-symex/path_symex_state.cpp index 4f422172374..2ce47fedc0f 100644 --- a/src/path-symex/path_symex_state.cpp +++ b/src/path-symex/path_symex_state.cpp @@ -18,7 +18,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "path_symex_state.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -135,7 +135,8 @@ path_symex_statet::var_statet &path_symex_statet::get_var_state( var_valt &var_val= var_info.is_shared()?shared_vars:threads[current_thread].local_vars; - if(var_val.size()<=var_info.number) var_val.resize(var_info.number+1); + if(var_val.size()<=var_info.number) + var_val.resize(var_info.number+1); return var_val[var_info.number]; } @@ -229,7 +230,8 @@ bool path_symex_statet::check_assertion( exprt assertion=read(instruction.guard); // trivial? - if(assertion.is_true()) return true; // no error + if(assertion.is_true()) + return true; // no error // the path constraint decision_procedure << history; diff --git a/src/path-symex/path_symex_state.h b/src/path-symex/path_symex_state.h index 46d71306618..1ca5a86c76e 100644 --- a/src/path-symex/path_symex_state.h +++ b/src/path-symex/path_symex_state.h @@ -16,7 +16,7 @@ Author: Daniel Kroening, kroening@kroening.com struct path_symex_statet { public: - inline path_symex_statet( + path_symex_statet( var_mapt &_var_map, const locst &_locs, path_symex_historyt &_path_symex_history): @@ -98,24 +98,24 @@ struct path_symex_statet bool inside_atomic_section; - inline unsigned get_current_thread() const + unsigned get_current_thread() const { return current_thread; } - inline void set_current_thread(unsigned _thread) + void set_current_thread(unsigned _thread) { current_thread=_thread; } loc_reft get_pc() const; - inline goto_programt::const_targett get_instruction() const + goto_programt::const_targett get_instruction() const { return locs[get_pc()].target; } - inline bool is_executable() const + bool is_executable() const { return !threads.empty() && threads[current_thread].active; @@ -129,28 +129,28 @@ struct path_symex_statet // various state transformers - inline threadt &add_thread() + threadt &add_thread() { threads.resize(threads.size()+1); return threads.back(); } - inline void disable_current_thread() + void disable_current_thread() { threads[current_thread].active=false; } - inline loc_reft pc() const + loc_reft pc() const { return threads[current_thread].pc; } - inline void next_pc() + void next_pc() { threads[current_thread].pc.increase(); } - inline void set_pc(loc_reft new_pc) + void set_pc(loc_reft new_pc) { threads[current_thread].pc=new_pc; } @@ -160,13 +160,13 @@ struct path_symex_statet void output(const threadt &thread, std::ostream &out) const; // instantiate expressions with propagation - inline exprt read(const exprt &src) + exprt read(const exprt &src) { return read(src, true); } // instantiate without constant propagation - inline exprt read_no_propagate(const exprt &src) + exprt read_no_propagate(const exprt &src) { return read(src, false); } @@ -175,22 +175,22 @@ struct path_symex_statet std::string array_index_as_string(const exprt &) const; - inline unsigned get_no_thread_interleavings() const + unsigned get_no_thread_interleavings() const { return no_thread_interleavings; } - inline unsigned get_depth() const + unsigned get_depth() const { return depth; } - inline unsigned get_no_branches() const + unsigned get_no_branches() const { return no_branches; } - inline bool last_was_branch() const + bool last_was_branch() const { return !history.is_nil() && history->is_branch(); } diff --git a/src/path-symex/path_symex_state_read.cpp b/src/path-symex/path_symex_state_read.cpp index 72fbc683f1c..df3621ee290 100644 --- a/src/path-symex/path_symex_state_read.cpp +++ b/src/path-symex/path_symex_state_read.cpp @@ -13,7 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "path_symex_state.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -35,7 +35,7 @@ Function: path_symex_statet::read exprt path_symex_statet::read(const exprt &src, bool propagate) { #ifdef DEBUG - //std::cout << "path_symex_statet::read " << src.pretty() << std::endl; + // std::cout << "path_symex_statet::read " << src.pretty() << std::endl; #endif // This has three phases! @@ -51,7 +51,7 @@ exprt path_symex_statet::read(const exprt &src, bool propagate) exprt tmp5=simplify_expr(tmp4, var_map.ns); #ifdef DEBUG - //std::cout << " ==> " << tmp.pretty() << std::endl; + // std::cout << " ==> " << tmp.pretty() << std::endl; #endif return tmp5; @@ -240,7 +240,6 @@ exprt path_symex_statet::array_theory(const exprt &src, bool propagate) { // TODO: variable-sized array } - } } @@ -475,7 +474,6 @@ exprt path_symex_statet::read_symbol_member_index( return var_state.ssa_symbol; } - } /*******************************************************************\ @@ -680,8 +678,10 @@ exprt path_symex_statet::instantiate_rec_address( else if(src.id()==ID_if) { if_exprt if_expr=to_if_expr(src); - if_expr.true_case()=instantiate_rec_address(if_expr.true_case(), propagate); - if_expr.false_case()=instantiate_rec_address(if_expr.false_case(), propagate); + if_expr.true_case()= + instantiate_rec_address(if_expr.true_case(), propagate); + if_expr.false_case()= + instantiate_rec_address(if_expr.false_case(), propagate); if_expr.cond()=instantiate_rec(if_expr.cond(), propagate); return if_expr; } diff --git a/src/path-symex/var_map.cpp b/src/path-symex/var_map.cpp index 3eb34238230..8f18b3f9726 100644 --- a/src/path-symex/var_map.cpp +++ b/src/path-symex/var_map.cpp @@ -28,7 +28,7 @@ Function: var_mapt::var_infot::operator() \*******************************************************************/ -var_mapt::var_infot & var_mapt::operator()( +var_mapt::var_infot &var_mapt::operator()( const irep_idt &symbol, const irep_idt &suffix, const typet &type) diff --git a/src/path-symex/var_map.h b/src/path-symex/var_map.h index 38a7b1ee1a9..cb5c7c7d9f5 100644 --- a/src/path-symex/var_map.h +++ b/src/path-symex/var_map.h @@ -27,7 +27,7 @@ class var_mapt { enum { SHARED, THREAD_LOCAL, PROCEDURE_LOCAL } kind; - inline bool is_shared() const + bool is_shared() const { return kind==SHARED; } @@ -57,7 +57,7 @@ class var_mapt return s; } - inline void increment_ssa_counter() + void increment_ssa_counter() { ++ssa_counter; } @@ -73,7 +73,7 @@ class var_mapt const irep_idt &suffix, const typet &type); - inline var_infot &operator[](const irep_idt &full_identifier) + var_infot &operator[](const irep_idt &full_identifier) { return id_map[full_identifier]; } diff --git a/src/pointer-analysis/add_failed_symbols.cpp b/src/pointer-analysis/add_failed_symbols.cpp index f4174e1f121..0a8f757a6d8 100644 --- a/src/pointer-analysis/add_failed_symbols.cpp +++ b/src/pointer-analysis/add_failed_symbols.cpp @@ -43,7 +43,8 @@ Function: add_failed_symbol void add_failed_symbol(symbolt &symbol, symbol_tablet &symbol_table) { - if(!symbol.is_lvalue) return; + if(!symbol.is_lvalue) + return; if(symbol.type.get(ID_C_failed_symbol)!="") return; diff --git a/src/pointer-analysis/dereference.cpp b/src/pointer-analysis/dereference.cpp index a256a5e39d9..b21313f85bf 100644 --- a/src/pointer-analysis/dereference.cpp +++ b/src/pointer-analysis/dereference.cpp @@ -6,7 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -385,7 +385,8 @@ bool dereferencet::type_compatible( // bit vectors of same size are ok if((object_type.id()==ID_signedbv || object_type.id()==ID_unsignedbv) && - (dereference_type.id()==ID_signedbv || dereference_type.id()==ID_unsignedbv)) + (dereference_type.id()==ID_signedbv || + dereference_type.id()==ID_unsignedbv)) { return object_type.get(ID_width)==dereference_type.get(ID_width); } diff --git a/src/pointer-analysis/dereference.h b/src/pointer-analysis/dereference.h index c52ac9b0f05..5036f702cde 100644 --- a/src/pointer-analysis/dereference.h +++ b/src/pointer-analysis/dereference.h @@ -82,7 +82,7 @@ class dereferencet const typet &type); }; -static inline exprt dereference(const exprt &pointer, const namespacet &ns) +inline exprt dereference(const exprt &pointer, const namespacet &ns) { dereferencet dereference_object(ns); return dereference_object(pointer); diff --git a/src/pointer-analysis/goto_program_dereference.cpp b/src/pointer-analysis/goto_program_dereference.cpp index 759aac08cf7..2ccce3f7a47 100644 --- a/src/pointer-analysis/goto_program_dereference.cpp +++ b/src/pointer-analysis/goto_program_dereference.cpp @@ -41,7 +41,8 @@ bool goto_program_dereferencet::has_failed_symbol( const irep_idt &failed_symbol= ptr_symbol.type.get("#failed_symbol"); - if(failed_symbol==irep_idt()) return false; + if(failed_symbol==irep_idt()) + return false; return !ns.lookup(failed_symbol, symbol); } @@ -416,10 +417,13 @@ void goto_program_dereferencet::dereference_instruction( code_function_callt &function_call=to_code_function_call(to_code(i.code)); if(function_call.lhs().is_not_nil()) - dereference_expr(function_call.lhs(), checks_only, value_set_dereferencet::WRITE); + dereference_expr( + function_call.lhs(), checks_only, value_set_dereferencet::WRITE); - dereference_expr(function_call.function(), checks_only, value_set_dereferencet::READ); - dereference_expr(function_call.op2(), checks_only, value_set_dereferencet::READ); + dereference_expr( + function_call.function(), checks_only, value_set_dereferencet::READ); + dereference_expr( + function_call.op2(), checks_only, value_set_dereferencet::READ); } else if(i.is_return()) { diff --git a/src/pointer-analysis/goto_program_dereference.h b/src/pointer-analysis/goto_program_dereference.h index ef7feac9a11..33904035fdc 100644 --- a/src/pointer-analysis/goto_program_dereference.h +++ b/src/pointer-analysis/goto_program_dereference.h @@ -76,8 +76,12 @@ class goto_program_dereferencet:protected dereference_callbackt bool checks_only=false); protected: - void dereference_rec(exprt &expr, guardt &guard, const value_set_dereferencet::modet mode); - void dereference_expr(exprt &expr, const bool checks_only, const value_set_dereferencet::modet mode); + void dereference_rec( + exprt &expr, guardt &guard, const value_set_dereferencet::modet mode); + void dereference_expr( + exprt &expr, + const bool checks_only, + const value_set_dereferencet::modet mode); const std::set *valid_local_variables; source_locationt dereference_location; diff --git a/src/pointer-analysis/show_value_sets.cpp b/src/pointer-analysis/show_value_sets.cpp index 7d73bc70dae..c0b87599ca4 100644 --- a/src/pointer-analysis/show_value_sets.cpp +++ b/src/pointer-analysis/show_value_sets.cpp @@ -44,7 +44,9 @@ void show_value_sets( value_set_analysis.output(goto_functions, std::cout); break; - default:; + default: + { + } } } @@ -79,6 +81,8 @@ void show_value_sets( value_set_analysis.output(goto_program, std::cout); break; - default:; + default: + { + } } } diff --git a/src/pointer-analysis/value_set.cpp b/src/pointer-analysis/value_set.cpp index 4a22fc40acb..629a25509d6 100644 --- a/src/pointer-analysis/value_set.cpp +++ b/src/pointer-analysis/value_set.cpp @@ -219,7 +219,8 @@ void value_sett::output( if(next!=object_map.end()) { out << ", "; - if(width>=40) out << "\n "; + if(width>=40) + out << "\n "; } } @@ -429,7 +430,8 @@ void value_sett::get_value_set( dest.push_back(to_expr(it)); #if 0 - for(value_setst::valuest::const_iterator it=dest.begin(); it!=dest.end(); it++) + for(value_setst::valuest::const_iterator it=dest.begin(); + it!=dest.end(); it++) std::cout << "GET_VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif } @@ -453,7 +455,8 @@ void value_sett::get_value_set( bool is_simplified) const { exprt tmp(expr); - if(!is_simplified) simplify(tmp, ns); + if(!is_simplified) + simplify(tmp, ns); get_value_set_rec(tmp, dest, "", tmp.type(), ns); } @@ -716,7 +719,8 @@ void value_sett::get_value_set_rec( { i*=pointer_offset_size(ptr_operand.type().subtype(), ns); - if(expr.id()==ID_minus) i.negate(); + if(expr.id()==ID_minus) + i.negate(); } get_value_set_rec( @@ -795,7 +799,8 @@ void value_sett::get_value_set_rec( static_cast(expr.find("#type")); dynamic_object_exprt dynamic_object(dynamic_type); - dynamic_object.instance()=from_integer(location_number, typet(ID_natural)); + dynamic_object.instance()= + from_integer(location_number, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert(dest, dynamic_object, 0); @@ -807,7 +812,8 @@ void value_sett::get_value_set_rec( assert(expr_type.id()==ID_pointer); dynamic_object_exprt dynamic_object(expr_type.subtype()); - dynamic_object.instance()=from_integer(location_number, typet(ID_natural)); + dynamic_object.instance()= + from_integer(location_number, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert(dest, dynamic_object, 0); @@ -1074,7 +1080,8 @@ void value_sett::get_reference_set_rec( const namespacet &ns) const { #if 0 - std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) << std::endl; + std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) + << std::endl; #endif if(expr.id()==ID_symbol || @@ -1098,7 +1105,8 @@ void value_sett::get_reference_set_rec( get_value_set_rec(expr.op0(), dest, "", expr.op0().type(), ns); #if 0 - for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(expr_sett::const_iterator it=value_set.begin(); + it!=value_set.end(); it++) std::cout << "VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif @@ -1193,7 +1201,7 @@ void value_sett::get_reference_set_rec( // We cannot introduce a cast from scalar to non-scalar, // thus, we can only adjust the types of structs and unions. - const typet& final_object_type = ns.follow(object.type()); + const typet &final_object_type = ns.follow(object.type()); if(final_object_type.id()==ID_struct || final_object_type.id()==ID_union) @@ -1301,7 +1309,12 @@ void value_sett::assign( if(rhs.id()==ID_unknown || rhs.id()==ID_invalid) { - assign(lhs_index, exprt(rhs.id(), type.subtype()), ns, is_simplified, add_to_sets); + assign( + lhs_index, + exprt(rhs.id(), type.subtype()), + ns, + is_simplified, + add_to_sets); } else { @@ -1547,7 +1560,8 @@ void value_sett::assign_rec( type.id()==ID_incomplete_struct || type.id()==ID_incomplete_union); - assign_rec(lhs.op0(), values_rhs, "."+component_name+suffix, ns, add_to_sets); + assign_rec( + lhs.op0(), values_rhs, "."+component_name+suffix, ns, add_to_sets); } else if(lhs.id()=="valid_object" || lhs.id()=="dynamic_size" || @@ -1632,7 +1646,8 @@ void value_sett::do_function_call( it++) { const irep_idt &identifier=it->get_identifier(); - if(identifier=="") continue; + if(identifier=="") + continue; const exprt v_expr= symbol_exprt("value_set::dummy_arg_"+std::to_string(i), it->type()); @@ -1661,7 +1676,8 @@ void value_sett::do_end_function( const exprt &lhs, const namespacet &ns) { - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; symbol_exprt rhs("value_set::return_value", lhs.type()); @@ -1803,11 +1819,11 @@ void value_sett::apply_code( } else if(statement==ID_input || statement==ID_output) { - // doesn't do anything + // doesn't do anything } else { - //std::cerr << code.pretty() << std::endl; + // std::cerr << code.pretty() << std::endl; throw "value_sett: unexpected statement: "+id2string(statement); } } @@ -1847,7 +1863,8 @@ void value_sett::guard( assert(expr.operands().size()==1); dynamic_object_exprt dynamic_object(unsigned_char_type()); - //dynamic_object.instance()=from_integer(location_number, typet(ID_natural)); + // dynamic_object.instance()= + // from_integer(location_number, typet(ID_natural)); dynamic_object.valid()=true_exprt(); address_of_exprt address_of(dynamic_object); diff --git a/src/pointer-analysis/value_set.h b/src/pointer-analysis/value_set.h index 70b7f15d698..486b55e998b 100644 --- a/src/pointer-analysis/value_set.h +++ b/src/pointer-analysis/value_set.h @@ -59,7 +59,7 @@ class value_sett { public: object_map_dt() {} - const static object_map_dt blank; + static const object_map_dt blank; }; exprt to_expr(object_map_dt::const_iterator it) const; @@ -81,7 +81,10 @@ class value_sett return insert(dest, object_numbering.number(src), objectt()); } - bool insert(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert(dest, object_numbering.number(src), objectt(offset)); } diff --git a/src/pointer-analysis/value_set_analysis.cpp b/src/pointer-analysis/value_set_analysis.cpp index 1f4254c654d..4e98c10aee4 100644 --- a/src/pointer-analysis/value_set_analysis.cpp +++ b/src/pointer-analysis/value_set_analysis.cpp @@ -74,7 +74,8 @@ void value_set_analysist::convert( { const source_locationt &location=i_it->source_location; - if(location==previous_location) continue; + if(location==previous_location) + continue; if(location.is_nil() || location.get_file()==irep_idt()) continue; diff --git a/src/pointer-analysis/value_set_analysis.h b/src/pointer-analysis/value_set_analysis.h index 4b843e6c4d1..3437b34af2c 100644 --- a/src/pointer-analysis/value_set_analysis.h +++ b/src/pointer-analysis/value_set_analysis.h @@ -22,10 +22,10 @@ class value_set_analysist: public static_analysist { public: - value_set_analysist(const namespacet &_ns): - static_analysist(_ns) - { - } + explicit value_set_analysist(const namespacet &_ns): + static_analysist(_ns) + { + } typedef static_analysist baset; @@ -33,16 +33,6 @@ class value_set_analysist: virtual void initialize(const goto_programt &goto_program); virtual void initialize(const goto_functionst &goto_functions); - friend void convert( - const goto_functionst &goto_functions, - const value_set_analysist &value_set_analysis, - xmlt &dest); - - friend void convert( - const goto_programt &goto_program, - const value_set_analysist &value_set_analysis, - xmlt &dest); - void convert( const goto_programt &goto_program, const irep_idt &identifier, @@ -59,4 +49,14 @@ class value_set_analysist: } }; +void convert( + const goto_functionst &goto_functions, + const value_set_analysist &value_set_analysis, + xmlt &dest); + +void convert( + const goto_programt &goto_program, + const value_set_analysist &value_set_analysis, + xmlt &dest); + #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_ANALYSIS_H diff --git a/src/pointer-analysis/value_set_analysis_fi.cpp b/src/pointer-analysis/value_set_analysis_fi.cpp index cba409fa8f5..2408f9816ed 100644 --- a/src/pointer-analysis/value_set_analysis_fi.cpp +++ b/src/pointer-analysis/value_set_analysis_fi.cpp @@ -269,7 +269,8 @@ bool value_set_analysis_fit::check_type(const typet &type) { if(type.id()==ID_pointer) { - switch(track_options) { + switch(track_options) + { case TRACK_ALL_POINTERS: { return true; break; } case TRACK_FUNCTION_POINTERS: @@ -277,7 +278,7 @@ bool value_set_analysis_fit::check_type(const typet &type) if(type.id()==ID_pointer) { const typet *t = &type; - while (t->id()==ID_pointer) t = &(t->subtype()); + while(t->id()==ID_pointer) t = &(t->subtype()); return (t->id()==ID_code); } @@ -301,7 +302,8 @@ bool value_set_analysis_fit::check_type(const typet &type) it!=components.end(); it++) { - if(check_type(it->type())) return true; + if(check_type(it->type())) + return true; } } else if(type.id()==ID_array) diff --git a/src/pointer-analysis/value_set_analysis_fi.h b/src/pointer-analysis/value_set_analysis_fi.h index edc14075976..e1c8f320cab 100644 --- a/src/pointer-analysis/value_set_analysis_fi.h +++ b/src/pointer-analysis/value_set_analysis_fi.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "value_set_domain_fi.h" #include "value_sets.h" -class value_set_analysis_fit : +class value_set_analysis_fit: public value_setst, public flow_insensitive_analysist { diff --git a/src/pointer-analysis/value_set_analysis_fivr.cpp b/src/pointer-analysis/value_set_analysis_fivr.cpp index 3ed0538bb1c..fe428100a72 100644 --- a/src/pointer-analysis/value_set_analysis_fivr.cpp +++ b/src/pointer-analysis/value_set_analysis_fivr.cpp @@ -269,7 +269,8 @@ bool value_set_analysis_fivrt::check_type(const typet &type) { if(type.id()==ID_pointer) { - switch(track_options) { + switch(track_options) + { case TRACK_ALL_POINTERS: { return true; break; } case TRACK_FUNCTION_POINTERS: @@ -277,7 +278,7 @@ bool value_set_analysis_fivrt::check_type(const typet &type) if(type.id()==ID_pointer) { const typet *t = &type; - while (t->id()==ID_pointer) t = &(t->subtype()); + while(t->id()==ID_pointer) t = &(t->subtype()); return (t->id()==ID_code); } @@ -301,7 +302,8 @@ bool value_set_analysis_fivrt::check_type(const typet &type) it!=components.end(); it++) { - if(check_type(it->type())) return true; + if(check_type(it->type())) + return true; } } else if(type.id()==ID_array) diff --git a/src/pointer-analysis/value_set_analysis_fivr.h b/src/pointer-analysis/value_set_analysis_fivr.h index 543ced1eac8..e6e30cfb456 100644 --- a/src/pointer-analysis/value_set_analysis_fivr.h +++ b/src/pointer-analysis/value_set_analysis_fivr.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "value_set_domain_fivr.h" #include "value_sets.h" -class value_set_analysis_fivrt : +class value_set_analysis_fivrt: public value_setst, public flow_insensitive_analysist { diff --git a/src/pointer-analysis/value_set_analysis_fivrns.cpp b/src/pointer-analysis/value_set_analysis_fivrns.cpp index 4fbe598ae13..d2f9e966437 100644 --- a/src/pointer-analysis/value_set_analysis_fivrns.cpp +++ b/src/pointer-analysis/value_set_analysis_fivrns.cpp @@ -269,7 +269,8 @@ bool value_set_analysis_fivrnst::check_type(const typet &type) { if(type.id()==ID_pointer) { - switch(track_options) { + switch(track_options) + { case TRACK_ALL_POINTERS: { return true; break; } case TRACK_FUNCTION_POINTERS: @@ -277,7 +278,7 @@ bool value_set_analysis_fivrnst::check_type(const typet &type) if(type.id()==ID_pointer) { const typet *t = &type; - while (t->id()==ID_pointer) t = &(t->subtype()); + while(t->id()==ID_pointer) t = &(t->subtype()); return (t->id()==ID_code); } @@ -301,7 +302,8 @@ bool value_set_analysis_fivrnst::check_type(const typet &type) it!=components.end(); it++) { - if(check_type(it->type())) return true; + if(check_type(it->type())) + return true; } } else if(type.id()==ID_array) diff --git a/src/pointer-analysis/value_set_analysis_fivrns.h b/src/pointer-analysis/value_set_analysis_fivrns.h index 8cf8e23f93e..b4d45524db2 100644 --- a/src/pointer-analysis/value_set_analysis_fivrns.h +++ b/src/pointer-analysis/value_set_analysis_fivrns.h @@ -15,7 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com, #include "value_set_domain_fivrns.h" #include "value_sets.h" -class value_set_analysis_fivrnst : +class value_set_analysis_fivrnst: public value_setst, public flow_insensitive_analysist { diff --git a/src/pointer-analysis/value_set_dereference.cpp b/src/pointer-analysis/value_set_dereference.cpp index c1913567448..98e6ab2cb2a 100644 --- a/src/pointer-analysis/value_set_dereference.cpp +++ b/src/pointer-analysis/value_set_dereference.cpp @@ -6,11 +6,10 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include -#include #endif #include @@ -175,7 +174,8 @@ exprt value_set_dereferencet::dereference( it=values.begin(); it!=values.end(); it++) - if(it->value.is_nil()) may_fail=true; + if(it->value.is_nil()) + may_fail=true; } if(may_fail) @@ -386,7 +386,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( } else if(root_object.id()==ID_dynamic_object) { - //const dynamic_object_exprt &dynamic_object= + // const dynamic_object_exprt &dynamic_object= // to_dynamic_object_expr(root_object); // the object produced by malloc @@ -407,7 +407,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( if(options.get_bool_option("pointer-check")) { - //if(!dynamic_object.valid().is_true()) + // if(!dynamic_object.valid().is_true()) { // check if it is still alive guardt tmp_guard(guard); @@ -466,7 +466,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( result.value=nil_exprt(); return result; } - + const symbolt &memory_symbol=ns.lookup(CPROVER_PREFIX "memory"); exprt symbol_expr=symbol_exprt(memory_symbol.name, memory_symbol.type); @@ -542,7 +542,9 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( result.value.make_typecast(dereference_type); } else if(root_object_type.id()==ID_array && - dereference_type_compare(root_object_type.subtype(), dereference_type)) + dereference_type_compare( + root_object_type.subtype(), + dereference_type)) { // We have an array with a subtype that matches // the dereferencing type. @@ -588,8 +590,11 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( if(ns.follow(result.value.type())!=ns.follow(dereference_type)) result.value.make_typecast(dereference_type); } - else if(get_subexpression_at_offset(root_object_subexpression, o.offset(), - dereference_type, ns)) + else if(get_subexpression_at_offset( + root_object_subexpression, + o.offset(), + dereference_type, + ns)) { // Successfully found a member, array index, or combination thereof // that matches the desired type and offset: diff --git a/src/pointer-analysis/value_set_domain.cpp b/src/pointer-analysis/value_set_domain.cpp index b05c0da9479..74656d23fe6 100644 --- a/src/pointer-analysis/value_set_domain.cpp +++ b/src/pointer-analysis/value_set_domain.cpp @@ -57,7 +57,9 @@ void value_set_domaint::transform( } break; - default:; - // do nothing + default: + { + // do nothing + } } } diff --git a/src/pointer-analysis/value_set_domain.h b/src/pointer-analysis/value_set_domain.h index 088157227f6..df028b0d4e1 100644 --- a/src/pointer-analysis/value_set_domain.h +++ b/src/pointer-analysis/value_set_domain.h @@ -21,7 +21,7 @@ class value_set_domaint:public domain_baset // overloading - inline bool merge(const value_set_domaint &other, locationt to) + bool merge(const value_set_domaint &other, locationt to) { return value_set.make_union(other.value_set); } @@ -53,7 +53,6 @@ class value_set_domaint:public domain_baset { value_set.get_reference_set(expr, dest, ns); } - }; #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DOMAIN_H diff --git a/src/pointer-analysis/value_set_domain_fi.cpp b/src/pointer-analysis/value_set_domain_fi.cpp index 0a4d7412f3b..a5d0668fe90 100644 --- a/src/pointer-analysis/value_set_domain_fi.cpp +++ b/src/pointer-analysis/value_set_domain_fi.cpp @@ -62,8 +62,10 @@ bool value_set_domain_fit::transform( } break; - default:; - // do nothing + default: + { + // do nothing + } } return (value_set.changed); diff --git a/src/pointer-analysis/value_set_domain_fi.h b/src/pointer-analysis/value_set_domain_fi.h index a78bad49488..ebcb9008f4c 100644 --- a/src/pointer-analysis/value_set_domain_fi.h +++ b/src/pointer-analysis/value_set_domain_fi.h @@ -52,11 +52,10 @@ class value_set_domain_fit:public flow_insensitive_abstract_domain_baset value_set.get_reference_set(expr, expr_set, ns); } - virtual void clear( void ) + virtual void clear(void) { value_set.clear(); } - }; #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DOMAIN_FI_H diff --git a/src/pointer-analysis/value_set_domain_fivr.cpp b/src/pointer-analysis/value_set_domain_fivr.cpp index 923acd64c92..51e63dfb91f 100644 --- a/src/pointer-analysis/value_set_domain_fivr.cpp +++ b/src/pointer-analysis/value_set_domain_fivr.cpp @@ -58,7 +58,9 @@ bool value_set_domain_fivrt::transform( break; } - default:; + default: + { + } } return value_set.handover(); diff --git a/src/pointer-analysis/value_set_domain_fivr.h b/src/pointer-analysis/value_set_domain_fivr.h index 21a7087402a..e1f82153191 100644 --- a/src/pointer-analysis/value_set_domain_fivr.h +++ b/src/pointer-analysis/value_set_domain_fivr.h @@ -47,11 +47,10 @@ class value_set_domain_fivrt:public flow_insensitive_abstract_domain_baset value_set.get_reference_set(expr, expr_set, ns); } - virtual void clear( void ) + virtual void clear(void) { value_set.clear(); } - }; #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DOMAIN_FIVR_H diff --git a/src/pointer-analysis/value_set_domain_fivrns.cpp b/src/pointer-analysis/value_set_domain_fivrns.cpp index 56ad4282197..8c8ef147dfa 100644 --- a/src/pointer-analysis/value_set_domain_fivrns.cpp +++ b/src/pointer-analysis/value_set_domain_fivrns.cpp @@ -58,7 +58,9 @@ bool value_set_domain_fivrnst::transform( break; } - default:; + default: + { + } } return value_set.handover(); diff --git a/src/pointer-analysis/value_set_domain_fivrns.h b/src/pointer-analysis/value_set_domain_fivrns.h index 70ddedb0818..62d4aeedc3e 100644 --- a/src/pointer-analysis/value_set_domain_fivrns.h +++ b/src/pointer-analysis/value_set_domain_fivrns.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "value_set_fivrns.h" -class value_set_domain_fivrnst : +class value_set_domain_fivrnst: public flow_insensitive_abstract_domain_baset { public: @@ -48,11 +48,10 @@ class value_set_domain_fivrnst : value_set.get_reference_set(expr, expr_set, ns); } - virtual void clear( void ) + virtual void clear(void) { value_set.clear(); } - }; #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DOMAIN_FIVRNS_H diff --git a/src/pointer-analysis/value_set_fi.cpp b/src/pointer-analysis/value_set_fi.cpp index ed1de7872ac..125a2cae58a 100644 --- a/src/pointer-analysis/value_set_fi.cpp +++ b/src/pointer-analysis/value_set_fi.cpp @@ -26,7 +26,7 @@ const value_set_fit::object_map_dt value_set_fit::object_map_dt::blank; object_numberingt value_set_fit::object_numbering; hash_numbering value_set_fit::function_numbering; -static std::string alloc_adapter_prefix = "alloc_adaptor::"; +static const char *alloc_adapter_prefix="alloc_adaptor::"; #define forall_objects(it, map) \ for(object_map_dt::const_iterator (it) = (map).begin(); \ @@ -100,7 +100,7 @@ void value_set_fit::output( result="<"; result+=from_expr(ns, identifier, o); result+=", *, "; // offset unknown - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; else result+=from_type(ns, identifier, o.type()); @@ -117,7 +117,7 @@ void value_set_fit::output( result+=", "; - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; else result+=from_type(ns, identifier, o.type()); @@ -135,7 +135,8 @@ void value_set_fit::output( if(next!=object_map.read().end()) { out << ", "; - if(width>=40) out << "\n "; + if(width>=40) + out << "\n "; } } @@ -201,18 +202,18 @@ void value_set_fit::flatten_rec( forall_objects(it, e.object_map.read()) { - const exprt& o=object_numbering[it->first]; + const exprt &o=object_numbering[it->first]; - if (o.type().id()=="#REF#") + if(o.type().id()=="#REF#") { - if (seen.find(o.get(ID_identifier))!=seen.end()) + if(seen.find(o.get(ID_identifier))!=seen.end()) { generalize_index = true; continue; } valuest::const_iterator fi = values.find(o.get(ID_identifier)); - if (fi==values.end()) + if(fi==values.end()) { // this is some static object, keep it in. exprt se(ID_symbol, o.type().subtype()); @@ -240,13 +241,12 @@ void value_set_fit::flatten_rec( forall_objects(oit, temp.read()) insert(dest, oit); } - } else insert(dest, it); } - if (generalize_index) // this means we had recursive symbols in there + if(generalize_index) // this means we had recursive symbols in there { Forall_objects(it, dest.write()) it->second.offset_is_set = false; @@ -388,14 +388,14 @@ void value_set_fit::get_value_set( forall_objects(it, object_map.read()) { const exprt &object=object_numbering[it->first]; - if (object.type().id()=="#REF#") + if(object.type().id()=="#REF#") { assert(object.id()==ID_symbol); const irep_idt &ident = object.get(ID_identifier); valuest::const_iterator v_it = values.find(ident); - if (v_it!=values.end()) + if(v_it!=values.end()) { object_mapt temp; flatten(v_it->second, temp); @@ -482,7 +482,8 @@ void value_set_fit::get_value_set_rec( gvs_recursion_sett &recursion_set) const { #if 0 - std::cout << "GET_VALUE_SET_REC EXPR: " << from_expr(ns, "", expr) << std::endl; + std::cout << "GET_VALUE_SET_REC EXPR: " << from_expr(ns, "", expr) + << std::endl; std::cout << "GET_VALUE_SET_REC SUFFIX: " << suffix << std::endl; std::cout << std::endl; #endif @@ -726,8 +727,9 @@ void value_set_fit::get_value_set_rec( dynamic_object_exprt dynamic_object(dynamic_type); // let's make up a `unique' number for this object... - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert(dest, dynamic_object, 0); @@ -740,8 +742,9 @@ void value_set_fit::get_value_set_rec( assert(expr.type().id()==ID_pointer); dynamic_object_exprt dynamic_object(expr.type().subtype()); - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert(dest, dynamic_object, 0); @@ -841,13 +844,13 @@ void value_set_fit::get_reference_set( forall_objects(it, object_map.read()) { - const exprt& expr = object_numbering[it->first]; + const exprt &expr = object_numbering[it->first]; - if (expr.type().id()=="#REF#") + if(expr.type().id()=="#REF#") { - const irep_idt& ident = expr.get(ID_identifier); + const irep_idt &ident = expr.get(ID_identifier); valuest::const_iterator vit = values.find(ident); - if (vit==values.end()) + if(vit==values.end()) { // Assume the variable never was assigned, // so assume it's reference set is unknown. @@ -922,7 +925,8 @@ void value_set_fit::get_reference_set_sharing_rec( const namespacet &ns) const { #if 0 - std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) << std::endl; + std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) + << std::endl; #endif if(expr.type().id()=="#REF#") @@ -960,12 +964,12 @@ void value_set_fit::get_reference_set_sharing_rec( forall_objects(it, temp.read()) { const exprt &obj = object_numbering[it->first]; - if (obj.type().id()=="#REF#") + if(obj.type().id()=="#REF#") { const irep_idt &ident = obj.get(ID_identifier); valuest::const_iterator v_it = values.find(ident); - if (v_it!=values.end()) + if(v_it!=values.end()) { object_mapt t2; flatten(v_it->second, t2); @@ -994,7 +998,9 @@ void value_set_fit::get_reference_set_sharing_rec( } #if 0 - for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(expr_sett::const_iterator it=value_set.begin(); + it!=value_set.end(); + it++) std::cout << "VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif @@ -1161,7 +1167,8 @@ void value_set_fit::assign( const irep_idt &name=c_it->get(ID_name); // ignore methods - if(subtype.id()==ID_code) continue; + if(subtype.id()==ID_code) + continue; exprt lhs_member(ID_member, subtype); lhs_member.set(ID_component_name, name); @@ -1434,7 +1441,7 @@ void value_set_fit::assign_rec( { entryt &entry = get_entry(identifier, suffix); - if (make_union(entry.object_map, values_rhs)) + if(make_union(entry.object_map, values_rhs)) changed = true; } } @@ -1447,7 +1454,7 @@ void value_set_fit::assign_rec( "value_set::dynamic_object"+ dynamic_object.instance().get_string(ID_value); - if (make_union(get_entry(name, suffix).object_map, values_rhs)) + if(make_union(get_entry(name, suffix).object_map, values_rhs)) changed = true; } else if(lhs.id()==ID_dereference) @@ -1473,7 +1480,9 @@ void value_set_fit::assign_rec( const typet &type=ns.follow(lhs.op0().type()); - assert(type.id()==ID_array || type.id()==ID_incomplete_array || type.id()=="#REF#"); + assert(type.id()==ID_array || + type.id()==ID_incomplete_array || + type.id()=="#REF#"); assign_rec(lhs.op0(), values_rhs, "[]"+suffix, ns, recursion_set); } @@ -1482,7 +1491,8 @@ void value_set_fit::assign_rec( if(lhs.operands().size()!=1) throw "member expected to have one operand"; - if(lhs.op0().is_nil()) return; + if(lhs.op0().is_nil()) + return; const std::string &component_name=lhs.get_string(ID_component_name); @@ -1579,7 +1589,8 @@ void value_set_fit::do_function_call( it++) { const irep_idt &identifier=it->get_identifier(); - if(identifier=="") continue; + if(identifier.empty()) + continue; add_var(identifier, ""); @@ -1609,7 +1620,8 @@ void value_set_fit::do_end_function( const exprt &lhs, const namespacet &ns) { - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; std::string rvs = "value_set::return_value" + std::to_string(from_function); symbol_exprt rhs(rvs, lhs.type()); @@ -1709,7 +1721,7 @@ void value_set_fit::apply_code( // this is turned into an assignment if(code.operands().size()==1) { - std::string rvs = "value_set::return_value" + std::to_string(from_function); + std::string rvs="value_set::return_value"+std::to_string(from_function); symbol_exprt lhs(rvs, code.op0().type()); assign(lhs, code.op0(), ns); } @@ -1719,7 +1731,7 @@ void value_set_fit::apply_code( } else if(statement==ID_input || statement==ID_output) { - // doesn't do anything + // doesn't do anything } else throw diff --git a/src/pointer-analysis/value_set_fi.h b/src/pointer-analysis/value_set_fi.h index fa8ddb551b6..5b76d0f48d9 100644 --- a/src/pointer-analysis/value_set_fi.h +++ b/src/pointer-analysis/value_set_fi.h @@ -32,7 +32,7 @@ class value_set_fit static object_numberingt object_numbering; static hash_numbering function_numbering; - void set_from(const irep_idt& function, unsigned inx) + void set_from(const irep_idt &function, unsigned inx) { from_function = function_numbering.number(function); from_target_index = inx; @@ -69,7 +69,7 @@ class value_set_fit { public: object_map_dt() {} - const static object_map_dt blank; + static const object_map_dt blank; }; exprt to_expr(object_map_dt::const_iterator it) const; @@ -91,7 +91,10 @@ class value_set_fit return insert(dest, object_numbering.number(src), objectt()); } - bool insert(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert(dest, object_numbering.number(src), objectt(offset)); } @@ -313,9 +316,10 @@ class value_set_fit void flatten(const entryt &e, object_mapt &dest) const; - void flatten_rec( const entryt&, - object_mapt&, - flatten_seent&) const; + void flatten_rec( + const entryt&, + object_mapt&, + flatten_seent&) const; }; #endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_FI_H diff --git a/src/pointer-analysis/value_set_fivr.cpp b/src/pointer-analysis/value_set_fivr.cpp index 3f34d861d89..582fe015dd3 100644 --- a/src/pointer-analysis/value_set_fivr.cpp +++ b/src/pointer-analysis/value_set_fivr.cpp @@ -27,29 +27,29 @@ const value_set_fivrt::object_map_dt value_set_fivrt::object_map_dt::blank; object_numberingt value_set_fivrt::object_numbering; hash_numbering value_set_fivrt::function_numbering; -static std::string alloc_adapter_prefix = "alloc_adaptor::"; +static const char *alloc_adapter_prefix="alloc_adaptor::"; #define forall_objects(it, map) \ - for(object_map_dt::const_iterator (it) = (map).begin(); \ + for(object_map_dt::const_iterator (it)=(map).begin(); \ (it)!=(map).end(); \ (it)++) #define forall_valid_objects(it, map) \ - for(object_map_dt::const_iterator (it) = (map).begin(); \ + for(object_map_dt::const_iterator (it)=(map).begin(); \ (it)!=(map).end(); \ (it)++) \ - if((map).is_valid_at((it)->first, from_function, from_target_index)) + if((map).is_valid_at((it)->first, from_function, from_target_index)) #define Forall_objects(it, map) \ - for(object_map_dt::iterator (it) = (map).begin(); \ + for(object_map_dt::iterator (it)=(map).begin(); \ (it)!=(map).end(); \ (it)++) #define Forall_valid_objects(it, map) \ - for(object_map_dt::iterator (it) = (map).begin(); \ - (it)!=(map).end(); \ - (it)++) \ - if((map).is_valid_at((it)->first, from_function, from_target_index)) + for(object_map_dt::iterator (it)=(map).begin(); \ + (it)!=(map).end(); \ + (it)++) \ + if((map).is_valid_at((it)->first, from_function, from_target_index)) /* NOLINT(*) */ /*******************************************************************\ @@ -86,7 +86,7 @@ void value_set_fivrt::output( // from_target_index)) yes=true; // if (!yes) continue; -// const object_mapt &object_map = e.object_map; +// const object_mapt &object_map=e.object_map; object_mapt object_map; flatten(e, object_map); @@ -112,8 +112,9 @@ void value_set_fivrt::output( #endif } - out << display_name << " = { "; - if(object_map.read().size()!=0) out << "\n "; + out << display_name << "={ "; + if(object_map.read().size()!=0) + out << "\n "; std::size_t width=0; @@ -121,27 +122,27 @@ void value_set_fivrt::output( { const exprt &o=object_numbering[o_it->first]; - std::string result="<"; //+std::to_string(o_it->first) + ","; + std::string result="<"; // +std::to_string(o_it->first) + ","; if(o.id()==ID_invalid) { result+='#'; result+=", *, "; // offset unknown - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; - else if (o.type().id()==ID_invalid) + else if(o.type().id()==ID_invalid) result+='#'; else result+=from_type(ns, identifier, o.type()); result+='>'; } - else if (o.id()==ID_unknown) + else if(o.id()==ID_unknown) { result+='*'; result+=", *, "; // offset unknown - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; - else if (o.type().id()==ID_invalid) + else if(o.type().id()==ID_invalid) result+='#'; else result+=from_type(ns, identifier, o.type()); @@ -158,11 +159,11 @@ void value_set_fivrt::output( result+=", "; - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; else { - if (o.type().id()=="#REF#") + if(o.type().id()=="#REF#") result += "#REF#"; else result+=from_type(ns, identifier, o.type()); @@ -178,24 +179,26 @@ void value_set_fivrt::output( object_map_dt::validity_rangest::const_iterator vr = object_map.read().validity_ranges.find(o_it->first); - if (vr != object_map.read().validity_ranges.end()) + if(vr != object_map.read().validity_ranges.end()) { - if (vr->second.empty()) + if(vr->second.empty()) std::cout << " Empty validity record" << std::endl; else - for (object_map_dt::vrange_listt::const_iterator vit = + { + for(object_map_dt::vrange_listt::const_iterator vit = vr->second.begin(); vit!=vr->second.end(); vit++) { out << " valid at " << function_numbering[vit->function] << " [" << vit->from << "," << vit->to << "]"; - if (from_function==vit->function && + if(from_function==vit->function && from_target_index>=vit->from && from_target_index<=vit->to) out << " (*)"; out << std::endl; } + } } else { @@ -269,37 +272,37 @@ void value_set_fivrt::flatten_rec( std::cout << "FLATTEN_REC: " << e.identifier << e.suffix << std::endl; #endif - std::string identifier = id2string(e.identifier); + std::string identifier=id2string(e.identifier); assert(seen.find(identifier + e.suffix)==seen.end()); - bool generalize_index = false; + bool generalize_index=false; std::list add_ranges; seen.insert(identifier + e.suffix); forall_valid_objects(it, e.object_map.read()) { - const exprt& o=object_numbering[it->first]; + const exprt &o=object_numbering[it->first]; - if (o.type().id()=="#REF#") + if(o.type().id()=="#REF#") { - if (seen.find(o.get(ID_identifier))!=seen.end()) + if(seen.find(o.get(ID_identifier))!=seen.end()) { - generalize_index = true; + generalize_index=true; - object_map_dt::validity_rangest::const_iterator vit= - e.object_map.read().validity_ranges.find(it->first); + object_map_dt::validity_rangest::const_iterator vit= + e.object_map.read().validity_ranges.find(it->first); - if (vit!=e.object_map.read().validity_ranges.end()) - { - const object_map_dt::vrange_listt &vl = vit->second; - add_ranges.push_back(&vl); - } + if(vit!=e.object_map.read().validity_ranges.end()) + { + const object_map_dt::vrange_listt &vl=vit->second; + add_ranges.push_back(&vl); + } continue; } - valuest::const_iterator fi = values.find(o.get(ID_identifier)); - if (fi==values.end()) + valuest::const_iterator fi=values.find(o.get(ID_identifier)); + if(fi==values.end()) { // this is some static object, keep it in. exprt se(ID_symbol, o.type().subtype()); @@ -308,68 +311,67 @@ void value_set_fivrt::flatten_rec( } else { - // we need to flatten_rec wherever the entry - // _started_ to become valid - - object_map_dt::validity_rangest::const_iterator ranges_it = - e.object_map.read().validity_ranges.find(it->first); - if (ranges_it!=e.object_map.read().validity_ranges.end()) - { - for(object_map_dt::vrange_listt::const_iterator r_it = - ranges_it->second.begin(); - r_it!=ranges_it->second.end(); - r_it++) - { - // we only need to check the current function; - // the entry must have been valid within that function - if(r_it->function==at_function) - { - object_mapt temp; - flatten_rec(fi->second, temp, seen, r_it->function, r_it->from); - - for(object_map_dt::iterator t_it=temp.write().begin(); - t_it!=temp.write().end(); - t_it++) - { - if(t_it->second.offset_is_set && - it->second.offset_is_set) - { - t_it->second.offset += it->second.offset; - } - else - t_it->second.offset_is_set=false; - } - - forall_objects(oit, temp.read()) - insert_from(dest, oit); - } - } - } - } + // we need to flatten_rec wherever the entry + // _started_ to become valid + + object_map_dt::validity_rangest::const_iterator ranges_it = + e.object_map.read().validity_ranges.find(it->first); + if(ranges_it!=e.object_map.read().validity_ranges.end()) + { + for(object_map_dt::vrange_listt::const_iterator r_it = + ranges_it->second.begin(); + r_it!=ranges_it->second.end(); + r_it++) + { + // we only need to check the current function; + // the entry must have been valid within that function + if(r_it->function==at_function) + { + object_mapt temp; + flatten_rec(fi->second, temp, seen, r_it->function, r_it->from); + + for(object_map_dt::iterator t_it=temp.write().begin(); + t_it!=temp.write().end(); + t_it++) + { + if(t_it->second.offset_is_set && + it->second.offset_is_set) + { + t_it->second.offset += it->second.offset; + } + else + t_it->second.offset_is_set=false; + } + forall_objects(oit, temp.read()) + insert_from(dest, oit); + } + } + } + } } else insert_from(dest, it); } - if (generalize_index) // this means we had recursive symbols in there - { - Forall_objects(it, dest.write()) - { - it->second.offset_is_set = false; - for (std::list::const_iterator vit = - add_ranges.begin(); - vit!=add_ranges.end(); - vit++) - { - for (object_map_dt::vrange_listt::const_iterator lit = - (*vit)->begin(); + if(generalize_index) // this means we had recursive symbols in there + { + Forall_objects(it, dest.write()) + { + it->second.offset_is_set=false; + for(std::list::const_iterator vit = + add_ranges.begin(); + vit!=add_ranges.end(); + vit++) + { + for(object_map_dt::vrange_listt::const_iterator lit = + (*vit)->begin(); lit!=(*vit)->end(); lit++) - dest.write().set_valid_at(it->first, *lit); - } - } - } + dest.write().set_valid_at(it->first, *lit); + } + } + } seen.erase(identifier + e.suffix); } @@ -478,7 +480,7 @@ void value_set_fivrt::copy_objects( { forall_valid_objects(it, src.read()) { - dest.write()[it->first] = it->second; + dest.write()[it->first]=it->second; dest.write().validity_ranges[it->first].push_back( object_map_dt::validity_ranget(from_function, from_target_index, @@ -511,19 +513,19 @@ void value_set_fivrt::get_value_set( forall_objects(it, object_map.read()) { const exprt &object=object_numbering[it->first]; - if (object.type().id()=="#REF#") + if(object.type().id()=="#REF#") { assert(object.id()==ID_symbol); - const irep_idt &ident = object.get(ID_identifier); - valuest::const_iterator v_it = values.find(ident); + const irep_idt &ident=object.get(ID_identifier); + valuest::const_iterator v_it=values.find(ident); - if (v_it!=values.end()) - { - object_mapt temp; - flatten(v_it->second, temp); + if(v_it!=values.end()) + { + object_mapt temp; + flatten(v_it->second, temp); - for(object_map_dt::iterator t_it=temp.write().begin(); + for(object_map_dt::iterator t_it=temp.write().begin(); t_it!=temp.write().end(); t_it++) { @@ -537,7 +539,7 @@ void value_set_fivrt::get_value_set( flat_map.write()[t_it->first]=t_it->second; } - } + } } else flat_map.write()[it->first]=it->second; @@ -555,7 +557,9 @@ void value_set_fivrt::get_value_set( #endif #if 0 - for(std::list::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(std::list::const_iterator it=value_set.begin(); + it!=value_set.end(); + it++) std::cout << "GET_VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif } @@ -612,7 +616,7 @@ void value_set_fivrt::get_value_set_rec( if(expr.type().id()=="#REF#") { - valuest::const_iterator fi = values.find(expr.get(ID_identifier)); + valuest::const_iterator fi=values.find(expr.get(ID_identifier)); if(fi!=values.end()) { @@ -673,26 +677,26 @@ void value_set_fivrt::get_value_set_rec( { // just keep a reference to the ident in the set // (if it exists) - irep_idt ident = expr.get_string(ID_identifier)+suffix; + irep_idt ident=expr.get_string(ID_identifier)+suffix; - if(has_prefix(id2string(ident), alloc_adapter_prefix)) - { - insert_from(dest, expr, 0); - return; - } - else - { - valuest::const_iterator v_it=values.find(ident); - - if(v_it!=values.end()) - { - typet t("#REF#"); - t.subtype() = expr.type(); - symbol_exprt sym(ident, t); - insert_from(dest, sym, 0); - return; - } - } + if(has_prefix(id2string(ident), alloc_adapter_prefix)) + { + insert_from(dest, expr, 0); + return; + } + else + { + valuest::const_iterator v_it=values.find(ident); + + if(v_it!=values.end()) + { + typet t("#REF#"); + t.subtype()=expr.type(); + symbol_exprt sym(ident, t); + insert_from(dest, sym, 0); + return; + } + } } else if(expr.id()==ID_if) { @@ -853,8 +857,9 @@ void value_set_fivrt::get_value_set_rec( dynamic_object_exprt dynamic_object(dynamic_type); // let's make up a `unique' number for this object... - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert_from(dest, dynamic_object, 0); @@ -868,8 +873,9 @@ void value_set_fivrt::get_value_set_rec( dynamic_object_exprt dynamic_object(expr.type().subtype()); // let's make up a unique number for this object... - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert_from(dest, dynamic_object, 0); @@ -964,13 +970,13 @@ void value_set_fivrt::get_reference_set( forall_objects(it, object_map.read()) { - const exprt& expr = object_numbering[it->first]; + const exprt &expr=object_numbering[it->first]; - if (expr.type().id()=="#REF#") + if(expr.type().id()=="#REF#") { - const irep_idt& ident = expr.get(ID_identifier); - valuest::const_iterator vit = values.find(ident); - if (vit==values.end()) + const irep_idt &ident=expr.get(ID_identifier); + valuest::const_iterator vit=values.find(ident); + if(vit==values.end()) { // Assume the variable never was assigned, // so assume it's reference set is unknown. @@ -1045,12 +1051,13 @@ void value_set_fivrt::get_reference_set_sharing_rec( const namespacet &ns) const { #if 0 - std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) << std::endl; + std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) + << std::endl; #endif if(expr.type().id()=="#REF#") { - valuest::const_iterator fi = values.find(expr.get(ID_identifier)); + valuest::const_iterator fi=values.find(expr.get(ID_identifier)); if(fi!=values.end()) { forall_valid_objects(it, fi->second.object_map.read()) @@ -1082,13 +1089,13 @@ void value_set_fivrt::get_reference_set_sharing_rec( // REF's need to be dereferenced manually! forall_objects(it, temp.read()) { - const exprt &obj = object_numbering[it->first]; - if (obj.type().id()=="#REF#") + const exprt &obj=object_numbering[it->first]; + if(obj.type().id()=="#REF#") { - const irep_idt &ident = obj.get(ID_identifier); - valuest::const_iterator v_it = values.find(ident); + const irep_idt &ident=obj.get(ID_identifier); + valuest::const_iterator v_it=values.find(ident); - if (v_it!=values.end()) + if(v_it!=values.end()) { object_mapt t2; flatten(v_it->second, t2); @@ -1117,7 +1124,9 @@ void value_set_fivrt::get_reference_set_sharing_rec( } #if 0 - for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(expr_sett::const_iterator it=value_set.begin(); + it!=value_set.end(); + it++) std::cout << "VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif @@ -1288,7 +1297,8 @@ void value_set_fivrt::assign( const irep_idt &name=c_it->get(ID_name); // ignore methods - if(subtype.id()==ID_code) continue; + if(subtype.id()==ID_code) + continue; exprt lhs_member(ID_member, subtype); lhs_member.set(ID_component_name, name); @@ -1303,7 +1313,7 @@ void value_set_fivrt::assign( } else { - if (!base_type_eq(rhs.type(), type, ns)) + if(!base_type_eq(rhs.type(), type, ns)) throw "type mismatch:\nRHS: "+rhs.type().pretty()+"\n"+ "LHS: "+type.pretty(); @@ -1430,7 +1440,7 @@ void value_set_fivrt::do_free( object_mapt value_set; get_value_set(op, value_set, ns); entryt e; e.identifier="VP:TEMP"; - e.object_map = value_set; + e.object_map=value_set; flatten(e, value_set); const object_map_dt &object_map=value_set.read(); @@ -1492,7 +1502,7 @@ void value_set_fivrt::do_free( if(changed) { - entryt &temp_entry = get_temporary_entry(v_it->second.identifier, + entryt &temp_entry=get_temporary_entry(v_it->second.identifier, v_it->second.suffix); temp_entry.object_map=new_object_map; } @@ -1530,7 +1540,7 @@ void value_set_fivrt::assign_rec( if(lhs.type().id()=="#REF#") { - const irep_idt &ident = lhs.get(ID_identifier); + const irep_idt &ident=lhs.get(ID_identifier); object_mapt temp; gvs_recursion_sett recset; get_value_set_rec(lhs, temp, "", lhs.type().subtype(), ns, recset); @@ -1557,7 +1567,7 @@ void value_set_fivrt::assign_rec( values.find(id2string(identifier)+suffix)!=values.end()) // otherwise we don't track this value { - entryt &temp_entry = get_temporary_entry(identifier, suffix); + entryt &temp_entry=get_temporary_entry(identifier, suffix); // check if the right hand side contains a reference to ourselves, // in that case we need to include all old values! @@ -1566,7 +1576,7 @@ void value_set_fivrt::assign_rec( if(add_to_sets || recursive_find(identifier, values_rhs, recset)) { - entryt &state_entry = get_entry(identifier, suffix); + entryt &state_entry=get_entry(identifier, suffix); make_valid_union(temp_entry.object_map, state_entry.object_map); } @@ -1582,7 +1592,7 @@ void value_set_fivrt::assign_rec( "value_set::dynamic_object"+ dynamic_object.instance().get_string(ID_value); - entryt &temp_entry = get_temporary_entry(name, suffix); + entryt &temp_entry=get_temporary_entry(name, suffix); // check if the right hand side contains a reference to ourselves, // in that case we need to include all old values! @@ -1591,7 +1601,7 @@ void value_set_fivrt::assign_rec( if(add_to_sets || recursive_find(name, values_rhs, recset)) { - entryt &state_entry = get_entry(name, suffix); + entryt &state_entry=get_entry(name, suffix); make_valid_union(temp_entry.object_map, state_entry.object_map); } @@ -1620,16 +1630,20 @@ void value_set_fivrt::assign_rec( const typet &type=ns.follow(lhs.op0().type()); - assert(type.id()==ID_array || type.id()==ID_incomplete_array || type.id()=="#REF#"); + assert(type.id()==ID_array || + type.id()==ID_incomplete_array || + type.id()=="#REF#"); - assign_rec(lhs.op0(), values_rhs, "[]"+suffix, ns, recursion_set, add_to_sets); + assign_rec( + lhs.op0(), values_rhs, "[]"+suffix, ns, recursion_set, add_to_sets); } else if(lhs.id()==ID_member) { if(lhs.operands().size()!=1) throw "member expected to have one operand"; - if(lhs.op0().is_nil()) return; + if(lhs.op0().is_nil()) + return; const std::string &component_name=lhs.get_string(ID_component_name); @@ -1745,7 +1759,8 @@ void value_set_fivrt::do_function_call( it++) { const irep_idt &identifier=it->get_identifier(); - if(identifier=="") continue; + if(identifier=="") + continue; add_var(identifier, ""); @@ -1775,9 +1790,10 @@ void value_set_fivrt::do_end_function( const exprt &lhs, const namespacet &ns) { - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; - std::string rvs = "value_set::return_value" + std::to_string(from_function); + std::string rvs="value_set::return_value" + std::to_string(from_function); symbol_exprt rhs(rvs, lhs.type()); assign(lhs, rhs, ns); @@ -1875,14 +1891,14 @@ void value_set_fivrt::apply_code( // this is turned into an assignment if(code.operands().size()==1) { - std::string rvs = "value_set::return_value" + std::to_string(from_function); + std::string rvs="value_set::return_value" + std::to_string(from_function); symbol_exprt lhs(rvs, code.op0().type()); assign(lhs, code.op0(), ns); } } else if(statement==ID_input || statement==ID_output) { - // doesn't do anything + // doesn't do anything } else @@ -1908,7 +1924,7 @@ bool value_set_fivrt::insert_to( unsigned n, const objectt &object) const { - object_map_dt &map = dest.write(); + object_map_dt &map=dest.write(); if(map.find(n)==map.end()) { // std::cout << "NEW(" << n << "): " << object_numbering[n] << std::endl; @@ -1922,7 +1938,7 @@ bool value_set_fivrt::insert_to( // std::cout << "UPD " << n << std::endl; objectt &old=map[n]; - bool res = map.set_valid_at(n, to_function, to_target_index); + bool res=map.set_valid_at(n, to_function, to_target_index); if(old.offset_is_set && object.offset_is_set) { @@ -1961,7 +1977,7 @@ bool value_set_fivrt::insert_from( unsigned n, const objectt &object) const { - object_map_dt &map = dest.write(); + object_map_dt &map=dest.write(); if(map.find(n)==map.end()) { // std::cout << "NEW(" << n << "): " << object_numbering[n] << std::endl; @@ -1975,7 +1991,7 @@ bool value_set_fivrt::insert_from( // std::cout << "UPD " << n << std::endl; objectt &old=map[n]; - bool res = map.set_valid_at(n, from_function, from_target_index); + bool res=map.set_valid_at(n, from_function, from_target_index); if(old.offset_is_set && object.offset_is_set) { @@ -2013,10 +2029,11 @@ bool value_set_fivrt::object_map_dt::set_valid_at( unsigned inx, const validity_ranget &vr) { - bool res = false; + bool res=false; for(unsigned i=vr.from; i<=vr.to; i++) - if(set_valid_at(inx, vr.function, i)) res = true; + if(set_valid_at(inx, vr.function, i)) + res=true; return res; } @@ -2038,9 +2055,10 @@ bool value_set_fivrt::object_map_dt::set_valid_at( unsigned f, unsigned line) { - if(is_valid_at(inx, f, line)) return false; + if(is_valid_at(inx, f, line)) + return false; - vrange_listt &ranges = validity_ranges[inx]; + vrange_listt &ranges=validity_ranges[inx]; vrange_listt::iterator it=ranges.begin(); while(it->function!=f && it!=ranges.end()) it++; // ffw to function block @@ -2056,13 +2074,13 @@ bool value_set_fivrt::object_map_dt::set_valid_at( it->to++; // by any chance: does the next one connect to this one? - vrange_listt::iterator n_it = it; n_it++; + vrange_listt::iterator n_it=it; n_it++; if(n_it!=ranges.end() && it->function == n_it->function && it->to+1 == n_it->from) { - n_it->from = it->from; // connected! - it = ranges.erase(it); + n_it->from=it->from; // connected! + it=ranges.erase(it); } return true; } @@ -2083,12 +2101,12 @@ bool value_set_fivrt::object_map_dt::set_valid_at( // by any chance: does the previous one connect to this one? if(it!=ranges.begin()) { - vrange_listt::iterator p_it = it; p_it--; + vrange_listt::iterator p_it=it; p_it--; if(p_it->function == it->function && p_it->to+1 == it->from) { - p_it->to = it->to; // connected! - it = ranges.erase(it); + p_it->to=it->to; // connected! + it=ranges.erase(it); } } return true; @@ -2125,20 +2143,22 @@ bool value_set_fivrt::object_map_dt::is_valid_at( std::endl; #endif - validity_rangest::const_iterator vrs = validity_ranges.find(inx); - if (vrs!=validity_ranges.end()) + validity_rangest::const_iterator vrs=validity_ranges.find(inx); + if(vrs!=validity_ranges.end()) { - const vrange_listt &ranges = vrs->second; + const vrange_listt &ranges=vrs->second; - object_map_dt::vrange_listt::const_iterator it = ranges.begin(); + object_map_dt::vrange_listt::const_iterator it=ranges.begin(); while(it->function!=f && - it!=ranges.end()) it++; // ffw to function block + it!=ranges.end()) + it++; // ffw to function block - for(; - it!=ranges.end() && it->function==f && it->from<=line ; + for( ; + it!=ranges.end() && it->function==f && it->from<=line; it++) - if(it->contains(f, line)) return true; + if(it->contains(f, line)) + return true; } return false; } @@ -2162,28 +2182,28 @@ bool value_set_fivrt::recursive_find( { forall_objects(it, rhs.read()) { - const exprt &o = object_numbering[it->first]; + const exprt &o=object_numbering[it->first]; - if (o.id()==ID_symbol && o.get(ID_identifier)==ident) + if(o.id()==ID_symbol && o.get(ID_identifier)==ident) return true; - else if (o.type().id()=="#REF#") + else if(o.type().id()=="#REF#") { - const irep_idt oid = o.get(ID_identifier); + const irep_idt oid=o.get(ID_identifier); - if (recursion_set.find(oid)!=recursion_set.end()) + if(recursion_set.find(oid)!=recursion_set.end()) return false; // we hit some other cycle on the way down if(oid==ident) return true; else { - valuest::const_iterator vit = values.find(oid); + valuest::const_iterator vit=values.find(oid); if(vit!=values.end()) { - const entryt &e = vit->second; + const entryt &e=vit->second; recursion_set.insert(oid); - if (recursive_find(ident, e.object_map, recursion_set)) + if(recursive_find(ident, e.object_map, recursion_set)) return true; recursion_set.erase(oid); } @@ -2210,13 +2230,13 @@ bool value_set_fivrt::handover(void) { bool changed=false; - for (valuest::iterator it=values.begin(); + for(valuest::iterator it=values.begin(); it!=values.end(); it++) { object_mapt &state_map=it->second.object_map; - irep_idt ident = id2string(it->second.identifier)+it->second.suffix; + irep_idt ident=id2string(it->second.identifier)+it->second.suffix; valuest::const_iterator t_it=temporary_values.find(ident); @@ -2227,14 +2247,14 @@ bool value_set_fivrt::handover(void) { if(state_map.write().set_valid_at(o_it->first, to_function, to_target_index)) - changed = true; + changed=true; } } else { // std::cout << "NEW VALUES FOR: " << ident << std::endl; if(make_union(state_map, t_it->second.object_map)) - changed = true; + changed=true; } } diff --git a/src/pointer-analysis/value_set_fivr.h b/src/pointer-analysis/value_set_fivr.h index e0bb75c0428..5a96e537e77 100644 --- a/src/pointer-analysis/value_set_fivr.h +++ b/src/pointer-analysis/value_set_fivr.h @@ -32,7 +32,7 @@ class value_set_fivrt static object_numberingt object_numbering; static hash_numbering function_numbering; - void set_from(const irep_idt& function, unsigned inx) + void set_from(const irep_idt &function, unsigned inx) { from_function = function_numbering.number(function); from_target_index = inx; @@ -70,12 +70,14 @@ class value_set_fivrt { public: object_map_dt() {} - const static object_map_dt blank; + static const object_map_dt blank; typedef std::map objmapt; objmapt objmap; + // NOLINTNEXTLINE(readability/identifiers) typedef objmapt::const_iterator const_iterator; + // NOLINTNEXTLINE(readability/identifiers) typedef objmapt::iterator iterator; const_iterator find(unsigned k) { return objmap.find(k); } @@ -86,15 +88,20 @@ class value_set_fivrt size_t size(void) const { return objmap.size(); } void clear(void) { objmap.clear(); validity_ranges.clear(); } - objectt& operator[](unsigned k) { + objectt &operator[](unsigned k) + { return objmap[k]; } // operator[] is the only way to insert something! - std::pair insert (const std::pair&) - { assert(false); } - iterator insert(iterator, const std::pair&) - { assert(false); } + std::pair insert(const std::pair&) + { + assert(false); + } + iterator insert(iterator, const std::pair&) + { + assert(false); + } class validity_ranget { @@ -102,11 +109,15 @@ class value_set_fivrt unsigned function; unsigned from, to; - validity_ranget(void) : - function(0),from(0), to(0) {}; + validity_ranget(void): + function(0), from(0), to(0) + { + } - validity_ranget(unsigned fnc, unsigned f, unsigned t) : - function(fnc),from(f), to(t) {}; + validity_ranget(unsigned fnc, unsigned f, unsigned t): + function(fnc), from(f), to(t) + { + } bool contains(unsigned f, unsigned line) const { @@ -115,7 +126,7 @@ class value_set_fivrt }; typedef std::list vrange_listt; - typedef std::map validity_rangest; + typedef std::map validity_rangest; validity_rangest validity_ranges; bool set_valid_at(unsigned inx, unsigned f, unsigned line); @@ -142,14 +153,20 @@ class value_set_fivrt return insert_to(dest, object_numbering.number(src), objectt()); } - bool insert_to(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert_to( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert_to(dest, object_numbering.number(src), objectt(offset)); } bool insert_to(object_mapt &dest, unsigned n, const objectt &object) const; - bool insert_to(object_mapt &dest, const exprt &expr, const objectt &object) const + bool insert_to( + object_mapt &dest, + const exprt &expr, + const objectt &object) const { return insert_to(dest, object_numbering.number(expr), object); } @@ -164,14 +181,20 @@ class value_set_fivrt return insert_from(dest, object_numbering.number(src), objectt()); } - bool insert_from(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert_from( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert_from(dest, object_numbering.number(src), objectt(offset)); } bool insert_from(object_mapt &dest, unsigned n, const objectt &object) const; - bool insert_from(object_mapt &dest, const exprt &expr, const objectt &object) const + bool insert_from( + object_mapt &dest, + const exprt &expr, + const objectt &object) const { return insert_from(dest, object_numbering.number(expr), object); } diff --git a/src/pointer-analysis/value_set_fivrns.cpp b/src/pointer-analysis/value_set_fivrns.cpp index 574942a73d7..41907d54cfb 100644 --- a/src/pointer-analysis/value_set_fivrns.cpp +++ b/src/pointer-analysis/value_set_fivrns.cpp @@ -27,7 +27,7 @@ const value_set_fivrnst::object_map_dt value_set_fivrnst::object_map_dt::blank; object_numberingt value_set_fivrnst::object_numbering; hash_numbering value_set_fivrnst::function_numbering; -static std::string alloc_adapter_prefix = "alloc_adaptor::"; +static const char *alloc_adapter_prefix="alloc_adaptor::"; #define forall_objects(it, map) \ for(object_map_dt::const_iterator (it) = (map).begin(); \ @@ -38,7 +38,7 @@ static std::string alloc_adapter_prefix = "alloc_adaptor::"; for(object_map_dt::const_iterator (it) = (map).begin(); \ (it)!=(map).end(); \ (it)++) \ - if((map).is_valid_at((it)->first, from_function, from_target_index)) + if((map).is_valid_at((it)->first, from_function, from_target_index)) #define Forall_objects(it, map) \ for(object_map_dt::iterator (it) = (map).begin(); \ @@ -47,9 +47,9 @@ static std::string alloc_adapter_prefix = "alloc_adaptor::"; #define Forall_valid_objects(it, map) \ for(object_map_dt::iterator (it) = (map).begin(); \ - (it)!=(map).end(); \ - (it)++) \ - if((map).is_valid_at((it)->first, from_function, from_target_index)) + (it)!=(map).end(); \ + (it)++) \ + if((map).is_valid_at((it)->first, from_function, from_target_index)) /* NOLINT(*) */ /*******************************************************************\ @@ -116,7 +116,8 @@ void value_set_fivrnst::output_entry( const object_mapt &object_map=e.object_map; out << display_name << " = { "; - if(object_map.read().size()!=0) out << "\n "; + if(object_map.read().size()!=0) + out << "\n "; std::size_t width=0; @@ -124,27 +125,27 @@ void value_set_fivrnst::output_entry( { const exprt &o=object_numbering[o_it->first]; - std::string result="<"; //+std::to_string(o_it->first) + ","; + std::string result="<"; // +std::to_string(o_it->first) + ","; if(o.id()==ID_invalid) { result+='#'; result+=", *, "; // offset unknown - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; - else if (o.type().id()==ID_invalid) + else if(o.type().id()==ID_invalid) result+='#'; else result+=from_type(ns, identifier, o.type()); result+='>'; } - else if (o.id()==ID_unknown) + else if(o.id()==ID_unknown) { result+='*'; result+=", *, "; // offset unknown - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; - else if (o.type().id()==ID_invalid) + else if(o.type().id()==ID_invalid) result+='#'; else result+=from_type(ns, identifier, o.type()); @@ -161,7 +162,7 @@ void value_set_fivrnst::output_entry( result+=", "; - if (o.type().id()==ID_unknown) + if(o.type().id()==ID_unknown) result+='*'; else { @@ -178,24 +179,26 @@ void value_set_fivrnst::output_entry( object_map_dt::validity_rangest::const_iterator vr = object_map.read().validity_ranges.find(o_it->first); - if (vr != object_map.read().validity_ranges.end()) + if(vr != object_map.read().validity_ranges.end()) { - if (vr->second.empty()) + if(vr->second.empty()) std::cout << " Empty validity record" << std::endl; else - for (object_map_dt::vrange_listt::const_iterator vit = + { + for(object_map_dt::vrange_listt::const_iterator vit = vr->second.begin(); vit!=vr->second.end(); vit++) { out << " valid at " << function_numbering[vit->function] << " [" << vit->from << "," << vit->to << "]"; - if (from_function==vit->function && + if(from_function==vit->function && from_target_index>=vit->from && from_target_index<=vit->to) out << " (*)"; out << std::endl; } + } } else { @@ -353,7 +356,8 @@ void value_set_fivrnst::get_value_set( value_set.push_back(to_expr(it)); #if 0 - for(std::list::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(std::list::const_iterator it=value_set.begin(); + it!=value_set.end(); it++) std::cout << "GET_VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif } @@ -627,8 +631,9 @@ void value_set_fivrnst::get_value_set_rec( dynamic_object_exprt dynamic_object(dynamic_type); // let's make up a `unique' number for this object... - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert_from(dest, dynamic_object, 0); @@ -642,8 +647,9 @@ void value_set_fivrnst::get_value_set_rec( dynamic_object_exprt dynamic_object(expr.type().subtype()); // let's make up a unique number for this object... - dynamic_object.instance()=from_integer( - (from_function << 16) | from_target_index, typet(ID_natural)); + dynamic_object.instance()= + from_integer( + (from_function << 16) | from_target_index, typet(ID_natural)); dynamic_object.valid()=true_exprt(); insert_from(dest, dynamic_object, 0); @@ -758,7 +764,8 @@ void value_set_fivrnst::get_reference_set_rec( const namespacet &ns) const { #if 0 - std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) << std::endl; + std::cout << "GET_REFERENCE_SET_REC EXPR: " << from_expr(ns, "", expr) + << std::endl; #endif if(expr.id()==ID_symbol || @@ -781,7 +788,8 @@ void value_set_fivrnst::get_reference_set_rec( get_value_set_rec(expr.op0(), dest, "", expr.op0().type(), ns); #if 0 - for(expr_sett::const_iterator it=value_set.begin(); it!=value_set.end(); it++) + for(expr_sett::const_iterator it=value_set.begin(); + it!=value_set.end(); it++) std::cout << "VALUE_SET: " << from_expr(ns, "", *it) << std::endl; #endif @@ -952,7 +960,8 @@ void value_set_fivrnst::assign( const irep_idt &name=c_it->get(ID_name); // ignore methods - if(subtype.id()==ID_code) continue; + if(subtype.id()==ID_code) + continue; exprt lhs_member(ID_member, subtype); lhs_member.set(ID_component_name, name); @@ -967,7 +976,7 @@ void value_set_fivrnst::assign( } else { - if (!base_type_eq(rhs.type(), type, ns)) + if(!base_type_eq(rhs.type(), type, ns)) throw "type mismatch:\nRHS: "+rhs.type().pretty()+"\n"+ "LHS: "+type.pretty(); @@ -1260,7 +1269,8 @@ void value_set_fivrnst::assign_rec( if(lhs.operands().size()!=1) throw "member expected to have one operand"; - if(lhs.op0().is_nil()) return; + if(lhs.op0().is_nil()) + return; const std::string &component_name=lhs.get_string(ID_component_name); @@ -1376,7 +1386,8 @@ void value_set_fivrnst::do_function_call( it++) { const irep_idt &identifier=it->get_identifier(); - if(identifier=="") continue; + if(identifier=="") + continue; add_var(identifier, ""); @@ -1406,7 +1417,8 @@ void value_set_fivrnst::do_end_function( const exprt &lhs, const namespacet &ns) { - if(lhs.is_nil()) return; + if(lhs.is_nil()) + return; irep_idt rvs = std::string("value_set::return_value") + std::to_string(from_function); @@ -1517,7 +1529,7 @@ void value_set_fivrnst::apply_code( } else if(statement==ID_input || statement==ID_output) { - // doesn't do anything + // doesn't do anything } else { @@ -1650,7 +1662,8 @@ bool value_set_fivrnst::object_map_dt::set_valid_at( unsigned f, unsigned line) { - if(is_valid_at(inx, f, line)) return false; + if(is_valid_at(inx, f, line)) + return false; vrange_listt &ranges = validity_ranges[inx]; vrange_listt::iterator it=ranges.begin(); @@ -1745,12 +1758,14 @@ bool value_set_fivrnst::object_map_dt::is_valid_at( object_map_dt::vrange_listt::const_iterator it = ranges.begin(); while(it->function!=f && - it!=ranges.end()) it++; // ffw to function block + it!=ranges.end()) + it++; // ffw to function block - for(; - it!=ranges.end() && it->function==f && it->from<=line ; + for( ; + it!=ranges.end() && it->function==f && it->from<=line; it++) - if(it->contains(f, line)) return true; + if(it->contains(f, line)) + return true; } return false; @@ -1772,7 +1787,7 @@ bool value_set_fivrnst::handover(void) { bool changed=false; - for (valuest::iterator it=values.begin(); + for(valuest::iterator it=values.begin(); it!=values.end(); it++) { diff --git a/src/pointer-analysis/value_set_fivrns.h b/src/pointer-analysis/value_set_fivrns.h index 8031f760e18..c1d826f2550 100644 --- a/src/pointer-analysis/value_set_fivrns.h +++ b/src/pointer-analysis/value_set_fivrns.h @@ -33,7 +33,7 @@ class value_set_fivrnst static object_numberingt object_numbering; static hash_numbering function_numbering; - void set_from(const irep_idt& function, unsigned inx) + void set_from(const irep_idt &function, unsigned inx) { from_function = function_numbering.number(function); from_target_index = inx; @@ -71,12 +71,14 @@ class value_set_fivrnst { public: object_map_dt() {} - const static object_map_dt blank; + static const object_map_dt blank; typedef std::map objmapt; objmapt objmap; + // NOLINTNEXTLINE(readability/identifiers) typedef objmapt::const_iterator const_iterator; + // NOLINTNEXTLINE(readability/identifiers) typedef objmapt::iterator iterator; const_iterator find(unsigned k) { return objmap.find(k); } @@ -87,15 +89,20 @@ class value_set_fivrnst size_t size(void) const { return objmap.size(); } void clear(void) { objmap.clear(); validity_ranges.clear(); } - objectt& operator[](unsigned k) { + objectt &operator[](unsigned k) + { return objmap[k]; } // operator[] is the only way to insert something! - std::pair insert (const std::pair&) - { assert(false); } - iterator insert(iterator, const std::pair&) - { assert(false); } + std::pair insert(const std::pair&) + { + assert(false); + } + iterator insert(iterator, const std::pair&) + { + assert(false); + } class validity_ranget { @@ -103,11 +110,15 @@ class value_set_fivrnst unsigned function; unsigned from, to; - validity_ranget(void) : - function(0),from(0), to(0) {}; + validity_ranget(void): + function(0), from(0), to(0) + { + } - validity_ranget(unsigned fnc, unsigned f, unsigned t) : - function(fnc),from(f), to(t) {}; + validity_ranget(unsigned fnc, unsigned f, unsigned t): + function(fnc), from(f), to(t) + { + } bool contains(unsigned f, unsigned line) const { @@ -116,7 +127,7 @@ class value_set_fivrnst }; typedef std::list vrange_listt; - typedef std::map validity_rangest; + typedef std::map validity_rangest; validity_rangest validity_ranges; bool set_valid_at(unsigned inx, unsigned f, unsigned line); @@ -142,14 +153,20 @@ class value_set_fivrnst return insert_to(dest, object_numbering.number(src), objectt()); } - bool insert_to(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert_to( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert_to(dest, object_numbering.number(src), objectt(offset)); } bool insert_to(object_mapt &dest, unsigned n, const objectt &object) const; - bool insert_to(object_mapt &dest, const exprt &expr, const objectt &object) const + bool insert_to( + object_mapt &dest, + const exprt &expr, + const objectt &object) const { return insert_to(dest, object_numbering.number(expr), object); } @@ -164,14 +181,20 @@ class value_set_fivrnst return insert_from(dest, object_numbering.number(src), objectt()); } - bool insert_from(object_mapt &dest, const exprt &src, const mp_integer &offset) const + bool insert_from( + object_mapt &dest, + const exprt &src, + const mp_integer &offset) const { return insert_from(dest, object_numbering.number(src), objectt(offset)); } bool insert_from(object_mapt &dest, unsigned n, const objectt &object) const; - bool insert_from(object_mapt &dest, const exprt &expr, const objectt &object) const + bool insert_from( + object_mapt &dest, + const exprt &expr, + const objectt &object) const { return insert_from(dest, object_numbering.number(expr), object); } diff --git a/src/solvers/dplib/dplib_conv.cpp b/src/solvers/dplib/dplib_conv.cpp index ae69746fc2e..d9d7eefbb11 100644 --- a/src/solvers/dplib/dplib_conv.cpp +++ b/src/solvers/dplib/dplib_conv.cpp @@ -248,7 +248,7 @@ Function: dplib_convt::convert_rest literalt dplib_convt::convert_rest(const exprt &expr) { - //dplib_prop.out << "%% E: " << expr << std::endl; + // dplib_prop.out << "%% E: " << expr << std::endl; literalt l=prop.new_variable(); @@ -396,17 +396,20 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) } else { + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast1 "+op.type().id_string()+" -> bool"; } } else if(expr.type().id()==ID_signedbv || expr.type().id()==ID_unsignedbv) { - unsigned to_width=unsafe_string2unsigned(id2string(expr.type().get(ID_width))); + unsigned to_width= + unsafe_string2unsigned(id2string(expr.type().get(ID_width))); if(op.type().id()==ID_signedbv) { - unsigned from_width=unsafe_string2unsigned(id2string(op.type().get(ID_width))); + unsigned from_width= + unsafe_string2unsigned(id2string(op.type().get(ID_width))); if(from_width==to_width) convert_dplib_expr(op); @@ -425,7 +428,8 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) } else if(op.type().id()==ID_unsignedbv) { - unsigned from_width=unsafe_string2unsigned(id2string(op.type().get(ID_width))); + unsigned from_width= + unsafe_string2unsigned(id2string(op.type().get(ID_width))); if(from_width==to_width) convert_dplib_expr(op); @@ -473,6 +477,7 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) } else { + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast2 "+op.type().id_string()+ " -> "+expr.type().id_string(); } @@ -484,9 +489,11 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) convert_dplib_expr(op); } else + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast3 "+op.type().id_string()+" -> pointer"; } else + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast4 ? -> "+expr.type().id_string(); } else if(expr.id()==ID_struct) @@ -506,7 +513,8 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) it!=components.end(); it++, i++) { - if(i!=0) dplib_prop.out << ", "; + if(i!=0) + dplib_prop.out << ", "; dplib_prop.out << it->get(ID_name); dplib_prop.out << ":="; convert_dplib_expr(expr.operands()[i]); @@ -718,13 +726,15 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) if(expr.op0().type().id()==ID_bool) { - if(expr.id()==ID_notequal) dplib_prop.out << "NOT ("; + if(expr.id()==ID_notequal) + dplib_prop.out << "NOT ("; dplib_prop.out << "("; convert_dplib_expr(expr.op0()); dplib_prop.out << ") <=> ("; convert_dplib_expr(expr.op1()); dplib_prop.out << ")"; - if(expr.id()==ID_notequal) dplib_prop.out << ")"; + if(expr.id()==ID_notequal) + dplib_prop.out << ")"; } else { @@ -781,7 +791,8 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) dplib_prop.out << ")"; } else - throw "unsupported type for "+expr.id_string()+": "+expr.type().id_string(); + throw + "unsupported type for "+expr.id_string()+": "+expr.type().id_string(); } else if(expr.id()==ID_plus) { @@ -975,7 +986,8 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) dplib_prop.out << ")"; } else - throw "unsupported type for "+expr.id_string()+": "+expr.type().id_string(); + throw + "unsupported type for "+expr.id_string()+": "+expr.type().id_string(); } else if(expr.id()==ID_with) { @@ -1013,7 +1025,9 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) dplib_prop.out << ")"; } else - throw "with expects struct or array type, but got "+expr.type().id_string(); + throw + "with expects struct or array type, but got "+ + expr.type().id_string(); } } else if(expr.id()==ID_member) @@ -1037,7 +1051,7 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) dplib_prop.out << "("; convert_dplib_expr(expr.op0()); dplib_prop.out << ").object"; - // TODO, this has the wrong type + // TODO this has the wrong type } #endif else if(expr.id()==ID_string_constant) @@ -1060,7 +1074,9 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) dplib_prop.out << "[" << i << "]"; } else - throw "unsupported type for "+expr.id_string()+": "+expr.op0().type().id_string(); + throw + "unsupported type for "+expr.id_string()+": "+ + expr.op0().type().id_string(); } else if(expr.id()==ID_replication) { @@ -1078,7 +1094,8 @@ void dplib_convt::convert_dplib_expr(const exprt &expr) for(mp_integer i=0; iget(ID_name); dplib_prop.out << ": "; diff --git a/src/solvers/dplib/dplib_dec.cpp b/src/solvers/dplib/dplib_dec.cpp index c4775cb5007..66369bdc1ff 100644 --- a/src/solvers/dplib/dplib_dec.cpp +++ b/src/solvers/dplib/dplib_dec.cpp @@ -123,7 +123,8 @@ void dplib_dect::read_assert(std::istream &in, std::string &line) { // strip ASSERT line=std::string(line, strlen("ASSERT "), std::string::npos); - if(line=="") return; + if(line=="") + return; // bit-vector if(line[0]=='(') @@ -135,7 +136,8 @@ void dplib_dect::read_assert(std::istream &in, std::string &line) std::string identifier=std::string(line, 1, pos-1); // get value - if(!std::getline(in, line)) return; + if(!std::getline(in, line)) + return; // skip spaces pos=0; @@ -143,7 +145,8 @@ void dplib_dect::read_assert(std::istream &in, std::string &line) // get final ")" std::string::size_type pos2=line.rfind(')'); - if(pos2==std::string::npos) return; + if(pos2==std::string::npos) + return; std::string value=std::string(line, pos, pos2-pos); @@ -163,7 +166,8 @@ void dplib_dect::read_assert(std::istream &in, std::string &line) value=tvt(false); } - if(line=="") return; + if(line=="") + return; if(line[0]=='l') { diff --git a/src/solvers/dplib/dplib_prop.cpp b/src/solvers/dplib/dplib_prop.cpp index ea9e169ffda..5153b6874de 100644 --- a/src/solvers/dplib/dplib_prop.cpp +++ b/src/solvers/dplib/dplib_prop.cpp @@ -191,7 +191,8 @@ literalt dplib_propt::land(const bvt &bv) forall_literals(it, bv) { - if(it!=bv.begin()) out << " & "; + if(it!=bv.begin()) + out << " & "; out << dplib_literal(*it); } @@ -220,7 +221,8 @@ literalt dplib_propt::lor(const bvt &bv) forall_literals(it, bv) { - if(it!=bv.begin()) out << " | "; + if(it!=bv.begin()) + out << " | "; out << dplib_literal(*it); } @@ -243,9 +245,12 @@ Function: dplib_propt::lxor literalt dplib_propt::lxor(const bvt &bv) { - if(bv.empty()) return const_literal(false); - if(bv.size()==1) return bv[0]; - if(bv.size()==2) return lxor(bv[0], bv[1]); + if(bv.empty()) + return const_literal(false); + if(bv.size()==1) + return bv[0]; + if(bv.size()==2) + return lxor(bv[0], bv[1]); literalt literal=const_literal(false); @@ -269,11 +274,16 @@ Function: dplib_propt::land literalt dplib_propt::land(literalt a, literalt b) { - if(a==const_literal(true)) return b; - if(b==const_literal(true)) return a; - if(a==const_literal(false)) return const_literal(false); - if(b==const_literal(false)) return const_literal(false); - if(a==b) return a; + if(a==const_literal(true)) + return b; + if(b==const_literal(true)) + return a; + if(a==const_literal(false)) + return const_literal(false); + if(b==const_literal(false)) + return const_literal(false); + if(a==b) + return a; literalt o=def_dplib_literal(); out << dplib_literal(a) << " & " << dplib_literal(b) @@ -296,11 +306,16 @@ Function: dplib_propt::lor literalt dplib_propt::lor(literalt a, literalt b) { - if(a==const_literal(false)) return b; - if(b==const_literal(false)) return a; - if(a==const_literal(true)) return const_literal(true); - if(b==const_literal(true)) return const_literal(true); - if(a==b) return a; + if(a==const_literal(false)) + return b; + if(b==const_literal(false)) + return a; + if(a==const_literal(true)) + return const_literal(true); + if(b==const_literal(true)) + return const_literal(true); + if(a==b) + return a; literalt o=def_dplib_literal(); out << dplib_literal(a) << " | " << dplib_literal(b) @@ -323,10 +338,14 @@ Function: dplib_propt::lxor literalt dplib_propt::lxor(literalt a, literalt b) { - if(a==const_literal(false)) return b; - if(b==const_literal(false)) return a; - if(a==const_literal(true)) return !b; - if(b==const_literal(true)) return !a; + if(a==const_literal(false)) + return b; + if(b==const_literal(false)) + return a; + if(a==const_literal(true)) + return !b; + if(b==const_literal(true)) + return !a; literalt o=def_dplib_literal(); out << "!(" << dplib_literal(a) << " <-> " << dplib_literal(b) @@ -417,9 +436,12 @@ Function: dplib_propt::lselect literalt dplib_propt::lselect(literalt a, literalt b, literalt c) { - if(a==const_literal(true)) return b; - if(a==const_literal(false)) return c; - if(b==c) return b; + if(a==const_literal(true)) + return b; + if(a==const_literal(false)) + return c; + if(b==c) + return b; out << "// lselect" << std::endl; @@ -489,7 +511,8 @@ Function: dplib_propt::lcnf void dplib_propt::lcnf(const bvt &bv) { - if(bv.empty()) return; + if(bv.empty()) + return; bvt new_bv; std::set s; @@ -514,7 +537,8 @@ void dplib_propt::lcnf(const bvt &bv) for(bvt::const_iterator it=new_bv.begin(); it!=new_bv.end(); it++) { - if(it!=new_bv.begin()) out << " | "; + if(it!=new_bv.begin()) + out << " | "; out << dplib_literal(*it); } diff --git a/src/solvers/dplib/dplib_prop.h b/src/solvers/dplib/dplib_prop.h index 5abdc41aaba..7aec9d47980 100644 --- a/src/solvers/dplib/dplib_prop.h +++ b/src/solvers/dplib/dplib_prop.h @@ -18,7 +18,7 @@ Author: Daniel Kroening, kroening@kroening.com class dplib_propt:virtual public propt { public: - dplib_propt(std::ostream &_out); + explicit dplib_propt(std::ostream &_out); virtual ~dplib_propt() { } virtual void land(literalt a, literalt b, literalt o); @@ -43,7 +43,7 @@ class dplib_propt:virtual public propt virtual literalt new_variable(); virtual size_t no_variables() const { return _no_variables; } virtual void set_no_variables(size_t no) { assert(false); } - //virtual unsigned no_clauses()=0; + // virtual unsigned no_clauses()=0; virtual void lcnf(const bvt &bv); @@ -53,7 +53,8 @@ class dplib_propt:virtual public propt virtual tvt l_get(literalt literal) const { unsigned v=literal.var_no(); - if(v>=assignment.size()) return tvt::unknown(); + if(v>=assignment.size()) + return tvt::unknown(); tvt r=assignment[v]; return literal.sign()?!r:r; } diff --git a/src/solvers/flattening/arrays.cpp b/src/solvers/flattening/arrays.cpp index 5fa7a9c9f44..9c710fc3737 100644 --- a/src/solvers/flattening/arrays.cpp +++ b/src/solvers/flattening/arrays.cpp @@ -6,7 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG +// #define DEBUG #include #include @@ -129,12 +129,12 @@ void arrayst::collect_indices(const exprt &expr) { if(expr.id()!=ID_index) { - forall_operands(op,expr) collect_indices(*op); + forall_operands(op, expr) collect_indices(*op); } else { const index_exprt &e = to_index_expr(expr); - collect_indices(e.index()); //necessary? + collect_indices(e.index()); // necessary? const typet &array_op_type=ns.follow(e.array().type()); @@ -190,7 +190,7 @@ void arrayst::collect_arrays(const exprt &a) index_expr.index()=a.op1(); record_array_index(index_expr); } - else if(a.id()==ID_update) //TODO: is this obsolete? + else if(a.id()==ID_update) // TODO: is this obsolete? { if(a.operands().size()!=3) throw "update expected to have three operands"; @@ -247,7 +247,8 @@ void arrayst::collect_arrays(const exprt &a) else if(a.id()==ID_member) { if(to_member_expr(a).struct_op().id()!=ID_symbol) - throw "unexpected array expression: member with `"+a.op0().id_string()+"'"; + throw + "unexpected array expression: member with `"+a.op0().id_string()+"'"; } else if(a.id()==ID_constant || a.id()==ID_array || @@ -301,12 +302,12 @@ Function: arrayst::add_array_constraint void arrayst::add_array_constraint(const lazy_constraintt &lazy, bool refine) { - if (lazy_arrays && refine) + if(lazy_arrays && refine) { // lazily add the constraint - if (incremental_cache) + if(incremental_cache) { - if (expr_map.find(lazy.lazy) == expr_map.end()) + if(expr_map.find(lazy.lazy) == expr_map.end()) { lazy_array_constraints.push_back(lazy); expr_map[lazy.lazy] = true; @@ -353,7 +354,7 @@ void arrayst::add_array_constraints() add_array_constraints(index_map[arrays.find_number(i)], a); - //we have to update before it gets used in the next add_* call + // we have to update before it gets used in the next add_* call update_index_map(false); } @@ -441,10 +442,10 @@ void arrayst::add_array_Ackermann_constraints() equal_exprt values_equal(index_expr1, index_expr2); - //add constraint + // add constraint lazy_constraintt lazy(ARRAY_ACKERMANN, or_exprt(literal_exprt(!indices_equal_lit), values_equal)); - add_array_constraint(lazy, true); //added lazily + add_array_constraint(lazy, true); // added lazily #if 0 // old code for adding, not significantly faster prop.lcnf(!indices_equal_lit, convert(values_equal)); @@ -490,8 +491,10 @@ void arrayst::update_index_map(bool update_all) // (and we cannot do that in record_array_index()) // -- equivalence classes have been merged if(update_all) + { for(std::size_t i=0; i::const_iterator @@ -502,7 +505,7 @@ void arrayst::update_index_map(bool update_all) } #ifdef DEBUG - //print index sets + // print index sets for(index_mapt::const_iterator i1=index_map.begin(); i1!=index_map.end(); @@ -513,9 +516,10 @@ void arrayst::update_index_map(bool update_all) i2++) std::cout << "Index set (" << i1->first << " = " << arrays.find_number(i1->first) << " = " - << from_expr(ns,"",arrays[arrays.find_number(i1->first)]) << "): " - << from_expr(ns,"",*i2) << std::endl; - std::cout << "-----" << std::endl; + << from_expr(ns, "", arrays[arrays.find_number(i1->first)]) + << "): " + << from_expr(ns, "", *i2) << std::endl; + std::cout << "-----" << std::endl; #endif } @@ -634,14 +638,16 @@ void arrayst::add_array_constraints( // add constraint lazy_constraintt lazy(ARRAY_TYPECAST, equal_exprt(index_expr1, index_expr2)); - add_array_constraint(lazy, false); //added immediately + add_array_constraint(lazy, false); // added immediately } } else if(expr.id()==ID_index) { } else - throw "unexpected array expression (add_array_constraints): `"+expr.id_string()+"'"; + throw + "unexpected array expression (add_array_constraints): `"+ + expr.id_string()+"'"; } /*******************************************************************\ @@ -679,7 +685,7 @@ void arrayst::add_array_constraints_with( } lazy_constraintt lazy(ARRAY_WITH, equal_exprt(index_expr, value)); - add_array_constraint(lazy,false); //added immediately + add_array_constraint(lazy, false); // added immediately } // use other array index applications for "else" case @@ -720,7 +726,7 @@ void arrayst::add_array_constraints_with( // add constraint lazy_constraintt lazy(ARRAY_WITH, or_exprt(equality_expr, literal_exprt(guard_lit))); - add_array_constraint(lazy,false); //added immediately + add_array_constraint(lazy, false); // added immediately #if 0 // old code for adding, not significantly faster { @@ -859,7 +865,7 @@ void arrayst::add_array_constraints_array_of( // add constraint lazy_constraintt lazy(ARRAY_OF, equal_exprt(index_expr, expr.op0())); - add_array_constraint(lazy, false); //added immediately + add_array_constraint(lazy, false); // added immediately } } @@ -909,7 +915,7 @@ void arrayst::add_array_constraints_if( lazy_constraintt lazy(ARRAY_IF, or_exprt(literal_exprt(!cond_lit), equal_exprt(index_expr1, index_expr2))); - add_array_constraint(lazy, false); //added immediately + add_array_constraint(lazy, false); // added immediately #if 0 // old code for adding, not significantly faster prop.lcnf(!cond_lit, convert(equal_exprt(index_expr1, index_expr2))); @@ -937,9 +943,9 @@ void arrayst::add_array_constraints_if( // add implication lazy_constraintt lazy(ARRAY_IF, or_exprt(literal_exprt(cond_lit), equal_exprt(index_expr1, index_expr2))); - add_array_constraint(lazy, false); //added immediately + add_array_constraint(lazy, false); // added immediately -#if 0 //old code for adding, not significantly faster +#if 0 // old code for adding, not significantly faster prop.lcnf(cond_lit, convert(equal_exprt(index_expr1, index_expr2))); #endif } diff --git a/src/solvers/flattening/arrays.h b/src/solvers/flattening/arrays.h index b9ade87e37f..51a0799187a 100644 --- a/src/solvers/flattening/arrays.h +++ b/src/solvers/flattening/arrays.h @@ -33,6 +33,7 @@ class arrayst:public equalityt SUB::post_process(); } + // NOLINTNEXTLINE(readability/identifiers) typedef equalityt SUB; literalt record_array_equality(const equal_exprt &expr); @@ -67,7 +68,14 @@ class arrayst:public equalityt index_mapt index_map; // adds array constraints lazily - typedef enum lazy_type {ARRAY_ACKERMANN, ARRAY_WITH, ARRAY_IF, ARRAY_OF, ARRAY_TYPECAST} lazy_typet; + typedef enum lazy_type + { + ARRAY_ACKERMANN, + ARRAY_WITH, + ARRAY_IF, + ARRAY_OF, + ARRAY_TYPECAST + } lazy_typet; struct lazy_constraintt { lazy_typet type; @@ -89,13 +97,20 @@ class arrayst:public equalityt // adds all the constraints eagerly void add_array_constraints(); void add_array_Ackermann_constraints(); - void add_array_constraints_equality(const index_sett &index_set, const array_equalityt &array_equality); - void add_array_constraints(const index_sett &index_set, const exprt &expr); - void add_array_constraints(const index_sett &index_set, const array_equalityt &array_equality); - void add_array_constraints_if(const index_sett &index_set, const if_exprt &exprt); - void add_array_constraints_with(const index_sett &index_set, const with_exprt &expr); - void add_array_constraints_update(const index_sett &index_set, const update_exprt &expr); - void add_array_constraints_array_of(const index_sett &index_set, const array_of_exprt &exprt); + void add_array_constraints_equality( + const index_sett &index_set, const array_equalityt &array_equality); + void add_array_constraints( + const index_sett &index_set, const exprt &expr); + void add_array_constraints( + const index_sett &index_set, const array_equalityt &array_equality); + void add_array_constraints_if( + const index_sett &index_set, const if_exprt &exprt); + void add_array_constraints_with( + const index_sett &index_set, const with_exprt &expr); + void add_array_constraints_update( + const index_sett &index_set, const update_exprt &expr); + void add_array_constraints_array_of( + const index_sett &index_set, const array_of_exprt &exprt); void update_index_map(bool update_all); void update_index_map(std::size_t i); diff --git a/src/solvers/flattening/boolbv.cpp b/src/solvers/flattening/boolbv.cpp index ca602dcd6b6..f5e9aad9f8b 100644 --- a/src/solvers/flattening/boolbv.cpp +++ b/src/solvers/flattening/boolbv.cpp @@ -9,7 +9,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include -#include // abort() #include #include @@ -28,7 +27,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "../floatbv/float_utils.h" -//#define DEBUG +// #define DEBUG /*******************************************************************\ @@ -62,12 +61,14 @@ bool boolbvt::literal( boolbv_mapt::mappingt::const_iterator it_m= map.mapping.find(identifier); - if(it_m==map.mapping.end()) return true; + if(it_m==map.mapping.end()) + return true; const boolbv_mapt::map_entryt &map_entry=it_m->second; assert(bit cache_result= bv_cache.insert(std::make_pair(expr, bvt())); if(!cache_result.second) { - //std::cerr << "Cache hit on " << expr << "\n"; + #ifdef DEBUG + std::cout << "Cache hit on " << expr << "\n"; + #endif return cache_result.first->second; } @@ -155,7 +158,8 @@ const bvt& boolbvt::convert_bv(const exprt &expr) // check forall_literals(it, cache_result.first->second) { - if(freeze_all && !it->is_constant()) prop.set_frozen(*it); + if(freeze_all && !it->is_constant()) + prop.set_frozen(*it); if(it->var_no()==literalt::unused_var_no()) { error() << "unused_var_no: " << expr.pretty() << eom; @@ -328,7 +332,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr) return convert_array_of(to_array_of_expr(expr)); else if(expr.id()==ID_let) { - //const let_exprt &let_expr=to_let_expr(expr); + // const let_exprt &let_expr=to_let_expr(expr); throw "let is todo"; } else if(expr.id()==ID_function_application) @@ -349,8 +353,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr) assert(expr.operands().size()==2); bvt bv0=convert_bitvector(expr.op0()); bvt bv1=convert_bitvector(expr.op1()); - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.type()); + float_utilst float_utils(prop, to_floatbv_type(expr.type())); bvt bv=expr.id()==ID_float_debug1? float_utils.debug1(bv0, bv1): float_utils.debug2(bv0, bv1); @@ -557,8 +560,7 @@ literalt boolbvt::convert_rest(const exprt &expr) if(expr.operands().size()!=2) throw "notequal expects two operands"; - return !convert_equality( - equal_exprt(expr.op0(), expr.op1())); + return !convert_equality(equal_exprt(expr.op0(), expr.op1())); } else if(expr.id()==ID_ieee_float_equal || expr.id()==ID_ieee_float_notequal) @@ -644,8 +646,7 @@ literalt boolbvt::convert_rest(const exprt &expr) if(expr.op0().type().id()==ID_floatbv) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.op0().type()); + float_utilst float_utils(prop, to_floatbv_type(expr.op0().type())); return float_utils.is_NaN(bv); } else if(expr.op0().type().id()==ID_fixedbv) @@ -660,8 +661,7 @@ literalt boolbvt::convert_rest(const exprt &expr) if(expr.op0().type().id()==ID_floatbv) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.op0().type()); + float_utilst float_utils(prop, to_floatbv_type(expr.op0().type())); return prop.land( !float_utils.is_infinity(bv), !float_utils.is_NaN(bv)); @@ -678,8 +678,7 @@ literalt boolbvt::convert_rest(const exprt &expr) if(expr.op0().type().id()==ID_floatbv) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.op0().type()); + float_utilst float_utils(prop, to_floatbv_type(expr.op0().type())); return float_utils.is_infinity(bv); } else if(expr.op0().type().id()==ID_fixedbv) @@ -694,8 +693,7 @@ literalt boolbvt::convert_rest(const exprt &expr) if(expr.op0().type().id()==ID_floatbv) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.op0().type()); + float_utilst float_utils(prop, to_floatbv_type(expr.op0().type())); return float_utils.is_normal(bv); } else if(expr.op0().type().id()==ID_fixedbv) @@ -719,7 +717,8 @@ Function: boolbvt::boolbv_set_equality_to_true bool boolbvt::boolbv_set_equality_to_true(const equal_exprt &expr) { - if(!equality_propagation) return true; + if(!equality_propagation) + return true; const typet &type=ns.follow(expr.lhs().type()); @@ -738,7 +737,8 @@ bool boolbvt::boolbv_set_equality_to_true(const equal_exprt &expr) map.set_literals(identifier, type, bv1); - if(freeze_all) set_frozen(bv1); + if(freeze_all) + set_frozen(bv1); return false; } @@ -848,16 +848,20 @@ Function: boolbvt::is_unbounded_array bool boolbvt::is_unbounded_array(const typet &type) const { - if(type.id()==ID_symbol) return is_unbounded_array(ns.follow(type)); + if(type.id()==ID_symbol) + return is_unbounded_array(ns.follow(type)); - if(type.id()!=ID_array) return false; + if(type.id()!=ID_array) + return false; - if(unbounded_array==U_ALL) return true; + if(unbounded_array==U_ALL) + return true; const exprt &size=to_array_type(type).size(); mp_integer s; - if(to_integer(size, s)) return true; + if(to_integer(size, s)) + return true; if(unbounded_array==U_AUTO) if(s>1000) // magic number! diff --git a/src/solvers/flattening/boolbv.h b/src/solvers/flattening/boolbv.h index 535d3e05541..a092be8c3af 100644 --- a/src/solvers/flattening/boolbv.h +++ b/src/solvers/flattening/boolbv.h @@ -42,7 +42,7 @@ class boolbvt:public arrayst { } - virtual const bvt& convert_bv(const exprt &expr); // check cache + virtual const bvt &convert_bv(const exprt &expr); // check cache virtual bvt convert_bitvector(const exprt &expr); // no cache // overloading @@ -101,6 +101,7 @@ class boolbvt:public arrayst virtual literalt convert_rest(const exprt &expr) override; virtual bool boolbv_set_equality_to_true(const equal_exprt &expr); + // NOLINTNEXTLINE(readability/identifiers) typedef arrayst SUB; void conversion_failed(const exprt &expr, bvt &bv) @@ -124,7 +125,8 @@ class boolbvt:public arrayst virtual literalt convert_extractbit(const extractbit_exprt &expr); virtual literalt convert_overflow(const exprt &expr); virtual literalt convert_equality(const equal_exprt &expr); - virtual literalt convert_verilog_case_equality(const binary_relation_exprt &expr); + virtual literalt convert_verilog_case_equality( + const binary_relation_exprt &expr); virtual literalt convert_ieee_float_rel(const exprt &expr); virtual literalt convert_quantifier(const exprt &expr); @@ -168,7 +170,8 @@ class boolbvt:public arrayst virtual bvt convert_bv_reduction(const unary_exprt &expr); virtual bvt convert_not(const not_exprt &expr); virtual bvt convert_power(const binary_exprt &expr); - virtual bvt convert_function_application(const function_application_exprt &expr); + virtual bvt convert_function_application( + const function_application_exprt &expr); virtual void make_bv_expr(const typet &type, const bvt &bv, exprt &dest); virtual void make_free_bv_expr(const typet &type, exprt &dest); diff --git a/src/solvers/flattening/boolbv_abs.cpp b/src/solvers/flattening/boolbv_abs.cpp index 2ff88b35510..0a9f7a9c4a5 100644 --- a/src/solvers/flattening/boolbv_abs.cpp +++ b/src/solvers/flattening/boolbv_abs.cpp @@ -54,8 +54,7 @@ bvt boolbvt::convert_abs(const exprt &expr) } else if(bvtype==IS_FLOAT) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.type()); + float_utilst float_utils(prop, to_floatbv_type(expr.type())); return float_utils.abs(op_bv); } diff --git a/src/solvers/flattening/boolbv_add_sub.cpp b/src/solvers/flattening/boolbv_add_sub.cpp index fa0e936602e..38a7effc5af 100644 --- a/src/solvers/flattening/boolbv_add_sub.cpp +++ b/src/solvers/flattening/boolbv_add_sub.cpp @@ -127,8 +127,7 @@ bvt boolbvt::convert_add_sub(const exprt &expr) if(type.subtype().id()==ID_floatbv) { // needs to change due to rounding mode - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(subtype); + float_utilst float_utils(prop, to_floatbv_type(subtype)); tmp_result=float_utils.add_sub(tmp_result, tmp_op, subtract); } else @@ -146,8 +145,7 @@ bvt boolbvt::convert_add_sub(const exprt &expr) else if(type.id()==ID_floatbv) { // needs to change due to rounding mode - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(arithmetic_type); + float_utilst float_utils(prop, to_floatbv_type(arithmetic_type)); bv=float_utils.add_sub(bv, op, subtract); } else if(no_overflow) diff --git a/src/solvers/flattening/boolbv_bv_rel.cpp b/src/solvers/flattening/boolbv_bv_rel.cpp index 58520d0ec97..901cd31fa04 100644 --- a/src/solvers/flattening/boolbv_bv_rel.cpp +++ b/src/solvers/flattening/boolbv_bv_rel.cpp @@ -46,8 +46,7 @@ literalt boolbvt::convert_bv_rel(const exprt &expr) { if(bvtype0==IS_FLOAT) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(op0.type()); + float_utilst float_utils(prop, to_floatbv_type(op0.type())); if(rel==ID_le) return float_utils.relation(bv0, float_utilst::LE, bv1); diff --git a/src/solvers/flattening/boolbv_equality.cpp b/src/solvers/flattening/boolbv_equality.cpp index 8fedbbaed8d..53cbb624815 100644 --- a/src/solvers/flattening/boolbv_equality.cpp +++ b/src/solvers/flattening/boolbv_equality.cpp @@ -45,7 +45,6 @@ literalt boolbvt::convert_equality(const equal_exprt &expr) if(has_byte_operator(expr)) { exprt tmp=flatten_byte_operators(expr, ns); - //std::cout << "X: " << from_expr(ns, "", tmp) << std::endl; return record_array_equality(to_equal_expr(tmp)); } @@ -86,7 +85,8 @@ Function: boolbvt::convert_verilog_case_equality \*******************************************************************/ -literalt boolbvt::convert_verilog_case_equality(const binary_relation_exprt &expr) +literalt boolbvt::convert_verilog_case_equality( + const binary_relation_exprt &expr) { // This is 4-valued comparison, i.e., z===z, x===x etc. // The result is always Boolean. diff --git a/src/solvers/flattening/boolbv_extractbits.cpp b/src/solvers/flattening/boolbv_extractbits.cpp index 7ec5a6987c4..5bf2ac0f4c4 100644 --- a/src/solvers/flattening/boolbv_extractbits.cpp +++ b/src/solvers/flattening/boolbv_extractbits.cpp @@ -69,7 +69,8 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr) throw 0; } - if(o2>o1) std::swap(o1, o2); + if(o2>o1) + std::swap(o1, o2); // now o2<=o1 diff --git a/src/solvers/flattening/boolbv_floatbv_op.cpp b/src/solvers/flattening/boolbv_floatbv_op.cpp index f05a8b39b5d..087faa0485a 100644 --- a/src/solvers/flattening/boolbv_floatbv_op.cpp +++ b/src/solvers/flattening/boolbv_floatbv_op.cpp @@ -48,33 +48,36 @@ bvt boolbvt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr) if(src_type.id()==ID_floatbv && dest_type.id()==ID_floatbv) { - float_utils.spec=to_floatbv_type(src_type); - return float_utils.conversion(bv0, to_floatbv_type(dest_type)); + float_utils.spec=ieee_float_spect(to_floatbv_type(src_type)); + return + float_utils.conversion( + bv0, + ieee_float_spect(to_floatbv_type(dest_type))); } else if(src_type.id()==ID_signedbv && dest_type.id()==ID_floatbv) { - float_utils.spec=to_floatbv_type(dest_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); return float_utils.from_signed_integer(bv0); } else if(src_type.id()==ID_unsignedbv && dest_type.id()==ID_floatbv) { - float_utils.spec=to_floatbv_type(dest_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); return float_utils.from_unsigned_integer(bv0); } else if(src_type.id()==ID_floatbv && dest_type.id()==ID_signedbv) { std::size_t dest_width=to_signedbv_type(dest_type).get_width(); - float_utils.spec=to_floatbv_type(src_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(src_type)); return float_utils.to_signed_integer(bv0, dest_width); } else if(src_type.id()==ID_floatbv && dest_type.id()==ID_unsignedbv) { std::size_t dest_width=to_unsignedbv_type(dest_type).get_width(); - float_utils.spec=to_floatbv_type(src_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(src_type)); return float_utils.to_unsigned_integer(bv0, dest_width); } else @@ -122,7 +125,7 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr) if(type.id()==ID_floatbv) { - float_utils.spec=to_floatbv_type(expr.type()); + float_utils.spec=ieee_float_spect(to_floatbv_type(expr.type())); if(expr.id()==ID_floatbv_plus) return float_utils.add_sub(bv0, bv1, false); @@ -143,7 +146,7 @@ bvt boolbvt::convert_floatbv_op(const exprt &expr) if(subtype.id()==ID_floatbv) { - float_utils.spec=to_floatbv_type(subtype); + float_utils.spec=ieee_float_spect(to_floatbv_type(subtype)); std::size_t width=boolbv_width(type); std::size_t sub_width=boolbv_width(subtype); diff --git a/src/solvers/flattening/boolbv_get.cpp b/src/solvers/flattening/boolbv_get.cpp index 6787d658db5..3e74ec872c1 100644 --- a/src/solvers/flattening/boolbv_get.cpp +++ b/src/solvers/flattening/boolbv_get.cpp @@ -17,7 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "boolbv.h" #include "boolbv_type.h" -//#define DEBUG +// #define DEBUG /*******************************************************************\ @@ -148,11 +148,15 @@ exprt boolbvt::bv_get_rec( } else if(type.id()==ID_struct_tag) { - return bv_get_rec(bv, unknown, offset, ns.follow_tag(to_struct_tag_type(type))); + return + bv_get_rec( + bv, unknown, offset, ns.follow_tag(to_struct_tag_type(type))); } else if(type.id()==ID_union_tag) { - return bv_get_rec(bv, unknown, offset, ns.follow_tag(to_union_tag_type(type))); + return + bv_get_rec( + bv, unknown, offset, ns.follow_tag(to_union_tag_type(type))); } else if(type.id()==ID_struct) { @@ -248,6 +252,7 @@ exprt boolbvt::bv_get_rec( if(unknown[bit_nr]) ch='0'; else + { switch(prop.l_get(bv[bit_nr]).get_value()) { case tvt::tv_enumt::TV_FALSE: ch='0'; break; @@ -255,6 +260,7 @@ exprt boolbvt::bv_get_rec( case tvt::tv_enumt::TV_UNKNOWN: ch='0'; break; default: assert(false); } + } value=ch+value; } @@ -361,7 +367,8 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const exprt size=simplify_expr(get(size_expr), ns); // no size, give up - if(size.is_nil()) return nil_exprt(); + if(size.is_nil()) + return nil_exprt(); // get the numeric value, unless it's infinity mp_integer size_mpint; diff --git a/src/solvers/flattening/boolbv_ieee_float_rel.cpp b/src/solvers/flattening/boolbv_ieee_float_rel.cpp index 33ce7e76746..bbdea7aea13 100644 --- a/src/solvers/flattening/boolbv_ieee_float_rel.cpp +++ b/src/solvers/flattening/boolbv_ieee_float_rel.cpp @@ -44,8 +44,7 @@ literalt boolbvt::convert_ieee_float_rel(const exprt &expr) if(bv0.size()==bv1.size() && !bv0.empty() && bvtype0==IS_FLOAT && bvtype1==IS_FLOAT) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(op0.type()); + float_utilst float_utils(prop, to_floatbv_type(op0.type())); if(rel==ID_ieee_float_equal) return float_utils.relation(bv0, float_utilst::EQ, bv1); diff --git a/src/solvers/flattening/boolbv_index.cpp b/src/solvers/flattening/boolbv_index.cpp index e01b18ea5c0..ec1ef27dd98 100644 --- a/src/solvers/flattening/boolbv_index.cpp +++ b/src/solvers/flattening/boolbv_index.cpp @@ -130,8 +130,10 @@ bvt boolbvt::convert_index(const index_exprt &expr) equal_exprt value_equality(result, array.op0()); - binary_relation_exprt lower_bound(from_integer(0, index.type()), ID_le, index); - binary_relation_exprt upper_bound(index, ID_lt, from_integer(array_size, index.type())); + binary_relation_exprt lower_bound( + from_integer(0, index.type()), ID_le, index); + binary_relation_exprt upper_bound( + index, ID_lt, from_integer(array_size, index.type())); if(lower_bound.lhs().is_nil() || upper_bound.rhs().is_nil()) @@ -347,7 +349,7 @@ bvt boolbvt::convert_index( // The assertion below is disabled as we want to be able // to run CBMC without simplifier. // Expression simplification should remove these cases - //assert(array.id()!=ID_array_of && + // assert(array.id()!=ID_array_of && // array.id()!=ID_array); // If not there are large improvements possible as above diff --git a/src/solvers/flattening/boolbv_map.cpp b/src/solvers/flattening/boolbv_map.cpp index 1038d372244..dbbb097e7b2 100644 --- a/src/solvers/flattening/boolbv_map.cpp +++ b/src/solvers/flattening/boolbv_map.cpp @@ -13,7 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "boolbv_map.h" #include "boolbv_width.h" -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include diff --git a/src/solvers/flattening/boolbv_mod.cpp b/src/solvers/flattening/boolbv_mod.cpp index 3313207f2d6..5ba8f5da37e 100644 --- a/src/solvers/flattening/boolbv_mod.cpp +++ b/src/solvers/flattening/boolbv_mod.cpp @@ -22,9 +22,12 @@ Function: boolbvt::convert_mod bvt boolbvt::convert_mod(const mod_exprt &expr) { + #if 0 + // TODO if(expr.type().id()==ID_floatbv) { } + #endif if(expr.type().id()!=ID_unsignedbv && expr.type().id()!=ID_signedbv) diff --git a/src/solvers/flattening/boolbv_quantifier.cpp b/src/solvers/flattening/boolbv_quantifier.cpp index 17c13666564..7cfc7f9e03e 100644 --- a/src/solvers/flattening/boolbv_quantifier.cpp +++ b/src/solvers/flattening/boolbv_quantifier.cpp @@ -30,8 +30,10 @@ Function: expr_eq bool expr_eq(const exprt &expr1, const exprt &expr2) { exprt e1=expr1, e2=expr2; - if(expr1.id()==ID_typecast) e1=expr1.op0(); - if(expr2.id()==ID_typecast) e2=expr2.op0(); + if(expr1.id()==ID_typecast) + e1=expr1.op0(); + if(expr2.id()==ID_typecast) + e2=expr2.op0(); return e1==e2; } @@ -65,9 +67,11 @@ exprt get_quantifier_var_min( */ for(auto &x : quantifier_expr.operands()) { - if(x.id()!=ID_not) continue; + if(x.id()!=ID_not) + continue; exprt y=x.op0(); - if(y.id()!=ID_ge) continue; + if(y.id()!=ID_ge) + continue; if(expr_eq(var_expr, y.op0()) && y.op1().id()==ID_constant) { return y.op1(); @@ -82,7 +86,8 @@ exprt get_quantifier_var_min( */ for(auto &x : quantifier_expr.operands()) { - if(x.id()!=ID_ge) continue; + if(x.id()!=ID_ge) + continue; if(expr_eq(var_expr, x.op0()) && x.op1().id()==ID_constant) { return x.op1(); @@ -121,7 +126,8 @@ exprt get_quantifier_var_max( */ for(auto &x : quantifier_expr.operands()) { - if(x.id()!=ID_ge) continue; + if(x.id()!=ID_ge) + continue; if(expr_eq(var_expr, x.op0()) && x.op1().id()==ID_constant) { exprt over_expr=x.op1(); @@ -146,9 +152,11 @@ exprt get_quantifier_var_max( */ for(auto &x : quantifier_expr.operands()) { - if(x.id()!=ID_not) continue; + if(x.id()!=ID_not) + continue; exprt y=x.op0(); - if(y.id()!=ID_ge) continue; + if(y.id()!=ID_ge) + continue; if(expr_eq(var_expr, y.op0()) && y.op1().id()==ID_constant) { exprt over_expr=y.op1(); @@ -283,7 +291,8 @@ void boolbvt::post_process_quantifiers() { std::set instances; - if(quantifier_list.empty()) return; + if(quantifier_list.empty()) + return; for(auto it=quantifier_list.begin(); it!=quantifier_list.end(); diff --git a/src/solvers/flattening/boolbv_reduction.cpp b/src/solvers/flattening/boolbv_reduction.cpp index 2b56afcaf02..e863657066b 100644 --- a/src/solvers/flattening/boolbv_reduction.cpp +++ b/src/solvers/flattening/boolbv_reduction.cpp @@ -46,7 +46,7 @@ literalt boolbvt::convert_reduction(const unary_exprt &expr) { switch(op) { - case O_OR: l=prop.lor (l, op_bv[i]); break; + case O_OR: l=prop.lor(l, op_bv[i]); break; case O_AND: l=prop.land(l, op_bv[i]); break; case O_XOR: l=prop.lxor(l, op_bv[i]); break; } @@ -110,9 +110,12 @@ bvt boolbvt::convert_bv_reduction(const unary_exprt &expr) { switch(op) { - case O_OR: l0=prop.lor (l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; - case O_AND: l0=prop.land(l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; - case O_XOR: l0=prop.lxor(l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; + case O_OR: + l0=prop.lor(l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; + case O_AND: + l0=prop.land(l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; + case O_XOR: + l0=prop.lxor(l0, op_bv[i]); l1=prop.lor(l1, op_bv[i+1]); break; } } diff --git a/src/solvers/flattening/boolbv_struct.cpp b/src/solvers/flattening/boolbv_struct.cpp index 73d929504b0..e1b0b29593a 100644 --- a/src/solvers/flattening/boolbv_struct.cpp +++ b/src/solvers/flattening/boolbv_struct.cpp @@ -44,7 +44,7 @@ bvt boolbvt::convert_struct(const struct_exprt &expr) std::size_t offset=0; exprt::operandst::const_iterator op_it=expr.operands().begin(); - for(const auto & comp : components) + for(const auto &comp : components) { const typet &subtype=comp.type(); const exprt &op=*op_it; diff --git a/src/solvers/flattening/boolbv_typecast.cpp b/src/solvers/flattening/boolbv_typecast.cpp index d193cd9d63a..5ffcd763f74 100644 --- a/src/solvers/flattening/boolbv_typecast.cpp +++ b/src/solvers/flattening/boolbv_typecast.cpp @@ -63,12 +63,20 @@ bool boolbvt::type_conversion( bvtypet src_bvtype=get_bvtype(src_type); if(src_bvtype==IS_C_BIT_FIELD) - return type_conversion( - c_bit_field_replacement_type(to_c_bit_field_type(src_type), ns), src, dest_type, dest); + return + type_conversion( + c_bit_field_replacement_type(to_c_bit_field_type(src_type), ns), + src, + dest_type, + dest); if(dest_bvtype==IS_C_BIT_FIELD) - return type_conversion( - src_type, src, c_bit_field_replacement_type(to_c_bit_field_type(dest_type), ns), dest); + return + type_conversion( + src_type, + src, + c_bit_field_replacement_type(to_c_bit_field_type(dest_type), ns), + dest); std::size_t src_width=src.size(); std::size_t dest_width=boolbv_width(dest_type); @@ -98,8 +106,16 @@ bool boolbvt::type_conversion( bvt lower, upper, lower_res, upper_res; lower.assign(src.begin(), src.begin()+src.size()/2); upper.assign(src.begin()+src.size()/2, src.end()); - type_conversion(ns.follow(src_type.subtype()), lower, ns.follow(dest_type.subtype()), lower_res); - type_conversion(ns.follow(src_type.subtype()), upper, ns.follow(dest_type.subtype()), upper_res); + type_conversion( + ns.follow(src_type.subtype()), + lower, + ns.follow(dest_type.subtype()), + lower_res); + type_conversion( + ns.follow(src_type.subtype()), + upper, + ns.follow(dest_type.subtype()), + upper_res); assert(lower_res.size()+upper_res.size()==dest_width); dest=lower_res; dest.insert(dest.end(), upper_res.begin(), upper_res.end()); @@ -183,13 +199,13 @@ bool boolbvt::type_conversion( case IS_SIGNED: // signed to float case IS_C_ENUM: - float_utils.spec=to_floatbv_type(dest_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); dest=float_utils.from_signed_integer(src); return false; case IS_UNSIGNED: // unsigned to float case IS_C_BOOL: // _Bool to float - float_utils.spec=to_floatbv_type(dest_type); + float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); dest=float_utils.from_unsigned_integer(src); return false; @@ -204,8 +220,7 @@ bool boolbvt::type_conversion( // bool to float // build a one - ieee_floatt f; - f.spec=to_floatbv_type(dest_type); + ieee_floatt f(to_floatbv_type(dest_type)); f.from_integer(1); dest=convert_bv(f.to_expr()); @@ -226,10 +241,12 @@ bool boolbvt::type_conversion( { // fixed to fixed - std::size_t dest_fraction_bits=to_fixedbv_type(dest_type).get_fraction_bits(), - dest_int_bits=dest_width-dest_fraction_bits; - std::size_t op_fraction_bits=to_fixedbv_type(src_type).get_fraction_bits(), - op_int_bits=src_width-op_fraction_bits; + std::size_t dest_fraction_bits= + to_fixedbv_type(dest_type).get_fraction_bits(); + std::size_t dest_int_bits=dest_width-dest_fraction_bits; + std::size_t op_fraction_bits= + to_fixedbv_type(src_type).get_fraction_bits(); + std::size_t op_int_bits=src_width-op_fraction_bits; dest.resize(dest_width); @@ -498,8 +515,7 @@ bool boolbvt::type_conversion( if(src_bvtype==IS_FLOAT) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(src_type); + float_utilst float_utils(prop, to_floatbv_type(src_type)); dest[0]=!float_utils.is_zero(src); } else if(src_bvtype==IS_C_BOOL) @@ -520,8 +536,7 @@ bool boolbvt::type_conversion( } else if(dest_type.id()==ID_struct) { - const struct_typet &dest_struct = - to_struct_type(dest_type); + const struct_typet &dest_struct=to_struct_type(dest_type); if(src_type.id()==ID_struct) { @@ -529,8 +544,7 @@ bool boolbvt::type_conversion( dest.resize(dest_width, const_literal(false)); - const struct_typet &op_struct = - to_struct_type(src_type); + const struct_typet &op_struct=to_struct_type(src_type); const struct_typet::componentst &dest_comp= dest_struct.components(); @@ -558,7 +572,8 @@ bool boolbvt::type_conversion( { std::size_t offset=dest_offsets[i]; std::size_t comp_width=boolbv_width(dest_comp[i].type()); - if(comp_width==0) continue; + if(comp_width==0) + continue; op_mapt::const_iterator it= op_map.find(dest_comp[i].get_name()); @@ -592,7 +607,6 @@ bool boolbvt::type_conversion( return false; } } - } return true; diff --git a/src/solvers/flattening/boolbv_unary_minus.cpp b/src/solvers/flattening/boolbv_unary_minus.cpp index 2eb285a48d5..20a05b32df1 100644 --- a/src/solvers/flattening/boolbv_unary_minus.cpp +++ b/src/solvers/flattening/boolbv_unary_minus.cpp @@ -81,8 +81,7 @@ bvt boolbvt::convert_unary_minus(const unary_exprt &expr) if(type.subtype().id()==ID_floatbv) { - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(subtype); + float_utilst float_utils(prop, to_floatbv_type(subtype)); tmp_result=float_utils.negate(tmp_op); } else @@ -109,8 +108,7 @@ bvt boolbvt::convert_unary_minus(const unary_exprt &expr) else if(bvtype==IS_FLOAT && op_bvtype==IS_FLOAT) { assert(!no_overflow); - float_utilst float_utils(prop); - float_utils.spec=to_floatbv_type(expr.type()); + float_utilst float_utils(prop, to_floatbv_type(expr.type())); return float_utils.negate(op_bv); } else if((op_bvtype==IS_SIGNED || op_bvtype==IS_UNSIGNED) && diff --git a/src/solvers/flattening/boolbv_union.cpp b/src/solvers/flattening/boolbv_union.cpp index 0e31083df0d..92ac97d0c2c 100644 --- a/src/solvers/flattening/boolbv_union.cpp +++ b/src/solvers/flattening/boolbv_union.cpp @@ -50,7 +50,8 @@ bvt boolbvt::convert_union(const union_exprt &expr) } else { - assert(config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_BIG_ENDIAN); + assert( + config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_BIG_ENDIAN); endianness_mapt map_u(expr.type(), false, ns); endianness_mapt map_op(expr.op0().type(), false, ns); diff --git a/src/solvers/flattening/boolbv_with.cpp b/src/solvers/flattening/boolbv_with.cpp index 2c5a2f5e556..d98cd6be3b9 100644 --- a/src/solvers/flattening/boolbv_with.cpp +++ b/src/solvers/flattening/boolbv_with.cpp @@ -66,11 +66,12 @@ bvt boolbvt::convert_with(const exprt &expr) { bv.swap(prev_bv); - convert_with(expr.op0().type(), - ops[op_no], - ops[op_no+1], - prev_bv, - bv); + convert_with( + expr.op0().type(), + ops[op_no], + ops[op_no+1], + prev_bv, + bv); } return bv; @@ -106,7 +107,8 @@ void boolbvt::convert_with( type.id()==ID_signedbv) return convert_with_bv(type, op1, op2, prev_bv, next_bv); else if(type.id()==ID_struct) - return convert_with_struct(to_struct_type(type), op1, op2, prev_bv, next_bv); + return + convert_with_struct(to_struct_type(type), op1, op2, prev_bv, next_bv); else if(type.id()==ID_union) return convert_with_union(to_union_type(type), op1, op2, prev_bv, next_bv); else if(type.id()==ID_symbol) @@ -276,7 +278,6 @@ void boolbvt::convert_with_struct( it!=components.end(); it++) { - const typet &subtype=it->type(); std::size_t sub_width=boolbv_width(subtype); @@ -348,7 +349,8 @@ void boolbvt::convert_with_union( } else { - assert(config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_BIG_ENDIAN); + assert( + config.ansi_c.endianness==configt::ansi_ct::endiannesst::IS_BIG_ENDIAN); endianness_mapt map_u(type, false, ns); endianness_mapt map_op2(op2.type(), false, ns); diff --git a/src/solvers/flattening/bv_pointers.cpp b/src/solvers/flattening/bv_pointers.cpp index 673a81f6e5a..777d51ba104 100644 --- a/src/solvers/flattening/bv_pointers.cpp +++ b/src/solvers/flattening/bv_pointers.cpp @@ -174,7 +174,8 @@ bool bv_pointerst::convert_address_of_rec( array_type.id()==ID_incomplete_array || array_type.id()==ID_string_constant) { - if(convert_address_of_rec(array, bv)) return true; + if(convert_address_of_rec(array, bv)) + return true; assert(bv.size()==bits); } else @@ -386,7 +387,8 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr) forall_operands(it, expr) { - if(it->type().id()==ID_pointer) continue; + if(it->type().id()==ID_pointer) + continue; if(it->type().id()!=ID_unsignedbv && it->type().id()!=ID_signedbv) @@ -630,6 +632,7 @@ exprt bv_pointerst::bv_get_rec( if(unknown[bit_nr]) ch='0'; else + { switch(prop.l_get(bv[bit_nr]).get_value()) { case tvt::tv_enumt::TV_FALSE: ch='0'; break; @@ -637,6 +640,7 @@ exprt bv_pointerst::bv_get_rec( case tvt::tv_enumt::TV_UNKNOWN: ch='0'; break; default: assert(false); } + } value=ch+value; @@ -846,7 +850,8 @@ void bv_pointerst::do_postponed( literalt l1=bv_utils.equal(bv, saved_bv); literalt l2=postponed.bv.front(); - if(!is_dynamic) l2=!l2; + if(!is_dynamic) + l2=!l2; prop.l_set_to(prop.limplies(l1, l2), true); } diff --git a/src/solvers/flattening/bv_pointers.h b/src/solvers/flattening/bv_pointers.h index 2300829e188..f92fdd08a7a 100644 --- a/src/solvers/flattening/bv_pointers.h +++ b/src/solvers/flattening/bv_pointers.h @@ -23,6 +23,7 @@ class bv_pointerst:public boolbvt protected: pointer_logict pointer_logic; + // NOLINTNEXTLINE(readability/identifiers) typedef boolbvt SUB; unsigned object_bits, offset_bits, bits; @@ -49,7 +50,8 @@ class bv_pointerst:public boolbvt void offset_arithmetic(bvt &bv, const mp_integer &x); void offset_arithmetic(bvt &bv, const mp_integer &factor, const exprt &index); - void offset_arithmetic(bvt &bv, const mp_integer &factor, const bvt &index_bv); + void offset_arithmetic( + bvt &bv, const mp_integer &factor, const bvt &index_bv); struct postponedt { diff --git a/src/solvers/flattening/bv_utils.cpp b/src/solvers/flattening/bv_utils.cpp index 9d8bc79aa68..dcecce593c4 100644 --- a/src/solvers/flattening/bv_utils.cpp +++ b/src/solvers/flattening/bv_utils.cpp @@ -96,7 +96,8 @@ bvt bv_utilst::extract(const bvt &a, std::size_t first, std::size_t last) bvt result=a; result.resize(last+1); - if(first!=0) result.erase(result.begin(), result.begin()+first); + if(first!=0) + result.erase(result.begin(), result.begin()+first); assert(result.size()==last-first+1); return result; @@ -269,13 +270,13 @@ literalt bv_utilst::full_adder( y = carry_in; constantProp = (a.is_true()) ? 1 : 0; } - else if (b.is_constant()) + else if(b.is_constant()) { x = a; y = carry_in; constantProp = (b.is_true()) ? 1 : 0; } - else if (carry_in.is_constant()) + else if(carry_in.is_constant()) { x = a; y = b; @@ -294,8 +295,8 @@ literalt bv_utilst::full_adder( else if(constantProp == 0) { // At least one input bit is 0 - carry_out = prop.land(x,y); - sum = prop.lxor(x,y); + carry_out = prop.land(x, y); + sum = prop.lxor(x, y); } else { @@ -313,23 +314,23 @@ literalt bv_utilst::full_adder( prop.lcnf(b, carry_in, !carry_out); // If both carry out and sum are 1 then all inputs are 1 - prop.lcnf( a, !sum, !carry_out); - prop.lcnf( b, !sum, !carry_out); + prop.lcnf(a, !sum, !carry_out); + prop.lcnf(b, !sum, !carry_out); prop.lcnf(carry_in, !sum, !carry_out); // If both carry out and sum are 0 then all inputs are 0 - prop.lcnf( !a, sum, carry_out); - prop.lcnf( !b, sum, carry_out); + prop.lcnf(!a, sum, carry_out); + prop.lcnf(!b, sum, carry_out); prop.lcnf(!carry_in, sum, carry_out); // If all of the inputs are 1 or all are 0 it sets the sum prop.lcnf(!a, !b, !carry_in, sum); - prop.lcnf( a, b, carry_in, !sum); + prop.lcnf(a, b, carry_in, !sum); } return sum; } - else + else // NOLINT(readability/braces) #endif // OPTIMAL_FULL_ADDER { // trivial encoding @@ -396,9 +397,9 @@ literalt bv_utilst::carry(literalt a, literalt b, literalt c) (x=((a AND b) OR (a AND c) OR (b AND c))); */ - prop.lcnf( a, b, !x); - prop.lcnf( a, !b, c, !x); - prop.lcnf( a, !b, !c, x); + prop.lcnf(a, b, !x); + prop.lcnf(a, !b, c, !x); + prop.lcnf(a, !b, !c, x); prop.lcnf(!a, b, c, !x); prop.lcnf(!a, b, !c, x); prop.lcnf(!a, !b, x); @@ -573,7 +574,8 @@ literalt bv_utilst::overflow_add( literalt sign_the_same=prop.lequal(op0[op0.size()-1], op1[op1.size()-1]); bvt result=add(op0, op1); - return prop.land(sign_the_same, prop.lxor(result[result.size()-1], old_sign)); + return + prop.land(sign_the_same, prop.lxor(result[result.size()-1], old_sign)); } else if(rep==UNSIGNED) { @@ -647,7 +649,8 @@ void bv_utilst::adder_no_overflow( // and the sign of the sum is the opposite literalt old_sign=sum[sum.size()-1]; - literalt sign_the_same=prop.lequal(sum[sum.size()-1], tmp_op[tmp_op.size()-1]); + literalt sign_the_same= + prop.lequal(sum[sum.size()-1], tmp_op[tmp_op.size()-1]); literalt carry; adder(sum, tmp_op, const_literal(subtract), carry); @@ -1097,7 +1100,8 @@ Function: bv_utilst::signed_multiplier bvt bv_utilst::signed_multiplier(const bvt &op0, const bvt &op1) { - if(op0.empty() || op1.empty()) return bvt(); + if(op0.empty() || op1.empty()) + return bvt(); literalt sign0=op0[op0.size()-1]; literalt sign1=op1[op1.size()-1]; @@ -1192,7 +1196,8 @@ bvt bv_utilst::signed_multiplier_no_overflow( const bvt &op0, const bvt &op1) { - if(op0.empty() || op1.empty()) return bvt(); + if(op0.empty() || op1.empty()) + return bvt(); literalt sign0=op0[op0.size()-1]; literalt sign1=op1[op1.size()-1]; @@ -1277,7 +1282,8 @@ void bv_utilst::signed_divider( bvt &res, bvt &rem) { - if(op0.empty() || op1.empty()) return; + if(op0.empty() || op1.empty()) + return; bvt _op0(op0), _op1(op1); @@ -1472,7 +1478,7 @@ literalt bv_utilst::equal_const_rec(bvt &var, bvt &constant) assert(size == constant.size()); assert(is_constant(constant)); - if (size == 1) + if(size == 1) { literalt comp = prop.lequal(var[size - 1], constant[size - 1]); var.pop_back(); @@ -1485,7 +1491,7 @@ literalt bv_utilst::equal_const_rec(bvt &var, bvt &constant) equal_const_cachet::iterator entry = equal_const_cache.find(index); - if (entry != equal_const_cache.end()) + if(entry != equal_const_cache.end()) { return entry->second; } @@ -1498,7 +1504,8 @@ literalt bv_utilst::equal_const_rec(bvt &var, bvt &constant) literalt rec = equal_const_rec(var, constant); literalt compare = prop.land(rec, comp); - equal_const_cache.insert(std::pair(index, compare)); + equal_const_cache.insert( + std::pair(index, compare)); return compare; } @@ -1529,7 +1536,7 @@ literalt bv_utilst::equal_const(const bvt &var, const bvt &constant) assert(var.size() == size); assert(!is_constant(var)); - assert( is_constant(constant)); + assert(is_constant(constant)); assert(size >= 2); // These get modified : be careful! @@ -1551,7 +1558,7 @@ literalt bv_utilst::equal_const(const bvt &var, const bvt &constant) for(split = size - 2; split != 0; --split) { - if (constant[split] != top_bit) + if(constant[split] != top_bit) { break; } @@ -1599,10 +1606,10 @@ literalt bv_utilst::equal(const bvt &op0, const bvt &op1) #ifdef COMPACT_EQUAL_CONST // simplify_expr should put the constant on the right // but bit-level simplification may result in the other cases - if (is_constant(op0) && !is_constant(op1) && op0.size() > 2 && + if(is_constant(op0) && !is_constant(op1) && op0.size() > 2 && equal_const_registered.find(op1) != equal_const_registered.end()) return equal_const(op1, op0); - else if (!is_constant(op0) && is_constant(op1) && op0.size() > 2 && + else if(!is_constant(op0) && is_constant(op1) && op0.size() > 2 && equal_const_registered.find(op0) != equal_const_registered.end()) return equal_const(op0, op1); #endif @@ -1633,11 +1640,11 @@ Function: bv_utilst::lt_or_le /* Some clauses are not needed for correctness but they remove models (effectively setting "don't care" bits) and so may be worth including.*/ -//#define INCLUDE_REDUNDANT_CLAUSES +// #define INCLUDE_REDUNDANT_CLAUSES // Saves space but slows the solver // There is a variant that uses the xor as an auxiliary that should improve both -//#define COMPACT_LT_OR_LE +// #define COMPACT_LT_OR_LE @@ -1653,7 +1660,7 @@ literalt bv_utilst::lt_or_le( top1=bv1[bv1.size()-1]; #ifdef COMPACT_LT_OR_LE - if (prop.has_set_to() && prop.cnf_handled_well()) + if(prop.has_set_to() && prop.cnf_handled_well()) { bvt compareBelow; // 1 if a compare is needed below this bit literalt result; @@ -1677,16 +1684,15 @@ literalt bv_utilst::lt_or_le( #endif // Four cases... - prop.lcnf( top0, top1, firstComp); // + + compare needed - prop.lcnf( top0, !top1, !result); // + - result false and no compare needed - prop.lcnf(!top0, top1, result); // - + result true and no compare needed - prop.lcnf(!top0, !top1, firstComp); // - - negated compare needed + prop.lcnf(top0, top1, firstComp); // + + compare needed + prop.lcnf(top0, !top1, !result); // + - result false and no compare needed + prop.lcnf(!top0, top1, result); // - + result true and no compare needed + prop.lcnf(!top0, !top1, firstComp); // - - negated compare needed #ifdef INCLUDE_REDUNDANT_CLAUSES - prop.lcnf( top0, !top1, !firstComp); + prop.lcnf(top0, !top1, !firstComp); prop.lcnf(!top0, top1, !firstComp); #endif - } else { @@ -1704,12 +1710,12 @@ literalt bv_utilst::lt_or_le( prop.lcnf(!compareBelow[i], bv0[i], !bv1[i], result); prop.lcnf(!compareBelow[i], !bv0[i], bv1[i], !result); } - while (i-- != 0); + while(i-- != 0); // Chain the comparison bit // \forall i != 0 . cb[i] & a[i] & b[i] => cb[i-1] // \forall i != 0 . cb[i] & -a[i] & -b[i] => cb[i-1] - for (i = start; i > 0; i--) + for(i = start; i > 0; i--) { prop.lcnf(!compareBelow[i], !bv0[i], !bv1[i], compareBelow[i-1]); prop.lcnf(!compareBelow[i], bv0[i], bv1[i], compareBelow[i-1]); @@ -1721,17 +1727,17 @@ literalt bv_utilst::lt_or_le( // \forall i != 0 . -c[i] => -c[i-1] // \forall i != 0 . c[i] & -a[i] & b[i] => -c[i-1] // \forall i != 0 . c[i] & a[i] & -b[i] => -c[i-1] - for (i = start; i > 0; i--) + for(i = start; i > 0; i--) { - prop.lcnf( compareBelow[i], !compareBelow[i-1]); + prop.lcnf(compareBelow[i], !compareBelow[i-1]); prop.lcnf(!compareBelow[i], bv0[i], !bv1[i], !compareBelow[i-1]); prop.lcnf(!compareBelow[i], !bv0[i], bv1[i], !compareBelow[i-1]); } #endif // The 'base case' of the induction is the case when they are equal - prop.lcnf(!compareBelow[0], !bv0[0], !bv1[0], (or_equal) ? result : !result); - prop.lcnf(!compareBelow[0], bv0[0], bv1[0], (or_equal) ? result : !result); + prop.lcnf(!compareBelow[0], !bv0[0], !bv1[0], (or_equal)?result:!result); + prop.lcnf(!compareBelow[0], bv0[0], bv1[0], (or_equal)?result:!result); return result; } @@ -1874,7 +1880,7 @@ void bv_utilst::cond_implies_equal( { assert(a.size()==b.size()); - if (prop.cnf_handled_well()) + if(prop.cnf_handled_well()) { for(std::size_t i=0; i equal_const_registeredt; @@ -100,7 +121,7 @@ class bv_utilst typedef std::map equal_const_cachet; equal_const_cachet equal_const_cache; - literalt equal_const_rec (bvt &var, bvt &constant); + literalt equal_const_rec(bvt &var, bvt &constant); literalt equal_const(const bvt &var, const bvt &constant); #endif @@ -130,14 +151,18 @@ class bv_utilst literalt is_all_ones(const bvt &op) { return prop.land(op); } - literalt lt_or_le(bool or_equal, - const bvt &bv0, - const bvt &bv1, - representationt rep); + literalt lt_or_le( + bool or_equal, + const bvt &bv0, + const bvt &bv1, + representationt rep); // id is one of ID_lt, le, gt, ge, equal, notequal - literalt rel(const bvt &bv0, irep_idt id, const bvt &bv1, - representationt rep); + literalt rel( + const bvt &bv0, + irep_idt id, + const bvt &bv1, + representationt rep); literalt unsigned_less_than(const bvt &bv0, const bvt &bv1); literalt signed_less_than(const bvt &bv0, const bvt &bv1); @@ -190,8 +215,11 @@ class bv_utilst protected: propt ∝ - void adder(bvt &sum, const bvt &op, - literalt carry_in, literalt &carry_out); + void adder( + bvt &sum, + const bvt &op, + literalt carry_in, + literalt &carry_out); void adder_no_overflow( bvt &sum, diff --git a/src/solvers/flattening/equality.cpp b/src/solvers/flattening/equality.cpp index 432e91d0132..208a4510a35 100644 --- a/src/solvers/flattening/equality.cpp +++ b/src/solvers/flattening/equality.cpp @@ -6,7 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG +// #define DEBUG #ifdef DEBUG #include @@ -102,7 +102,8 @@ literalt equalityt::equality2(const exprt &e1, const exprt &e2) if(result==equalities.end()) { l=prop.new_variable(); - if(freeze_all && !l.is_constant()) prop.set_frozen(l); + if(freeze_all && !l.is_constant()) + prop.set_frozen(l); equalities.insert(equalitiest::value_type(u, l)); } else diff --git a/src/solvers/flattening/flatten_byte_operators.cpp b/src/solvers/flattening/flatten_byte_operators.cpp index bd3d4198da6..68ad4b9197e 100644 --- a/src/solvers/flattening/flatten_byte_operators.cpp +++ b/src/solvers/flattening/flatten_byte_operators.cpp @@ -238,9 +238,11 @@ exprt flatten_byte_update( else { byte_extract_exprt byte_extract_expr( - src.id()==ID_byte_update_little_endian?ID_byte_extract_little_endian: - src.id()==ID_byte_update_big_endian?ID_byte_extract_big_endian: - throw "unexpected src.id() in flatten_byte_update", + src.id()==ID_byte_update_little_endian? + ID_byte_extract_little_endian: + src.id()==ID_byte_update_big_endian? + ID_byte_extract_big_endian: + throw "unexpected src.id() in flatten_byte_update", subtype); byte_extract_expr.op()=src.op2(); @@ -270,7 +272,7 @@ exprt flatten_byte_update( mp_integer num_elements= element_size/sub_size+((element_size%sub_size==0)?1:2); - const auto& offset_type=ns.follow(src.op1().type()); + const auto &offset_type=ns.follow(src.op1().type()); exprt zero_offset=from_integer(0, offset_type); exprt sub_size_expr=from_integer(sub_size, offset_type); @@ -364,8 +366,9 @@ exprt flatten_byte_update( } else { - throw "flatten_byte_update can only do arrays of scalars right now, but got "+ - subtype.id_string(); + throw + "flatten_byte_update can only do arrays of scalars right now, " + "but got "+subtype.id_string(); } } else if(t.id()==ID_signedbv || @@ -390,9 +393,11 @@ exprt flatten_byte_update( exprt value_extended; if(width>integer2unsigned(element_size)*8) - value_extended=concatenation_exprt( - from_integer(0, unsignedbv_typet(width-integer2unsigned(element_size)*8)), - src.op2(), t); + value_extended= + concatenation_exprt( + from_integer( + 0, unsignedbv_typet(width-integer2unsigned(element_size)*8)), + src.op2(), t); else value_extended=src.op2(); @@ -476,7 +481,8 @@ bool has_byte_operator(const exprt &src) return true; forall_operands(it, src) - if(has_byte_operator(*it)) return true; + if(has_byte_operator(*it)) + return true; return false; } diff --git a/src/solvers/flattening/functions.cpp b/src/solvers/flattening/functions.cpp index 057d1536976..37380aa323b 100644 --- a/src/solvers/flattening/functions.cpp +++ b/src/solvers/flattening/functions.cpp @@ -6,7 +6,7 @@ Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ -//#define DEBUG +// #define DEBUG #include diff --git a/src/solvers/flattening/pointer_logic.cpp b/src/solvers/flattening/pointer_logic.cpp index ff6568c969c..c2b9d1175d0 100644 --- a/src/solvers/flattening/pointer_logic.cpp +++ b/src/solvers/flattening/pointer_logic.cpp @@ -29,7 +29,8 @@ Function: pointer_logict::is_dynamic_object bool pointer_logict::is_dynamic_object(const exprt &expr) const { - if(expr.type().get_bool("#dynamic")) return true; + if(expr.type().get_bool("#dynamic")) + return true; if(expr.id()==ID_symbol) if(has_prefix(id2string(to_symbol_expr(expr).get_identifier()), @@ -199,11 +200,13 @@ exprt pointer_logict::object_rec( mp_integer size= pointer_offset_size(src.type().subtype(), ns); - if(size==0) return src; + if(size==0) + return src; mp_integer index=offset/size; mp_integer rest=offset%size; - if(rest<0) rest=-rest; + if(rest<0) + rest=-rest; index_exprt tmp(src.type().subtype()); tmp.index()=from_integer(index, typet(ID_integer)); @@ -216,7 +219,8 @@ exprt pointer_logict::object_rec( const struct_typet::componentst &components= to_struct_type(src.type()).components(); - if(offset<0) return src; + if(offset<0) + return src; mp_integer current_offset=0; diff --git a/src/solvers/flattening/sat_minimizer.h b/src/solvers/flattening/sat_minimizer.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/solvers/floatbv/float_approximation.h b/src/solvers/floatbv/float_approximation.h index dd0a495db39..c0a266b8fb6 100644 --- a/src/solvers/floatbv/float_approximation.h +++ b/src/solvers/floatbv/float_approximation.h @@ -14,7 +14,7 @@ Module: Floating Point with under/over-approximation class float_approximationt:public float_utilst { public: - float_approximationt(propt &_prop): + explicit float_approximationt(propt &_prop): float_utilst(_prop), over_approximate(false), partial_interpretation(false) @@ -31,6 +31,7 @@ class float_approximationt:public float_utilst bvt overapproximating_left_shift(const bvt &src, unsigned dist); private: + // NOLINTNEXTLINE(readability/identifiers) typedef float_utilst SUB; }; diff --git a/src/solvers/floatbv/float_bv.cpp b/src/solvers/floatbv/float_bv.cpp index 99bfc7af317..6a0e37fc1d8 100644 --- a/src/solvers/floatbv/float_bv.cpp +++ b/src/solvers/floatbv/float_bv.cpp @@ -43,12 +43,20 @@ exprt float_bvt::convert(const exprt &expr) if(dest_type.id()==ID_signedbv && src_type.id()==ID_floatbv) // float -> signed - return to_signed_integer( - expr.op0(), to_signedbv_type(dest_type).get_width(), expr.op1(), get_spec(expr.op0())); + return + to_signed_integer( + expr.op0(), + to_signedbv_type(dest_type).get_width(), + expr.op1(), + get_spec(expr.op0())); else if(dest_type.id()==ID_unsignedbv && src_type.id()==ID_floatbv) // float -> unsigned - return to_unsigned_integer( - expr.op0(), to_unsignedbv_type(dest_type).get_width(), expr.op1(), get_spec(expr.op0())); + return + to_unsigned_integer( + expr.op0(), + to_unsignedbv_type(dest_type).get_width(), + expr.op1(), + get_spec(expr.op0())); else if(src_type.id()==ID_signedbv && dest_type.id()==ID_floatbv) // signed -> float return from_signed_integer( @@ -59,7 +67,9 @@ exprt float_bvt::convert(const exprt &expr) expr.op0(), expr.op1(), get_spec(expr)); else if(dest_type.id()==ID_floatbv && src_type.id()==ID_floatbv) // float -> float - return conversion(expr.op0(), expr.op1(), get_spec(expr.op0()), get_spec(expr)); + return + conversion( + expr.op0(), expr.op1(), get_spec(expr.op0()), get_spec(expr)); else return nil_exprt(); } @@ -305,8 +315,10 @@ Function: float_bvt::rounding_mode_bitst::get void float_bvt::rounding_mode_bitst::get(const exprt &rm) { exprt round_to_even_const=from_integer(ieee_floatt::ROUND_TO_EVEN, rm.type()); - exprt round_to_plus_inf_const=from_integer(ieee_floatt::ROUND_TO_PLUS_INF, rm.type()); - exprt round_to_minus_inf_const=from_integer(ieee_floatt::ROUND_TO_MINUS_INF, rm.type()); + exprt round_to_plus_inf_const= + from_integer(ieee_floatt::ROUND_TO_PLUS_INF, rm.type()); + exprt round_to_minus_inf_const= + from_integer(ieee_floatt::ROUND_TO_MINUS_INF, rm.type()); exprt round_to_zero_const=from_integer(ieee_floatt::ROUND_TO_ZERO, rm.type()); round_to_even=equal_exprt(rm, round_to_even_const); @@ -625,8 +637,10 @@ exprt float_bvt::subtract_exponents( std::size_t old_width2=to_signedbv_type(src2.exponent.type()).get_width(); assert(old_width1==old_width2); - exprt extended_exponent1=typecast_exprt(src1.exponent, signedbv_typet(old_width1+1)); - exprt extended_exponent2=typecast_exprt(src2.exponent, signedbv_typet(old_width2+1)); + exprt extended_exponent1= + typecast_exprt(src1.exponent, signedbv_typet(old_width1+1)); + exprt extended_exponent2= + typecast_exprt(src2.exponent, signedbv_typet(old_width2+1)); assert(extended_exponent1.type()==extended_exponent2.type()); @@ -684,8 +698,10 @@ exprt float_bvt::add_sub( // pad fractions with 3 zeros from below exprt three_zeros=from_integer(0, unsignedbv_typet(3)); // add 4 to spec.f because unpacked new_fraction has the hidden bit - const exprt fraction1_padded=concatenation_exprt(new_fraction1, three_zeros, unsignedbv_typet(spec.f+4)); - const exprt fraction2_padded=concatenation_exprt(new_fraction2, three_zeros, unsignedbv_typet(spec.f+4)); + const exprt fraction1_padded= + concatenation_exprt(new_fraction1, three_zeros, unsignedbv_typet(spec.f+4)); + const exprt fraction2_padded= + concatenation_exprt(new_fraction2, three_zeros, unsignedbv_typet(spec.f+4)); // shift new_fraction2 exprt sticky_bit; @@ -702,8 +718,10 @@ exprt float_bvt::add_sub( fraction2_shifted.type())); // need to have two extra fraction bits for addition and rounding - const exprt fraction1_ext=typecast_exprt(fraction1_shifted, unsignedbv_typet(spec.f+4+2)); - const exprt fraction2_ext=typecast_exprt(fraction2_stickied, unsignedbv_typet(spec.f+4+2)); + const exprt fraction1_ext= + typecast_exprt(fraction1_shifted, unsignedbv_typet(spec.f+4+2)); + const exprt fraction2_ext= + typecast_exprt(fraction2_stickied, unsignedbv_typet(spec.f+4+2)); unbiased_floatt result; @@ -717,10 +735,13 @@ exprt float_bvt::add_sub( plus_exprt(fraction1_ext, fraction2_ext)); // sign of result - std::size_t width = to_bitvector_type(result.fraction.type()).get_width(); - exprt fraction_sign=sign_exprt(typecast_exprt(result.fraction, signedbv_typet(width))); - result.fraction=typecast_exprt(abs_exprt(typecast_exprt(result.fraction, signedbv_typet(width))), - unsignedbv_typet(width)); + std::size_t width=to_bitvector_type(result.fraction.type()).get_width(); + exprt fraction_sign= + sign_exprt(typecast_exprt(result.fraction, signedbv_typet(width))); + result.fraction= + typecast_exprt( + abs_exprt(typecast_exprt(result.fraction, signedbv_typet(width))), + unsignedbv_typet(width)); result.exponent=bigger_exponent; @@ -942,12 +963,15 @@ exprt float_bvt::div( // we throw this into the result, as least-significand bit, // to get the right rounding decision result.fraction= - concatenation_exprt(result.fraction, have_remainder, unsignedbv_typet(div_width+1)); + concatenation_exprt( + result.fraction, have_remainder, unsignedbv_typet(div_width+1)); // We will subtract the exponents; // to account for overflow, we add a bit. - const exprt exponent1=typecast_exprt(unpacked1.exponent, signedbv_typet(spec.e+1)); - const exprt exponent2=typecast_exprt(unpacked2.exponent, signedbv_typet(spec.e+1)); + const exprt exponent1= + typecast_exprt(unpacked1.exponent, signedbv_typet(spec.e+1)); + const exprt exponent2= + typecast_exprt(unpacked2.exponent, signedbv_typet(spec.e+1)); // subtract exponents exprt added_exponent=minus_exprt(exponent1, exponent2); @@ -1061,7 +1085,8 @@ exprt float_bvt::relation( { exprt and_bv(ID_and, bool_typet()); and_bv.copy_to_operands(less_than3); - and_bv.copy_to_operands(not_exprt(bitwise_equal)); // for the case of two negative numbers + // for the case of two negative numbers + and_bv.copy_to_operands(not_exprt(bitwise_equal)); and_bv.copy_to_operands(not_exprt(both_zero)); and_bv.copy_to_operands(not_exprt(nan)); diff --git a/src/solvers/floatbv/float_bv.h b/src/solvers/floatbv/float_bv.h index d71ef8be4e9..74f31f8dc00 100644 --- a/src/solvers/floatbv/float_bv.h +++ b/src/solvers/floatbv/float_bv.h @@ -17,7 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com class float_bvt { public: - explicit float_bvt() + float_bvt() { } @@ -25,7 +25,7 @@ class float_bvt { } - inline exprt operator()(const exprt &src) + exprt operator()(const exprt &src) { return convert(src); } @@ -42,29 +42,71 @@ class float_bvt exprt isfinite(const exprt &, const ieee_float_spect &); // add/sub - exprt add_sub(bool subtract, const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &); + exprt add_sub( + bool subtract, + const exprt &, + const exprt &, + const exprt &rm, + const ieee_float_spect &); // mul/div - exprt mul(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &); - exprt div(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &); + exprt mul( + const exprt &, + const exprt &, + const exprt &rm, + const ieee_float_spect &); + exprt div( + const exprt &, + const exprt &, + const exprt &rm, + const ieee_float_spect &); // conversion - exprt from_unsigned_integer(const exprt &, const exprt &rm, const ieee_float_spect &); - exprt from_signed_integer(const exprt &, const exprt &rm, const ieee_float_spect &); - exprt to_signed_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &); - exprt to_unsigned_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &); - exprt to_integer(const exprt &src, std::size_t dest_width, bool is_signed, const exprt &rm, const ieee_float_spect &); - exprt conversion(const exprt &src, const exprt &rm, const ieee_float_spect &src_spec, const ieee_float_spect &dest_spec); + exprt from_unsigned_integer( + const exprt &, + const exprt &rm, + const ieee_float_spect &); + exprt from_signed_integer( + const exprt &, + const exprt &rm, + const ieee_float_spect &); + exprt to_signed_integer( + const exprt &src, + std::size_t dest_width, + const exprt &rm, + const ieee_float_spect &); + exprt to_unsigned_integer( + const exprt &src, + std::size_t dest_width, + const exprt &rm, + const ieee_float_spect &); + exprt to_integer( + const exprt &src, + std::size_t dest_width, + bool is_signed, + const exprt &rm, + const ieee_float_spect &); + exprt conversion( + const exprt &src, + const exprt &rm, + const ieee_float_spect &src_spec, + const ieee_float_spect &dest_spec); // relations typedef enum { LT, LE, EQ, GT, GE } relt; - exprt relation(const exprt &, relt rel, const exprt &, const ieee_float_spect &); + exprt relation( + const exprt &, + relt rel, + const exprt &, + const ieee_float_spect &); protected: // helpers ieee_float_spect get_spec(const exprt &); - exprt get_exponent(const exprt &, const ieee_float_spect &); // still biased - exprt get_fraction(const exprt &, const ieee_float_spect &); // without hidden bit + // still biased + exprt get_exponent(const exprt &, const ieee_float_spect &); + // without hidden bit + exprt get_fraction(const exprt &, const ieee_float_spect &); exprt sign_bit(const exprt &); exprt exponent_all_ones(const exprt &, const ieee_float_spect &); @@ -86,7 +128,10 @@ class float_bvt // unpacked void normalization_shift(exprt &fraction, exprt &exponent); - void denormalization_shift(exprt &fraction, exprt &exponent, const ieee_float_spect &); + void denormalization_shift( + exprt &fraction, + exprt &exponent, + const ieee_float_spect &); exprt add_bias(const exprt &exponent, const ieee_float_spect &); exprt sub_bias(const exprt &exponent, const ieee_float_spect &); @@ -122,12 +167,21 @@ class float_bvt biased_floatt bias(const unbiased_floatt &, const ieee_float_spect &); // this takes unpacked format, and returns packed - virtual exprt rounder(const unbiased_floatt &, const exprt &rm, const ieee_float_spect &); + virtual exprt rounder( + const unbiased_floatt &, + const exprt &rm, + const ieee_float_spect &); exprt pack(const biased_floatt &, const ieee_float_spect &); unbiased_floatt unpack(const exprt &, const ieee_float_spect &); - void round_fraction(unbiased_floatt &result, const rounding_mode_bitst &, const ieee_float_spect &); - void round_exponent(unbiased_floatt &result, const rounding_mode_bitst &, const ieee_float_spect &); + void round_fraction( + unbiased_floatt &result, + const rounding_mode_bitst &, + const ieee_float_spect &); + void round_exponent( + unbiased_floatt &result, + const rounding_mode_bitst &, + const ieee_float_spect &); // rounding decision for fraction exprt fraction_rounding_decision( @@ -150,7 +204,7 @@ class float_bvt exprt &sticky); }; -static inline exprt float_bv(const exprt &src) +inline exprt float_bv(const exprt &src) { return float_bvt()(src); } diff --git a/src/solvers/floatbv/float_utils.cpp b/src/solvers/floatbv/float_utils.cpp index 1b3bbf81f1d..c277e51e6b0 100644 --- a/src/solvers/floatbv/float_utils.cpp +++ b/src/solvers/floatbv/float_utils.cpp @@ -27,10 +27,14 @@ Function: float_utilst::set_rounding_mode void float_utilst::set_rounding_mode(const bvt &src) { - bvt round_to_even=bv_utils.build_constant(ieee_floatt::ROUND_TO_EVEN, src.size()); - bvt round_to_plus_inf=bv_utils.build_constant(ieee_floatt::ROUND_TO_PLUS_INF, src.size()); - bvt round_to_minus_inf=bv_utils.build_constant(ieee_floatt::ROUND_TO_MINUS_INF, src.size()); - bvt round_to_zero=bv_utils.build_constant(ieee_floatt::ROUND_TO_ZERO, src.size()); + bvt round_to_even= + bv_utils.build_constant(ieee_floatt::ROUND_TO_EVEN, src.size()); + bvt round_to_plus_inf= + bv_utils.build_constant(ieee_floatt::ROUND_TO_PLUS_INF, src.size()); + bvt round_to_minus_inf= + bv_utils.build_constant(ieee_floatt::ROUND_TO_MINUS_INF, src.size()); + bvt round_to_zero= + bv_utils.build_constant(ieee_floatt::ROUND_TO_ZERO, src.size()); rounding_mode_bits.round_to_even=bv_utils.equal(src, round_to_even); rounding_mode_bits.round_to_plus_inf=bv_utils.equal(src, round_to_plus_inf); @@ -259,13 +263,13 @@ bvt float_utilst::conversion( // new format. Note that this is rare and will only // happen with very non-standard formats. - int sourceSmallestNormalExponent = -((1 << (spec.e - 1)) - 1); + int sourceSmallestNormalExponent=-((1 << (spec.e - 1)) - 1); int sourceSmallestDenormalExponent = sourceSmallestNormalExponent - spec.f; // Using the fact that f doesn't include the hidden bit - int destSmallestNormalExponent = -((1 << (dest_spec.e - 1)) - 1); + int destSmallestNormalExponent=-((1 << (dest_spec.e - 1)) - 1); if(dest_spec.e>=spec.e && dest_spec.f>=spec.f && @@ -287,7 +291,7 @@ bvt float_utilst::conversion( // normalise it! if(dest_spec.e > spec.e) { - normalization_shift(result.fraction,result.exponent); + normalization_shift(result.fraction, result.exponent); } // the flags get copied @@ -299,7 +303,7 @@ bvt float_utilst::conversion( spec=dest_spec; return pack(bias(result)); } - else + else // NOLINT(readability/braces) #endif { // we actually need to round @@ -345,8 +349,10 @@ bvt float_utilst::subtract_exponents( const unbiased_floatt &src2) { // extend both - bvt extended_exponent1=bv_utils.sign_extension(src1.exponent, src1.exponent.size()+1); - bvt extended_exponent2=bv_utils.sign_extension(src2.exponent, src2.exponent.size()+1); + bvt extended_exponent1= + bv_utils.sign_extension(src1.exponent, src1.exponent.size()+1); + bvt extended_exponent2= + bv_utils.sign_extension(src2.exponent, src2.exponent.size()+1); assert(extended_exponent1.size()==extended_exponent2.size()); @@ -399,8 +405,10 @@ bvt float_utilst::add_sub( const bvt limited_dist=limit_distance(distance, spec.f+3); // pad fractions with 2 zeros from below - const bvt fraction1_padded=bv_utils.concatenate(bv_utils.zeros(3), new_fraction1); - const bvt fraction2_padded=bv_utils.concatenate(bv_utils.zeros(3), new_fraction2); + const bvt fraction1_padded= + bv_utils.concatenate(bv_utils.zeros(3), new_fraction1); + const bvt fraction2_padded= + bv_utils.concatenate(bv_utils.zeros(3), new_fraction2); // shift new_fraction2 literalt sticky_bit; @@ -413,8 +421,10 @@ bvt float_utilst::add_sub( fraction2_stickied[0]=prop.lor(fraction2_shifted[0], sticky_bit); // need to have two extra fraction bits for addition and rounding - const bvt fraction1_ext=bv_utils.zero_extension(fraction1_shifted, fraction1_shifted.size()+2); - const bvt fraction2_ext=bv_utils.zero_extension(fraction2_stickied, fraction2_stickied.size()+2); + const bvt fraction1_ext= + bv_utils.zero_extension(fraction1_shifted, fraction1_shifted.size()+2); + const bvt fraction2_ext= + bv_utils.zero_extension(fraction2_stickied, fraction2_stickied.size()+2); unbiased_floatt result; @@ -431,7 +441,8 @@ bvt float_utilst::add_sub( // adjust the exponent for the fact that we added two bits to the fraction result.exponent= - bv_utils.add(bv_utils.sign_extension(result.exponent, result.exponent.size()+1), + bv_utils.add( + bv_utils.sign_extension(result.exponent, result.exponent.size()+1), bv_utils.build_constant(2, result.exponent.size()+1)); // NaN? @@ -452,7 +463,7 @@ bvt float_utilst::add_sub( // 2. Subnormals mean that addition or subtraction can't round to 0, // thus we can perform this test now // 3. The rules for sign are different for zero - result.zero = prop.land( + result.zero=prop.land( !prop.lor(result.infinity, result.NaN), !prop.lor(result.fraction)); @@ -490,7 +501,7 @@ bvt float_utilst::add_sub( result.exponent.resize(spec.e, const_literal(false)); result.NaN=const_literal(false); result.infinity=const_literal(false); - //for(std::size_t i=0; i #include "miniBDD.h" @@ -12,14 +21,14 @@ int main() auto x=mgr.Var("x"); auto y=mgr.Var("y"); auto z=mgr.Var("z"); - result=x | (y & z); + result=x | (y &z); } #elif 0 { auto y=mgr.Var("y"); auto x=mgr.Var("x"); auto z=mgr.Var("z"); - result=x | (y & z); + result=x | (y &z); } #elif 0 { diff --git a/src/solvers/miniBDD/miniBDD.cpp b/src/solvers/miniBDD/miniBDD.cpp index 345a84b9b97..756a9dc6e52 100644 --- a/src/solvers/miniBDD/miniBDD.cpp +++ b/src/solvers/miniBDD/miniBDD.cpp @@ -1,3 +1,12 @@ +/*******************************************************************\ + +Module: A minimalistic BDD library, following Bryant's original paper + and Andersen's lecture notes + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #include #include @@ -7,10 +16,7 @@ #define forall_nodes(it) for(nodest::const_iterator it=nodes.begin(); \ it!=nodes.end(); it++) -namespace miniBDD -{ - -void node::remove_reference() +void mini_bdd_nodet::remove_reference() { assert(reference_counter!=0); @@ -18,7 +24,7 @@ void node::remove_reference() if(reference_counter==0 && node_number>=2) { - mgr::reverse_keyt reverse_key(var, low, high); + mini_bdd_mgrt::reverse_keyt reverse_key(var, low, high); mgr->reverse_map.erase(reverse_key); low.clear(); high.clear(); @@ -26,7 +32,7 @@ void node::remove_reference() } } -BDD mgr::Var(const std::string &label) +mini_bddt mini_bdd_mgrt::Var(const std::string &label) { var_table.push_back(var_table_entryt(label)); true_bdd.node->var=var_table.size()+1; @@ -34,7 +40,7 @@ BDD mgr::Var(const std::string &label) return mk(var_table.size(), false_bdd, true_bdd); } -void mgr::DumpDot(std::ostream &out, bool suppress_zero) const +void mini_bdd_mgrt::DumpDot(std::ostream &out, bool suppress_zero) const { out << "digraph BDD {\n"; @@ -76,8 +82,10 @@ void mgr::DumpDot(std::ostream &out, bool suppress_zero) const forall_nodes(u) { - if(u->reference_counter==0) continue; - if(u->node_number<=1) continue; + if(u->reference_counter==0) + continue; + if(u->node_number<=1) + continue; if(!suppress_zero || u->high.node_number()!=0) out << '"' << u->node_number << '"' << " -> " @@ -95,7 +103,7 @@ void mgr::DumpDot(std::ostream &out, bool suppress_zero) const out << "}\n"; } -void mgr::DumpTikZ( +void mini_bdd_mgrt::DumpTikZ( std::ostream &out, bool suppress_zero, bool node_numbers) const @@ -129,7 +137,8 @@ void mgr::DumpTikZ( out << "right of=n" << previous; out << "] (n" << u->node_number << ") {"; - if(node_numbers) out << "\\small $" << u->node_number << "$"; + if(node_numbers) + out << "\\small $" << u->node_number << "$"; out << "};\n"; previous=u->node_number; } @@ -172,24 +181,27 @@ void mgr::DumpTikZ( out << "\\end{tikzpicture}\n"; } -class apply +class mini_bdd_applyt { public: - inline explicit apply(bool (*_fkt)(bool, bool)):fkt(_fkt) + inline explicit mini_bdd_applyt(bool (*_fkt)(bool, bool)):fkt(_fkt) { } - BDD operator()(const BDD &x, const BDD &y) { return APP(x, y); } + mini_bddt operator()(const mini_bddt &x, const mini_bddt &y) + { + return APP(x, y); + } protected: bool (*fkt)(bool, bool); - BDD APP(const BDD &x, const BDD &y); + mini_bddt APP(const mini_bddt &x, const mini_bddt &y); - typedef std::map, BDD> Gt; + typedef std::map, mini_bddt> Gt; Gt G; }; -BDD apply::APP(const BDD &x, const BDD &y) +mini_bddt mini_bdd_applyt::APP(const mini_bddt &x, const mini_bddt &y) { assert(x.is_initialized() && y.is_initialized()); assert(x.node->mgr==y.node->mgr); @@ -197,14 +209,15 @@ BDD apply::APP(const BDD &x, const BDD &y) // dynamic programming std::pair key(x.node_number(), y.node_number()); Gt::const_iterator G_it=G.find(key); - if(G_it!=G.end()) return G_it->second; + if(G_it!=G.end()) + return G_it->second; - mgr *mgr=x.node->mgr; + mini_bdd_mgrt *mgr=x.node->mgr; - BDD u; + mini_bddt u; if(x.is_constant() && y.is_constant()) - u=BDD(fkt(x.is_true(), y.is_true())?mgr->True():mgr->False()); + u=mini_bddt(fkt(x.is_true(), y.is_true())?mgr->True():mgr->False()); else if(x.var()==y.var()) u=mgr->mk(x.var(), APP(x.low(), y.low()), @@ -228,24 +241,24 @@ bool equal_fkt(bool x, bool y) return x==y; } -BDD BDD::operator ==(const BDD &other) const +mini_bddt mini_bddt::operator==(const mini_bddt &other) const { - return apply(equal_fkt)(*this, other); + return mini_bdd_applyt(equal_fkt)(*this, other); } bool xor_fkt(bool x, bool y) { - return x ^ y; + return x^y; } -BDD BDD::operator ^(const BDD &other) const +mini_bddt mini_bddt::operator^(const mini_bddt &other) const { - return apply(xor_fkt)(*this, other); + return mini_bdd_applyt(xor_fkt)(*this, other); } -BDD BDD::operator !() const +mini_bddt mini_bddt::operator!() const { - return node->mgr->True() ^ *this; + return node->mgr->True()^*this; } bool and_fkt(bool x, bool y) @@ -253,9 +266,9 @@ bool and_fkt(bool x, bool y) return x && y; } -BDD BDD::operator &(const BDD &other) const +mini_bddt mini_bddt::operator&(const mini_bddt &other) const { - return apply(and_fkt)(*this, other); + return mini_bdd_applyt(and_fkt)(*this, other); } bool or_fkt(bool x, bool y) @@ -263,25 +276,28 @@ bool or_fkt(bool x, bool y) return x || y; } -BDD BDD::operator |(const BDD &other) const +mini_bddt mini_bddt::operator|(const mini_bddt &other) const { - return apply(or_fkt)(*this, other); + return mini_bdd_applyt(or_fkt)(*this, other); } -mgr::mgr() +mini_bdd_mgrt::mini_bdd_mgrt() { // add true/false nodes - nodes.push_back(node(this, 0, 0, BDD(), BDD())); - false_bdd=BDD(&nodes.back()); - nodes.push_back(node(this, 1, 1, BDD(), BDD())); - true_bdd=BDD(&nodes.back()); + nodes.push_back(mini_bdd_nodet(this, 0, 0, mini_bddt(), mini_bddt())); + false_bdd=mini_bddt(&nodes.back()); + nodes.push_back(mini_bdd_nodet(this, 1, 1, mini_bddt(), mini_bddt())); + true_bdd=mini_bddt(&nodes.back()); } -mgr::~mgr() +mini_bdd_mgrt::~mini_bdd_mgrt() { } -BDD mgr::mk(unsigned var, const BDD &low, const BDD &high) +mini_bddt mini_bdd_mgrt::mk( + unsigned var, + const mini_bddt &low, + const mini_bddt &high) { assert(var<=var_table.size()); @@ -293,15 +309,15 @@ BDD mgr::mk(unsigned var, const BDD &low, const BDD &high) reverse_mapt::const_iterator it=reverse_map.find(reverse_key); if(it!=reverse_map.end()) - return BDD(it->second); + return mini_bddt(it->second); else { - node *n; + mini_bdd_nodet *n; if(free.empty()) { unsigned new_number=nodes.back().node_number+1; - nodes.push_back(node(this, var, new_number, low, high)); + nodes.push_back(mini_bdd_nodet(this, var, new_number, low, high)); n=&nodes.back(); } else // reuse a node @@ -314,22 +330,23 @@ BDD mgr::mk(unsigned var, const BDD &low, const BDD &high) } reverse_map[reverse_key]=n; - return BDD(n); + return mini_bddt(n); } } } -bool operator < (const mgr::reverse_keyt &x, - const mgr::reverse_keyt &y) +bool mini_bdd_mgrt::reverse_keyt::operator<( + const mini_bdd_mgrt::reverse_keyt &other) const { - if(x.vary.var) return false; - if(x.lowy.low) return false; - return x.highother.var || low>other.low) + return false; + + return highlow.node_number() << " & " << it->high.node_number() << " \\\\"; - if(it->node_number==1) out << "\\hline"; + if(it->node_number==1) + out << "\\hline"; out << " % " << it->reference_counter << '\n'; } @@ -361,23 +379,23 @@ class restrictt { } - BDD operator()(const BDD &u) { return RES(u); } + mini_bddt operator()(const mini_bddt &u) { return RES(u); } protected: const unsigned var; const bool value; - BDD RES(const BDD &u); + mini_bddt RES(const mini_bddt &u); }; -BDD restrictt::RES(const BDD &u) +mini_bddt restrictt::RES(const mini_bddt &u) { // replace 'var' in 'u' by constant 'value' assert(u.is_initialized()); - mgr *mgr=u.node->mgr; + mini_bdd_mgrt *mgr=u.node->mgr; - BDD t; + mini_bddt t; if(u.var()>var) t=u; @@ -389,29 +407,29 @@ BDD restrictt::RES(const BDD &u) return t; } -BDD restrict(const BDD &u, unsigned var, const bool value) +mini_bddt restrict(const mini_bddt &u, unsigned var, const bool value) { return restrictt(var, value)(u); } -BDD exists(const BDD &u, const unsigned var) +mini_bddt exists(const mini_bddt &u, const unsigned var) { // u[var/0] OR u[var/1] return restrict(u, var, false) | restrict(u, var, true); } -BDD substitute(const BDD &t, unsigned var, const BDD &tp) +mini_bddt substitute(const mini_bddt &t, unsigned var, const mini_bddt &tp) { // t[var/tp] = - // ( tp & t[var/1]) | - // (!tp & t[var/0]) + // ( tp &t[var/1]) | + // (!tp &t[var/0]) - return ( tp & restrict(t, var, true)) | - ((!tp) & restrict(t, var, false)); + return ( tp &restrict(t, var, true)) | + ((!tp) &restrict(t, var, false)); } -void cubes(const BDD &u, const std::string &path, std::string &result) +void cubes(const mini_bddt &u, const std::string &path, std::string &result) { if(u.is_false()) return; @@ -422,17 +440,21 @@ void cubes(const BDD &u, const std::string &path, std::string &result) return; } - mgr *mgr=u.node->mgr; + mini_bdd_mgrt *mgr=u.node->mgr; std::string path_low=path; std::string path_high=path; - if(!path.empty()) { path_low+=" & "; path_high+=" & "; } + if(!path.empty()) + { + path_low+=" & "; + path_high+=" & "; + } path_low+='!'+mgr->var_table[u.var()-1].label; path_high+=mgr->var_table[u.var()-1].label; cubes(u.low(), path_low, result); cubes(u.high(), path_high, result); } -std::string cubes(const BDD &u) +std::string cubes(const mini_bddt &u) { if(u.is_false()) return "false\n"; @@ -446,7 +468,7 @@ std::string cubes(const BDD &u) } } -bool OneSat(const BDD &v, std::map &assignment) +bool OneSat(const mini_bddt &v, std::map &assignment) { // http://www.ecs.umass.edu/ece/labs/vlsicad/ece667/reading/somenzi99bdd.pdf if(v.is_true()) @@ -456,10 +478,9 @@ bool OneSat(const BDD &v, std::map &assignment) else { assignment[v.var()]=true; - if(OneSat(v.high(), assignment)) return true; + if(OneSat(v.high(), assignment)) + return true; assignment[v.var()]=false; return OneSat(v.low(), assignment); } } - -} // namespace miniBDD diff --git a/src/solvers/miniBDD/miniBDD.h b/src/solvers/miniBDD/miniBDD.h index eb1a6ea0da2..aab378edbae 100644 --- a/src/solvers/miniBDD/miniBDD.h +++ b/src/solvers/miniBDD/miniBDD.h @@ -24,120 +24,120 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -namespace miniBDD -{ - -class BDD +class mini_bddt { public: - inline BDD(); - inline BDD(const BDD &x); - inline ~BDD(); + mini_bddt(); + mini_bddt(const mini_bddt &x); + ~mini_bddt(); // Boolean operators on BDDs - BDD operator !() const; - BDD operator ^(const BDD &) const; - BDD operator ==(const BDD &) const; - BDD operator &(const BDD &) const; - BDD operator |(const BDD &) const; + mini_bddt operator!() const; + mini_bddt operator^(const mini_bddt &) const; + mini_bddt operator==(const mini_bddt &) const; + mini_bddt operator&(const mini_bddt &) const; + mini_bddt operator|(const mini_bddt &) const; // copy operator - inline BDD &operator=(const BDD &); + mini_bddt &operator=(const mini_bddt &); - inline bool is_constant() const; - inline bool is_true() const; - inline bool is_false() const; + bool is_constant() const; + bool is_true() const; + bool is_false() const; - inline unsigned var() const; - inline const BDD &low() const; - inline const BDD &high() const; - inline unsigned node_number() const; - inline void clear(); + unsigned var() const; + const mini_bddt &low() const; + const mini_bddt &high() const; + unsigned node_number() const; + void clear(); bool is_initialized() const { return node!=0; } // internal - explicit inline BDD(class node *_node); - class node *node; + explicit mini_bddt(class mini_bdd_nodet *_node); + class mini_bdd_nodet *node; }; -class node +class mini_bdd_nodet { public: - class mgr *mgr; + class mini_bdd_mgrt *mgr; unsigned var, node_number, reference_counter; - BDD low, high; + mini_bddt low, high; - inline node( - class mgr *_mgr, + mini_bdd_nodet( + class mini_bdd_mgrt *_mgr, unsigned _var, unsigned _node_number, - const BDD &_low, const BDD &_high); + const mini_bddt &_low, const mini_bddt &_high); - inline void add_reference(); + void add_reference(); void remove_reference(); }; -class mgr +class mini_bdd_mgrt { public: - mgr(); - ~mgr(); + mini_bdd_mgrt(); + ~mini_bdd_mgrt(); - BDD Var(const std::string &label); + mini_bddt Var(const std::string &label); void DumpDot(std::ostream &out, bool supress_zero=false) const; - void DumpTikZ(std::ostream &out, bool supress_zero=false, bool node_numbers=true) const; + void DumpTikZ( + std::ostream &out, + bool supress_zero=false, + bool node_numbers=true) const; void DumpTable(std::ostream &out) const; - inline const BDD &True() const; - inline const BDD &False() const; + const mini_bddt &True() const; + const mini_bddt &False() const; - friend class BDD; - friend class node; + friend class mini_bdd_nodet; // create a node (consulting the reverse-map) - BDD mk(unsigned var, const BDD &low, const BDD &high); + mini_bddt mk(unsigned var, const mini_bddt &low, const mini_bddt &high); - inline std::size_t number_of_nodes(); + std::size_t number_of_nodes(); struct var_table_entryt { std::string label; - inline var_table_entryt(const std::string &_label); + explicit var_table_entryt(const std::string &_label); }; typedef std::vector var_tablet; var_tablet var_table; protected: - typedef std::list nodest; + typedef std::list nodest; nodest nodes; - BDD true_bdd, false_bdd; + mini_bddt true_bdd, false_bdd; // this is our reverse-map for nodes struct reverse_keyt { unsigned var, low, high; - inline reverse_keyt( - unsigned _var, const BDD &_low, const BDD &_high); - }; + reverse_keyt( + unsigned _var, const mini_bddt &_low, const mini_bddt &_high); - friend bool operator < (const reverse_keyt &x, const reverse_keyt &y); + bool operator<(const reverse_keyt &other) const; + }; - typedef std::map reverse_mapt; + typedef std::map reverse_mapt; reverse_mapt reverse_map; - typedef std::stack freet; + typedef std::stack freet; freet free; }; -BDD restrict(const BDD &u, unsigned var, const bool value); -BDD exists(const BDD &u, unsigned var); -BDD substitute(const BDD &where, unsigned var, const BDD &by_what); -std::string cubes(const BDD &u); -bool OneSat(const BDD &v, std::map &assignment); - -} // namespace miniBDD +mini_bddt restrict(const mini_bddt &u, unsigned var, const bool value); +mini_bddt exists(const mini_bddt &u, unsigned var); +mini_bddt substitute( + const mini_bddt &where, + unsigned var, + const mini_bddt &by_what); +std::string cubes(const mini_bddt &u); +bool OneSat(const mini_bddt &v, std::map &assignment); // inline functions #include "miniBDD.inc" diff --git a/src/solvers/miniBDD/miniBDD.inc b/src/solvers/miniBDD/miniBDD.inc index a73d8a97daf..a48f56770cd 100644 --- a/src/solvers/miniBDD/miniBDD.inc +++ b/src/solvers/miniBDD/miniBDD.inc @@ -2,24 +2,21 @@ // inline functions -namespace miniBDD -{ - -BDD::BDD():node(0) +mini_bddt::mini_bddt():node(0) { } -BDD::BDD(const BDD &x):node(x.node) +mini_bddt::mini_bddt(const mini_bddt &x):node(x.node) { if(is_initialized()) node->add_reference(); } -BDD::BDD(class node *_node):node(_node) +mini_bddt::mini_bddt(class mini_bdd_nodet *_node):node(_node) { if(is_initialized()) node->add_reference(); } -BDD &BDD::operator=(const BDD &x) +mini_bddt &mini_bddt::operator=(const mini_bddt &x) { assert(&x!=this); clear(); @@ -31,56 +28,56 @@ BDD &BDD::operator=(const BDD &x) return *this; } -BDD::~BDD() +mini_bddt::~mini_bddt() { clear(); } -bool BDD::is_constant() const +bool mini_bddt::is_constant() const { assert(is_initialized()); return node->node_number<=1; } -bool BDD::is_true() const +bool mini_bddt::is_true() const { assert(is_initialized()); return node->node_number==1; } -bool BDD::is_false() const +bool mini_bddt::is_false() const { assert(is_initialized()); return node->node_number==0; } -unsigned BDD::var() const +unsigned mini_bddt::var() const { assert(is_initialized()); return node->var; } -unsigned BDD::node_number() const +unsigned mini_bddt::node_number() const { assert(is_initialized()); return node->node_number; } -const BDD &BDD::low() const +const mini_bddt &mini_bddt::low() const { assert(is_initialized()); assert(node->node_number>=2); return node->low; } -const BDD &BDD::high() const +const mini_bddt &mini_bddt::high() const { assert(is_initialized()); assert(node->node_number>=2); return node->high; } -void BDD::clear() +void mini_bddt::clear() { if(is_initialized()) { @@ -89,45 +86,43 @@ void BDD::clear() } } -node::node( - class mgr *_mgr, +mini_bdd_nodet::mini_bdd_nodet( + class mini_bdd_mgrt *_mgr, unsigned _var, unsigned _node_number, - const BDD &_low, const BDD &_high): + const mini_bddt &_low, const mini_bddt &_high): mgr(_mgr), var(_var), node_number(_node_number), reference_counter(0), low(_low), high(_high) { } -mgr::var_table_entryt::var_table_entryt( +mini_bdd_mgrt::var_table_entryt::var_table_entryt( const std::string &_label):label(_label) { } -const BDD &mgr::True() const +const mini_bddt &mini_bdd_mgrt::True() const { return true_bdd; } -const BDD &mgr::False() const +const mini_bddt &mini_bdd_mgrt::False() const { return false_bdd; } -void node::add_reference() +void mini_bdd_nodet::add_reference() { reference_counter++; } -mgr::reverse_keyt::reverse_keyt( - unsigned _var, const BDD &_low, const BDD &_high): +mini_bdd_mgrt::reverse_keyt::reverse_keyt( + unsigned _var, const mini_bddt &_low, const mini_bddt &_high): var(_var), low(_low.node->node_number), high(_high.node->node_number) { } -std::size_t mgr::number_of_nodes() +std::size_t mini_bdd_mgrt::number_of_nodes() { return nodes.size()-free.size(); } - -} // namespace miniBDD diff --git a/src/solvers/prop/aig.cpp b/src/solvers/prop/aig.cpp index 1b6d186d271..791436646f9 100644 --- a/src/solvers/prop/aig.cpp +++ b/src/solvers/prop/aig.cpp @@ -127,7 +127,7 @@ Function: aigt::print \*******************************************************************/ void aigt::print( - std::ostream& out, + std::ostream &out, literalt a) const { if(a==const_literal(false)) @@ -148,20 +148,24 @@ void aigt::print( if(node.is_and()) { - if(a.sign()) out << "!("; + if(a.sign()) + out << "!("; print(out, node.a); out << " & "; print(out, node.b); - if(a.sign()) out << ")"; + if(a.sign()) + out << ")"; } else if(node.is_var()) { - if(a.sign()) out << "!"; + if(a.sign()) + out << "!"; out << label(node_nr);\ } else { - if(a.sign()) out << "!"; + if(a.sign()) + out << "!"; out << "unknown(" << node_nr << ")"; } } @@ -211,7 +215,7 @@ Function: aigt::output_dot_edge \*******************************************************************/ void aigt::output_dot_edge( - std::ostream& out, + std::ostream &out, nodest::size_type v, literalt l) const { @@ -227,7 +231,8 @@ void aigt::output_dot_edge( else { out << l.var_no() << " -> " << v; - if(l.sign()) out << " [arrowhead=odiamond]"; + if(l.sign()) + out << " [arrowhead=odiamond]"; } out << "\n"; @@ -245,7 +250,7 @@ Function: aigt::output_dot \*******************************************************************/ -void aigt::output_dot(std::ostream& out) const +void aigt::output_dot(std::ostream &out) const { // constant TRUE out << "TRUE [label=\"TRUE\", shape=box]" << "\n"; diff --git a/src/solvers/prop/aig.h b/src/solvers/prop/aig.h index a32728de7e6..cf66e770a2a 100644 --- a/src/solvers/prop/aig.h +++ b/src/solvers/prop/aig.h @@ -20,16 +20,16 @@ class aig_nodet public: literalt a, b; - inline aig_nodet() + aig_nodet() { } - inline bool is_and() const + bool is_and() const { return a.var_no()!=literalt::unused_var_no(); } - inline bool is_var() const + bool is_var() const { return a.var_no()==literalt::unused_var_no(); } @@ -49,7 +49,7 @@ class aig_nodet class aigt { public: - inline aigt() + aigt() { } @@ -61,7 +61,7 @@ class aigt typedef std::vector nodest; nodest nodes; - inline void clear() + void clear() { nodes.clear(); } @@ -73,22 +73,22 @@ class aigt // should get re-written void get_terminals(terminalst &terminals) const; - inline const aig_nodet &get_node(literalt l) const + const aig_nodet &get_node(literalt l) const { return nodes[l.var_no()]; } - inline aig_nodet &get_node(literalt l) + aig_nodet &get_node(literalt l) { return nodes[l.var_no()]; } - inline nodest::size_type number_of_nodes() const + nodest::size_type number_of_nodes() const { return nodes.size(); } - inline void swap(aigt &g) + void swap(aigt &g) { nodes.swap(g.nodes); } @@ -101,21 +101,21 @@ class aigt return l; } - inline literalt new_var_node() + literalt new_var_node() { literalt l=new_node(); nodes.back().make_var(); return l; } - inline literalt new_and_node(literalt a, literalt b) + literalt new_and_node(literalt a, literalt b) { literalt l=new_node(); nodes.back().make_and(a, b); return l; } - inline bool empty() const + bool empty() const { return nodes.empty(); } @@ -123,7 +123,8 @@ class aigt void print(std::ostream &out) const; void print(std::ostream &out, literalt a) const; void output_dot_node(std::ostream &out, nodest::size_type v) const; - void output_dot_edge(std::ostream &out, nodest::size_type v, literalt l) const; + void output_dot_edge( + std::ostream &out, nodest::size_type v, literalt l) const; void output_dot(std::ostream &out) const; std::string label(nodest::size_type v) const; @@ -143,7 +144,7 @@ class aig_plus_constraintst:public aigt typedef std::vector constraintst; constraintst constraints; - inline void clear() + void clear() { aigt::clear(); constraints.clear(); diff --git a/src/solvers/prop/aig_prop.cpp b/src/solvers/prop/aig_prop.cpp index ea64eb0405f..70d9d9bf2a2 100644 --- a/src/solvers/prop/aig_prop.cpp +++ b/src/solvers/prop/aig_prop.cpp @@ -103,13 +103,15 @@ Function: aig_prop_baset::land literalt aig_prop_baset::land(literalt a, literalt b) { - if(a.is_true()) return b; - if(b.is_true()) return a; - if(a.is_false()) return a; - if(b.is_false()) return b; + if(a.is_true() || b.is_false()) + return b; + if(b.is_true() || a.is_false()) + return a; - if(a==neg(b)) return const_literal(false); - if(a==b) return a; + if(a==neg(b)) + return const_literal(false); + if(a==b) + return a; return dest.new_and_node(a, b); } @@ -145,13 +147,19 @@ Function: aig_prop_baset::lxor literalt aig_prop_baset::lxor(literalt a, literalt b) { - if(a.is_false()) return b; - if(b.is_false()) return a; - if(a.is_true()) return neg(b); - if(b.is_true()) return neg(a); - - if(a==b) return const_literal(false); - if(a==neg(b)) return const_literal(true); + if(a.is_false()) + return b; + if(b.is_false()) + return a; + if(a.is_true()) + return neg(b); + if(b.is_true()) + return neg(a); + + if(a==b) + return const_literal(false); + if(a==neg(b)) + return const_literal(true); // This produces up to three nodes! // See convert_node for where this overhead is removed @@ -239,10 +247,13 @@ Function: aig_prop_baset::lselect \*******************************************************************/ literalt aig_prop_baset::lselect(literalt a, literalt b, literalt c) -{ // a?b:c = (a AND b) OR (/a AND c) - if(a.is_true()) return b; - if(a.is_false()) return c; - if(b==c) return b; +{ // a?b:c=(a AND b) OR (/a AND c) + if(a.is_true()) + return b; + if(a.is_false()) + return c; + if(b==c) + return b; // This produces unnecessary clauses and variables // See convert_node for where this overhead is removed @@ -266,7 +277,7 @@ void aig_prop_baset::set_equal(literalt a, literalt b) { #ifdef USE_AIG_COMPACT // The compact encoding should reduce this - l_set_to_true(lequal(a,b)); + l_set_to_true(lequal(a, b)); #else // we produce two constraints: @@ -345,13 +356,15 @@ void aig_prop_solvert::compute_phase( literalt l=queue.top(); queue.pop(); - if(l.is_constant()) continue; + if(l.is_constant()) + continue; bool sign=l.sign(); unsigned var_no=l.var_no(); // already set? - if(sign?n_neg[var_no]:n_pos[var_no]) continue; // done already + if(sign?n_neg[var_no]:n_pos[var_no]) + continue; // done already // set sign?n_neg[var_no]=1:n_pos[var_no]=1; @@ -408,73 +421,81 @@ void aig_prop_solvert::usage_count( c_it!=aig.constraints.end(); c_it++) { - if (!((*c_it).is_constant())) + if(!((*c_it).is_constant())) { - if ((*c_it).sign()) { + if((*c_it).sign()) + { ++n_usage_count[(*c_it).var_no()]; - } else { + } + else + { ++p_usage_count[(*c_it).var_no()]; } - } } - for (unsigned n=0; n= 2) + if(p_usage_count[n]>=2) { ++usedTwicePositive; } - else if (n_usage_count[n] >= 2) + else if(n_usage_count[n]>=2) { ++usedTwiceNegative; } else { - assert(p_usage_count[n] == 1 && n_usage_count[n] == 1); + assert(p_usage_count[n]==1 && n_usage_count[n]==1); ++usedTwiceMixed; } break; @@ -487,7 +508,8 @@ void aig_prop_solvert::usage_count( << "Used once: " << usedOncePositive + usedOnceNegative << " (P: " << usedOncePositive << ", N: " << usedOnceNegative << ") " - << "Used twice: " << usedTwicePositive + usedTwiceNegative + usedTwiceMixed + << "Used twice: " + << usedTwicePositive + usedTwiceNegative + usedTwiceMixed << " (P: " << usedTwicePositive << ", N: " << usedTwiceNegative << ", M: " << usedTwiceMixed << ") " @@ -516,7 +538,7 @@ void aig_prop_solvert::convert_node( std::vector &p_usage_count, std::vector &n_usage_count) { - if (p_usage_count[n] > 0 || n_usage_count[n] > 0) + if(p_usage_count[n]>0 || n_usage_count[n]>0) { literalt o=literalt(n, false); bvt body(2); @@ -527,17 +549,17 @@ void aig_prop_solvert::convert_node( // Inline positive literals // This should remove the overhead introduced by land and lor for bvt - for (bvt::size_type i = 0; i < body.size(); i++) + for(bvt::size_type i=0; i < body.size(); i++) { - literalt l = body[i]; - - if (!l.sign() && // Used positively... - aig.nodes[l.var_no()].is_and() && // ... is a gate ... - p_usage_count[l.var_no()] == 1 && // ... only used here. - n_usage_count[l.var_no()] == 0) { + literalt l=body[i]; - const aigt::nodet &rep = aig.nodes[l.var_no()]; - body[i] = rep.a; + if(!l.sign() && // Used positively... + aig.nodes[l.var_no()].is_and() && // ... is a gate ... + p_usage_count[l.var_no()] == 1 && // ... only used here. + n_usage_count[l.var_no()] == 0) + { + const aigt::nodet &rep=aig.nodes[l.var_no()]; + body[i]=rep.a; body.push_back(rep.b); --i; // Repeat the process --p_usage_count[l.var_no()]; // Supress generation of inlined node @@ -556,8 +578,8 @@ void aig_prop_solvert::convert_node( // Recognise something of the form: // - // neg(o) = lor(land(a,b), land(neg(a),c)) - // o = land(lneg(land(a,b)), lneg(land(neg(a),c))) + // neg(o)=lor(land(a,b), land(neg(a),c)) + // o =land(lneg(land(a,b)), lneg(land(neg(a),c))) // // Note that lxor and lselect generate the negation of this // but will still be recognised because the negation is @@ -565,43 +587,43 @@ void aig_prop_solvert::convert_node( if(body.size() == 2 && body[0].sign() && body[1].sign()) { - const aigt::nodet &left = aig.nodes[body[0].var_no()]; - const aigt::nodet &right = aig.nodes[body[1].var_no()]; + const aigt::nodet &left=aig.nodes[body[0].var_no()]; + const aigt::nodet &right=aig.nodes[body[1].var_no()]; if(left.is_and() && right.is_and()) { - if(left.a == neg(right.a)) + if(left.a==neg(right.a)) { - if (p_usage_count[body[0].var_no()] == 0 && - n_usage_count[body[0].var_no()] == 1 && - p_usage_count[body[1].var_no()] == 0 && - n_usage_count[body[1].var_no()] == 1) + if(p_usage_count[body[0].var_no()]==0 && + n_usage_count[body[0].var_no()]==1 && + p_usage_count[body[1].var_no()]==0 && + n_usage_count[body[1].var_no()]==1) { bvt lits(3); - if (n_neg) + if(n_neg) { - lits[0] = left.a; - lits[1] = right.b; - lits[2] = o; + lits[0]=left.a; + lits[1]=right.b; + lits[2]=o; solver.lcnf(lits); - lits[0] = neg(left.a); - lits[1] = left.b; - lits[2] = o; + lits[0]=neg(left.a); + lits[1]=left.b; + lits[2]=o; solver.lcnf(lits); } - if (n_pos) + if(n_pos) { - lits[0] = left.a; - lits[1] = neg(right.b); - lits[2] = neg(o); + lits[0]=left.a; + lits[1]=neg(right.b); + lits[2]=neg(o); solver.lcnf(lits); - lits[0] = neg(left.a); - lits[1] = neg(left.b); - lits[2] = neg(o); + lits[0]=neg(left.a); + lits[1]=neg(left.b); + lits[2]=neg(o); solver.lcnf(lits); } @@ -618,62 +640,63 @@ void aig_prop_solvert::convert_node( // Likewise, carry has an improved encoding which is generated // by the CNF encoding - if (body.size() == 3 && body[0].sign() && body[1].sign() && body[2].sign()) + if(body.size() == 3 && body[0].sign() && body[1].sign() && body[2].sign()) { - const aigt::nodet &left = aig.nodes[body[0].var_no()]; - const aigt::nodet &mid = aig.nodes[body[1].var_no()]; - const aigt::nodet &right = aig.nodes[body[2].var_no()]; - - if (left.is_and() && mid.is_and() && right.is_and()) { - if (p_usage_count[body[0].var_no()] == 0 && - n_usage_count[body[0].var_no()] == 1 && - p_usage_count[body[1].var_no()] == 0 && - n_usage_count[body[1].var_no()] == 1 && - p_usage_count[body[2].var_no()] == 0 && - n_usage_count[body[2].var_no()] == 1) { + const aigt::nodet &left=aig.nodes[body[0].var_no()]; + const aigt::nodet &mid=aig.nodes[body[1].var_no()]; + const aigt::nodet &right=aig.nodes[body[2].var_no()]; - literalt a = left.a; - literalt b = left.b; - literalt c = mid.a; - - if (a == right.b && b == mid.b && c == right.a) { + if(left.is_and() && mid.is_and() && right.is_and()) + { + if(p_usage_count[body[0].var_no()]==0 && + n_usage_count[body[0].var_no()]==1 && + p_usage_count[body[1].var_no()]==0 && + n_usage_count[body[1].var_no()]==1 && + p_usage_count[body[2].var_no()]==0 && + n_usage_count[body[2].var_no()]==1) + { + literalt a=left.a; + literalt b=left.b; + literalt c=mid.a; + if(a==right.b && b==mid.b && c==right.a) + { // A (negative) carry -- 1 if at most one input is 1 bvt lits(3); - if (n_neg) + if(n_neg) { - lits[0] = a; - lits[1] = b; - lits[2] = o; + lits[0]=a; + lits[1]=b; + lits[2]=o; solver.lcnf(lits); - lits[0] = a; - lits[1] = c; - lits[2] = o; + lits[0]=a; + lits[1]=c; + lits[2]=o; solver.lcnf(lits); - lits[0] = b; - lits[1] = c; - lits[2] = o; + lits[0]=b; + lits[1]=c; + lits[2]=o; solver.lcnf(lits); } - if (n_pos) + if(n_pos) { - lits[0] = neg(a); - lits[1] = neg(b); - lits[2] = neg(o); + lits[0]=neg(a); + lits[1]=neg(b); + lits[2]=neg(o); solver.lcnf(lits); - lits[0] = neg(a); - lits[1] = neg(c); - lits[2] = neg(o); + lits[0]=neg(a); + lits[1]=neg(c); + lits[2]=neg(o); solver.lcnf(lits); - lits[0] = neg(b); - lits[1] = neg(c); - lits[2] = neg(o); + lits[0]=neg(b); + lits[1]=neg(c); + lits[2]=neg(o); solver.lcnf(lits); } @@ -716,7 +739,6 @@ void aig_prop_solvert::convert_node( lits.push_back(pos(o)); solver.lcnf(lits); } - } } @@ -758,16 +780,17 @@ void aig_prop_solvert::convert_aig() #endif // 2. Do nodes - for(std::size_t n = aig.nodes.size() - 1; n != 0; n--) + for(std::size_t n=aig.nodes.size() - 1; n!=0; n--) { if(aig.nodes[n].is_and()) - { + { #ifdef USE_PG - convert_node(n, aig.nodes[n], n_pos[n], n_neg[n], p_usage_count, n_usage_count); + convert_node( + n, aig.nodes[n], n_pos[n], n_neg[n], p_usage_count, n_usage_count); #else - convert_node(n, aig.nodes[n], true, true, p_usage_count, n_usage_count); + convert_node(n, aig.nodes[n], true, true, p_usage_count, n_usage_count); #endif - } + } } // Skip zero as it is not used or a valid literal @@ -778,5 +801,4 @@ void aig_prop_solvert::convert_aig() // HACK! aig.nodes.clear(); - } diff --git a/src/solvers/prop/aig_prop.h b/src/solvers/prop/aig_prop.h index e2d63691b0b..d88b5e86a9e 100644 --- a/src/solvers/prop/aig_prop.h +++ b/src/solvers/prop/aig_prop.h @@ -19,7 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com class aig_prop_baset:public propt { public: - explicit inline aig_prop_baset(aigt &_dest):dest(_dest) + explicit aig_prop_baset(aigt &_dest):dest(_dest) { } @@ -66,7 +66,7 @@ class aig_prop_baset:public propt class aig_prop_constraintt:public aig_prop_baset { public: - inline explicit aig_prop_constraintt(aig_plus_constraintst &_dest): + explicit aig_prop_constraintt(aig_plus_constraintst &_dest): aig_prop_baset(_dest), dest(_dest) { @@ -89,7 +89,7 @@ class aig_prop_constraintt:public aig_prop_baset class aig_prop_solvert:public aig_prop_constraintt { public: - explicit inline aig_prop_solvert(propt &_solver): + explicit aig_prop_solvert(propt &_solver): aig_prop_constraintt(aig), solver(_solver) { @@ -98,8 +98,11 @@ class aig_prop_solvert:public aig_prop_constraintt aig_plus_constraintst aig; const std::string solver_text() override - { return "conversion into and-inverter graph followed by "+ - solver.solver_text(); } + { + return + "conversion into and-inverter graph followed by "+ + solver.solver_text(); + } tvt l_get(literalt a) const override; resultt prop_solve() override; @@ -114,9 +117,16 @@ class aig_prop_solvert:public aig_prop_constraintt propt &solver; void convert_aig(); - void usage_count(std::vector &p_usage_count, std::vector &n_usage_count); + void usage_count( + std::vector &p_usage_count, std::vector &n_usage_count); void compute_phase(std::vector &n_pos, std::vector &n_neg); - void convert_node(unsigned n, const aigt::nodet &node, bool n_pos, bool n_neg, std::vector &p_usage_count, std::vector &n_usage_count); + void convert_node( + unsigned n, + const aigt::nodet &node, + bool n_pos, + bool n_neg, + std::vector &p_usage_count, + std::vector &n_usage_count); }; #endif // CPROVER_SOLVERS_PROP_AIG_PROP_H diff --git a/src/solvers/prop/bdd_expr.cpp b/src/solvers/prop/bdd_expr.cpp index 434314b39d4..91e06dfb08a 100644 --- a/src/solvers/prop/bdd_expr.cpp +++ b/src/solvers/prop/bdd_expr.cpp @@ -25,7 +25,7 @@ Function: bdd_exprt::from_expr_rec \*******************************************************************/ -bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) +mini_bddt bdd_exprt::from_expr_rec(const exprt &expr) { assert(expr.type().id()==ID_bool); @@ -40,8 +40,8 @@ bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) assert(expr.operands().size()>=2); exprt bin_expr=make_binary(expr); - bdd_exprt::BDDt op0=from_expr_rec(bin_expr.op0()); - bdd_exprt::BDDt op1=from_expr_rec(bin_expr.op1()); + mini_bddt op0=from_expr_rec(bin_expr.op0()); + mini_bddt op1=from_expr_rec(bin_expr.op1()); return expr.id()==ID_and ? (op0&op1) : (expr.id()==ID_or ? (op0|op1) : (op0^op1)); @@ -50,8 +50,8 @@ bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) { const implies_exprt &imp_expr=to_implies_expr(expr); - bdd_exprt::BDDt n_op0=!from_expr_rec(imp_expr.op0()); - bdd_exprt::BDDt op1=from_expr_rec(imp_expr.op1()); + mini_bddt n_op0=!from_expr_rec(imp_expr.op0()); + mini_bddt op1=from_expr_rec(imp_expr.op1()); return n_op0|op1; } @@ -61,8 +61,8 @@ bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) { const equal_exprt &eq_expr=to_equal_expr(expr); - bdd_exprt::BDDt op0=from_expr_rec(eq_expr.op0()); - bdd_exprt::BDDt op1=from_expr_rec(eq_expr.op1()); + mini_bddt op0=from_expr_rec(eq_expr.op0()); + mini_bddt op1=from_expr_rec(eq_expr.op1()); return op0==op1; } @@ -70,8 +70,8 @@ bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) { assert(expr.operands().size()==2); - bdd_exprt::BDDt op0=from_expr_rec(expr.op0()); - bdd_exprt::BDDt op1=from_expr_rec(expr.op1()); + mini_bddt op0=from_expr_rec(expr.op0()); + mini_bddt op1=from_expr_rec(expr.op1()); return op0==op1; } @@ -79,16 +79,16 @@ bdd_exprt::BDDt bdd_exprt::from_expr_rec(const exprt &expr) { const if_exprt &if_expr=to_if_expr(expr); - bdd_exprt::BDDt cond=from_expr_rec(if_expr.cond()); - bdd_exprt::BDDt t_case=from_expr_rec(if_expr.true_case()); - bdd_exprt::BDDt f_case=from_expr_rec(if_expr.false_case()); + mini_bddt cond=from_expr_rec(if_expr.cond()); + mini_bddt t_case=from_expr_rec(if_expr.true_case()); + mini_bddt f_case=from_expr_rec(if_expr.false_case()); return ((!cond)|t_case)&(cond|f_case); } else { std::pair entry= - expr_map.insert(std::make_pair(expr, bdd_exprt::BDDt())); + expr_map.insert(std::make_pair(expr, mini_bddt())); if(entry.second) { @@ -132,7 +132,7 @@ Function: bdd_exprt::as_expr \*******************************************************************/ -exprt bdd_exprt::as_expr(const bdd_exprt::BDDt &r) const +exprt bdd_exprt::as_expr(const mini_bddt &r) const { if(r.is_constant()) { diff --git a/src/solvers/prop/bdd_expr.h b/src/solvers/prop/bdd_expr.h index 608be1694e2..3c35aa5dc21 100644 --- a/src/solvers/prop/bdd_expr.h +++ b/src/solvers/prop/bdd_expr.h @@ -27,25 +27,23 @@ class namespacet; class bdd_exprt { public: - bdd_exprt(const namespacet &_ns):ns(_ns) { } + explicit bdd_exprt(const namespacet &_ns):ns(_ns) { } void from_expr(const exprt &expr); exprt as_expr() const; - typedef miniBDD::BDD BDDt; - protected: const namespacet &ns; - miniBDD::mgr bdd_mgr; - BDDt root; + mini_bdd_mgrt bdd_mgr; + mini_bddt root; - typedef std::unordered_map expr_mapt; + typedef std::unordered_map expr_mapt; expr_mapt expr_map; typedef std::map node_mapt; node_mapt node_map; - BDDt from_expr_rec(const exprt &expr); - exprt as_expr(const BDDt &r) const; + mini_bddt from_expr_rec(const exprt &expr); + exprt as_expr(const mini_bddt &r) const; }; #endif // CPROVER_SOLVERS_PROP_BDD_EXPR_H diff --git a/src/solvers/prop/bformula.h b/src/solvers/prop/bformula.h deleted file mode 100644 index a0ae99220bf..00000000000 --- a/src/solvers/prop/bformula.h +++ /dev/null @@ -1,128 +0,0 @@ -/*******************************************************************\ - -Module: - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#ifndef CPROVER_SOLVERS_PROP_BFORMULA_H -#define CPROVER_SOLVERS_PROP_BFORMULA_H - -#include "prop.h" - -class bformulat -{ -protected: - literalt l; - propt *prop; - -public: - // constructors - bformulat():prop(NULL) - { - } - - friend bformulat operator! (bformulat f) - { - f.l.invert(); - return f; - } - - friend bformulat operator? ( - bformulat c, bformulat a, bformulat b); - - friend bformulat operator | (bformulat a, bformulat b); - friend bformulat operator & (bformulat a, bformulat b); - friend bformulat operator ^ (bformulat a, bformulat b); - friend bformulat operator ==(bformulat a, bformulat b); - friend bformulat operator !=(bformulat a, bformulat b); - - // for sets - friend inline bool operator <(const bformulat a, const bformulat b) - { - return a.ll_get(l); - } - - friend inline bformulat const_bformula(bool value) - { - bformulat f; - f.l=const_literal(value); - return f; - } - - inline bool is_constant() const - { - return l.is_constant(); - } -}; - -// constants -bformulat const_bformula(bool value); - -//typedef std::vector bvt; - -#endif // CPROVER_SOLVERS_PROP_BFORMULA_H diff --git a/src/solvers/prop/cover_goals.h b/src/solvers/prop/cover_goals.h index ed97ea22dd7..afb93c9e534 100644 --- a/src/solvers/prop/cover_goals.h +++ b/src/solvers/prop/cover_goals.h @@ -26,7 +26,7 @@ Author: Daniel Kroening, kroening@kroening.com class cover_goalst:public messaget { public: - explicit inline cover_goalst(prop_convt &_prop_conv): + explicit cover_goalst(prop_convt &_prop_conv): prop_conv(_prop_conv) { } @@ -53,24 +53,24 @@ class cover_goalst:public messaget // statistics - inline std::size_t number_covered() const + std::size_t number_covered() const { return _number_covered; } - inline unsigned iterations() const + unsigned iterations() const { return _iterations; } - inline goalst::size_type size() const + goalst::size_type size() const { return goals.size(); } // managing the goals - inline void add(const literalt condition) + void add(const literalt condition) { goals.push_back(goalt()); goals.back().condition=condition; @@ -86,7 +86,7 @@ class cover_goalst:public messaget virtual void satisfying_assignment() { } }; - inline void register_observer(observert &o) + void register_observer(observert &o) { observers.push_back(&o); } diff --git a/src/solvers/prop/literal.cpp b/src/solvers/prop/literal.cpp index 7d0b4a3728a..d57da3e91a3 100644 --- a/src/solvers/prop/literal.cpp +++ b/src/solvers/prop/literal.cpp @@ -22,7 +22,7 @@ Function: operator << \*******************************************************************/ -std::ostream & operator << (std::ostream &out, literalt l) +std::ostream &operator << (std::ostream &out, literalt l) { if(l.is_constant()) return out << (l.is_true()?"true":"false"); diff --git a/src/solvers/prop/literal.h b/src/solvers/prop/literal.h index a15cb3aabc8..694f5701a12 100644 --- a/src/solvers/prop/literal.h +++ b/src/solvers/prop/literal.h @@ -29,81 +29,81 @@ class literalt typedef unsigned var_not; // constructors - inline literalt() + literalt() { set(unused_var_no(), false); } - inline literalt(var_not v, bool sign) + literalt(var_not v, bool sign) { set(v, sign); } - friend inline bool operator ==(const literalt a, const literalt b) + bool operator==(const literalt other) const { - return a.l==b.l; + return l==other.l; } - friend inline bool operator !=(const literalt a, const literalt b) + bool operator!=(const literalt other) const { - return a.l!=b.l; + return l!=other.l; } // for sets - friend inline bool operator <(const literalt a, const literalt b) + bool operator<(const literalt other) const { - return a.l>1; } - inline bool sign() const + bool sign() const { return l&1; } - inline void set(var_not _l) + void set(var_not _l) { l=_l; } - inline void set(var_not v, bool sign) + void set(var_not v, bool sign) { l=(v<<1)|((var_not)sign); } - inline var_not get() const + var_not get() const { return l; } - inline void invert() + void invert() { l^=(var_not)1; } @@ -125,54 +125,47 @@ class literalt void from_dimacs(int d) { bool sign=d<0; - if(sign) d=-d; + if(sign) + d=-d; set(d, sign); } - inline void clear() + void clear() { l=0; } - inline void swap(literalt &x) + void swap(literalt &x) { std::swap(x.l, l); } // constants - inline void make_true() + void make_true() { set(const_var_no(), true); } - inline void make_false() + void make_false() { set(const_var_no(), false); } - inline bool is_true() const + bool is_true() const { return is_constant() && sign(); } - inline bool is_false() const + bool is_false() const { return is_constant() && !sign(); } - friend inline literalt const_literal(bool value) - { - return literalt(literalt::const_var_no(), value); - } - - inline bool is_constant() const + bool is_constant() const { return var_no()==const_var_no(); } - friend inline literalt neg(literalt a) { return !a; } - friend inline literalt pos(literalt a) { return a; } - static inline var_not const_var_no() { return (var_not(-1)<<1)>>1; @@ -187,13 +180,17 @@ class literalt var_not l; }; -std::ostream & operator << (std::ostream &out, literalt l); +std::ostream &operator << (std::ostream &out, literalt l); // constants -literalt const_literal(bool value); +inline literalt const_literal(bool value) +{ + return literalt(literalt::const_var_no(), value); +} + +inline literalt neg(literalt a) { return !a; } +inline literalt pos(literalt a) { return a; } -literalt neg(literalt a); -literalt pos(literalt a); // bit-vectors typedef std::vector bvt; diff --git a/src/solvers/prop/literal_expr.h b/src/solvers/prop/literal_expr.h index ebfb908b9ac..b76c23b0ba5 100644 --- a/src/solvers/prop/literal_expr.h +++ b/src/solvers/prop/literal_expr.h @@ -16,20 +16,20 @@ Author: Daniel Kroening, kroening@kroening.com class literal_exprt:public predicate_exprt { public: - inline explicit literal_exprt(literalt a): + explicit literal_exprt(literalt a): predicate_exprt(ID_literal) { set_literal(a); } - inline literalt get_literal() const + literalt get_literal() const { literalt result; result.set(literalt::var_not(get_long_long(ID_literal))); return result; } - inline void set_literal(literalt a) + void set_literal(literalt a) { set(ID_literal, a.get()); } @@ -45,7 +45,7 @@ class literal_exprt:public predicate_exprt * * \ingroup gr_std_expr */ -extern inline const literal_exprt &to_literal_expr(const exprt &expr) +inline const literal_exprt &to_literal_expr(const exprt &expr) { assert(expr.id()==ID_literal && !expr.has_operands()); return static_cast(expr); @@ -54,7 +54,7 @@ extern inline const literal_exprt &to_literal_expr(const exprt &expr) /*! \copydoc to_literal_expr(const exprt &) * \ingroup gr_std_expr */ -extern inline literal_exprt &to_literal_expr(exprt &expr) +inline literal_exprt &to_literal_expr(exprt &expr) { assert(expr.id()==ID_literal && !expr.has_operands()); return static_cast(expr); diff --git a/src/solvers/prop/minimize.h b/src/solvers/prop/minimize.h index 1e170aa0ce0..f546f8442ee 100644 --- a/src/solvers/prop/minimize.h +++ b/src/solvers/prop/minimize.h @@ -27,7 +27,7 @@ Author: Daniel Kroening, kroening@kroening.com class prop_minimizet:public messaget { public: - explicit inline prop_minimizet(prop_convt &_prop_conv): + explicit prop_minimizet(prop_convt &_prop_conv): _number_objectives(0), prop_conv(_prop_conv) { @@ -37,17 +37,17 @@ class prop_minimizet:public messaget // statistics - inline std::size_t number_satisfied() const + std::size_t number_satisfied() const { return _number_satisfied; } - inline unsigned iterations() const + unsigned iterations() const { return _iterations; } - inline std::size_t size() const + std::size_t size() const { return _number_objectives; } diff --git a/src/solvers/prop/prop.h b/src/solvers/prop/prop.h index e557ccef098..6f58faef3b0 100644 --- a/src/solvers/prop/prop.h +++ b/src/solvers/prop/prop.h @@ -49,14 +49,27 @@ class propt:public messaget, public prop_assignmentt { l_set_to(a, false); } // constraints - inline void lcnf(literalt l0, literalt l1) + void lcnf(literalt l0, literalt l1) { lcnf_bv.resize(2); lcnf_bv[0]=l0; lcnf_bv[1]=l1; lcnf(lcnf_bv); } - inline void lcnf(literalt l0, literalt l1, literalt l2) - { lcnf_bv.resize(3); lcnf_bv[0]=l0; lcnf_bv[1]=l1; lcnf_bv[2]=l2; lcnf(lcnf_bv); } + void lcnf(literalt l0, literalt l1, literalt l2) + { + lcnf_bv.resize(3); + lcnf_bv[0]=l0; + lcnf_bv[1]=l1; + lcnf_bv[2]=l2; + lcnf(lcnf_bv); + } - inline void lcnf(literalt l0, literalt l1, literalt l2, literalt l3) - { lcnf_bv.resize(4); lcnf_bv[0]=l0; lcnf_bv[1]=l1; lcnf_bv[2]=l2; lcnf_bv[3]=l3; lcnf(lcnf_bv); } + void lcnf(literalt l0, literalt l1, literalt l2, literalt l3) + { + lcnf_bv.resize(4); + lcnf_bv[0]=l0; + lcnf_bv[1]=l1; + lcnf_bv[2]=l2; + lcnf_bv[3]=l3; + lcnf(lcnf_bv); + } virtual void lcnf(const bvt &bv)=0; virtual bool has_set_to() const { return true; } diff --git a/src/solvers/prop/prop_conv.cpp b/src/solvers/prop/prop_conv.cpp index e8bdcbdfb11..01ae3fcd841 100644 --- a/src/solvers/prop/prop_conv.cpp +++ b/src/solvers/prop/prop_conv.cpp @@ -18,7 +18,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "prop_conv.h" #include "literal_expr.h" -//#define DEBUG +// #define DEBUG /*******************************************************************\ @@ -114,7 +114,8 @@ bool prop_conv_solvert::literal(const exprt &expr, literalt &dest) const symbolst::const_iterator result=symbols.find(identifier); - if(result==symbols.end()) return true; + if(result==symbols.end()) + return true; dest=result->second; return false; } @@ -185,7 +186,8 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const symbolst::const_iterator result= symbols.find(to_symbol_expr(expr).get_identifier()); - if(result==symbols.end()) return true; + if(result==symbols.end()) + return true; value=prop.l_get(result->second); return false; @@ -198,7 +200,8 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const if(expr.type().id()==ID_bool && expr.operands().size()==1) { - if(get_bool(expr.op0(), value)) return true; + if(get_bool(expr.op0(), value)) + return true; value=!value; return false; } @@ -213,17 +216,26 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const forall_operands(it, expr) { tvt tmp; - if(get_bool(*it, tmp)) return true; + if(get_bool(*it, tmp)) + return true; if(expr.id()==ID_and) { - if(tmp.is_false()) { value=tvt(false); return false; } + if(tmp.is_false()) + { + value=tvt(false); + return false; + } value=value && tmp; } else // or { - if(tmp.is_true()) { value=tvt(true); return false; } + if(tmp.is_true()) + { + value=tvt(true); + return false; + } value=value || tmp; } @@ -236,7 +248,8 @@ bool prop_conv_solvert::get_bool(const exprt &expr, tvt &value) const // check cache cachet::const_iterator cache_result=cache.find(expr); - if(cache_result==cache.end()) return true; + if(cache_result==cache.end()) + return true; value=prop.l_get(cache_result->second); return false; @@ -261,7 +274,8 @@ literalt prop_conv_solvert::convert(const exprt &expr) expr.id()==ID_constant) { literalt literal=convert_bool(expr); - if(freeze_all && !literal.is_constant()) prop.set_frozen(literal); + if(freeze_all && !literal.is_constant()) + prop.set_frozen(literal); return literal; } // check cache first @@ -277,7 +291,8 @@ literalt prop_conv_solvert::convert(const exprt &expr) // insert into cache result.first->second=literal; - if(freeze_all && !literal.is_constant()) prop.set_frozen(literal); + if(freeze_all && !literal.is_constant()) + prop.set_frozen(literal); #if 0 std::cout << literal << "=" << expr << std::endl; @@ -419,7 +434,7 @@ literalt prop_conv_solvert::convert_bool(const exprt &expr) } else if(expr.id()==ID_let) { - //const let_exprt &let_expr=to_let_expr(expr); + // const let_exprt &let_expr=to_let_expr(expr); throw "let is todo"; } @@ -459,7 +474,8 @@ Function: prop_conv_solvert::set_equality_to_true bool prop_conv_solvert::set_equality_to_true(const equal_exprt &expr) { - if(!equality_propagation) return true; + if(!equality_propagation) + return true; // optimization for constraint of the form // new_variable = value @@ -659,9 +675,9 @@ decision_proceduret::resultt prop_conv_solvert::dec_solve() switch(result) { - case propt::P_SATISFIABLE: return D_SATISFIABLE; - case propt::P_UNSATISFIABLE: return D_UNSATISFIABLE; - default: return D_ERROR; + case propt::P_SATISFIABLE: return D_SATISFIABLE; + case propt::P_UNSATISFIABLE: return D_UNSATISFIABLE; + default: return D_ERROR; } return D_ERROR; diff --git a/src/solvers/prop/prop_conv.h b/src/solvers/prop/prop_conv.h index f250ea9e00a..5f3cf35c2c8 100644 --- a/src/solvers/prop/prop_conv.h +++ b/src/solvers/prop/prop_conv.h @@ -34,7 +34,7 @@ class prop_convt:public decision_proceduret // conversion to handle virtual literalt convert(const exprt &expr)=0; - inline literalt operator()(const exprt &expr) + literalt operator()(const exprt &expr) { return convert(expr); } @@ -88,12 +88,16 @@ class prop_conv_solvert:public prop_convt using prop_convt::set_frozen; virtual tvt l_get(literalt a) const override { return prop.l_get(a); } virtual void set_frozen(literalt a) override { prop.set_frozen(a); } - virtual void set_assumptions(const bvt &_assumptions) override { prop.set_assumptions(_assumptions); } - virtual bool has_set_assumptions() const override { return prop.has_set_assumptions(); } + virtual void set_assumptions(const bvt &_assumptions) override + { prop.set_assumptions(_assumptions); } + virtual bool has_set_assumptions() const override + { return prop.has_set_assumptions(); } virtual void set_all_frozen() override { freeze_all = true; } virtual literalt convert(const exprt &expr) override; - virtual bool is_in_conflict(literalt l) const override { return prop.is_in_conflict(l); } - virtual bool has_is_in_conflict() const override { return prop.has_is_in_conflict(); } + virtual bool is_in_conflict(literalt l) const override + { return prop.is_in_conflict(l); } + virtual bool has_is_in_conflict() const override + { return prop.has_is_in_conflict(); } // get literal for expression, if available virtual bool literal(const exprt &expr, literalt &literal) const; diff --git a/src/solvers/prop/prop_conv_store.cpp b/src/solvers/prop/prop_conv_store.cpp index 671766a9f79..19e290ce5ea 100644 --- a/src/solvers/prop/prop_conv_store.cpp +++ b/src/solvers/prop/prop_conv_store.cpp @@ -116,7 +116,7 @@ void prop_conv_storet::constraintt::replay(prop_convt &dest) const break; case CONVERT: - //dest.prop.set_equal(dest.convert_rest(expr), literal); + // dest.prop.set_equal(dest.convert_rest(expr), literal); break; default: diff --git a/src/solvers/prop/prop_conv_store.h b/src/solvers/prop/prop_conv_store.h index 675bda541ac..74ee286926d 100644 --- a/src/solvers/prop/prop_conv_store.h +++ b/src/solvers/prop/prop_conv_store.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com class prop_conv_storet:public prop_convt { public: - prop_conv_storet(const namespacet &_ns):prop_convt(_ns) + explicit prop_conv_storet(const namespacet &_ns):prop_convt(_ns) { } diff --git a/src/solvers/prop/prop_wrapper.h b/src/solvers/prop/prop_wrapper.h index ac40bc81d1c..d21b2e85a4e 100644 --- a/src/solvers/prop/prop_wrapper.h +++ b/src/solvers/prop/prop_wrapper.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com class prop_wrappert:public virtual propt { public: - prop_wrappert(propt &_prop):propt(_prop), p(_prop) { } + explicit prop_wrappert(propt &_prop):propt(_prop), p(_prop) { } virtual ~prop_wrappert() { } virtual literalt constant(bool value) diff --git a/src/solvers/qbf/qbf_bdd_core.cpp b/src/solvers/qbf/qbf_bdd_core.cpp index 57b47b90d54..7071a6abc66 100644 --- a/src/solvers/qbf/qbf_bdd_core.cpp +++ b/src/solvers/qbf/qbf_bdd_core.cpp @@ -435,7 +435,7 @@ void qbf_bdd_coret::compress_certificate(void) { status() << "Compressing Certificate" << eom; - for(const quantifiert& quantifier : quantifiers) + for(const quantifiert &quantifier : quantifiers) { if(quantifier.type==quantifiert::EXISTENTIAL) { diff --git a/src/solvers/qbf/qdimacs_cnf.cpp b/src/solvers/qbf/qdimacs_cnf.cpp index 6899921fccd..380f31ec12a 100644 --- a/src/solvers/qbf/qdimacs_cnf.cpp +++ b/src/solvers/qbf/qdimacs_cnf.cpp @@ -87,7 +87,7 @@ void qdimacs_cnft::write_prefix(std::ostream &out) const /*******************************************************************\ -Function: operator== +Function: qdimacs_cnft::operator== Inputs: @@ -97,10 +97,9 @@ Function: operator== \*******************************************************************/ -bool operator==(const qdimacs_cnft &a, const qdimacs_cnft &b) +bool qdimacs_cnft::operator==(const qdimacs_cnft &other) const { - return a.quantifiers==b.quantifiers && - a.clauses==b.clauses; + return quantifiers==other.quantifiers && clauses==other.clauses; } /*******************************************************************\ diff --git a/src/solvers/qbf/qdimacs_cnf.h b/src/solvers/qbf/qdimacs_cnf.h index 5e4b342836a..3cf039caea5 100644 --- a/src/solvers/qbf/qdimacs_cnf.h +++ b/src/solvers/qbf/qdimacs_cnf.h @@ -44,9 +44,9 @@ class qdimacs_cnft:public dimacs_cnft { } - friend bool operator==(const quantifiert &a, const quantifiert &b) + bool operator==(const quantifiert &other) const { - return a.type==b.type && a.var_no==b.var_no; + return type==other.type && var_no==other.var_no; } size_t hash() const @@ -64,17 +64,17 @@ class qdimacs_cnft:public dimacs_cnft quantifiers.push_back(quantifier); } - inline void add_quantifier(const quantifiert::typet type, const literalt l) + void add_quantifier(const quantifiert::typet type, const literalt l) { add_quantifier(quantifiert(type, l)); } - inline void add_existential_quantifier(const literalt l) + void add_existential_quantifier(const literalt l) { add_quantifier(quantifiert(quantifiert::EXISTENTIAL, l)); } - inline void add_universal_quantifier(const literalt l) + void add_universal_quantifier(const literalt l) { add_quantifier(quantifiert(quantifiert::UNIVERSAL, l)); } @@ -85,7 +85,8 @@ class qdimacs_cnft:public dimacs_cnft virtual void set_quantifier(const quantifiert::typet type, const literalt l); void copy_to(qdimacs_cnft &cnf) const; - friend bool operator==(const qdimacs_cnft &a, const qdimacs_cnft &b); + bool operator==(const qdimacs_cnft &other) const; + size_t hash() const; protected: diff --git a/src/solvers/refinement/bv_refinement.h b/src/solvers/refinement/bv_refinement.h index 00379373265..cc96bfccf45 100644 --- a/src/solvers/refinement/bv_refinement.h +++ b/src/solvers/refinement/bv_refinement.h @@ -24,8 +24,11 @@ class bv_refinementt:public bv_pointerst virtual decision_proceduret::resultt dec_solve(); virtual std::string decision_procedure_text() const - { return "refinement loop with "+prop.solver_text(); } + { + return "refinement loop with "+prop.solver_text(); + } + // NOLINTNEXTLINE(readability/identifiers) typedef bv_pointerst SUB; // maximal number of times we refine a formula node @@ -108,7 +111,6 @@ class bv_refinementt:public bv_pointerst // use gui format language_uit::uit ui; - }; #endif // CPROVER_SOLVERS_REFINEMENT_BV_REFINEMENT_H diff --git a/src/solvers/refinement/bv_refinement_loop.cpp b/src/solvers/refinement/bv_refinement_loop.cpp index b6eb359bca7..228de631637 100644 --- a/src/solvers/refinement/bv_refinement_loop.cpp +++ b/src/solvers/refinement/bv_refinement_loop.cpp @@ -101,19 +101,22 @@ decision_proceduret::resultt bv_refinementt::dec_solve() return D_SATISFIABLE; } else - status() << "BV-Refinement: got SAT, and it is spurious, refining" << eom; + status() << "BV-Refinement: got SAT, and it is spurious, refining" + << eom; break; case D_UNSATISFIABLE: check_UNSAT(); if(!progress) { - status() << "BV-Refinement: got UNSAT, and the proof passes => UNSAT" << eom; + status() << "BV-Refinement: got UNSAT, and the proof passes => UNSAT" + << eom; status() << "Total iterations: " << iteration << eom; return D_UNSATISFIABLE; } else - status() << "BV-Refinement: got UNSAT, and the proof fails, refining" << eom; + status() << "BV-Refinement: got UNSAT, and the proof fails, refining" + << eom; break; default: @@ -137,7 +140,7 @@ Function: bv_refinementt::prop_solve decision_proceduret::resultt bv_refinementt::prop_solve() { // this puts the underapproximations into effect - bvt assumptions = parent_assumptions; + bvt assumptions=parent_assumptions; for(approximationst::const_iterator a_it=approximations.begin(); @@ -158,9 +161,9 @@ decision_proceduret::resultt bv_refinementt::prop_solve() switch(result) { - case propt::P_SATISFIABLE: return D_SATISFIABLE; - case propt::P_UNSATISFIABLE: return D_UNSATISFIABLE; - default: return D_ERROR; + case propt::P_SATISFIABLE: return D_SATISFIABLE; + case propt::P_UNSATISFIABLE: return D_UNSATISFIABLE; + default: return D_ERROR; } } @@ -231,9 +234,11 @@ void bv_refinementt::set_to(const exprt &expr, bool value) SUB::set_to(expr, value); unsigned n=prop.no_variables()-prev; std::cout << n << " EEE " << expr.id() << "@" << expr.type().id(); - forall_operands(it, expr) std::cout << " " << it->id() << "@" << it->type().id(); + forall_operands(it, expr) + std::cout << " " << it->id() << "@" << it->type().id(); if(expr.id()=="=" && expr.operands().size()==2) - forall_operands(it, expr.op1()) std::cout << " " << it->id() << "@" << it->type().id(); + forall_operands(it, expr.op1()) + std::cout << " " << it->id() << "@" << it->type().id(); std::cout << std::endl; #else SUB::set_to(expr, value); @@ -252,7 +257,8 @@ Function: bv_refinementt::set_assumptions \*******************************************************************/ -void bv_refinementt::set_assumptions(const bvt &_assumptions) { - parent_assumptions = _assumptions; +void bv_refinementt::set_assumptions(const bvt &_assumptions) +{ + parent_assumptions=_assumptions; prop.set_assumptions(_assumptions); } diff --git a/src/solvers/refinement/refine_arithmetic.cpp b/src/solvers/refinement/refine_arithmetic.cpp index eb774866c02..3c59537900b 100644 --- a/src/solvers/refinement/refine_arithmetic.cpp +++ b/src/solvers/refinement/refine_arithmetic.cpp @@ -267,7 +267,8 @@ void bv_refinementt::check_SAT(approximationt &a) // these are all trinary assert(a.expr.operands().size()==3); - if(a.over_state==MAX_STATE) return; + if(a.over_state==MAX_STATE) + return; ieee_float_spect spec(to_floatbv_type(type)); ieee_floatt o0(spec), o1(spec); @@ -317,7 +318,7 @@ void bv_refinementt::check_SAT(approximationt &a) << "==" << integer2binary(result.pack(), spec.width()) << eom; #endif - //if(a.over_state==1) { debug() << "DISAGREEMENT!\n"; exit(1); } + // if(a.over_state==1) { debug() << "DISAGREEMENT!\n"; exit(1); } if(a.over_state0) return; + if(a.over_state>0) + return; bv_spect spec(type); bv_arithmetict o0(spec), o1(spec); @@ -410,19 +412,22 @@ void bv_refinementt::check_SAT(approximationt &a) { r=bv_utils.multiplier( a.op0_bv, a.op1_bv, - a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); + a.expr.type().id()==ID_signedbv? + bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else if(a.expr.id()==ID_div) { r=bv_utils.divider( a.op0_bv, a.op1_bv, - a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); + a.expr.type().id()==ID_signedbv? + bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else if(a.expr.id()==ID_mod) { r=bv_utils.remainder( a.op0_bv, a.op1_bv, - a.expr.type().id()==ID_signedbv?bv_utilst::SIGNED:bv_utilst::UNSIGNED); + a.expr.type().id()==ID_signedbv? + bv_utilst::SIGNED:bv_utilst::UNSIGNED); } else assert(0); @@ -434,7 +439,7 @@ void bv_refinementt::check_SAT(approximationt &a) } else if(type.id()==ID_fixedbv) { - //TODO: not implemented + // TODO: not implemented assert(0); } else @@ -466,7 +471,8 @@ Function: bv_refinementt::check_UNSAT void bv_refinementt::check_UNSAT(approximationt &a) { // part of the conflict? - if(!is_in_conflict(a)) return; + if(!is_in_conflict(a)) + return; status() << "Found assumption for `" << a.as_string() << "' in proof (state " << a.under_state << ")" << eom; @@ -478,7 +484,7 @@ void bv_refinementt::check_UNSAT(approximationt &a) if(a.expr.type().id()==ID_floatbv) { const floatbv_typet &floatbv_type=to_floatbv_type(a.expr.type()); - ieee_float_spect spec=floatbv_type; + ieee_float_spect spec(floatbv_type); a.under_assumptions.reserve(a.op0_bv.size()+a.op1_bv.size()); diff --git a/src/solvers/refinement/refine_arrays.cpp b/src/solvers/refinement/refine_arrays.cpp index 8f0212e2c8a..2296f3c42ad 100644 --- a/src/solvers/refinement/refine_arrays.cpp +++ b/src/solvers/refinement/refine_arrays.cpp @@ -38,7 +38,7 @@ void bv_refinementt::post_process_arrays() update_index_map(true); // we don't actually add any constraints - lazy_arrays = do_array_refinement; + lazy_arrays=do_array_refinement; add_array_constraints(); freeze_lazy_constraints(); } @@ -57,47 +57,48 @@ Function: bv_refinementt::arrays_overapproximated void bv_refinementt::arrays_overapproximated() { - if(!do_array_refinement) return; + if(!do_array_refinement) + return; - unsigned nb_active = 0; + unsigned nb_active=0; - std::list::iterator it = lazy_array_constraints.begin(); - while(it != lazy_array_constraints.end()) + std::list::iterator it=lazy_array_constraints.begin(); + while(it!=lazy_array_constraints.end()) { satcheck_no_simplifiert sat_check; - bv_pointerst solver(ns,sat_check); + bv_pointerst solver(ns, sat_check); solver.unbounded_array=bv_pointerst::U_ALL; - exprt current = (*it).lazy; + exprt current=(*it).lazy; // some minor simplifications // check if they are worth having - if (current.id() == ID_implies) + if(current.id()==ID_implies) { - implies_exprt imp = to_implies_expr(current); - assert (imp.operands().size() == 2); - exprt implies_simplified = get(imp.op0()); - if (implies_simplified == false_exprt()) + implies_exprt imp=to_implies_expr(current); + assert(imp.operands().size()==2); + exprt implies_simplified=get(imp.op0()); + if(implies_simplified==false_exprt()) { ++it; continue; } } - if (current.id() == ID_or) + if(current.id()==ID_or) { - or_exprt orexp = to_or_expr(current); - assert (orexp.operands().size() == 2); - exprt o1 = get(orexp.op0()); - exprt o2 = get(orexp.op1()); - if (o1 == true_exprt() || o2 == true_exprt()) + or_exprt orexp=to_or_expr(current); + assert(orexp.operands().size()==2); + exprt o1=get(orexp.op0()); + exprt o2=get(orexp.op1()); + if(o1==true_exprt() || o2 == true_exprt()) { ++it; continue; } } - exprt simplified = get(current); + exprt simplified=get(current); solver << simplified; switch(sat_check.prop_solve()) @@ -113,15 +114,14 @@ void bv_refinementt::arrays_overapproximated() default: assert(false); } - } debug() << "BV-Refinement: " << nb_active << " array expressions become active" << eom; debug() << "BV-Refinement: " << lazy_array_constraints.size() << " inactive array expressions" << eom; - if (nb_active > 0) - progress = true; + if(nb_active > 0) + progress=true; } @@ -139,20 +139,22 @@ Function: bv_refinementt::freeze_lazy_constraints void bv_refinementt::freeze_lazy_constraints() { - if(!lazy_arrays) return; + if(!lazy_arrays) + return; for(std::list::iterator - l_it = lazy_array_constraints.begin(); - l_it != lazy_array_constraints.end(); ++l_it) + l_it=lazy_array_constraints.begin(); + l_it!=lazy_array_constraints.end(); ++l_it) { std::set symbols; - find_symbols(l_it->lazy,symbols); - for(std::set::const_iterator it = symbols.begin(); - it != symbols.end(); ++it) + find_symbols(l_it->lazy, symbols); + for(std::set::const_iterator it=symbols.begin(); + it!=symbols.end(); ++it) { - bvt bv = convert_bv(l_it->lazy); + bvt bv=convert_bv(l_it->lazy); forall_literals(b_it, bv) - if(!b_it->is_constant()) prop.set_frozen(*b_it); + if(!b_it->is_constant()) + prop.set_frozen(*b_it); } } } diff --git a/src/solvers/sat/cnf.cpp b/src/solvers/sat/cnf.cpp index f656859bd7c..a69947df8f4 100644 --- a/src/solvers/sat/cnf.cpp +++ b/src/solvers/sat/cnf.cpp @@ -12,7 +12,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include "cnf.h" -//#define VERBOSE +// #define VERBOSE /*******************************************************************\ @@ -233,9 +233,12 @@ Function: cnft::land literalt cnft::land(const bvt &bv) { - if(bv.empty()) return const_literal(true); - if(bv.size()==1) return bv[0]; - if(bv.size()==2) return land(bv[0], bv[1]); + if(bv.empty()) + return const_literal(true); + if(bv.size()==1) + return bv[0]; + if(bv.size()==2) + return land(bv[0], bv[1]); for(const auto l : bv) if(l.is_false()) @@ -282,9 +285,12 @@ Function: cnft::lor literalt cnft::lor(const bvt &bv) { - if(bv.empty()) return const_literal(false); - if(bv.size()==1) return bv[0]; - if(bv.size()==2) return lor(bv[0], bv[1]); + if(bv.empty()) + return const_literal(false); + if(bv.size()==1) + return bv[0]; + if(bv.size()==2) + return lor(bv[0], bv[1]); for(const auto l : bv) if(l.is_true()) @@ -331,9 +337,12 @@ Function: cnft::lxor literalt cnft::lxor(const bvt &bv) { - if(bv.empty()) return const_literal(false); - if(bv.size()==1) return bv[0]; - if(bv.size()==2) return lxor(bv[0], bv[1]); + if(bv.empty()) + return const_literal(false); + if(bv.size()==1) + return bv[0]; + if(bv.size()==2) + return lxor(bv[0], bv[1]); literalt literal=const_literal(false); @@ -357,11 +366,12 @@ Function: cnft::land literalt cnft::land(literalt a, literalt b) { - if(a.is_true()) return b; - if(b.is_true()) return a; - if(a.is_false()) return a; - if(b.is_false()) return b; - if(a==b) return a; + if(a.is_true() || b.is_false()) + return b; + if(b.is_true() || a.is_false()) + return a; + if(a==b) + return a; literalt o=new_variable(); gate_and(a, b, o); @@ -382,11 +392,12 @@ Function: cnft::lor literalt cnft::lor(literalt a, literalt b) { - if(a.is_false()) return b; - if(b.is_false()) return a; - if(a.is_true()) return a; - if(b.is_true()) return b; - if(a==b) return a; + if(a.is_false() || b.is_true()) + return b; + if(b.is_false() || a.is_true()) + return a; + if(a==b) + return a; literalt o=new_variable(); gate_or(a, b, o); @@ -407,12 +418,18 @@ Function: cnft::lxor literalt cnft::lxor(literalt a, literalt b) { - if(a.is_false()) return b; - if(b.is_false()) return a; - if(a.is_true()) return !b; - if(b.is_true()) return !a; - if(a==b) return const_literal(false); - if(a==!b) return const_literal(true); + if(a.is_false()) + return b; + if(b.is_false()) + return a; + if(a.is_true()) + return !b; + if(b.is_true()) + return !a; + if(a==b) + return const_literal(false); + if(a==!b) + return const_literal(true); literalt o=new_variable(); gate_xor(a, b, o); @@ -502,16 +519,20 @@ Function: cnft::lselect // Tino observed slow-downs up to 50% with OPTIMAL_COMPACT_ITE. #define COMPACT_ITE -//#define OPTIMAL_COMPACT_ITE +// #define OPTIMAL_COMPACT_ITE literalt cnft::lselect(literalt a, literalt b, literalt c) -{ // a?b:c = (a AND b) OR (/a AND c) - - if(a.is_constant()) return a.sign() ? b : c; - if(b==c) return b; +{ + // a?b:c = (a AND b) OR (/a AND c) + if(a.is_constant()) + return a.sign() ? b : c; + if(b==c) + return b; - if(b.is_constant()) return b.sign() ? lor(a, c) : land(!a, c); - if(c.is_constant()) return c.sign() ? lor(!a, b) : land(a, b); + if(b.is_constant()) + return b.sign() ? lor(a, c) : land(!a, c); + if(c.is_constant()) + return c.sign() ? lor(!a, b) : land(a, b); #ifdef COMPACT_ITE @@ -521,14 +542,14 @@ literalt cnft::lselect(literalt a, literalt b, literalt c) bvt lits; - lcnf( a, !c, o); - lcnf( a, c, !o); + lcnf(a, !c, o); + lcnf(a, c, !o); lcnf(!a, !b, o); lcnf(!a, b, !o); #ifdef OPTIMAL_COMPACT_ITE // additional clauses to enable better propagation - lcnf( b, c, !o); + lcnf(b, c, !o); lcnf(!b, !c, o); #endif @@ -605,7 +626,8 @@ bool cnft::process_clause(const bvt &bv, bvt &dest) dest.clear(); // empty clause! this is UNSAT - if(bv.empty()) return false; + if(bv.empty()) + return false; // first check simple things @@ -624,7 +646,8 @@ bool cnft::process_clause(const bvt &bv, bvt &dest) continue; // will remove later if(l.var_no()>=_no_variables) - std::cout << "l.var_no()=" << l.var_no() << " _no_variables=" << _no_variables << std::endl; + std::cout << "l.var_no()=" << l.var_no() + << " _no_variables=" << _no_variables << std::endl; assert(l.var_no()<_no_variables); } diff --git a/src/solvers/sat/cnf.h b/src/solvers/sat/cnf.h index e9519fb8d79..49af573bda8 100644 --- a/src/solvers/sat/cnf.h +++ b/src/solvers/sat/cnf.h @@ -16,7 +16,7 @@ class cnft:public propt public: // For CNF, we don't use index 0 as a matter of principle, // so we'll start counting variables at 1. - inline cnft():_no_variables(1) { } + cnft():_no_variables(1) { } virtual ~cnft() { } virtual literalt land(literalt a, literalt b) override; @@ -29,7 +29,8 @@ class cnft:public propt virtual literalt lnor(literalt a, literalt b) override; virtual literalt lequal(literalt a, literalt b) override; virtual literalt limplies(literalt a, literalt b) override; - virtual literalt lselect(literalt a, literalt b, literalt c) override; // a?b:c + // a?b:c + virtual literalt lselect(literalt a, literalt b, literalt c) override; virtual literalt new_variable() override; virtual size_t no_variables() const override { return _no_variables; } virtual void set_no_variables(size_t no) { _no_variables=no; } @@ -53,7 +54,8 @@ class cnft:public propt static bool is_all(const bvt &bv, literalt l) { forall_literals(it, bv) - if(*it!=l) return false; + if(*it!=l) + return false; return true; } }; diff --git a/src/solvers/sat/cnf_clause_list.h b/src/solvers/sat/cnf_clause_list.h index 78cc650ff6e..ca9f652fd72 100644 --- a/src/solvers/sat/cnf_clause_list.h +++ b/src/solvers/sat/cnf_clause_list.h @@ -81,15 +81,17 @@ class cnf_clause_list_assignmentt:public cnf_clause_listt public: typedef std::vector assignmentt; - inline assignmentt &get_assignment() + assignmentt &get_assignment() { return assignment; } virtual tvt l_get(literalt literal) const { - if(literal.is_true()) return tvt(true); - if(literal.is_false()) return tvt(false); + if(literal.is_true()) + return tvt(true); + if(literal.is_false()) + return tvt(false); unsigned v=literal.var_no(); diff --git a/src/solvers/sat/dimacs_cnf.cpp b/src/solvers/sat/dimacs_cnf.cpp index 54ec2a1a6a7..8a7fc02d97a 100644 --- a/src/solvers/sat/dimacs_cnf.cpp +++ b/src/solvers/sat/dimacs_cnf.cpp @@ -110,7 +110,8 @@ static void write_dimacs_clause( { out << clause[j].dimacs() << " "; // newline to avoid overflow in sat checkers - if((j&15)==0 && j!=0 && break_lines) out << "\n"; + if((j&15)==0 && j!=0 && break_lines) + out << "\n"; } out << "0" << "\n"; diff --git a/src/solvers/sat/pbs_dimacs_cnf.cpp b/src/solvers/sat/pbs_dimacs_cnf.cpp index 2c2337a323f..073c16ad89b 100644 --- a/src/solvers/sat/pbs_dimacs_cnf.cpp +++ b/src/solvers/sat/pbs_dimacs_cnf.cpp @@ -27,25 +27,26 @@ Function: pbs_dimacs_cnft::write_dimacs_cnf_pb void pbs_dimacs_cnft::write_dimacs_pb(std::ostream &out) { - double d_sum = 0; + double d_sum=0; - //std::cout << "enter: No Lit. = " << no_variables () << "\n"; + // std::cout << "enter: No Lit.=" << no_variables () << "\n"; - for(std::map::const_iterator it=pb_constraintmap.begin(); - it != pb_constraintmap.end (); ++it) + for(std::map::const_iterator it=pb_constraintmap.begin(); + it!=pb_constraintmap.end(); ++it) d_sum += ((*it).second); - if (!optimize) + if(!optimize) { out << "# PBType: E" << "\n"; out << "# PBGoal: " << goal << "\n"; } - else if (!maximize) + else if(!maximize) { out << "# PBType: SE" << "\n"; out << "# PBGoal: " << d_sum << "\n"; out << "# PBObj : MIN" << "\n"; - } else + } + else { out << "# PBType: GE" << "\n"; out << "# PBGoal: " << 0 << "\n"; @@ -54,14 +55,13 @@ void pbs_dimacs_cnft::write_dimacs_pb(std::ostream &out) out << "# NumCoef: " << pb_constraintmap.size() << "\n"; - for(std::map::const_iterator it=pb_constraintmap.begin(); - it!=pb_constraintmap.end();++it) - { - int dimacs_lit = (*it).first.dimacs(); - out << "v" << dimacs_lit << " c" << ((*it).second) << "\n"; - } + for(const auto &lit_entry : pb_constraintmap) + { + int dimacs_lit=lit_entry.first.dimacs(); + out << "v" << dimacs_lit << " c" << lit_entry.second << "\n"; + } - //std::cout << "exit: No Lit. = " << no_variables () << "\n"; + // std::cout << "exit: No Lit.=" << no_variables () << "\n"; } /*******************************************************************\ @@ -78,23 +78,24 @@ Function: pbs_dimacs_cnft::pbs_solve bool pbs_dimacs_cnft::pbs_solve() { - //std::cout << "solve: No Lit. = " << no_variables () << "\n"; + // std::cout << "solve: No Lit.=" << no_variables () << "\n"; std::string command; - if(!pbs_path.empty()) { + if(!pbs_path.empty()) + { command += pbs_path; - if (command.substr(command.length(),1) != "/") + if(command.substr(command.length(), 1)!="/") command += "/"; } command += "pbs"; - //std::cout << "PBS COMMAND IS: " << command << "\n"; + // std::cout << "PBS COMMAND IS: " << command << "\n"; /* - if (!(getenv("PBS_PATH") == NULL)) + if (!(getenv("PBS_PATH")==NULL)) { - command = getenv("PBS_PATH"); + command=getenv("PBS_PATH"); } else { @@ -106,20 +107,22 @@ bool pbs_dimacs_cnft::pbs_solve() command += " -f temp.cnf"; #if 1 - if (optimize) + if(optimize) + { + if(binary_search) { - if (binary_search) { - command += " -S 1000 -D 1 -H -I -a"; - } - else { - //std::cout << "NO BINARY SEARCH" << "\n"; - command += " -S 1000 -D 1 -I -a"; - } + command += " -S 1000 -D 1 -H -I -a"; } - else + else { - command += " -S 1000 -D 1 -a"; + // std::cout << "NO BINARY SEARCH" << "\n"; + command += " -S 1000 -D 1 -I -a"; } + } + else + { + command += " -S 1000 -D 1 -a"; + } #else command += " -z"; #endif @@ -127,12 +130,12 @@ bool pbs_dimacs_cnft::pbs_solve() command += " -a > temp.out"; int res=system(command.c_str()); - assert(0 == res); + assert(0==res); std::ifstream file("temp.out"); std::string line; int v; - bool satisfied = false; + bool satisfied=false; if(file.fail()) { @@ -140,54 +143,57 @@ bool pbs_dimacs_cnft::pbs_solve() return false; } - opt_sum = -1; + opt_sum=-1; while(file && !file.eof ()) { - std::getline(file,line); + std::getline(file, line); if(strstr(line.c_str(), "Variable Assignments Satisfying CNF Formula:")!=NULL) { - //print ("Reading assignments...\n"); - //std::cout << "No literals: " << no_variables() << "\n"; - satisfied = true; - assigned.clear (); - for (size_t i = 0; (file && (i < no_variables())); ++i) + // print ("Reading assignments...\n"); + // std::cout << "No literals: " << no_variables() << "\n"; + satisfied=true; + assigned.clear(); + for(size_t i=0; (file && (i < no_variables())); ++i) { file >> v; - if (v > 0) + if(v > 0) { - //std::cout << v << " "; + // std::cout << v << " "; assigned.insert(v); } } - //std::cout << "\n"; - //print ("Finished reading assignments.\n"); + // std::cout << "\n"; + // print ("Finished reading assignments.\n"); } - else if (strstr(line.c_str(),"SAT... SUM") != NULL) + else if(strstr(line.c_str(), "SAT... SUM")!=NULL) { - //print (line); - sscanf(line.c_str(),"%*s %*s %*s %d", &opt_sum); + // print (line); + sscanf(line.c_str(), "%*s %*s %*s %d", &opt_sum); } - else if (strstr(line.c_str(),"SAT - All implied") != NULL) + else if(strstr(line.c_str(), "SAT - All implied")!=NULL) { - //print (line); - sscanf(line.c_str(),"%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d", &opt_sum); + // print (line); + sscanf( + line.c_str(), + "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d", + &opt_sum); } - else if (strstr(line.c_str(),"SAT... Solution") != NULL) + else if(strstr(line.c_str(), "SAT... Solution")!=NULL) { - //print(line); - sscanf(line.c_str(),"%*s %*s %*s %d", &opt_sum); + // print(line); + sscanf(line.c_str(), "%*s %*s %*s %d", &opt_sum); } - else if (strstr(line.c_str(),"Optimal Soln") != NULL) + else if(strstr(line.c_str(), "Optimal Soln")!=NULL) { - //print(line); - if (strstr(line.c_str(),"time out") != NULL) + // print(line); + if(strstr(line.c_str(), "time out")!=NULL) { - print (6, "WARNING: TIMED OUT. SOLUTION MAY BE INCORRECT.\n"); + print(6, "WARNING: TIMED OUT. SOLUTION MAY BE INCORRECT.\n"); return satisfied; } - sscanf(line.c_str(),"%*s %*s %*s %d", &opt_sum); + sscanf(line.c_str(), "%*s %*s %*s %d", &opt_sum); } } @@ -260,43 +266,43 @@ Function: pbs_dimacs_cnft::l_get tvt pbs_dimacs_cnft::l_get(literalt a) const { - int dimacs_lit = a.dimacs(); + int dimacs_lit=a.dimacs(); - //std::cout << a << " / " << dimacs_lit << " = "; + // std::cout << a << " / " << dimacs_lit << "="; - bool neg = (dimacs_lit < 0); + bool neg=(dimacs_lit < 0); if(neg) - dimacs_lit = -dimacs_lit; + dimacs_lit=-dimacs_lit; - std::set::const_iterator f = assigned.find(dimacs_lit); + std::set::const_iterator f=assigned.find(dimacs_lit); if(!neg) { - if(f == assigned.end()) + if(f==assigned.end()) { - //std::cout << "FALSE" << "\n"; + // std::cout << "FALSE" << "\n"; return tvt(false); } else { - //std::cout << "TRUE" << "\n"; + // std::cout << "TRUE" << "\n"; return tvt(true); } } else { - if(f != assigned.end()) + if(f!=assigned.end()) { - //std::cout << "FALSE" << "\n"; + // std::cout << "FALSE" << "\n"; return tvt(false); } else { - //std::cout << "TRUE" << "\n"; + // std::cout << "TRUE" << "\n"; return tvt(true); } } - //std::cout << "ERROR" << "\n"; + // std::cout << "ERROR" << "\n"; return tvt::unknown(); } diff --git a/src/solvers/sat/pbs_dimacs_cnf.h b/src/solvers/sat/pbs_dimacs_cnf.h index 915429016e7..8d2b04bae24 100644 --- a/src/solvers/sat/pbs_dimacs_cnf.h +++ b/src/solvers/sat/pbs_dimacs_cnf.h @@ -17,7 +17,7 @@ Author: Alex Groce class pbs_dimacs_cnft:public dimacs_cnft { - public: +public: pbs_dimacs_cnft(): optimize(false), maximize(false), @@ -42,7 +42,7 @@ class pbs_dimacs_cnft:public dimacs_cnft int goal; int opt_sum; - std::map pb_constraintmap; + std::map pb_constraintmap; bool pbs_solve(); @@ -53,10 +53,11 @@ class pbs_dimacs_cnft:public dimacs_cnft // dummy functions virtual const std::string solver_text() - { return "PBS - Pseudo Boolean/CNF Solver and Optimizer"; } - - protected: + { + return "PBS - Pseudo Boolean/CNF Solver and Optimizer"; + } +protected: std::set assigned; }; diff --git a/src/solvers/sat/read_dimacs_cnf.cpp b/src/solvers/sat/read_dimacs_cnf.cpp index cf30a208904..42e63a5e9e2 100644 --- a/src/solvers/sat/read_dimacs_cnf.cpp +++ b/src/solvers/sat/read_dimacs_cnf.cpp @@ -13,7 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "read_dimacs_cnf.h" -//#define VERBOSE +// #define VERBOSE /*******************************************************************\ @@ -56,14 +56,13 @@ void read_dimacs_cnf(std::istream &in, cnft &dest) if(pos!=std::string::npos) { std::string decision = line.substr(0, pos); - line.erase(0,pos+1); + line.erase(0, pos+1); #ifdef VERBOSE std::cout << "i am here\n"; std::cout << decision << std::endl; std::cout << "line" << line << std::endl; #endif if(!decision.compare(std::string("c"))) - // if(!strcasecmp(decision.c_str(),"c")) { #ifdef VERBOSE std::cout << "c " << std::endl; @@ -72,7 +71,6 @@ void read_dimacs_cnf(std::istream &in, cnft &dest) } if(!decision.compare(std::string("p"))) - // if(!strcasecmp(decision.c_str(),"p")) { #ifdef VERBOSE std::cout << "p " << std::endl; @@ -80,7 +78,7 @@ void read_dimacs_cnf(std::istream &in, cnft &dest) break; } - if(pos_char == std::string::npos) //no char present in the clause + if(pos_char == std::string::npos) // no char present in the clause { int parsed_lit = unsafe_string2int(decision); #ifdef VERBOSE @@ -98,7 +96,7 @@ void read_dimacs_cnf(std::istream &in, cnft &dest) } else { - unsigned var = abs(parsed_lit); //because of the const variable + unsigned var = abs(parsed_lit); // because of the const variable literalt l; bool sign = (parsed_lit > 0) ? false : true; l.set(var, sign); diff --git a/src/solvers/sat/resolution_proof.cpp b/src/solvers/sat/resolution_proof.cpp index 77b2307fd91..20c10498a96 100644 --- a/src/solvers/sat/resolution_proof.cpp +++ b/src/solvers/sat/resolution_proof.cpp @@ -40,7 +40,8 @@ void resolution_prooft::build_core(std::vector &in_core) typename clausest::size_type c_id=s.top(); s.pop(); - if(seen[c_id]) continue; + if(seen[c_id]) + continue; seen[c_id]=true; const T &c=clauses[c_id]; diff --git a/src/solvers/sat/satcheck.h b/src/solvers/sat/satcheck.h index 69d75fbabec..19fc7759f69 100644 --- a/src/solvers/sat/satcheck.h +++ b/src/solvers/sat/satcheck.h @@ -11,14 +11,14 @@ Author: Daniel Kroening, kroening@kroening.com // this picks the "default" SAT solver -//#define SATCHECK_ZCHAFF -//#define SATCHECK_MINISAT1 +// #define SATCHECK_ZCHAFF +// #define SATCHECK_MINISAT1 #define SATCHECK_MINISAT2 -//#define SATCHECK_GLUCOSE -//#define SATCHECK_BOOLEFORCE -//#define SATCHECK_PRECOSAT -//#define SATCHECK_PICOSAT -//#define SATCHECK_LINGELING +// #define SATCHECK_GLUCOSE +// #define SATCHECK_BOOLEFORCE +// #define SATCHECK_PRECOSAT +// #define SATCHECK_PICOSAT +// #define SATCHECK_LINGELING #if defined SATCHECK_ZCHAFF diff --git a/src/solvers/sat/satcheck_booleforce.cpp b/src/solvers/sat/satcheck_booleforce.cpp index 6fe9bb6784f..16a23f152f9 100644 --- a/src/solvers/sat/satcheck_booleforce.cpp +++ b/src/solvers/sat/satcheck_booleforce.cpp @@ -11,7 +11,8 @@ Author: Daniel Kroening, kroening@kroening.com #include "satcheck_booleforce.h" -extern "C" { +extern "C" +{ #include "booleforce.h" } @@ -101,7 +102,8 @@ tvt satcheck_booleforce_baset::l_get(literalt a) const else result=tvt(tvt::tv_enumt::TV_UNKNOWN); - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } diff --git a/src/solvers/sat/satcheck_core.h b/src/solvers/sat/satcheck_core.h index 0c9c4550b8e..65ad61bab83 100644 --- a/src/solvers/sat/satcheck_core.h +++ b/src/solvers/sat/satcheck_core.h @@ -9,9 +9,9 @@ Author: Daniel Kroening, kroening@kroening.com #ifndef CPROVER_SOLVERS_SAT_SATCHECK_CORE_H #define CPROVER_SOLVERS_SAT_SATCHECK_CORE_H -//#define SATCHECK_CORE_ZCHAFF -//#define SATCHECK_CORE_MINISAT1 -//#define SATCHECK_CORE_BOOLEFORCE +// #define SATCHECK_CORE_ZCHAFF +// #define SATCHECK_CORE_MINISAT1 +// #define SATCHECK_CORE_BOOLEFORCE #ifdef SATCHECK_CORE_ZCHAFF diff --git a/src/solvers/sat/satcheck_glucose.cpp b/src/solvers/sat/satcheck_glucose.cpp index 652139164cc..152716d8157 100644 --- a/src/solvers/sat/satcheck_glucose.cpp +++ b/src/solvers/sat/satcheck_glucose.cpp @@ -79,7 +79,8 @@ tvt satcheck_glucose_baset::l_get(literalt a) const else return tvt(tvt::tv_enumt::TV_UNKNOWN); - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } diff --git a/src/solvers/sat/satcheck_glucose.h b/src/solvers/sat/satcheck_glucose.h index 12f1ec8f32f..100a514e601 100644 --- a/src/solvers/sat/satcheck_glucose.h +++ b/src/solvers/sat/satcheck_glucose.h @@ -16,10 +16,10 @@ Author: Daniel Kroening, kroening@kroening.com // when used incrementally, as variables may disappear // unless set to 'frozen'. -namespace Glucose +namespace Glucose // NOLINT(readability/namespace) { - class Solver; - class SimpSolver; +class Solver; // NOLINT(readability/identifiers) +class SimpSolver; // NOLINT(readability/identifiers) } template diff --git a/src/solvers/sat/satcheck_limmat.cpp b/src/solvers/sat/satcheck_limmat.cpp index f99db080c7a..a1aadbbff39 100644 --- a/src/solvers/sat/satcheck_limmat.cpp +++ b/src/solvers/sat/satcheck_limmat.cpp @@ -11,11 +11,12 @@ Author: Daniel Kroening, kroening@kroening.com #include "satcheck_limmat.h" -extern "C" { +extern "C" +{ #include "limmat.h" } -//#define DEBUG +// #define DEBUG /*******************************************************************\ @@ -48,7 +49,8 @@ Function: satcheck_limmatt::~satcheck_limmatt satcheck_limmatt::~satcheck_limmatt() { - if(solver!=NULL) delete_Limmat(solver); + if(solver!=NULL) + delete_Limmat(solver); } /*******************************************************************\ @@ -77,12 +79,13 @@ tvt satcheck_limmatt::l_get(literalt a) const switch(assignment[v]) { - case 0: result=tvt(false); break; - case 1: result=tvt(true); break; - default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; + case 0: result=tvt(false); break; + case 1: result=tvt(true); break; + default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; } - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } @@ -121,7 +124,7 @@ void satcheck_limmatt::copy_cnf() for(clausest::iterator it=clauses.begin(); it!=clauses.end(); it++) - //it=clauses.erase(it)) + // it=clauses.erase(it)) { int *clause=new int[it->size()+1]; @@ -196,7 +199,8 @@ propt::resultt satcheck_limmatt::prop_solve() for(const int *a=assignment_Limmat(solver); *a!=0; a++) { int v=*a; - if(v<0) v=-v; + if(v<0) + v=-v; assert((unsigned)v=0; } diff --git a/src/solvers/sat/satcheck_lingeling.cpp b/src/solvers/sat/satcheck_lingeling.cpp index 4b058569ecf..18237a903ab 100644 --- a/src/solvers/sat/satcheck_lingeling.cpp +++ b/src/solvers/sat/satcheck_lingeling.cpp @@ -12,7 +12,8 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk #include "satcheck_lingeling.h" -extern "C" { +extern "C" +{ #include } diff --git a/src/solvers/sat/satcheck_lingeling.h b/src/solvers/sat/satcheck_lingeling.h index e98c46179a3..bc9a9198f77 100644 --- a/src/solvers/sat/satcheck_lingeling.h +++ b/src/solvers/sat/satcheck_lingeling.h @@ -11,6 +11,7 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk #include "cnf.h" +// NOLINTNEXTLINE(readability/identifiers) struct LGL; class satcheck_lingelingt:public cnf_solvert @@ -33,6 +34,7 @@ class satcheck_lingelingt:public cnf_solvert virtual void set_frozen(literalt a); protected: + // NOLINTNEXTLINE(readability/identifiers) struct LGL * solver; bvt assumptions; }; diff --git a/src/solvers/sat/satcheck_minisat.cpp b/src/solvers/sat/satcheck_minisat.cpp index 70908fde236..b615d04e112 100644 --- a/src/solvers/sat/satcheck_minisat.cpp +++ b/src/solvers/sat/satcheck_minisat.cpp @@ -143,7 +143,8 @@ tvt satcheck_minisat1_baset::l_get(literalt a) const else result=tvt(tvt::tv_enumt::TV_UNKNOWN); - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } @@ -179,7 +180,6 @@ Function: satcheck_minisat1_baset::add_variables void satcheck_minisat1_baset::add_variables() { - while((unsigned)solver->nVars()newVar(); } diff --git a/src/solvers/sat/satcheck_minisat.h b/src/solvers/sat/satcheck_minisat.h index d818e91ec7d..3924d26b816 100644 --- a/src/solvers/sat/satcheck_minisat.h +++ b/src/solvers/sat/satcheck_minisat.h @@ -27,7 +27,7 @@ class satcheck_minisat1_baset:public cnf_solvert virtual resultt prop_solve() override; virtual tvt l_get(literalt a) const override; - virtual void lcnf(const bvt &bv) override final; + virtual void lcnf(const bvt &bv) final; virtual void set_assignment(literalt a, bool value) override; @@ -41,6 +41,7 @@ class satcheck_minisat1_baset:public cnf_solvert virtual bool is_in_conflict(literalt l) const override; protected: + // NOLINTNEXTLINE(readability/identifiers) class Solver *solver; void add_variables(); bvt assumptions; @@ -61,9 +62,10 @@ class satcheck_minisat1_prooft:public satcheck_minisat1t virtual const std::string solver_text() override; simple_prooft &get_resolution_proof(); - //void set_partition_id(unsigned p_id); + // void set_partition_id(unsigned p_id); protected: + // NOLINTNEXTLINE(readability/identifiers) class Proof *proof; class minisat_prooft *minisat_proof; }; diff --git a/src/solvers/sat/satcheck_minisat2.cpp b/src/solvers/sat/satcheck_minisat2.cpp index 743bee634b1..c17f7f553f8 100644 --- a/src/solvers/sat/satcheck_minisat2.cpp +++ b/src/solvers/sat/satcheck_minisat2.cpp @@ -79,7 +79,8 @@ tvt satcheck_minisat2_baset::l_get(literalt a) const else return tvt::unknown(); - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } diff --git a/src/solvers/sat/satcheck_minisat2.h b/src/solvers/sat/satcheck_minisat2.h index d7b72bd0425..f31018d7125 100644 --- a/src/solvers/sat/satcheck_minisat2.h +++ b/src/solvers/sat/satcheck_minisat2.h @@ -16,10 +16,10 @@ Author: Daniel Kroening, kroening@kroening.com // when used incrementally, as variables may disappear // unless set to 'frozen'. -namespace Minisat +namespace Minisat // NOLINT(readability/namespace) { - class Solver; - class SimpSolver; +class Solver; // NOLINT(readability/identifiers) +class SimpSolver; // NOLINT(readability/identifiers) } template @@ -30,9 +30,9 @@ class satcheck_minisat2_baset:public cnf_solvert virtual ~satcheck_minisat2_baset(); virtual resultt prop_solve() override; - virtual tvt l_get(literalt a) const override final; + virtual tvt l_get(literalt a) const final; - virtual void lcnf(const bvt &bv) override final; + virtual void lcnf(const bvt &bv) final; virtual void set_assignment(literalt a, bool value) override; // extra MiniSat feature: solve with assumptions @@ -42,8 +42,8 @@ class satcheck_minisat2_baset:public cnf_solvert void set_polarity(literalt a, bool value); virtual bool is_in_conflict(literalt a) const override; - virtual bool has_set_assumptions() const override final { return true; } - virtual bool has_is_in_conflict() const override final { return true; } + virtual bool has_set_assumptions() const final { return true; } + virtual bool has_is_in_conflict() const final { return true; } protected: T *solver; @@ -65,8 +65,8 @@ class satcheck_minisat_simplifiert: { public: satcheck_minisat_simplifiert(); - virtual const std::string solver_text() override final; - virtual void set_frozen(literalt a) override final; + virtual const std::string solver_text() final; + virtual void set_frozen(literalt a) final; bool is_eliminated(literalt a) const; }; diff --git a/src/solvers/sat/satcheck_picosat.cpp b/src/solvers/sat/satcheck_picosat.cpp index c701ab88823..7c3417592a3 100644 --- a/src/solvers/sat/satcheck_picosat.cpp +++ b/src/solvers/sat/satcheck_picosat.cpp @@ -12,7 +12,8 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk #include "satcheck_picosat.h" -extern "C" { +extern "C" +{ #include } @@ -39,7 +40,7 @@ tvt satcheck_picosatt::l_get(literalt a) const tvt result; - if((int)a.var_no()>picosat_variables(picosat)) + if(static_cast(a.var_no())>picosat_variables(picosat)) return tvt(tvt::tv_enumt::TV_UNKNOWN); const int val=picosat_deref(picosat, a.dimacs()); diff --git a/src/solvers/sat/satcheck_picosat.h b/src/solvers/sat/satcheck_picosat.h index 8c684d15568..43e4b7f356d 100644 --- a/src/solvers/sat/satcheck_picosat.h +++ b/src/solvers/sat/satcheck_picosat.h @@ -11,6 +11,7 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk #include "cnf.h" +// NOLINTNEXTLINE(readability/identifiers) struct PicoSAT; class satcheck_picosatt:public cnf_solvert diff --git a/src/solvers/sat/satcheck_precosat.h b/src/solvers/sat/satcheck_precosat.h index 9f28d22b10b..c2cf053ac49 100644 --- a/src/solvers/sat/satcheck_precosat.h +++ b/src/solvers/sat/satcheck_precosat.h @@ -11,9 +11,9 @@ Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk #include "cnf.h" -namespace PrecoSat +namespace PrecoSat // NOLINT(readability/namespace) { - class Solver; +class Solver; // NOLINT(readability/identifiers) } class satcheck_precosatt:public cnf_solvert diff --git a/src/solvers/sat/satcheck_smvsat.cpp b/src/solvers/sat/satcheck_smvsat.cpp index 2316f07fd95..8064900735d 100644 --- a/src/solvers/sat/satcheck_smvsat.cpp +++ b/src/solvers/sat/satcheck_smvsat.cpp @@ -94,12 +94,13 @@ tvt satcheck_smvsatt::l_get(literalt a) const switch(sat_instance_value(satsolver, v)) { - case 0: result=tvt(false); break; - case 1: result=tvt(true); break; - default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; + case 0: result=tvt(false); break; + case 1: result=tvt(true); break; + default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; } - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } @@ -140,7 +141,7 @@ void satcheck_smvsatt::lcnf(const bvt &bv) if(process_clause(bv, tmp)) return; - int lits[tmp.size()+1]; + int *lits=new int[tmp.size()+1]; for(unsigned i=0; i stack; + std::stack stack; - stack.push(entry(output, &dest)); + stack.push(entryt(output, &dest)); while(!stack.empty()) { - entry x=stack.top(); + entryt x=stack.top(); stack.pop(); bool invert=x.g<0; @@ -349,8 +356,8 @@ void satcheck_smvsat_interpolatort::build_aig( unsigned g0=interpolator_satsolver.aig_arg(n, 0); unsigned g1=interpolator_satsolver.aig_arg(n, 1); - stack.push(entry(g0, &e.op0())); - stack.push(entry(g1, &e.op1())); + stack.push(entryt(g0, &e.op0())); + stack.push(entryt(g1, &e.op1())); } if(invert) diff --git a/src/solvers/sat/satcheck_smvsat.h b/src/solvers/sat/satcheck_smvsat.h index a4079794b14..fa347ca2fad 100644 --- a/src/solvers/sat/satcheck_smvsat.h +++ b/src/solvers/sat/satcheck_smvsat.h @@ -28,6 +28,7 @@ class satcheck_smvsatt:public cnf_solvert virtual void lcnf(const bvt &bv); protected: + // NOLINTNEXTLINE(readability/identifiers) struct sat_instance *satsolver; }; @@ -69,20 +70,20 @@ class satcheck_smvsat_interpolatort:public satcheck_smvsatt std::vector partition_numbers; void build_aig( + // NOLINTNEXTLINE(readability/identifiers) struct interpolator &interpolator_satsolver, int output, exprt &dest); - struct entry + struct entryt { int g; exprt *e; - entry(int _g, exprt *_e):g(_g), e(_e) + entryt(int _g, exprt *_e):g(_g), e(_e) { } }; - }; #endif // CPROVER_SOLVERS_SAT_SATCHECK_SMVSAT_H diff --git a/src/solvers/sat/satcheck_zchaff.cpp b/src/solvers/sat/satcheck_zchaff.cpp index bcca0ff2f2b..5a94615e221 100644 --- a/src/solvers/sat/satcheck_zchaff.cpp +++ b/src/solvers/sat/satcheck_zchaff.cpp @@ -13,7 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include -//#define DEBUG +// #define DEBUG /*******************************************************************\ @@ -77,12 +77,13 @@ tvt satcheck_zchaff_baset::l_get(literalt a) const switch(solver->variable(a.var_no()).value()) { - case 0: result=tvt(false); break; - case 1: result=tvt(true); break; - default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; + case 0: result=tvt(false); break; + case 1: result=tvt(true); break; + default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break; } - if(a.sign()) result=!result; + if(a.sign()) + result=!result; return result; } @@ -126,7 +127,8 @@ void satcheck_zchaff_baset::copy_cnf() for(clausest::const_iterator it=clauses.begin(); it!=clauses.end(); it++) - solver->add_orig_clause((int *)&((*it)[0]), it->size()); + solver->add_orig_clause( + reinterpret_cast(&((*it)[0])), it->size()); } /*******************************************************************\ diff --git a/src/solvers/sat/satcheck_zchaff.h b/src/solvers/sat/satcheck_zchaff.h index d86a426be9f..218c3d3c1c1 100644 --- a/src/solvers/sat/satcheck_zchaff.h +++ b/src/solvers/sat/satcheck_zchaff.h @@ -14,11 +14,13 @@ Author: Daniel Kroening, kroening@kroening.com // use this only if you want to have something // derived from CSolver // otherwise, use satcheck_zchafft +// NOLINTNEXTLINE(readability/identifiers) +class CSolver; class satcheck_zchaff_baset:public cnf_clause_listt { public: - satcheck_zchaff_baset(class CSolver *_solver); + explicit satcheck_zchaff_baset(CSolver *_solver); virtual ~satcheck_zchaff_baset(); virtual const std::string solver_text(); @@ -27,13 +29,13 @@ class satcheck_zchaff_baset:public cnf_clause_listt virtual void set_assignment(literalt a, bool value); virtual void copy_cnf(); - class CSolver *zchaff_solver() + CSolver *zchaff_solver() { return solver; } protected: - class CSolver *solver; + CSolver *solver; typedef enum { INIT, SAT, UNSAT, ERROR } statust; statust status; diff --git a/src/solvers/sat/satcheck_zcore.cpp b/src/solvers/sat/satcheck_zcore.cpp index 700d632bfec..5079259d6cf 100644 --- a/src/solvers/sat/satcheck_zcore.cpp +++ b/src/solvers/sat/satcheck_zcore.cpp @@ -119,7 +119,8 @@ propt::resultt satcheck_zcoret::prop_solve() system(std::string("zchaff_verify "+cnf_file+" > "+output_file).c_str()); // get core - system(std::string("zcore "+cnf_file+" "+trace_file+" >> "+output_file).c_str()); + system( + std::string("zcore "+cnf_file+" "+trace_file+" >> "+output_file).c_str()); in_core.clear(); @@ -130,25 +131,29 @@ propt::resultt satcheck_zcoret::prop_solve() while(true) { std::string line; - if(!std::getline(in, line)) break; + if(!std::getline(in, line)) + break; - if(!(line.substr(0,1)=="c" || line.substr(0,1)=="p")) + if(!(line.substr(0, 1)=="c" || line.substr(0, 1)=="p")) { const char *p=line.c_str(); while(true) { int l=unsafe_str2int(p); - if(l==0) break; + if(l==0) + break; - if(l<0) l=-l; + if(l<0) + l=-l; in_core.insert(l); // next one const char *q=strchr(p, ' '); while(*q==' ') q++; - if(q==NULL) break; + if(q==NULL) + break; p=q; } } @@ -159,9 +164,9 @@ propt::resultt satcheck_zcoret::prop_solve() return P_ERROR; remove(cnf_file.c_str()); - //remove(core_file.c_str()); + // remove(core_file.c_str()); remove(trace_file.c_str()); - //remove(output_file.c_str()); + // remove(output_file.c_str()); return P_UNSATISFIABLE; } diff --git a/src/solvers/smt1/smt1_conv.cpp b/src/solvers/smt1/smt1_conv.cpp index 0a403f6dd76..493271afd27 100644 --- a/src/solvers/smt1/smt1_conv.cpp +++ b/src/solvers/smt1/smt1_conv.cpp @@ -66,8 +66,10 @@ Function: smt1_convt::l_get tvt smt1_convt::l_get(literalt l) const { - if(l.is_true()) return tvt(true); - if(l.is_false()) return tvt(false); + if(l.is_true()) + return tvt(true); + if(l.is_false()) + return tvt(false); assert(l.var_no()0) out << "(zero_extend[" << ext << "] "; @@ -1079,7 +1088,8 @@ void smt1_convt::convert_expr(const exprt &expr, bool bool_as_bv) convert_expr(expr.op0(), true); out << ")"; - if(ext>0) out << ")"; + if(ext>0) + out << ")"; } else if(expr.id()=="is_dynamic_object") { @@ -1379,8 +1389,10 @@ void smt1_convt::convert_expr(const exprt &expr, bool bool_as_bv) out << ") (sign_extend[" << width << "] "; convert_expr(expr.op1(), true); out << "))) "; // sign_extend, bvmul, ?prod - out << "(or (bvsge ?prod (bv" << power(2, width-1) << "[" << width*2 << "]))"; - out << " (bvslt ?prod (bvneg (bv" << power(2, width-1) << "[" << width*2 << "])))"; + out << "(or (bvsge ?prod (bv" << power(2, width-1) + << "[" << width*2 << "]))"; + out << " (bvslt ?prod (bvneg (bv" << power(2, width-1) + << "[" << width*2 << "])))"; out << "))"; // or, let } else if(op_type.id()==ID_unsignedbv) @@ -1549,6 +1561,7 @@ void smt1_convt::convert_typecast( } else { + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast1 "+src_type.id_string()+" -> bool"; } @@ -1580,6 +1593,7 @@ void smt1_convt::convert_typecast( } else { + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast1 "+src_type.id_string()+" -> bool"; } } @@ -1707,6 +1721,7 @@ void smt1_convt::convert_typecast( } else { + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast2 "+src_type.id_string()+ " -> "+dest_type.id_string(); } @@ -1863,10 +1878,12 @@ void smt1_convt::convert_typecast( } } else + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast3 "+src_type.id_string()+" -> pointer"; } else if(dest_type.id()==ID_range) { + // NOLINTNEXTLINE(readability/throw) throw "TODO range typecast"; } else if(dest_type.id()==ID_c_bit_field) @@ -1884,6 +1901,7 @@ void smt1_convt::convert_typecast( } } else + // NOLINTNEXTLINE(readability/throw) throw "TODO typecast4 ? -> "+dest_type.id_string(); } @@ -1937,14 +1955,16 @@ void smt1_convt::convert_struct(const exprt &expr) if(op.type().id()!=ID_code) { - if(!first) out << " "; + if(!first) + out << " "; if(op.type().id()==ID_array) flatten_array(op); else convert_expr(op, true); - if(!first) out << ")"; // concat + if(!first) + out << ")"; // concat first=false; } } @@ -2023,7 +2043,8 @@ void smt1_convt::convert_constant( std::size_t width=boolbv_width(expr.type()); - if(value<0) value=power(2, width)+value; + if(value<0) + value=power(2, width)+value; out << "bv" << value << "[" << width << "]"; @@ -2086,7 +2107,7 @@ void smt1_convt::convert_constant( out << value << ".0"; else { - out << "(/ " << value.substr(0,pos) << ".0 " + out << "(/ " << value.substr(0, pos) << ".0 " << value.substr(pos+1) << ".0)"; } } @@ -2729,7 +2750,7 @@ void smt1_convt::convert_with(const exprt &expr) out << ")"; // concat // shift it to the index - if (width>=array_index_bits) + if(width>=array_index_bits) out << " (zero_extend[" << width-array_index_bits << "]"; else out << " (extract[" << width-1 << ":0]"; @@ -2746,7 +2767,7 @@ void smt1_convt::convert_with(const exprt &expr) // shift it to the index out << ")"; - if (width>=array_index_bits) + if(width>=array_index_bits) out << " (zero_extend[" << width-array_index_bits << "]"; else out << " (extract[" << width-1 << ":0]"; @@ -2796,7 +2817,7 @@ void smt1_convt::convert_with(const exprt &expr) out << ")"; // concat // shift it to the index - if (width>=array_index_bits) + if(width>=array_index_bits) out << " (zero_extend[" << width-array_index_bits << "]"; else out << " (extract[" << width-1 << ":0]"; @@ -2812,7 +2833,7 @@ void smt1_convt::convert_with(const exprt &expr) convert_expr(value, true); // shift it to the index out << ")"; - if (width>=array_index_bits) + if(width>=array_index_bits) out << " (zero_extend[" << width-array_index_bits << "]"; else out << " (extract[" << width-1 << ":0]"; @@ -2871,7 +2892,8 @@ void smt1_convt::convert_with(const exprt &expr) out << ")"; } - if(offset!=0) out << " (concat"; + if(offset!=0) + out << " (concat"; out << " "; convert_expr(value, true); @@ -2884,7 +2906,8 @@ void smt1_convt::convert_with(const exprt &expr) out << ")"; // concat } - if(offset+width!=total_width) out << ")"; // concat + if(offset+width!=total_width) + out << ")"; // concat } } else if(expr_type.id()==ID_union) @@ -3031,7 +3054,7 @@ void smt1_convt::convert_index(const index_exprt &expr, bool bool_as_bv) out << "(extract[" << elem_width-1 << ":0] "; out << "(bvlshr "; convert_expr(expr.array(), true); - if (width>=array_index_bits) + if(width>=array_index_bits) out << " (zero_extend[" << width-array_index_bits << "]"; else out << " (extract[" << width-1 << ":0]"; @@ -3326,7 +3349,6 @@ void smt1_convt::find_symbols(const exprt &expr) array_expr_map[t]=id; } } - } /*******************************************************************\ @@ -3696,7 +3718,7 @@ void smt1_convt::flatten_array(const exprt &op) const exprt &size=array_type.size(); if(size.id()!=ID_constant) - throw ("non-constant size array cannot be flattened."); + throw "non-constant size array cannot be flattened"; mp_integer sizei; if(to_integer(size, sizei)) @@ -3727,7 +3749,8 @@ void smt1_convt::flatten_array(const exprt &op) out << " "; out << "bv" << i << "[" << array_index_bits << "]"; out << ")"; - if(i!=0) out << ")"; // concat + if(i!=0) + out << ")"; // concat } #if 0 diff --git a/src/solvers/smt1/smt1_conv.h b/src/solvers/smt1/smt1_conv.h index a51eb8bd438..5cdf736bda6 100644 --- a/src/solvers/smt1/smt1_conv.h +++ b/src/solvers/smt1/smt1_conv.h @@ -28,7 +28,8 @@ class member_exprt; class smt1_convt:public prop_convt { public: - typedef enum { GENERIC, BOOLECTOR, CVC3, CVC4, MATHSAT, OPENSMT, YICES, Z3 } solvert; + typedef enum + { GENERIC, BOOLECTOR, CVC3, CVC4, MATHSAT, OPENSMT, YICES, Z3 } solvert; smt1_convt( const namespacet &_ns, diff --git a/src/solvers/smt1/smt1_dec.cpp b/src/solvers/smt1/smt1_dec.cpp index ee1615ad48b..e994ba109d2 100644 --- a/src/solvers/smt1/smt1_dec.cpp +++ b/src/solvers/smt1/smt1_dec.cpp @@ -70,8 +70,7 @@ smt1_temp_filet::smt1_temp_filet() temp_out.open( temp_out_filename.c_str(), - std::ios_base::out | std::ios_base::trunc - ); + std::ios_base::out | std::ios_base::trunc); } /*******************************************************************\ @@ -298,7 +297,8 @@ decision_proceduret::resultt smt1_dect::read_result_boolector(std::istream &in) i_it=v.index_value_map.begin(); i_it!=v.index_value_map.end(); i_it++) set_value(it->second, i_it->first, i_it->second); - if(v.value!="") set_value(it->second, "", v.value); + if(v.value!="") + set_value(it->second, "", v.value); } // Booleans @@ -306,7 +306,8 @@ decision_proceduret::resultt smt1_dect::read_result_boolector(std::istream &in) for(unsigned v=0; vsecond.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; - if(value=="") continue; + if(value=="") + continue; exprt e; if(string_to_expr_z3(it->second.type, value, e)) @@ -537,7 +541,8 @@ decision_proceduret::resultt smt1_dect::read_result_z3(std::istream &in) for(unsigned v=0; vsecond!=id) fit++; - if(fit==array_of_map.end()) return false; + if(fit==array_of_map.end()) + return false; e = fit->first; @@ -655,7 +665,7 @@ bool smt1_dect::string_to_expr_z3( constant_exprt result; result.type()=rational_typet(); - if(value.substr(0,4)=="val!") + if(value.substr(0, 4)=="val!") result.set_value(value.substr(4)); else result.set_value(value); @@ -698,10 +708,12 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) res = D_UNSATISFIABLE; else if(line.find("Current scope level")!=std::string::npos || line.find("Variable Assignment")!=std::string::npos) - ; //ignore + { + // ignore + } else { - assert(line.substr(0,13)==" :assumption"); + assert(line.substr(0, 13)==" :assumption"); std::size_t pos=line.find('('); if(pos!=std::string::npos) @@ -716,17 +728,17 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) var = ops.substr(0, blank); val = ops.substr(blank+1, ops.length()-blank); - if((var.length()>=4 && var.substr(0,4)=="cvc3") || - (val.length()>=4 && val.substr(0,4)=="cvc3") || + if((var.length()>=4 && var.substr(0, 4)=="cvc3") || + (val.length()>=4 && val.substr(0, 4)=="cvc3") || var==val) continue; - else if((var.substr(0,9)=="array_of'") || - (var.substr(0,2)=="bv" && val.substr(0,2)!="bv")) + else if((var.substr(0, 9)=="array_of'") || + (var.substr(0, 2)=="bv" && val.substr(0, 2)!="bv")) { std::string t=var; var=val; val=t; } } - else if(line.substr(pos+1,3)=="not") + else if(line.substr(pos+1, 3)=="not") { var = line.substr(pos+5, line.length()-pos-6); val = "false"; @@ -751,16 +763,19 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) it->second.value.make_nil(); std::string conv_id=convert_identifier(it->first); std::string value=values[conv_id]; - if(value=="") continue; + if(value=="") + continue; - if(value.substr(0,2)=="bv") + if(value.substr(0, 2)=="bv") { std::string v=value.substr(2, value.find('[')-2); size_t p = value.find('[')+1; std::string w=value.substr(p, value.find(']')-p); - std::string binary=integer2binary(string2integer(v,10), - integer2unsigned(string2integer(w,10))); + std::string binary= + integer2binary( + string2integer(v, 10), + integer2unsigned(string2integer(w, 10))); set_value(it->second, "", binary); } @@ -768,7 +783,7 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) it->second.value=false_exprt(); else if(value=="true") it->second.value=true_exprt(); - else if(value.substr(0,8)=="array_of") + else if(value.substr(0, 8)=="array_of") { // We assume that array_of has only concrete arguments... irep_idt id(value); @@ -786,7 +801,8 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) for(unsigned v=0; v=assignment.size()) return tvt(tvt::tv_enumt::TV_UNKNOWN); + if(v>=assignment.size()) + return tvt(tvt::tv_enumt::TV_UNKNOWN); tvt r=assignment[v]; return literal.sign()?!r:r; } @@ -486,7 +512,8 @@ Function: smt1_propt::set_assignment void smt1_propt::set_assignment(literalt literal, bool value) { - if(literal.is_true() || literal.is_false()) return; + if(literal.is_true() || literal.is_false()) + return; unsigned v=literal.var_no(); assert(vsecond; @@ -1235,7 +1249,7 @@ void smt2_convt::convert_expr(const exprt &expr) { if(use_datatypes) { - assert(datatype_map.find(expr.type()) != datatype_map.end()); + assert(datatype_map.find(expr.type())!=datatype_map.end()); const std::string smt_typename= datatype_map.find(expr.type())->second; @@ -1282,7 +1296,7 @@ void smt2_convt::convert_expr(const exprt &expr) } else if(expr.id()==ID_sign) { - assert(expr.operands().size() == 1); + assert(expr.operands().size()==1); const typet &op_type=expr.op0().type(); @@ -1306,7 +1320,7 @@ void smt2_convt::convert_expr(const exprt &expr) out << " (_ bv0 " << op_width << "))"; } else - UNEXPECTEDCASE("sign applied to type " + expr.type().id_string()); + UNEXPECTEDCASE("sign applied to type "+expr.type().id_string()); } else if(expr.id()==ID_if) { @@ -1527,12 +1541,15 @@ void smt2_convt::convert_expr(const exprt &expr) } } else - UNEXPECTEDCASE("unsupported op1 type for "+expr.id_string()+": "+type.id_string()); + UNEXPECTEDCASE( + "unsupported op1 type for "+expr.id_string()+": "+ + type.id_string()); out << ")"; // bv*sh } else - UNEXPECTEDCASE("unsupported type for "+expr.id_string()+": "+type.id_string()); + UNEXPECTEDCASE( + "unsupported type for "+expr.id_string()+": "+type.id_string()); } else if(expr.id()==ID_with) { @@ -1554,7 +1571,8 @@ void smt2_convt::convert_expr(const exprt &expr) std::size_t result_width=boolbv_width(expr.type()); // max extract width - if(offset_bits>result_width) offset_bits=result_width; + if(offset_bits>result_width) + offset_bits=result_width; // too few bits? if(result_width>offset_bits) @@ -1655,7 +1673,8 @@ void smt2_convt::convert_expr(const exprt &expr) if(to_integer(expr.op2(), op2_i)) INVALIDEXPR("extractbits: to_integer failed"); - if(op2_i>op1_i) std::swap(op1_i, op2_i); + if(op2_i>op1_i) + std::swap(op1_i, op2_i); // now op1_i>=op2_i @@ -1887,8 +1906,8 @@ void smt2_convt::convert_expr(const exprt &expr) convert_expr(expr.op1()); out << ")))) "; // sign_extend, bvadd/sub let2 out << "(not (= " - "((_ extract " << width << " " << width << ") ?sum) " - "((_ extract " << (width-1) << " " << (width-1) << ") ?sum)"; + "((_ extract " << width << " " << width << ") ?sum) " + "((_ extract " << (width-1) << " " << (width-1) << ") ?sum)"; out << ")))"; // =, not, let } else if(op_type.id()==ID_unsignedbv || @@ -1926,8 +1945,10 @@ void smt2_convt::convert_expr(const exprt &expr) out << ") ((_ sign_extend " << width << ") "; convert_expr(expr.op1()); out << ")) )) "; - out << "(or (bvsge prod (_ bv" << power(2, width-1) << " " << width*2 << "))"; - out << " (bvslt prod (bvneg (_ bv" << power(2, width-1) << " " << width*2 << ")))))"; + out << "(or (bvsge prod (_ bv" << power(2, width-1) << " " + << width*2 << "))"; + out << " (bvslt prod (bvneg (_ bv" << power(2, width-1) << " " + << width*2 << ")))))"; } else if(op_type.id()==ID_unsignedbv) { @@ -1954,6 +1975,7 @@ void smt2_convt::convert_expr(const exprt &expr) expr.id()==ID_exists) { if(solver==MATHSAT) + // NOLINTNEXTLINE(readability/throw) throw "MathSAT does not support quantifiers"; if(expr.id()==ID_forall) @@ -2021,10 +2043,13 @@ void smt2_convt::convert_expr(const exprt &expr) } else if(expr.id()==ID_constraint_select_one) { - UNEXPECTEDCASE("smt2_convt::convert_expr: `"+expr.id_string()+"' is not yet supported"); + UNEXPECTEDCASE( + "smt2_convt::convert_expr: `"+expr.id_string()+ + "' is not yet supported"); } else - UNEXPECTEDCASE("smt2_convt::convert_expr: `"+expr.id_string()+"' is unsupported"); + UNEXPECTEDCASE( + "smt2_convt::convert_expr: `"+expr.id_string()+"' is unsupported"); } /*******************************************************************\ @@ -2175,8 +2200,8 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) "(_ bv0 " << from_fraction_bits << ")))"; // number negative - out << " (= ((_ extract " << (from_width-1) << " " << (from_width-1) << ") ?tcop) " - "#b1)"; + out << " (= ((_ extract " << (from_width-1) << " " << (from_width-1) + << ") ?tcop) #b1)"; out << ")"; // and @@ -2203,15 +2228,19 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) convert_expr(src); } } - else if (dest_type.id()==ID_signedbv) + else if(dest_type.id()==ID_signedbv) { // this should be floatbv_typecast, not typecast - UNEXPECTEDCASE("typecast unexpected "+src_type.id_string()+" -> "+dest_type.id_string()); + UNEXPECTEDCASE( + "typecast unexpected "+src_type.id_string()+" -> "+ + dest_type.id_string()); } - else if (dest_type.id()==ID_unsignedbv) + else if(dest_type.id()==ID_unsignedbv) { // this should be floatbv_typecast, not typecast - UNEXPECTEDCASE("typecast unexpected "+src_type.id_string()+" -> "+dest_type.id_string()); + UNEXPECTEDCASE( + "typecast unexpected "+src_type.id_string()+" -> "+ + dest_type.id_string()); } } else if(src_type.id()==ID_bool) // from boolean to int @@ -2299,7 +2328,9 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) } else { - UNEXPECTEDCASE("TODO typecast2 "+src_type.id_string()+" -> "+dest_type.id_string() + " src == " + from_expr(ns, "", src)); + UNEXPECTEDCASE( + "TODO typecast2 "+src_type.id_string()+" -> "+ + dest_type.id_string()+" src == "+from_expr(ns, "", src)); } } else if(dest_type.id()==ID_fixedbv) // to fixedbv @@ -2466,8 +2497,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) { constant_exprt val(dest_type); - ieee_floatt a; - a.spec=to_floatbv_type(dest_type); + ieee_floatt a(to_floatbv_type(dest_type)); mp_integer significand; mp_integer exponent; @@ -2516,7 +2546,8 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr) } } else - UNEXPECTEDCASE("TODO typecast8 "+src_type.id_string()+" -> "+dest_type.id_string()); + UNEXPECTEDCASE( + "TODO typecast8 "+src_type.id_string()+" -> "+dest_type.id_string()); } /*******************************************************************\ @@ -2534,7 +2565,7 @@ Function: smt2_convt::convert_floatbv_typecast void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr) { const exprt &src=expr.op(); - //const exprt &rounding_mode=expr.rounding_mode(); + // const exprt &rounding_mode=expr.rounding_mode(); const typet &src_type=src.type(); const typet &dest_type=expr.type(); @@ -2632,12 +2663,15 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr) // We first convert to 'underlying type' floatbv_typecast_exprt tmp=expr; - tmp.op()=typecast_exprt(src, - ns.follow_tag(to_c_enum_tag_type(src_type)).subtype()); + tmp.op()= + typecast_exprt( + src, + ns.follow_tag(to_c_enum_tag_type(src_type)).subtype()); convert_floatbv_typecast(tmp); } else - UNEXPECTEDCASE("TODO typecast11 "+src_type.id_string()+" -> "+dest_type.id_string()); + UNEXPECTEDCASE( + "TODO typecast11 "+src_type.id_string()+" -> "+dest_type.id_string()); } else if(dest_type.id()==ID_signedbv) { @@ -2669,7 +2703,8 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr) } else { - UNEXPECTEDCASE("TODO typecast12 "+src_type.id_string()+" -> "+dest_type.id_string()); + UNEXPECTEDCASE( + "TODO typecast12 "+src_type.id_string()+" -> "+dest_type.id_string()); } } @@ -2698,7 +2733,7 @@ void smt2_convt::convert_struct(const struct_exprt &expr) if(use_datatypes) { - assert(datatype_map.find(struct_type) != datatype_map.end()); + assert(datatype_map.find(struct_type)!=datatype_map.end()); const std::string smt_typename = datatype_map.find(struct_type)->second; @@ -2777,11 +2812,13 @@ void smt2_convt::flatten_array(const exprt &expr) for(mp_integer i=size; i!=0; --i) { - if(i!=1) out << "(concat "; + if(i!=1) + out << "(concat "; out << "(select ?far "; convert_expr(from_integer(i-1, array_type.size().type())); out << ")"; - if(i!=1) out << " "; + if(i!=1) + out << " "; } // close the many parentheses @@ -2890,8 +2927,8 @@ void smt2_convt::convert_constant(const constant_exprt &expr) is needed to get to IEEE-754 style representations. */ ieee_floatt v=ieee_floatt(expr); - size_t e = floatbv_type.get_e(); - size_t f = floatbv_type.get_f() + 1; + size_t e=floatbv_type.get_e(); + size_t f=floatbv_type.get_f()+1; /* Should be sufficient, but not currently supported by mathsat */ #if 0 @@ -2907,7 +2944,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr) } else if(v.is_infinity()) { - if (v.get_sign()) + if(v.get_sign()) out << "(_ -oo " << e << " " << f << ")"; else out << "(_ +oo " << e << " " << f << ")"; @@ -2972,7 +3009,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr) out << value << ".0"; else { - out << "(/ " << value.substr(0,pos) << ".0 " + out << "(/ " << value.substr(0, pos) << ".0 " << value.substr(pos+1) << ".0)"; } } @@ -3161,8 +3198,8 @@ void smt2_convt::convert_relation(const exprt &expr) out << ")"; } else - UNEXPECTEDCASE("unsupported type for "+expr.id_string()+": "+op_type.id_string()); - + UNEXPECTEDCASE( + "unsupported type for "+expr.id_string()+": "+op_type.id_string()); } /*******************************************************************\ @@ -3230,7 +3267,7 @@ void smt2_convt::convert_plus(const plus_exprt &expr) out << "(bvmul "; convert_expr(i); out << " (_ bv" << element_size - << " " << boolbv_width(expr.type()) << "))"; + << " " << boolbv_width(expr.type()) << "))"; } else convert_expr(i); @@ -3273,7 +3310,10 @@ void smt2_convt::convert_plus(const plus_exprt &expr) exprt tmp(ID_plus, vector_type.subtype()); forall_operands(it, expr) tmp.copy_to_operands( - index_exprt(*it, from_integer(size-i-1, index_type), vector_type.subtype())); + index_exprt( + *it, + from_integer(size-i-1, index_type), + vector_type.subtype())); out << " "; convert_expr(tmp); @@ -3331,7 +3371,9 @@ void smt2_convt::convert_rounding_mode_FPA(const exprt &expr) else if(value==3) out << "roundTowardZero"; else - INVALIDEXPR("Unknown constant rounding mode with value "+id2string(cexpr.get_value())); + INVALIDEXPR( + "Unknown constant rounding mode with value "+ + id2string(cexpr.get_value())); } else { @@ -3495,7 +3537,10 @@ void smt2_convt::convert_minus(const minus_exprt &expr) exprt tmp(ID_minus, vector_type.subtype()); forall_operands(it, expr) tmp.copy_to_operands( - index_exprt(*it, from_integer(size-i-1, index_type), vector_type.subtype())); + index_exprt( + *it, + from_integer(size-i-1, index_type), + vector_type.subtype())); out << " "; convert_expr(tmp); @@ -3828,7 +3873,8 @@ void smt2_convt::convert_with(const with_exprt &expr) out << "(bvor "; out << "(bvand "; - out << "(bvlshr (_ bv" << power(2, array_width)-1 << " " << array_width << ") "; + out << "(bvlshr (_ bv" << power(2, array_width)-1 << " " + << array_width << ") "; out << "distance?) "; convert_expr(expr.old()); out << ") "; // bvand @@ -3852,7 +3898,7 @@ void smt2_convt::convert_with(const with_exprt &expr) if(use_datatypes) { - assert(datatype_map.find(expr_type) != datatype_map.end()); + assert(datatype_map.find(expr_type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(expr_type)->second; @@ -3883,7 +3929,8 @@ void smt2_convt::convert_with(const with_exprt &expr) { // the member is at the beginning out << "(concat " - << "((_ extract " << (struct_width-1) << " " << m.width << ") ?withop) "; + << "((_ extract " << (struct_width-1) << " " + << m.width << ") ?withop) "; convert_expr(value); out << ")"; // concat } @@ -3898,7 +3945,8 @@ void smt2_convt::convert_with(const with_exprt &expr) { // most general case, need two concat-s out << "(concat (concat " - << "((_ extract " << (struct_width-1) << " " << (m.offset+m.width) << ") ?withop) "; + << "((_ extract " << (struct_width-1) << " " + << (m.offset+m.width) << ") ?withop) "; convert_expr(value); out << ") ((_ extract " << (m.offset-1) << " 0) ?withop)"; out << ")"; // concat @@ -3994,7 +4042,9 @@ void smt2_convt::convert_with(const with_exprt &expr) out << ")"; // bvor } else - UNEXPECTEDCASE("with expects struct, union, or array type, but got "+expr.type().id_string()); + UNEXPECTEDCASE( + "with expects struct, union, or array type, but got "+ + expr.type().id_string()); } /*******************************************************************\ @@ -4126,7 +4176,8 @@ void smt2_convt::convert_index(const index_exprt &expr) } } else - UNEXPECTEDCASE("index with unsupported array type: "+array_op_type.id_string()); + UNEXPECTEDCASE( + "index with unsupported array type: "+array_op_type.id_string()); } /*******************************************************************\ @@ -4160,7 +4211,7 @@ void smt2_convt::convert_member(const member_exprt &expr) if(use_datatypes) { - assert(datatype_map.find(struct_type) != datatype_map.end()); + assert(datatype_map.find(struct_type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(struct_type)->second; @@ -4202,7 +4253,8 @@ void smt2_convt::convert_member(const member_exprt &expr) unflatten(END, expr.type()); } else - UNEXPECTEDCASE("convert_member on an unexpected type " + struct_op_type.id_string()); + UNEXPECTEDCASE( + "convert_member on an unexpected type "+struct_op_type.id_string()); } /*******************************************************************\ @@ -4231,7 +4283,7 @@ void smt2_convt::flatten2bv(const exprt &expr) { if(use_datatypes) { - assert(datatype_map.find(type) != datatype_map.end()); + assert(datatype_map.find(type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(type)->second; @@ -4267,7 +4319,7 @@ void smt2_convt::flatten2bv(const exprt &expr) { if(use_datatypes) { - assert(datatype_map.find(type) != datatype_map.end()); + assert(datatype_map.find(type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(type)->second; @@ -4344,7 +4396,7 @@ void smt2_convt::unflatten( { if(use_datatypes) { - assert(datatype_map.find(type) != datatype_map.end()); + assert(datatype_map.find(type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(type)->second; @@ -4396,7 +4448,7 @@ void smt2_convt::unflatten( { out << ")) "; - assert(datatype_map.find(type) != datatype_map.end()); + assert(datatype_map.find(type)!=datatype_map.end()); const std::string smt_typename= datatype_map.find(type)->second; @@ -4504,7 +4556,8 @@ void smt2_convt::set_to(const exprt &expr, bool value) if(equal_expr.lhs().id()==ID_symbol) { - const irep_idt &identifier=to_symbol_expr(equal_expr.lhs()).get_identifier(); + const irep_idt &identifier= + to_symbol_expr(equal_expr.lhs()).get_identifier(); if(identifier_map.find(identifier)==identifier_map.end()) { @@ -4685,10 +4738,10 @@ void smt2_convt::find_symbols(const exprt &expr) { const exprt &op = expr.op0(); - if (op.type().id() == ID_pointer || - op.type().id() == ID_reference) + if(op.type().id()==ID_pointer || + op.type().id()==ID_reference) { - if (object_sizes.find(expr)==object_sizes.end()) + if(object_sizes.find(expr)==object_sizes.end()) { irep_idt id="object_size."+std::to_string(object_sizes.size()); out << "(declare-fun " << id << " () "; @@ -4734,7 +4787,8 @@ void smt2_convt::find_symbols(const exprt &expr) for(unsigned i=0; i &recstack) { if(type.id()==ID_array) - { - const array_typet &array_type=to_array_type(type); - find_symbols(array_type.size()); - find_symbols_rec(array_type.subtype(), recstack); - } - else if(type.id()==ID_incomplete_array) - { - find_symbols_rec(type.subtype(), recstack); - } - else if(type.id()==ID_complex) - { - find_symbols_rec(type.subtype(), recstack); - - if(use_datatypes && - datatype_map.find(type)==datatype_map.end()) - { - std::string smt_typename = "complex."+std::to_string(datatype_map.size()); - datatype_map[type] = smt_typename; - - out << "(declare-datatypes () ((" << smt_typename << " " - << "(mk-" << smt_typename; - - out << " (" << smt_typename << ".imag "; - convert_type(type.subtype()); - out << ")"; - - out << " (" << smt_typename << ".real "; - convert_type(type.subtype()); - out << ")"; - - out << "))))\n"; - } - } - else if(type.id()==ID_vector) - { - find_symbols_rec(type.subtype(), recstack); - - if(use_datatypes && - datatype_map.find(type)==datatype_map.end()) - { - const vector_typet &vector_type=to_vector_type(type); - - mp_integer size; - if(to_integer(vector_type.size(), size)) - INVALIDEXPR("failed to convert vector size to constant"); - - std::string smt_typename = "vector."+std::to_string(datatype_map.size()); - datatype_map[type] = smt_typename; - - out << "(declare-datatypes () ((" << smt_typename << " " - << "(mk-" << smt_typename; - - for(mp_integer i=0; i!=size; ++i) - { - out << " (" << smt_typename << "." << i << " "; - convert_type(type.subtype()); - out << ")"; - } - - out << "))))\n"; - } - } - else if(type.id()==ID_struct) - { - // Cater for mutually recursive struct types - bool need_decl=false; - if(use_datatypes && - datatype_map.find(type)==datatype_map.end()) - { - std::string smt_typename = "struct."+std::to_string(datatype_map.size()); - datatype_map[type] = smt_typename; - need_decl=true; - } - - const struct_typet::componentst &components= - to_struct_type(type).components(); + { + const array_typet &array_type=to_array_type(type); + find_symbols(array_type.size()); + find_symbols_rec(array_type.subtype(), recstack); + } + else if(type.id()==ID_incomplete_array) + { + find_symbols_rec(type.subtype(), recstack); + } + else if(type.id()==ID_complex) + { + find_symbols_rec(type.subtype(), recstack); - for(const auto &component : components) - find_symbols_rec(component.type(), recstack); + if(use_datatypes && + datatype_map.find(type)==datatype_map.end()) + { + std::string smt_typename = "complex."+std::to_string(datatype_map.size()); + datatype_map[type] = smt_typename; - // Declare the corresponding SMT type if we haven't already. - if(need_decl) - { - std::string smt_typename = datatype_map[type]; - - // We're going to create a datatype named something like `struct.0'. - // It's going to have a single constructor named `mk-struct.0' with an - // argument for each member of the struct. The declaration that - // creates this type looks like: - // - // (declare-datatypes () ((struct.0 (mk-struct.0 - // (struct.0.component1 type1) - // ... - // (struct.0.componentN typeN))))) - out << "(declare-datatypes () ((" << smt_typename << " " - << "(mk-" << smt_typename << " "; - - for(const auto &component : components) - { - out << "(" << smt_typename << "." << component.get_name() - << " "; - convert_type(component.type()); - out << ") "; - } - - out << "))))" << "\n"; - - // Let's also declare convenience functions to update individual members of - // the struct whil we're at it. The functions are named like - // `update-struct.0.component1'. Their declarations look like: - // - // (declare-fun update-struct.0.component1 - // ((s struct.0) ; first arg -- the struct to update - // (v type1)) ; second arg -- the value to update - // struct.0 ; the output type - // (mk-struct.0 ; build the new struct... - // v ; the updated value - // (struct.0.component2 s) ; retain the other members - // ... - // (struct.0.componentN s))) - - for(std::size_t i = 0; i < components.size(); i++) - { - const struct_union_typet::componentt &component = components[i]; - out << "(define-fun update-" << smt_typename << "." - << component.get_name() << " " - << "((s " << smt_typename << ") " - << "(v "; - convert_type(component.type()); - out << ")) " << smt_typename << " " - << "(mk-" << smt_typename - << " "; - - for(std::size_t j = 0; j < components.size(); j++) - { - if(j==i) - out << "v "; - else - { - out << "(" << smt_typename << "." - << components[j].get_name() << " s) "; - } - } - - out << "))" << "\n"; - } - - out << "\n"; - } - } - else if(type.id()==ID_union) - { - const union_typet::componentst &components= - to_union_type(type).components(); + out << "(declare-datatypes () ((" << smt_typename << " " + << "(mk-" << smt_typename; + + out << " (" << smt_typename << ".imag "; + convert_type(type.subtype()); + out << ")"; + + out << " (" << smt_typename << ".real "; + convert_type(type.subtype()); + out << ")"; + + out << "))))\n"; + } + } + else if(type.id()==ID_vector) + { + find_symbols_rec(type.subtype(), recstack); + + if(use_datatypes && + datatype_map.find(type)==datatype_map.end()) + { + const vector_typet &vector_type=to_vector_type(type); + + mp_integer size; + if(to_integer(vector_type.size(), size)) + INVALIDEXPR("failed to convert vector size to constant"); + + std::string smt_typename = "vector."+std::to_string(datatype_map.size()); + datatype_map[type] = smt_typename; + + out << "(declare-datatypes () ((" << smt_typename << " " + << "(mk-" << smt_typename; + + for(mp_integer i=0; i!=size; ++i) + { + out << " (" << smt_typename << "." << i << " "; + convert_type(type.subtype()); + out << ")"; + } + + out << "))))\n"; + } + } + else if(type.id()==ID_struct) + { + // Cater for mutually recursive struct types + bool need_decl=false; + if(use_datatypes && + datatype_map.find(type)==datatype_map.end()) + { + std::string smt_typename = "struct."+std::to_string(datatype_map.size()); + datatype_map[type] = smt_typename; + need_decl=true; + } + + const struct_typet::componentst &components= + to_struct_type(type).components(); for(const auto &component : components) find_symbols_rec(component.type(), recstack); - } - else if(type.id()==ID_code) - { - const code_typet::parameterst ¶meters= - to_code_type(type).parameters(); - for(const auto ¶m : parameters) - find_symbols_rec(param.type(), recstack); - - find_symbols_rec(to_code_type(type).return_type(), recstack); - } - else if(type.id()==ID_pointer) - { - find_symbols_rec(type.subtype(), recstack); - } - else if(type.id()==ID_symbol) - { - const symbol_typet &st=to_symbol_type(type); - const irep_idt &id=st.get_identifier(); - - if(recstack.find(id)==recstack.end()) - { - recstack.insert(id); - find_symbols_rec(ns.follow(type), recstack); - } - } + + // Declare the corresponding SMT type if we haven't already. + if(need_decl) + { + std::string smt_typename = datatype_map[type]; + + // We're going to create a datatype named something like `struct.0'. + // It's going to have a single constructor named `mk-struct.0' with an + // argument for each member of the struct. The declaration that + // creates this type looks like: + // + // (declare-datatypes () ((struct.0 (mk-struct.0 + // (struct.0.component1 type1) + // ... + // (struct.0.componentN typeN))))) + out << "(declare-datatypes () ((" << smt_typename << " " + << "(mk-" << smt_typename << " "; + + for(const auto &component : components) + { + out << "(" << smt_typename << "." << component.get_name() + << " "; + convert_type(component.type()); + out << ") "; + } + + out << "))))" << "\n"; + + // Let's also declare convenience functions to update individual + // members of the struct whil we're at it. The functions are + // named like `update-struct.0.component1'. Their declarations + // look like: + // + // (declare-fun update-struct.0.component1 + // ((s struct.0) ; first arg -- the struct to update + // (v type1)) ; second arg -- the value to update + // struct.0 ; the output type + // (mk-struct.0 ; build the new struct... + // v ; the updated value + // (struct.0.component2 s) ; retain the other members + // ... + // (struct.0.componentN s))) + + for(struct_union_typet::componentst::const_iterator + it=components.begin(); + it!=components.end(); + ++it) + { + const struct_union_typet::componentt &component=*it; + out << "(define-fun update-" << smt_typename << "." + << component.get_name() << " " + << "((s " << smt_typename << ") " + << "(v "; + convert_type(component.type()); + out << ")) " << smt_typename << " " + << "(mk-" << smt_typename + << " "; + + for(struct_union_typet::componentst::const_iterator + it2=components.begin(); + it2!=components.end(); + ++it2) + { + if(it==it2) + out << "v "; + else + { + out << "(" << smt_typename << "." + << it2->get_name() << " s) "; + } + } + + out << "))" << "\n"; + } + + out << "\n"; + } + } + else if(type.id()==ID_union) + { + const union_typet::componentst &components= + to_union_type(type).components(); + + for(const auto &component : components) + find_symbols_rec(component.type(), recstack); + } + else if(type.id()==ID_code) + { + const code_typet::parameterst ¶meters= + to_code_type(type).parameters(); + for(const auto ¶m : parameters) + find_symbols_rec(param.type(), recstack); + + find_symbols_rec(to_code_type(type).return_type(), recstack); + } + else if(type.id()==ID_pointer) + { + find_symbols_rec(type.subtype(), recstack); + } + else if(type.id()==ID_symbol) + { + const symbol_typet &st=to_symbol_type(type); + const irep_idt &id=st.get_identifier(); + + if(recstack.find(id)==recstack.end()) + { + recstack.insert(id); + find_symbols_rec(ns.follow(type), recstack); + } + } } /*******************************************************************\ @@ -5217,13 +5277,13 @@ exprt smt2_convt::letify_rec( const seen_expressionst &map, unsigned i) { - if(i >= let_order.size()) + if(i>=let_order.size()) return substitute_let(expr, map); exprt current=let_order[i]; - assert(map.find(current) != map.end()); + assert(map.find(current)!=map.end()); - if (map.find(current)->second.first < LET_COUNT) + if(map.find(current)->second.firstsecond; + let_count_idt &count_id=it->second; ++(count_id.first); return; } @@ -5265,10 +5325,10 @@ void smt2_convt::collect_bindings( if(expr.operands().empty()) return; - for (unsigned i = 0; i < expr.operands().size(); ++i) - collect_bindings(expr.operands()[i], map, let_order); + Forall_operands(it, expr) + collect_bindings(*it, map, let_order); - assert(map.find(expr) == map.end()); + assert(map.find(expr)==map.end()); symbol_exprt let= symbol_exprt("_let_"+std::to_string(++let_id_count), expr.type()); diff --git a/src/solvers/smt2/smt2_conv.h b/src/solvers/smt2/smt2_conv.h index 3e27a1500d0..c5127db59f0 100644 --- a/src/solvers/smt2/smt2_conv.h +++ b/src/solvers/smt2/smt2_conv.h @@ -27,7 +27,17 @@ class member_exprt; class smt2_convt:public prop_convt { public: - typedef enum { GENERIC, BOOLECTOR, CVC3, CVC4, MATHSAT, OPENSMT, YICES, Z3 } solvert; + typedef enum + { + GENERIC, + BOOLECTOR, + CVC3, + CVC4, + MATHSAT, + OPENSMT, + YICES, + Z3 + } solvert; smt2_convt( const namespacet &_ns, @@ -163,27 +173,26 @@ class smt2_convt:public prop_convt void find_symbols_rec(const typet &type, std::set &recstack); // letification - typedef std::pair let_count_id; - typedef std::unordered_map seen_expressionst; + typedef std::pair let_count_idt; + typedef std::unordered_map seen_expressionst; unsigned let_id_count; - const static unsigned LET_COUNT = 2; + static const unsigned LET_COUNT=2; - class let_visitort : public expr_visitort + class let_visitort:public expr_visitort { const seen_expressionst &let_map; public: - let_visitort(const seen_expressionst &map):let_map(map) { } + explicit let_visitort(const seen_expressionst &map):let_map(map) { } void operator()(exprt &expr) { - seen_expressionst::const_iterator it = let_map.find(expr); - if (it != let_map.end() && - it->second.first >= LET_COUNT) + seen_expressionst::const_iterator it=let_map.find(expr); + if(it!=let_map.end() && + it->second.first>=LET_COUNT) { - symbol_exprt symb = it->second.second; - expr = symb; - return; + symbol_exprt symb=it->second.second; + expr=symb; } } }; @@ -191,8 +200,8 @@ class smt2_convt:public prop_convt exprt letify(exprt &expr); exprt letify_rec( exprt &expr, - std::vector& let_order, - const seen_expressionst& map, + std::vector &let_order, + const seen_expressionst &map, unsigned i); void collect_bindings( @@ -224,13 +233,13 @@ class smt2_convt:public prop_convt exprt(ID_smt2_symbol, _type) { set(ID_identifier, _identifier); } - inline const irep_idt &get_identifier() const + const irep_idt &get_identifier() const { return get(ID_identifier); } }; - inline const smt2_symbolt &to_smt2_symbol(const exprt &expr) + const smt2_symbolt &to_smt2_symbol(const exprt &expr) { assert(expr.id()==ID_smt2_symbol && !expr.has_operands()); return static_cast(expr); diff --git a/src/solvers/smt2/smt2_dec.cpp b/src/solvers/smt2/smt2_dec.cpp index 722a6b43bee..451f9da0d0a 100644 --- a/src/solvers/smt2/smt2_dec.cpp +++ b/src/solvers/smt2/smt2_dec.cpp @@ -72,8 +72,7 @@ smt2_temp_filet::smt2_temp_filet() temp_out.open( temp_out_filename.c_str(), - std::ios_base::out | std::ios_base::trunc - ); + std::ios_base::out | std::ios_base::trunc); } /*******************************************************************\ diff --git a/src/solvers/smt2/smt2_parser.cpp b/src/solvers/smt2/smt2_parser.cpp index 2705092fcc7..96439833c11 100644 --- a/src/solvers/smt2/smt2_parser.cpp +++ b/src/solvers/smt2/smt2_parser.cpp @@ -206,7 +206,8 @@ void smt2_parsert::get_quoted_symbol() char ch; while(in.get(ch)) { - if(ch=='|') return; // done + if(ch=='|') + return; // done buffer+=ch; } @@ -281,14 +282,16 @@ void smt2_parsert::operator()() case '\n': case '\r': case '\t': - case (char)160: // non-breaking space + case static_cast(160): // non-breaking space // skip any whitespace break; case ';': // comment // skip until newline while(in.get(ch) && ch!='\n') - ; // ignore + { + // ignore + } break; case '(': @@ -317,19 +320,22 @@ void smt2_parsert::operator()() case '|': // quoted symbol get_quoted_symbol(); symbol(); - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done break; case '"': // string literal get_string_literal(); string_literal(); - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done break; case ':': // keyword get_simple_symbol(); keyword(); - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done break; case '#': @@ -351,7 +357,8 @@ void smt2_parsert::operator()() return; } - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done } else { @@ -366,14 +373,16 @@ void smt2_parsert::operator()() in.unget(); get_decimal_numeral(); numeral(); - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done } else if(is_simple_symbol_character(ch)) { in.unget(); get_simple_symbol(); symbol(); - if(open_parentheses==0) return; // done + if(open_parentheses==0) + return; // done } else { diff --git a/src/solvers/smt2/smt2_parser.h b/src/solvers/smt2/smt2_parser.h index 41e95a45ffe..c01069b3cfd 100644 --- a/src/solvers/smt2/smt2_parser.h +++ b/src/solvers/smt2/smt2_parser.h @@ -15,7 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com class smt2_parsert { public: - smt2_parsert(std::istream &_in):in(_in) + explicit smt2_parsert(std::istream &_in):in(_in) { } diff --git a/src/solvers/smt2/smt2_prop.cpp b/src/solvers/smt2/smt2_prop.cpp index 060f5848501..d1f7f8bd21f 100644 --- a/src/solvers/smt2/smt2_prop.cpp +++ b/src/solvers/smt2/smt2_prop.cpp @@ -37,7 +37,7 @@ smt2_propt::smt2_propt( out << "(set-info :source \"" << source << "\")" << "\n"; out << "(set-option :produce-models true)" << "\n"; - if (core_enabled) + if(core_enabled) { out << "(set-option :produce-unsat-cores true)" << "\n"; } @@ -167,8 +167,10 @@ Function: smt2_propt::lxor literalt smt2_propt::lxor(const bvt &bv) { - if(bv.empty()) return const_literal(false); - if(bv.size()==1) return bv[0]; + if(bv.empty()) + return const_literal(false); + if(bv.size()==1) + return bv[0]; out << "\n"; @@ -199,11 +201,16 @@ Function: smt2_propt::land literalt smt2_propt::land(literalt a, literalt b) { - if(a==const_literal(true)) return b; - if(b==const_literal(true)) return a; - if(a==const_literal(false)) return const_literal(false); - if(b==const_literal(false)) return const_literal(false); - if(a==b) return a; + if(a==const_literal(true)) + return b; + if(b==const_literal(true)) + return a; + if(a==const_literal(false)) + return const_literal(false); + if(b==const_literal(false)) + return const_literal(false); + if(a==b) + return a; out << "\n"; @@ -232,11 +239,16 @@ Function: smt2_propt::lor literalt smt2_propt::lor(literalt a, literalt b) { - if(a==const_literal(false)) return b; - if(b==const_literal(false)) return a; - if(a==const_literal(true)) return const_literal(true); - if(b==const_literal(true)) return const_literal(true); - if(a==b) return a; + if(a==const_literal(false)) + return b; + if(b==const_literal(false)) + return a; + if(a==const_literal(true)) + return const_literal(true); + if(b==const_literal(true)) + return const_literal(true); + if(a==b) + return a; out << "\n"; @@ -265,10 +277,14 @@ Function: smt2_propt::lxor literalt smt2_propt::lxor(literalt a, literalt b) { - if(a==const_literal(false)) return b; - if(b==const_literal(false)) return a; - if(a==const_literal(true)) return !b; - if(b==const_literal(true)) return !a; + if(a==const_literal(false)) + return b; + if(b==const_literal(false)) + return a; + if(a==const_literal(true)) + return !b; + if(b==const_literal(true)) + return !a; out << "\n"; @@ -365,14 +381,21 @@ Function: smt2_propt::lselect literalt smt2_propt::lselect(literalt a, literalt b, literalt c) { - if(a==const_literal(true)) return b; - if(a==const_literal(false)) return c; - if(b==c) return b; - - if(a==const_literal(false)) return b; - if(b==const_literal(false)) return a; - if(a==const_literal(true)) return !b; - if(b==const_literal(true)) return !a; + if(a==const_literal(true)) + return b; + if(a==const_literal(false)) + return c; + if(b==c) + return b; + + if(a==const_literal(false)) + return b; + if(b==const_literal(false)) + return a; + if(a==const_literal(true)) + return !b; + if(b==const_literal(true)) + return !a; out << "\n"; @@ -512,11 +535,14 @@ Function: smt2_propt::l_get tvt smt2_propt::l_get(literalt literal) const { - if(literal.is_true()) return tvt(true); - if(literal.is_false()) return tvt(false); + if(literal.is_true()) + return tvt(true); + if(literal.is_false()) + return tvt(false); unsigned v=literal.var_no(); - if(v>=assignment.size()) return tvt(tvt::tv_enumt::TV_UNKNOWN); + if(v>=assignment.size()) + return tvt(tvt::tv_enumt::TV_UNKNOWN); tvt r=assignment[v]; return literal.sign()?!r:r; } @@ -535,7 +561,8 @@ Function: smt2_propt::set_assignment void smt2_propt::set_assignment(literalt literal, bool value) { - if(literal.is_true() || literal.is_false()) return; + if(literal.is_true() || literal.is_false()) + return; unsigned v=literal.var_no(); assert(v property_mapt; property_mapt property_map; @@ -112,7 +112,7 @@ class path_searcht:public safety_checkert loc_datat():visited(false) { } }; - expanding_vector loc_data; + expanding_vectort loc_data; bool execute(queuet::iterator state); diff --git a/src/symex/symex_cover.cpp b/src/symex/symex_cover.cpp index c2f54a2a639..e5a7195d924 100644 --- a/src/symex/symex_cover.cpp +++ b/src/symex/symex_cover.cpp @@ -89,7 +89,8 @@ void symex_parse_optionst::report_cover( if(property.source_location.is_not_nil()) status() << ' ' << property.source_location; - if(!property.description.empty()) status() << ' ' << property.description; + if(!property.description.empty()) + status() << ' ' << property.description; status() << ": " << (property.is_failure()?"SATISFIED":"FAILED") << eom; @@ -108,8 +109,10 @@ void symex_parse_optionst::report_cover( xmlt xml_result("result"); xml_result.set_attribute("goal", id2string(prop_pair.first)); - xml_result.set_attribute("description", id2string(property.description)); - xml_result.set_attribute("status", property.is_failure()?"SATISFIED":"FAILED"); + xml_result.set_attribute( + "description", id2string(property.description)); + xml_result.set_attribute( + "status", property.is_failure()?"SATISFIED":"FAILED"); if(property.source_location.is_not_nil()) xml_result.new_element()=xml(property.source_location); @@ -137,7 +140,6 @@ void symex_parse_optionst::report_cover( xml(step.io_args.front(), ns); } } - } } @@ -155,7 +157,8 @@ void symex_parse_optionst::report_cover( const auto &property=prop_pair.second; json_objectt &result=result_array.push_back().make_object(); - result["status"]=json_stringt(property.is_failure()?"satisfied":"failed"); + result["status"]= + json_stringt(property.is_failure()?"satisfied":"failed"); result["goal"]=json_stringt(id2string(prop_pair.first)); result["description"]=json_stringt(id2string(property.description)); @@ -186,11 +189,11 @@ void symex_parse_optionst::report_cover( json_test.push_back(json_input); } } - } } } - json_result["totalGoals"]=json_numbert(std::to_string(property_map.size())); + json_result["totalGoals"]= + json_numbert(std::to_string(property_map.size())); json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered)); std::cout << ",\n" << json_result; break; @@ -200,7 +203,8 @@ void symex_parse_optionst::report_cover( status() << "** " << goals_covered << " of " << property_map.size() << " covered (" << std::fixed << std::setw(1) << std::setprecision(1) - << (property_map.empty()?100.0:100.0*goals_covered/property_map.size()) + << (property_map.empty()? + 100.0:100.0*goals_covered/property_map.size()) << "%)" << eom; diff --git a/src/symex/symex_parse_options.cpp b/src/symex/symex_parse_options.cpp index 148f5b646d1..518e64a2ecd 100644 --- a/src/symex/symex_parse_options.cpp +++ b/src/symex/symex_parse_options.cpp @@ -213,16 +213,20 @@ int symex_parse_optionst::doit() path_search.set_message_handler(get_message_handler()); if(cmdline.isset("depth")) - path_search.set_depth_limit(unsafe_string2unsigned(cmdline.get_value("depth"))); + path_search.set_depth_limit( + unsafe_string2unsigned(cmdline.get_value("depth"))); if(cmdline.isset("context-bound")) - path_search.set_context_bound(unsafe_string2unsigned(cmdline.get_value("context-bound"))); + path_search.set_context_bound( + unsafe_string2unsigned(cmdline.get_value("context-bound"))); if(cmdline.isset("branch-bound")) - path_search.set_branch_bound(unsafe_string2unsigned(cmdline.get_value("branch-bound"))); + path_search.set_branch_bound( + unsafe_string2unsigned(cmdline.get_value("branch-bound"))); if(cmdline.isset("unwind")) - path_search.set_unwind_limit(unsafe_string2unsigned(cmdline.get_value("unwind"))); + path_search.set_unwind_limit( + unsafe_string2unsigned(cmdline.get_value("unwind"))); if(cmdline.isset("dfs")) path_search.set_dfs(); @@ -308,7 +312,8 @@ bool symex_parse_optionst::set_properties() try { if(cmdline.isset("property")) - ::set_properties(goto_model.goto_functions, cmdline.get_values("property")); + ::set_properties( + goto_model.goto_functions, cmdline.get_values("property")); } catch(const char *e) @@ -668,9 +673,12 @@ void symex_parse_optionst::help() " symex file.c ... source file names\n" "\n" "Analysis options:\n" + // NOLINTNEXTLINE(whitespace/line_length) " --show-properties show the properties, but don't run analysis\n" " --property id only check one specific property\n" + // NOLINTNEXTLINE(whitespace/line_length) " --stop-on-fail stop analysis once a failed property is detected\n" + // NOLINTNEXTLINE(whitespace/line_length) " --trace give a counterexample trace for failed properties\n" "\n" "Frontend options:\n" @@ -697,6 +705,7 @@ void symex_parse_optionst::help() #endif " --no-arch don't set up an architecture\n" " --no-library disable built-in abstract C library\n" + // NOLINTNEXTLINE(whitespace/line_length) " --round-to-nearest IEEE floating point rounding mode (default)\n" " --round-to-plus-inf IEEE floating point rounding mode\n" " --round-to-minus-inf IEEE floating point rounding mode\n" diff --git a/src/util/arith_tools.cpp b/src/util/arith_tools.cpp index 4df13e8b3a0..37e96ec8ef8 100644 --- a/src/util/arith_tools.cpp +++ b/src/util/arith_tools.cpp @@ -29,7 +29,8 @@ Function: to_integer bool to_integer(const exprt &expr, mp_integer &int_value) { - if(!expr.is_constant()) return true; + if(!expr.is_constant()) + return true; return to_integer(to_constant_expr(expr), int_value); } @@ -164,7 +165,12 @@ constant_exprt from_integer( } else if(type_id==ID_natural) { - if(int_value<0) { constant_exprt r; r.make_nil(); return r; } + if(int_value<0) + { + constant_exprt r; + r.make_nil(); + return r; + } constant_exprt result(type); result.set_value(integer2string(int_value)); return result; @@ -226,14 +232,13 @@ constant_exprt from_integer( else if(type_id==ID_fixedbv) { fixedbvt fixedbv; - fixedbv.spec=to_fixedbv_type(type); + fixedbv.spec=fixedbv_spect(to_fixedbv_type(type)); fixedbv.from_integer(int_value); return fixedbv.to_expr(); } else if(type_id==ID_floatbv) { - ieee_floatt ieee_float; - ieee_float.spec=to_floatbv_type(type); + ieee_floatt ieee_float(to_floatbv_type(type)); ieee_float.from_integer(int_value); return ieee_float.to_expr(); } @@ -262,7 +267,7 @@ mp_integer address_bits(const mp_integer &size) { mp_integer result, x=2; - for(result=1; xa) a=b; + if(b>a) + a=b; } diff --git a/src/util/base_type.cpp b/src/util/base_type.cpp index 2090d863339..340d13116a0 100644 --- a/src/util/base_type.cpp +++ b/src/util/base_type.cpp @@ -207,8 +207,10 @@ bool base_type_eqt::base_type_eq_rec( { const typet &subtype1=components1[i].type(); const typet &subtype2=components2[i].type(); - if(!base_type_eq_rec(subtype1, subtype2)) return false; - if(components1[i].get_name()!=components2[i].get_name()) return false; + if(!base_type_eq_rec(subtype1, subtype2)) + return false; + if(components1[i].get_name()!=components2[i].get_name()) + return false; } return true; @@ -236,7 +238,8 @@ bool base_type_eqt::base_type_eq_rec( { const typet &subtype1=parameters1[i].type(); const typet &subtype2=parameters2[i].type(); - if(!base_type_eq_rec(subtype1, subtype2)) return false; + if(!base_type_eq_rec(subtype1, subtype2)) + return false; } const typet &return_type1=to_code_type(type1).return_type(); diff --git a/src/util/base_type.h b/src/util/base_type.h index b456f417de4..41e2fe6df4f 100644 --- a/src/util/base_type.h +++ b/src/util/base_type.h @@ -37,7 +37,7 @@ bool base_type_eq( class base_type_eqt { public: - base_type_eqt(const namespacet &_ns):ns(_ns) + explicit base_type_eqt(const namespacet &_ns):ns(_ns) { } diff --git a/src/util/bv_arithmetic.cpp b/src/util/bv_arithmetic.cpp index 93c5cb3ce9c..4e077ad0a1e 100644 --- a/src/util/bv_arithmetic.cpp +++ b/src/util/bv_arithmetic.cpp @@ -29,7 +29,8 @@ Function: bv_spect::to_type typet bv_spect::to_type() const { - if(is_signed) return signedbv_typet(width); + if(is_signed) + return signedbv_typet(width); return unsignedbv_typet(width); } @@ -184,7 +185,8 @@ Function: bv_arithmetict::pack mp_integer bv_arithmetict::pack() const { - if(value>=0) return value; + if(value>=0) + return value; return value+power(2, spec.width); } @@ -219,7 +221,7 @@ Function: operator /= \*******************************************************************/ -bv_arithmetict &bv_arithmetict::operator /= (const bv_arithmetict &other) +bv_arithmetict &bv_arithmetict::operator/=(const bv_arithmetict &other) { assert(other.spec==spec); @@ -243,7 +245,7 @@ Function: operator *= \*******************************************************************/ -bv_arithmetict &bv_arithmetict::operator *= (const bv_arithmetict &other) +bv_arithmetict &bv_arithmetict::operator*=(const bv_arithmetict &other) { assert(other.spec==spec); @@ -265,7 +267,7 @@ Function: operator += \*******************************************************************/ -bv_arithmetict &bv_arithmetict::operator += (const bv_arithmetict &other) +bv_arithmetict &bv_arithmetict::operator+=(const bv_arithmetict &other) { assert(other.spec==spec); @@ -309,7 +311,7 @@ Function: operator %= \*******************************************************************/ -bv_arithmetict &bv_arithmetict::operator %= (const bv_arithmetict &other) +bv_arithmetict &bv_arithmetict::operator%=(const bv_arithmetict &other) { assert(other.spec==spec); @@ -331,14 +333,14 @@ Function: operator < \*******************************************************************/ -bool operator < (const bv_arithmetict &a, const bv_arithmetict &b) +bool bv_arithmetict::operator<(const bv_arithmetict &other) { - return a.value +Function: bv_arithmetict::operator> Inputs: @@ -365,14 +367,14 @@ Function: operator > \*******************************************************************/ -bool operator > (const bv_arithmetict &a, const bv_arithmetict &b) +bool bv_arithmetict::operator>(const bv_arithmetict &other) { - return a.value>b.value; + return value>other.value; } /*******************************************************************\ -Function: operator >= +Function: bv_arithmetict::operator>= Inputs: @@ -382,14 +384,14 @@ Function: operator >= \*******************************************************************/ -bool operator >=(const bv_arithmetict &a, const bv_arithmetict &b) +bool bv_arithmetict::operator>=(const bv_arithmetict &other) { - return a.value>=b.value; + return value>=other.value; } /*******************************************************************\ -Function: operator == +Function: bv_arithmetict::operator== Inputs: @@ -399,14 +401,14 @@ Function: operator == \*******************************************************************/ -bool operator ==(const bv_arithmetict &a, const bv_arithmetict &b) +bool bv_arithmetict::operator==(const bv_arithmetict &other) { - return a.value==b.value; + return value==other.value; } /*******************************************************************\ -Function: operator == +Function: bv_arithmetict::operator== Inputs: @@ -416,14 +418,14 @@ Function: operator == \*******************************************************************/ -bool operator ==(const bv_arithmetict &a, int i) +bool bv_arithmetict::operator==(int i) { - return a.value==i; + return value==i; } /*******************************************************************\ -Function: operator != +Function: bv_arithmetict::operator!= Inputs: @@ -433,9 +435,9 @@ Function: operator != \*******************************************************************/ -bool operator !=(const bv_arithmetict &a, const bv_arithmetict &b) +bool bv_arithmetict::operator!=(const bv_arithmetict &other) { - return a.value!=b.value; + return value!=other.value; } /*******************************************************************\ @@ -471,6 +473,6 @@ Function: bv_arithmetict::from_expr void bv_arithmetict::from_expr(const exprt &expr) { assert(expr.is_constant()); - spec=expr.type(); + spec=bv_spect(expr.type()); value=binary2integer(expr.get_string(ID_value), spec.is_signed); } diff --git a/src/util/bv_arithmetic.h b/src/util/bv_arithmetic.h index 888cdd2606c..a5d91485490 100644 --- a/src/util/bv_arithmetic.h +++ b/src/util/bv_arithmetic.h @@ -23,7 +23,7 @@ class bv_spect std::size_t width; bool is_signed; - bv_spect(const typet &type) + explicit bv_spect(const typet &type) { from_type(type); } @@ -38,6 +38,11 @@ class bv_spect mp_integer min_value() const; typet to_type() const; + + bool operator==(const bv_spect &other) const + { + return width==other.width && is_signed==other.is_signed; + } }; class bv_arithmetict @@ -45,7 +50,7 @@ class bv_arithmetict public: bv_spect spec; - bv_arithmetict(const bv_spect &_spec): + explicit bv_arithmetict(const bv_spect &_spec): spec(_spec), value(0) { } @@ -54,7 +59,7 @@ class bv_arithmetict { } - bv_arithmetict(const exprt &expr) + explicit bv_arithmetict(const exprt &expr) { from_expr(expr); } @@ -88,23 +93,23 @@ class bv_arithmetict exprt to_expr() const; void from_expr(const exprt &expr); - bv_arithmetict &operator /= (const bv_arithmetict &other); - bv_arithmetict &operator *= (const bv_arithmetict &other); - bv_arithmetict &operator += (const bv_arithmetict &other); - bv_arithmetict &operator -= (const bv_arithmetict &other); - bv_arithmetict &operator %= (const bv_arithmetict &other); - - friend bool operator < (const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator <=(const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator > (const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator >=(const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator ==(const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator !=(const bv_arithmetict &a, const bv_arithmetict &b); - friend bool operator ==(const bv_arithmetict &a, int i); - - friend std::ostream& operator << (std::ostream &out, const bv_arithmetict &f) + bv_arithmetict &operator/=(const bv_arithmetict &other); + bv_arithmetict &operator*=(const bv_arithmetict &other); + bv_arithmetict &operator+=(const bv_arithmetict &other); + bv_arithmetict &operator-=(const bv_arithmetict &other); + bv_arithmetict &operator%=(const bv_arithmetict &other); + + bool operator<(const bv_arithmetict &other); + bool operator<=(const bv_arithmetict &other); + bool operator>(const bv_arithmetict &other); + bool operator>=(const bv_arithmetict &other); + bool operator==(const bv_arithmetict &other); + bool operator!=(const bv_arithmetict &other); + bool operator==(int i); + + std::ostream &operator<<(std::ostream &out) { - return out << f.to_ansi_c_string(); + return out << to_ansi_c_string(); } // turn into natural number representation @@ -119,12 +124,4 @@ class bv_arithmetict void adjust(); }; -bool operator < (const bv_arithmetict &a, const bv_arithmetict &b); -bool operator <=(const bv_arithmetict &a, const bv_arithmetict &b); -bool operator > (const bv_arithmetict &a, const bv_arithmetict &b); -bool operator >=(const bv_arithmetict &a, const bv_arithmetict &b); -bool operator ==(const bv_arithmetict &a, const bv_arithmetict &b); -bool operator !=(const bv_arithmetict &a, const bv_arithmetict &b); -std::ostream& operator << (std::ostream &, const bv_arithmetict &); - #endif // CPROVER_UTIL_BV_ARITHMETIC_H diff --git a/src/util/byte_operators.h b/src/util/byte_operators.h index 6b1878b9a0e..9b0745833cc 100644 --- a/src/util/byte_operators.h +++ b/src/util/byte_operators.h @@ -23,18 +23,18 @@ Author: Daniel Kroening, kroening@kroening.com class byte_extract_exprt:public exprt { public: - explicit inline byte_extract_exprt(irep_idt _id):exprt(_id) + explicit byte_extract_exprt(irep_idt _id):exprt(_id) { operands().resize(2); } - explicit inline byte_extract_exprt(irep_idt _id, const typet &_type): + explicit byte_extract_exprt(irep_idt _id, const typet &_type): exprt(_id, _type) { operands().resize(2); } - inline byte_extract_exprt( + byte_extract_exprt( irep_idt _id, const exprt &_op, const exprt &_offset, const typet &_type): exprt(_id, _type) @@ -42,20 +42,20 @@ class byte_extract_exprt:public exprt copy_to_operands(_op, _offset); } - inline exprt &op() { return op0(); } - inline exprt &offset() { return op1(); } + exprt &op() { return op0(); } + exprt &offset() { return op1(); } - inline const exprt &op() const { return op0(); } - inline const exprt &offset() const { return op1(); } + const exprt &op() const { return op0(); } + const exprt &offset() const { return op1(); } }; -extern inline const byte_extract_exprt &to_byte_extract_expr(const exprt &expr) +inline const byte_extract_exprt &to_byte_extract_expr(const exprt &expr) { assert(expr.operands().size()==2); return static_cast(expr); } -extern inline byte_extract_exprt &to_byte_extract_expr(exprt &expr) +inline byte_extract_exprt &to_byte_extract_expr(exprt &expr) { assert(expr.operands().size()==2); return static_cast(expr); @@ -69,20 +69,21 @@ irep_idt byte_update_id(); class byte_extract_little_endian_exprt:public byte_extract_exprt { public: - inline byte_extract_little_endian_exprt(): + byte_extract_little_endian_exprt(): byte_extract_exprt(ID_byte_extract_little_endian) { } - }; -extern inline const byte_extract_little_endian_exprt &to_byte_extract_little_endian_expr(const exprt &expr) +inline const byte_extract_little_endian_exprt + &to_byte_extract_little_endian_expr(const exprt &expr) { assert(expr.id()==ID_byte_extract_little_endian && expr.operands().size()==2); return static_cast(expr); } -extern inline byte_extract_little_endian_exprt &to_byte_extract_little_endian_expr(exprt &expr) +inline byte_extract_little_endian_exprt + &to_byte_extract_little_endian_expr(exprt &expr) { assert(expr.id()==ID_byte_extract_little_endian && expr.operands().size()==2); return static_cast(expr); @@ -93,7 +94,7 @@ extern inline byte_extract_little_endian_exprt &to_byte_extract_little_endian_ex class byte_extract_big_endian_exprt:public byte_extract_exprt { public: - inline byte_extract_big_endian_exprt(): + byte_extract_big_endian_exprt(): byte_extract_exprt(ID_byte_extract_big_endian) { } @@ -105,13 +106,15 @@ class byte_extract_big_endian_exprt:public byte_extract_exprt } }; -extern inline const byte_extract_big_endian_exprt &to_byte_extract_big_endian_expr(const exprt &expr) +inline const byte_extract_big_endian_exprt + &to_byte_extract_big_endian_expr(const exprt &expr) { assert(expr.id()==ID_byte_extract_big_endian && expr.operands().size()==2); return static_cast(expr); } -extern inline byte_extract_big_endian_exprt &to_byte_extract_big_endian_expr(exprt &expr) +inline byte_extract_big_endian_exprt + &to_byte_extract_big_endian_expr(exprt &expr) { assert(expr.id()==ID_byte_extract_big_endian && expr.operands().size()==2); return static_cast(expr); @@ -122,18 +125,18 @@ extern inline byte_extract_big_endian_exprt &to_byte_extract_big_endian_expr(exp class byte_update_exprt:public exprt { public: - explicit inline byte_update_exprt(irep_idt _id):exprt(_id) + explicit byte_update_exprt(irep_idt _id):exprt(_id) { operands().resize(3); } - inline byte_update_exprt(irep_idt _id, const typet &_type): + byte_update_exprt(irep_idt _id, const typet &_type): exprt(_id, _type) { operands().resize(3); } - inline byte_update_exprt( + byte_update_exprt( irep_idt _id, const exprt &_op, const exprt &_offset, const exprt &_value): exprt(_id, _op.type()) @@ -141,22 +144,22 @@ class byte_update_exprt:public exprt copy_to_operands(_op, _offset, _value); } - inline exprt &op() { return op0(); } - inline exprt &offset() { return op1(); } - inline exprt &value() { return op2(); } + exprt &op() { return op0(); } + exprt &offset() { return op1(); } + exprt &value() { return op2(); } - inline const exprt &op() const { return op0(); } - inline const exprt &offset() const { return op1(); } - inline const exprt &value() const { return op2(); } + const exprt &op() const { return op0(); } + const exprt &offset() const { return op1(); } + const exprt &value() const { return op2(); } }; -extern inline const byte_update_exprt &to_byte_update_expr(const exprt &expr) +inline const byte_update_exprt &to_byte_update_expr(const exprt &expr) { assert(expr.operands().size()==3); return static_cast(expr); } -extern inline byte_update_exprt &to_byte_update_expr(exprt &expr) +inline byte_update_exprt &to_byte_update_expr(exprt &expr) { assert(expr.operands().size()==3); return static_cast(expr); @@ -167,26 +170,27 @@ extern inline byte_update_exprt &to_byte_update_expr(exprt &expr) class byte_update_little_endian_exprt:public byte_update_exprt { public: - inline byte_update_little_endian_exprt(): + byte_update_little_endian_exprt(): byte_update_exprt(ID_byte_update_little_endian) { } - inline byte_update_little_endian_exprt( + byte_update_little_endian_exprt( const exprt &_op, const exprt &_offset, const exprt &_value): byte_update_exprt(ID_byte_update_little_endian, _op, _offset, _value) { } - }; -extern inline const byte_update_little_endian_exprt &to_byte_update_little_endian_expr(const exprt &expr) +inline const byte_update_little_endian_exprt + &to_byte_update_little_endian_expr(const exprt &expr) { assert(expr.id()==ID_byte_update_little_endian && expr.operands().size()==3); return static_cast(expr); } -extern inline byte_update_little_endian_exprt &to_byte_update_little_endian_expr(exprt &expr) +inline byte_update_little_endian_exprt + &to_byte_update_little_endian_expr(exprt &expr) { assert(expr.id()==ID_byte_update_little_endian && expr.operands().size()==3); return static_cast(expr); @@ -197,26 +201,27 @@ extern inline byte_update_little_endian_exprt &to_byte_update_little_endian_expr class byte_update_big_endian_exprt:public byte_update_exprt { public: - inline byte_update_big_endian_exprt(): + byte_update_big_endian_exprt(): byte_update_exprt(ID_byte_update_big_endian) { } - inline byte_update_big_endian_exprt( + byte_update_big_endian_exprt( const exprt &_op, const exprt &_offset, const exprt &_value): byte_update_exprt(ID_byte_update_big_endian, _op, _offset, _value) { } - }; -extern inline const byte_update_big_endian_exprt &to_byte_update_big_endian_expr(const exprt &expr) +inline const byte_update_big_endian_exprt + &to_byte_update_big_endian_expr(const exprt &expr) { assert(expr.id()==ID_byte_update_big_endian && expr.operands().size()==3); return static_cast(expr); } -extern inline byte_update_big_endian_exprt &to_byte_update_big_endian_expr(exprt &expr) +inline byte_update_big_endian_exprt + &to_byte_update_big_endian_expr(exprt &expr) { assert(expr.id()==ID_byte_update_big_endian && expr.operands().size()==3); return static_cast(expr); diff --git a/src/util/cmdline.cpp b/src/util/cmdline.cpp index 06b6189abe6..56d6a7a1a6c 100644 --- a/src/util/cmdline.cpp +++ b/src/util/cmdline.cpp @@ -78,7 +78,8 @@ Function: cmdlinet::isset bool cmdlinet::isset(char option) const { int i=getoptnr(option); - if(i<0) return false; + if(i<0) + return false; return options[i].isset; } @@ -97,7 +98,8 @@ Function: cmdlinet::isset bool cmdlinet::isset(const char *option) const { int i=getoptnr(option); - if(i<0) return false; + if(i<0) + return false; return options[i].isset; } @@ -116,8 +118,10 @@ Function: cmdlinet::get_value std::string cmdlinet::get_value(char option) const { int i=getoptnr(option); - if(i<0) return ""; - if(options[i].values.empty()) return ""; + if(i<0) + return ""; + if(options[i].values.empty()) + return ""; return options[i].values.front(); } @@ -136,7 +140,8 @@ Function: cmdlinet::set void cmdlinet::set(const std::string &option) { int i=getoptnr(option); - if(i<0) return; // ignore + if(i<0) + return; // ignore options[i].isset=true; } @@ -155,7 +160,8 @@ Function: cmdlinet::set void cmdlinet::set(const std::string &option, const std::string &value) { int i=getoptnr(option); - if(i<0) return; // ignore + if(i<0) + return; // ignore options[i].isset=true; options[i].values.push_back(value); } @@ -194,8 +200,10 @@ Function: cmdlinet::get_value std::string cmdlinet::get_value(const char *option) const { int i=getoptnr(option); - if(i<0) return ""; - if(options[i].values.empty()) return ""; + if(i<0) + return ""; + if(options[i].values.empty()) + return ""; return options[i].values.front(); } @@ -211,7 +219,8 @@ Function: cmdlinet::get_values \*******************************************************************/ -const std::list& cmdlinet::get_values(const std::string &option) const +const std::list &cmdlinet::get_values( + const std::string &option) const { int i=getoptnr(option); assert(i>=0); @@ -296,7 +305,8 @@ bool cmdlinet::parse(int argc, const char **argv, const char *optstring) for(optstring++; optstring[0]!=')' && optstring[0]!=0; optstring++) option.optstring+=optstring[0]; - if(optstring[0]==')') optstring++; + if(optstring[0]==')') + optstring++; } else { @@ -341,15 +351,18 @@ bool cmdlinet::parse(int argc, const char **argv, const char *optstring) optnr=getoptnr(argv[i]+1); } - if(optnr<0) return true; + if(optnr<0) + return true; options[optnr].isset=true; if(options[optnr].hasval) { if(argv[i][2]==0 || options[optnr].islong) { i++; - if(i==argc) return true; - if(argv[i][0]=='-' && argv[i][1]!=0) return true; + if(i==argc) + return true; + if(argv[i][0]=='-' && argv[i][1]!=0) + return true; options[optnr].values.push_back(argv[i]); } else diff --git a/src/util/config.cpp b/src/util/config.cpp index 48021c5754a..8751a35b711 100644 --- a/src/util/config.cpp +++ b/src/util/config.cpp @@ -538,7 +538,8 @@ void configt::ansi_ct::set_arch_spec_mips(const irep_idt &subarch) case flavourt::GCC: defines.push_back("__mips__"); defines.push_back("mips"); - defines.push_back("_MIPS_SZPTR="+std::to_string(config.ansi_c.pointer_width)); + defines.push_back( + "_MIPS_SZPTR="+std::to_string(config.ansi_c.pointer_width)); break; case flavourt::VISUAL_STUDIO: @@ -1041,7 +1042,8 @@ bool configt::set(const cmdlinet &cmdline) ansi_c.os=ansi_ct::ost::NO_OS; ansi_c.arch="none"; ansi_c.lib=configt::ansi_ct::libt::LIB_NONE; - ansi_c.NULL_is_zero=(size_t)((void*)0)==0; + // NOLINTNEXTLINE(readability/casting) + ansi_c.NULL_is_zero=reinterpret_cast((void*)0)==0; // Default is ROUND_TO_EVEN, justified by C99: // 1 At program startup the floating-point environment is initialized as @@ -1241,7 +1243,7 @@ bool configt::set(const cmdlinet &cmdline) assert(ansi_c.pointer_width==sizeof(void *)*8); assert(ansi_c.single_width==sizeof(float)*8); assert(ansi_c.double_width==sizeof(double)*8); - assert(ansi_c.char_is_unsigned==(char(255)==255)); + assert(ansi_c.char_is_unsigned==(static_cast(255)==255)); #ifndef _WIN32 // On Windows, long double width varies by compiler @@ -1389,7 +1391,9 @@ static irep_idt string_from_ns( tmp.op0().operands().size()!=2 || tmp.op0().op0().id()!=ID_string_constant) { - throw "symbol table configuration entry `"+id2string(id)+"' is not a string constant"; + throw + "symbol table configuration entry `"+id2string(id)+ + "' is not a string constant"; } return tmp.op0().op0().get(ID_value); @@ -1421,12 +1425,14 @@ static unsigned unsigned_from_ns( simplify(tmp, ns); if(tmp.id()!=ID_constant) - throw "symbol table configuration entry `"+id2string(id)+"' is not a constant"; + throw + "symbol table configuration entry `"+id2string(id)+"' is not a constant"; mp_integer int_value; if(to_integer(to_constant_expr(tmp), int_value)) - throw "failed to convert symbol table configuration entry `"+id2string(id)+"'"; + throw + "failed to convert symbol table configuration entry `"+id2string(id)+"'"; return integer2unsigned(int_value); } @@ -1493,7 +1499,7 @@ void configt::set_from_symbol_table( else ansi_c.os=ansi_ct::string_to_os(id2string(string_from_ns(ns, "os"))); - //NULL_is_zero=from_ns("NULL_is_zero"); + // NULL_is_zero=from_ns("NULL_is_zero"); ansi_c.NULL_is_zero=true; // mode, preprocessor (and all preprocessor command line options), @@ -1547,7 +1553,8 @@ irep_idt configt::this_architecture() this_arch="mips64"; #endif #elif __powerpc__ - #if defined(__ppc64__) || defined(__PPC64__) || defined(__powerpc64__) || defined(__POWERPC64__) + #if defined(__ppc64__) || defined(__PPC64__) || \ + defined(__powerpc64__) || defined(__POWERPC64__) #ifdef __LITTLE_ENDIAN__ this_arch="ppc64le"; #else @@ -1629,7 +1636,8 @@ void configt::set_classpath(const std::string &cp) current+=cp[pos]; } - if(!current.empty()) java.classpath.push_back(current); + if(!current.empty()) + java.classpath.push_back(current); } /*******************************************************************\ diff --git a/src/util/config.h b/src/util/config.h index 49aebffc173..f8c2f1f96dd 100644 --- a/src/util/config.h +++ b/src/util/config.h @@ -128,7 +128,6 @@ class configt void set_cpp03() { cpp_standard=cpp_standardt::CPP03; } void set_cpp11() { cpp_standard=cpp_standardt::CPP11; } void set_cpp14() { cpp_standard=cpp_standardt::CPP14; } - } cpp; struct verilogt diff --git a/src/util/cout_message.cpp b/src/util/cout_message.cpp index 6ed5125ba47..af315c696c5 100644 --- a/src/util/cout_message.cpp +++ b/src/util/cout_message.cpp @@ -39,7 +39,8 @@ void cout_message_handlert::print( std::cout << message << '\n'; // We flush for level 6 or below. - if(level<=6) std::cout << std::flush; + if(level<=6) + std::cout << std::flush; } } @@ -158,14 +159,15 @@ void gcc_message_handlert::print( const irep_idt line=location.get_line(); const irep_idt column=location.get_column(); const irep_idt function=location.get_function(); - + std::string dest; if(!function.empty()) { if(!file.empty()) dest+=id2string(file)+":"; - if(dest!="") dest+=' '; + if(dest!="") + dest+=' '; dest+="In function '"+id2string(function)+"':\n"; } diff --git a/src/util/cprover_prefix.h b/src/util/cprover_prefix.h index e9090a3b808..01fc391bf02 100644 --- a/src/util/cprover_prefix.h +++ b/src/util/cprover_prefix.h @@ -1,3 +1,11 @@ +/*******************************************************************\ + +Module: + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + #ifndef CPROVER_UTIL_CPROVER_PREFIX_H #define CPROVER_UTIL_CPROVER_PREFIX_H diff --git a/src/util/decision_procedure.h b/src/util/decision_procedure.h index c2e07d0081a..db609b1137e 100644 --- a/src/util/decision_procedure.h +++ b/src/util/decision_procedure.h @@ -32,10 +32,10 @@ class decision_proceduret:public messaget // the expression must be of Boolean type virtual void set_to(const exprt &expr, bool value)=0; - inline void set_to_true(const exprt &expr) + void set_to_true(const exprt &expr) { set_to(expr, true); } - inline void set_to_false(const exprt &expr) + void set_to_false(const exprt &expr) { set_to(expr, false); } // solve the problem @@ -44,7 +44,7 @@ class decision_proceduret:public messaget // will eventually be protected, use below call operator virtual resultt dec_solve()=0; - inline resultt operator()() + resultt operator()() { return dec_solve(); } @@ -59,7 +59,7 @@ class decision_proceduret:public messaget const namespacet &ns; }; -static inline decision_proceduret & operator << ( +inline decision_proceduret &operator<<( decision_proceduret &dest, const exprt &src) { diff --git a/src/util/dstring.h b/src/util/dstring.h index cddf885265b..9fdfd1ecddd 100644 --- a/src/util/dstring.h +++ b/src/util/dstring.h @@ -13,14 +13,14 @@ Author: Daniel Kroening, kroening@kroening.com #include "string_container.h" -class dstring +class dstringt { public: // this is safe for static objects #ifdef __GNUC__ constexpr #endif - dstring():no(0) + dstringt():no(0) { } @@ -29,7 +29,7 @@ class dstring #ifdef __GNUC__ constexpr #endif - dstring(unsigned _no, unsigned):no(_no) + dstringt(unsigned _no, unsigned):no(_no) { } @@ -40,48 +40,50 @@ class dstring #endif // this one is not safe for static objects - inline dstring(const char *s):no(string_container[s]) + // NOLINTNEXTLINE(runtime/explicit) + dstringt(const char *s):no(string_container[s]) { } // this one is not safe for static objects - inline dstring(const std::string &s):no(string_container[s]) + // NOLINTNEXTLINE(runtime/explicit) + dstringt(const std::string &s):no(string_container[s]) { } // access - inline bool empty() const + bool empty() const { return no==0; // string 0 is exactly the empty string } - inline char operator[](size_t i) const + char operator[](size_t i) const { return as_string()[i]; } // the pointer is guaranteed to be stable - inline const char *c_str() const + const char *c_str() const { return as_string().c_str(); } - inline size_t size() const + size_t size() const { return as_string().size(); } // ordering -- not the same as lexicographical ordering - inline bool operator< (const dstring &b) const { return no (const std::string &b) const { return as_string()> b; } + bool operator<(const std::string &b) const { return as_string()(const std::string &b) const { return as_string()>b; } bool operator<=(const std::string &b) const { return as_string()<=b; } bool operator>=(const std::string &b) const { return as_string()>=b; } - int compare(const dstring &b) const + int compare(const dstringt &b) const { - if(no==b.no) return 0; // equal + if(no==b.no) + return 0; // equal return as_string().compare(b.as_string()); } - inline friend bool ordering(const dstring &a, const dstring &b) - { - return a.no template -class expanding_vector:public std::vector +class expanding_vectort:public std::vector { public: - inline T & operator[] (typename std::vector::size_type n) + T &operator[] (typename std::vector::size_type n) { check_index(n); return subt::operator[](n); } - inline const T & operator[] (typename std::vector::size_type n) const + const T &operator[] (typename std::vector::size_type n) const { // hack-ish const cast - const_cast(this)->check_index(n); + const_cast(this)->check_index(n); return subt::operator[](n); } @@ -32,9 +32,10 @@ class expanding_vector:public std::vector typedef std::vector subt; // make the vector large enough to contain 'n' - inline void check_index(typename std::vector::size_type n) + void check_index(typename std::vector::size_type n) { - if(n>=subt::size()) subt::resize(n+1); + if(n>=subt::size()) + subt::resize(n+1); } }; diff --git a/src/util/expr.cpp b/src/util/expr.cpp index b317b434e41..963def60b12 100644 --- a/src/util/expr.cpp +++ b/src/util/expr.cpp @@ -140,8 +140,10 @@ Function: exprt::copy_to_operands \*******************************************************************/ -void exprt::copy_to_operands(const exprt &e1, const exprt &e2, - const exprt &e3) +void exprt::copy_to_operands( + const exprt &e1, + const exprt &e2, + const exprt &e3) { operandst &op=operands(); #ifndef USE_LIST @@ -325,23 +327,6 @@ void exprt::make_false() /*******************************************************************\ -Function: operator< - - Inputs: - - Outputs: - - Purpose: defines ordering on expressions for canonicalization - -\*******************************************************************/ - -bool operator<(const exprt &X, const exprt &Y) -{ - return (irept &)X < (irept &)Y; -} - -/*******************************************************************\ - Function: exprt::negate Inputs: @@ -460,7 +445,8 @@ bool exprt::is_zero() const else if(type_id==ID_rational) { rationalt rat_value; - if(to_rational(*this, rat_value)) assert(false); + if(to_rational(*this, rat_value)) + assert(false); return rat_value.is_zero(); } else if(type_id==ID_unsignedbv || type_id==ID_signedbv) @@ -469,11 +455,13 @@ bool exprt::is_zero() const } else if(type_id==ID_fixedbv) { - if(fixedbvt(constant)==0) return true; + if(fixedbvt(constant)==0) + return true; } else if(type_id==ID_floatbv) { - if(ieee_floatt(constant)==0) return true; + if(ieee_floatt(constant)==0) + return true; } else if(type_id==ID_pointer) { @@ -507,18 +495,21 @@ bool exprt::is_one() const if(type_id==ID_integer || type_id==ID_natural) { mp_integer int_value=string2integer(value); - if(int_value==1) return true; + if(int_value==1) + return true; } else if(type_id==ID_rational) { rationalt rat_value; - if(to_rational(*this, rat_value)) assert(false); + if(to_rational(*this, rat_value)) + assert(false); return rat_value.is_one(); } else if(type_id==ID_unsignedbv || type_id==ID_signedbv) { mp_integer int_value=binary2integer(value, false); - if(int_value==1) return true; + if(int_value==1) + return true; } else if(type_id==ID_fixedbv) { @@ -549,8 +540,10 @@ Function: exprt::sum bool exprt::sum(const exprt &expr) { - if(!is_constant() || !expr.is_constant()) return true; - if(type()!=expr.type()) return true; + if(!is_constant() || !expr.is_constant()) + return true; + if(type()!=expr.type()) + return true; const irep_idt &type_id=type().id(); @@ -612,8 +605,10 @@ Function: exprt::mul bool exprt::mul(const exprt &expr) { - if(!is_constant() || !expr.is_constant()) return true; - if(type()!=expr.type()) return true; + if(!is_constant() || !expr.is_constant()) + return true; + if(type()!=expr.type()) + return true; const irep_idt &type_id=type().id(); @@ -675,9 +670,11 @@ Function: exprt::subtract bool exprt::subtract(const exprt &expr) { - if(!is_constant() || !expr.is_constant()) return true; + if(!is_constant() || !expr.is_constant()) + return true; - if(type()!=expr.type()) return true; + if(type()!=expr.type()) + return true; const irep_idt &type_id=type().id(); @@ -726,12 +723,14 @@ const source_locationt &exprt::find_source_location() const { const source_locationt &l=source_location(); - if(l.is_not_nil()) return l; + if(l.is_not_nil()) + return l; forall_operands(it, (*this)) { const source_locationt &l=it->find_source_location(); - if(l.is_not_nil()) return l; + if(l.is_not_nil()) + return l; } return static_cast(get_nil_irep()); diff --git a/src/util/expr.h b/src/util/expr.h index 620d23316f6..47a85b50f1c 100644 --- a/src/util/expr.h +++ b/src/util/expr.h @@ -14,13 +14,13 @@ Author: Daniel Kroening, kroening@kroening.com #include "type.h" #define forall_operands(it, expr) \ - if((expr).has_operands()) \ + if((expr).has_operands()) /* NOLINT(readability/braces) */ \ for(exprt::operandst::const_iterator it=(expr).operands().begin(), \ it##_end=(expr).operands().end(); \ it!=it##_end; ++it) #define Forall_operands(it, expr) \ - if((expr).has_operands()) \ + if((expr).has_operands()) /* NOLINT(readability/braces) */ \ for(exprt::operandst::iterator it=(expr).operands().begin(); \ it!=(expr).operands().end(); ++it) @@ -48,65 +48,73 @@ class exprt:public irept typedef std::vector operandst; // constructors - inline exprt() { } - inline explicit exprt(const irep_idt &_id):irept(_id) { } - inline exprt(const irep_idt &_id, const typet &_type):irept(_id) { add(ID_type, _type); } + exprt() { } + explicit exprt(const irep_idt &_id):irept(_id) { } + exprt(const irep_idt &_id, const typet &_type):irept(_id) + { + add(ID_type, _type); + } // returns the type of the expression - inline typet &type() { return static_cast(add(ID_type)); } - inline const typet &type() const { return static_cast(find(ID_type)); } + typet &type() { return static_cast(add(ID_type)); } + const typet &type() const + { + return static_cast(find(ID_type)); + } // returns true if there is at least one operand - inline bool has_operands() const + bool has_operands() const { return !operands().empty(); } - inline operandst &operands() + operandst &operands() #ifdef OPERANDS_IN_GETSUB { return (operandst &)get_sub(); } #else { return (operandst &)(add(ID_operands).get_sub()); } #endif - inline const operandst &operands() const + const operandst &operands() const #ifdef OPERANDS_IN_GETSUB { return (const operandst &)get_sub(); } #else { return (const operandst &)(find(ID_operands).get_sub()); } #endif - inline exprt &op0() + exprt &op0() { return operands().front(); } - inline exprt &op1() + exprt &op1() { return operands()[1]; } - inline exprt &op2() + exprt &op2() { return operands()[2]; } - inline exprt &op3() + exprt &op3() { return operands()[3]; } - inline const exprt &op0() const + const exprt &op0() const { return operands().front(); } - inline const exprt &op1() const + const exprt &op1() const { return operands()[1]; } - inline const exprt &op2() const + const exprt &op2() const { return operands()[2]; } - inline const exprt &op3() const + const exprt &op3() const { return operands()[3]; } - inline void reserve_operands(operandst::size_type n) + void reserve_operands(operandst::size_type n) { operands().reserve(n) ; } - void move_to_operands(exprt &expr); // destroys expr - void move_to_operands(exprt &e1, exprt &e2); // destroys e1, e2 - void move_to_operands(exprt &e1, exprt &e2, exprt &e3); // destroys e1, e2, e3 - void copy_to_operands(const exprt &expr); // does not destroy expr - void copy_to_operands(const exprt &e1, const exprt &e2); // does not destroy expr - void copy_to_operands(const exprt &e1, const exprt &e2, const exprt &e3); // does not destroy expr + // destroys expr, e1, e2, e3 + void move_to_operands(exprt &expr); + void move_to_operands(exprt &e1, exprt &e2); + void move_to_operands(exprt &e1, exprt &e2, exprt &e3); + // does not destroy expr, e1, e2, e3 + void copy_to_operands(const exprt &expr); + void copy_to_operands(const exprt &e1, const exprt &e2); + void copy_to_operands(const exprt &e1, const exprt &e2, const exprt &e3); // the following are deprecated -- use constructors instead void make_typecast(const typet &_type); @@ -128,26 +136,24 @@ class exprt:public irept bool is_one() const; bool is_boolean() const; - friend bool operator<(const exprt &X, const exprt &Y); - const source_locationt &find_source_location() const; - inline const source_locationt &source_location() const + const source_locationt &source_location() const { return static_cast(find(ID_C_source_location)); } - inline source_locationt &add_source_location() + source_locationt &add_source_location() { return static_cast(add(ID_C_source_location)); } - inline exprt &add_expr(const irep_idt &name) + exprt &add_expr(const irep_idt &name) { return static_cast(add(name)); } - inline const exprt &find_expr(const irep_idt &name) const + const exprt &find_expr(const irep_idt &name) const { return static_cast(find(name)); } diff --git a/src/util/expr_util.cpp b/src/util/expr_util.cpp index 09f3ef2a7c6..f5abbc06c28 100644 --- a/src/util/expr_util.cpp +++ b/src/util/expr_util.cpp @@ -52,7 +52,8 @@ exprt make_binary(const exprt &expr) { const exprt::operandst &operands=expr.operands(); - if(operands.size()<=2) return expr; + if(operands.size()<=2) + return expr; exprt previous=operands.front(); @@ -102,7 +103,7 @@ with_exprt make_with_expr(const update_exprt &src) } else if(it->id()==ID_member_designator) { - //irep_idt component_name= + // irep_idt component_name= // to_member_designator(*it).get_component_name(); } else @@ -194,7 +195,8 @@ Function: has_subexpr bool has_subexpr(const exprt &src, const irep_idt &id) { - if(src.id()==id) return true; + if(src.id()==id) + return true; forall_operands(it, src) if(has_subexpr(*it, id)) @@ -217,7 +219,7 @@ Function: lift_if if_exprt lift_if(const exprt &src, std::size_t operand_number) { - assert(operand_number < src.operands().size()); + assert(operand_number + #if defined(__linux__) || \ defined(__FreeBSD_kernel__) || \ defined(__GNU__) || \ @@ -15,7 +17,6 @@ Date: January 2012 defined(__CYGWIN__) || \ defined(__MACH__) #include -#include #include #include #include @@ -25,7 +26,6 @@ Date: January 2012 #include #include #include -#include #define chdir _chdir #define popen _popen #define pclose _pclose @@ -49,15 +49,16 @@ std::string get_current_working_directory() { unsigned bsize=50; - char *buf=(char*)malloc(sizeof(char)*bsize); - if(!buf) abort(); + char *buf=reinterpret_cast(malloc(sizeof(char)*bsize)); + if(!buf) + abort(); errno=0; while(buf && getcwd(buf, bsize-1)==NULL && errno==ERANGE) { bsize*=2; - buf=(char*)realloc(buf, sizeof(char)*bsize); + buf=reinterpret_cast(realloc(buf, sizeof(char)*bsize)); } std::string working_directory=buf; @@ -84,6 +85,7 @@ void delete_directory(const std::string &path) std::string pattern=path+"\\*"; + // NOLINTNEXTLINE(readability/identifiers) struct _finddata_t info; intptr_t handle=_findfirst(pattern.c_str(), &info); @@ -105,7 +107,7 @@ void delete_directory(const std::string &path) struct dirent *ent; while((ent=readdir(dir))!=NULL) - remove((path + "/" + ent->d_name).c_str()); + remove((path+"/"+ent->d_name).c_str()); closedir(dir); } @@ -128,8 +130,9 @@ Function: concat_dir_file \*******************************************************************/ -std::string concat_dir_file(const std::string &directory, - const std::string &file_name) +std::string concat_dir_file( + const std::string &directory, + const std::string &file_name) { #ifdef _WIN32 return (file_name.size()>1 && diff --git a/src/util/find_symbols.cpp b/src/util/find_symbols.cpp index 7f40ae43c8d..03cd78f4347 100644 --- a/src/util/find_symbols.cpp +++ b/src/util/find_symbols.cpp @@ -225,7 +225,8 @@ void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest) src.id()==ID_union) { const struct_union_typet &struct_union_type=to_struct_union_type(src); - const struct_union_typet::componentst &components=struct_union_type.components(); + const struct_union_typet::componentst &components= + struct_union_type.components(); for(struct_union_typet::componentst::const_iterator it=components.begin(); @@ -246,8 +247,8 @@ void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest) { find_symbols(kind, *it, dest); - //irep_idt identifier=it->get_identifier(); - //if(identifier!=irep_idt() && (kind==F_TYPE || kind==F_BOTH)) + // irep_idt identifier=it->get_identifier(); + // if(identifier!=irep_idt() && (kind==F_TYPE || kind==F_BOTH)) // dest.insert(identifier); } } diff --git a/src/util/fixedbv.cpp b/src/util/fixedbv.cpp index 9d1fee75d64..d1703d85ca9 100644 --- a/src/util/fixedbv.cpp +++ b/src/util/fixedbv.cpp @@ -60,7 +60,7 @@ Function: fixedbvt::from_expr void fixedbvt::from_expr(const constant_exprt &expr) { - spec=to_fixedbv_type(expr.type()); + spec=fixedbv_spect(to_fixedbv_type(expr.type())); v=binary2integer(id2string(expr.get_value()), true); } @@ -149,11 +149,15 @@ void fixedbvt::round(const fixedbv_spect &dest_spec) mp_integer p=power(2, old_fraction_bits-new_fraction_bits); mp_integer div=v/p; mp_integer rem=v%p; - if(rem<0) rem=-rem; + if(rem<0) + rem=-rem; if(rem*2>=p) { - if(v<0) --div; else ++div; + if(v<0) + --div; + else + ++div; } result=div; diff --git a/src/util/fixedbv.h b/src/util/fixedbv.h index 3ea681f6aa3..14e5946c445 100644 --- a/src/util/fixedbv.h +++ b/src/util/fixedbv.h @@ -29,9 +29,9 @@ class fixedbv_spect { } - fixedbv_spect(const fixedbv_typet &type); + explicit fixedbv_spect(const fixedbv_typet &type); - inline std::size_t get_fraction_bits() const + std::size_t get_fraction_bits() const { return width-integer_bits; } @@ -61,7 +61,8 @@ class fixedbvt std::string format(const format_spect &format_spec) const; - bool operator == (int i) const; + bool operator==(int i) const; + bool is_zero() const { return v==0; @@ -69,17 +70,17 @@ class fixedbvt void negate(); - fixedbvt &operator /= (const fixedbvt &other); - fixedbvt &operator *= (const fixedbvt &other); - fixedbvt &operator += (const fixedbvt &other); - fixedbvt &operator -= (const fixedbvt &other); + fixedbvt &operator/=(const fixedbvt &other); + fixedbvt &operator*=(const fixedbvt &other); + fixedbvt &operator+=(const fixedbvt &other); + fixedbvt &operator-=(const fixedbvt &other); - friend bool operator < (const fixedbvt &a, const fixedbvt &b) { return a.v (const fixedbvt &a, const fixedbvt &b) { return a.v>b.v; } - friend bool operator >=(const fixedbvt &a, const fixedbvt &b) { return a.v>=b.v; } - friend bool operator ==(const fixedbvt &a, const fixedbvt &b) { return a.v==b.v; } - friend bool operator !=(const fixedbvt &a, const fixedbvt &b) { return a.v!=b.v; } + bool operator<(const fixedbvt &other) const { return v(const fixedbvt &other) const { return v>other.v; } + bool operator>=(const fixedbvt &other) const { return v>=other.v; } + bool operator==(const fixedbvt &other) const { return v==other.v; } + bool operator!=(const fixedbvt &other) const { return v!=other.v; } const mp_integer &get_value() const { return v; } void set_value(const mp_integer &_v) { v=_v; } @@ -89,11 +90,4 @@ class fixedbvt mp_integer v; }; -bool operator < (const fixedbvt &a, const fixedbvt &b); -bool operator <=(const fixedbvt &a, const fixedbvt &b); -bool operator > (const fixedbvt &a, const fixedbvt &b); -bool operator >=(const fixedbvt &a, const fixedbvt &b); -bool operator ==(const fixedbvt &a, const fixedbvt &b); -bool operator !=(const fixedbvt &a, const fixedbvt &b); - #endif // CPROVER_UTIL_FIXEDBV_H diff --git a/src/util/format_constant.cpp b/src/util/format_constant.cpp index c1f22a67d63..a63b1d01555 100644 --- a/src/util/format_constant.cpp +++ b/src/util/format_constant.cpp @@ -35,7 +35,8 @@ std::string format_constantt::operator()(const exprt &expr) expr.type().id()==ID_signedbv) { mp_integer i; - if(to_integer(expr, i)) return "(number conversion failed)"; + if(to_integer(expr, i)) + return "(number conversion failed)"; return integer2string(i); } diff --git a/src/util/get_base_name.cpp b/src/util/get_base_name.cpp index 08915427740..3f7bb186937 100644 --- a/src/util/get_base_name.cpp +++ b/src/util/get_base_name.cpp @@ -27,16 +27,20 @@ std::string get_base_name(const std::string &in, bool strip_suffix) size_t r=std::string::npos; if(strip_suffix) r=in.rfind('.', in.length()-1); - if(r==std::string::npos) r=in.length(); + if(r==std::string::npos) + r=in.length(); size_t f=in.rfind('/', in.length()-1); - if(f==std::string::npos) f=0; + if(f==std::string::npos) + f=0; size_t fw=in.rfind('\\', in.length()-1); - if(fw==std::string::npos) fw=0; + if(fw==std::string::npos) + fw=0; f = (fw>f)?fw:f; - if(in[f]=='/' || in[f]=='\\') f++; + if(in[f]=='/' || in[f]=='\\') + f++; return in.substr(f, r-f); } diff --git a/src/util/get_module.cpp b/src/util/get_module.cpp index 63eea030fb1..e4afd21400f 100644 --- a/src/util/get_module.cpp +++ b/src/util/get_module.cpp @@ -45,7 +45,8 @@ const symbolt &get_module_by_name( forall_symbol_base_map(it, symbol_table.symbol_base_map, module) { - symbol_tablet::symbolst::const_iterator it2=symbol_table.symbols.find(it->second); + symbol_tablet::symbolst::const_iterator it2= + symbol_table.symbols.find(it->second); if(it2==symbol_table.symbols.end()) continue; diff --git a/src/util/graph.h b/src/util/graph.h index 26b8a835e6e..42988914362 100644 --- a/src/util/graph.h +++ b/src/util/graph.h @@ -32,22 +32,22 @@ class graph_nodet edgest in, out; - inline void add_in(node_indext n) + void add_in(node_indext n) { in.insert(std::pair(n, edget())); } - inline void add_out(node_indext n) + void add_out(node_indext n) { out.insert(std::pair(n, edget())); } - inline void erase_in(node_indext n) + void erase_in(node_indext n) { in.erase(n); } - inline void erase_out(node_indext n) + void erase_out(node_indext n) { out.erase(n); } @@ -63,7 +63,7 @@ class visited_nodet:public graph_nodet bool visited; - inline visited_nodet():visited(false) + visited_nodet():visited(false) { } }; @@ -97,7 +97,7 @@ void intersection( // a generic graph class with a parametric node type template > -class graph +class grapht { public: typedef N nodet; @@ -110,66 +110,66 @@ class graph nodest nodes; public: - inline node_indext add_node() + node_indext add_node() { node_indext no=nodes.size(); nodes.push_back(nodet()); return no; } - inline void swap(graph &other) + void swap(grapht &other) { nodes.swap(other.nodes); } - inline bool has_edge(node_indext i, node_indext j) const + bool has_edge(node_indext i, node_indext j) const { return nodes[i].out.find(j)!=nodes[i].out.end(); } - inline const nodet &operator[](node_indext n) const + const nodet &operator[](node_indext n) const { return nodes[n]; } - inline nodet &operator[](node_indext n) + nodet &operator[](node_indext n) { return nodes[n]; } - inline void resize(node_indext s) + void resize(node_indext s) { nodes.resize(s); } - inline std::size_t size() const + std::size_t size() const { return nodes.size(); } - inline const edgest &in(node_indext n) const + const edgest &in(node_indext n) const { return nodes[n].in; } - inline const edgest &out(node_indext n) const + const edgest &out(node_indext n) const { return nodes[n].out; } - inline void add_edge(node_indext a, node_indext b) + void add_edge(node_indext a, node_indext b) { nodes[a].add_out(b); nodes[b].add_in(a); } - inline void remove_edge(node_indext a, node_indext b) + void remove_edge(node_indext a, node_indext b) { nodes[a].erase_out(b); nodes[b].erase_in(a); } - inline edget &edge(node_indext a, node_indext b) + edget &edge(node_indext a, node_indext b) { return nodes[a].out[b]; } @@ -179,20 +179,20 @@ class graph void remove_in_edges(node_indext n); void remove_out_edges(node_indext n); - inline void remove_edges(node_indext n) + void remove_edges(node_indext n) { remove_in_edges(n); remove_out_edges(n); } - inline void clear() + void clear() { nodes.clear(); } typedef std::list patht; - inline void shortest_path( + void shortest_path( node_indext src, node_indext dest, patht &path) const @@ -200,7 +200,7 @@ class graph shortest_path(src, dest, path, false); } - inline void shortest_loop( + void shortest_loop( node_indext node, patht &path) const { @@ -257,7 +257,7 @@ class graph /*******************************************************************\ -Function: graph::add_undirected_edge +Function: grapht::add_undirected_edge Inputs: @@ -268,7 +268,7 @@ Function: graph::add_undirected_edge \*******************************************************************/ template -void graph::add_undirected_edge(node_indext a, node_indext b) +void grapht::add_undirected_edge(node_indext a, node_indext b) { assert(a::add_undirected_edge(node_indext a, node_indext b) /*******************************************************************\ -Function: graph::remove_undirected_edge +Function: grapht::remove_undirected_edge Inputs: @@ -293,7 +293,7 @@ Function: graph::remove_undirected_edge \*******************************************************************/ template -void graph::remove_undirected_edge(node_indext a, node_indext b) +void grapht::remove_undirected_edge(node_indext a, node_indext b) { nodet &na=nodes[a]; nodet &nb=nodes[b]; @@ -305,7 +305,7 @@ void graph::remove_undirected_edge(node_indext a, node_indext b) /*******************************************************************\ -Function: graph::remove_in_edges +Function: grapht::remove_in_edges Inputs: @@ -316,7 +316,7 @@ Function: graph::remove_in_edges \*******************************************************************/ template -void graph::remove_in_edges(node_indext n) +void grapht::remove_in_edges(node_indext n) { nodet &node=nodes[n]; @@ -332,7 +332,7 @@ void graph::remove_in_edges(node_indext n) /*******************************************************************\ -Function: graph::remove_out_edges +Function: grapht::remove_out_edges Inputs: @@ -343,7 +343,7 @@ Function: graph::remove_out_edges \*******************************************************************/ template -void graph::remove_out_edges(node_indext n) +void grapht::remove_out_edges(node_indext n) { nodet &node=nodes[n]; @@ -359,7 +359,7 @@ void graph::remove_out_edges(node_indext n) /*******************************************************************\ -Function: graph::shortest_path +Function: grapht::shortest_path Inputs: @@ -370,7 +370,7 @@ Function: graph::shortest_path \*******************************************************************/ template -void graph::shortest_path( +void grapht::shortest_path( node_indext src, node_indext dest, patht &path, @@ -462,7 +462,7 @@ void graph::shortest_path( /*******************************************************************\ -Function: graph::visit_reachable +Function: grapht::visit_reachable Inputs: @@ -473,7 +473,7 @@ Function: graph::visit_reachable \*******************************************************************/ template -void graph::visit_reachable(node_indext src) +void grapht::visit_reachable(node_indext src) { // DFS @@ -499,7 +499,7 @@ void graph::visit_reachable(node_indext src) /*******************************************************************\ -Function: graph::connected_subgraphs +Function: grapht::connected_subgraphs Inputs: @@ -510,7 +510,7 @@ Function: graph::connected_subgraphs \*******************************************************************/ template -std::size_t graph::connected_subgraphs( +std::size_t grapht::connected_subgraphs( std::vector &subgraph_nr) { std::vector visited; @@ -522,7 +522,8 @@ std::size_t graph::connected_subgraphs( for(node_indext src=0; src::connected_subgraphs( /*******************************************************************\ -Function: graph::tarjan +Function: grapht::tarjan Inputs: @@ -566,7 +567,7 @@ Function: graph::tarjan \*******************************************************************/ template -void graph::tarjan(tarjant &t, node_indext v) +void grapht::tarjan(tarjant &t, node_indext v) { t.scc_stack.push(v); t.in_scc[v]=true; @@ -601,7 +602,8 @@ void graph::tarjan(tarjant &t, node_indext v) t.scc_stack.pop(); t.in_scc[vp]=false; t.subgraph_nr[vp]=t.scc_count; - if(vp==v) break; + if(vp==v) + break; } t.scc_count++; @@ -610,7 +612,7 @@ void graph::tarjan(tarjant &t, node_indext v) /*******************************************************************\ -Function: graph::SCCs +Function: grapht::SCCs Inputs: @@ -621,7 +623,7 @@ Function: graph::SCCs \*******************************************************************/ template -std::size_t graph::SCCs(std::vector &subgraph_nr) +std::size_t grapht::SCCs(std::vector &subgraph_nr) { tarjant t(nodes.size(), subgraph_nr); @@ -634,7 +636,7 @@ std::size_t graph::SCCs(std::vector &subgraph_nr) /*******************************************************************\ -Function: graph::make_chordal +Function: grapht::make_chordal Inputs: @@ -645,9 +647,9 @@ Function: graph::make_chordal \*******************************************************************/ template -void graph::make_chordal() +void grapht::make_chordal() { - graph tmp(*this); + grapht tmp(*this); // This assumes an undirected graph. // 1. remove all nodes in tmp, reconnecting the remaining ones @@ -682,7 +684,7 @@ void graph::make_chordal() /*******************************************************************\ -Function: graph::output_dot +Function: grapht::output_dot Inputs: @@ -693,7 +695,7 @@ Function: graph::output_dot \*******************************************************************/ template -void graph::output_dot(std::ostream &out) const +void grapht::output_dot(std::ostream &out) const { for(node_indext n=0; n::output_dot(std::ostream &out) const /*******************************************************************\ -Function: graph::output_dot_node +Function: grapht::output_dot_node Inputs: @@ -712,7 +714,7 @@ Function: graph::output_dot_node \*******************************************************************/ template -void graph::output_dot_node(std::ostream &out, node_indext n) const +void grapht::output_dot_node(std::ostream &out, node_indext n) const { const nodet &node=nodes[n]; diff --git a/src/util/guard.cpp b/src/util/guard.cpp index e5362143018..da9cc130723 100644 --- a/src/util/guard.cpp +++ b/src/util/guard.cpp @@ -177,8 +177,13 @@ Function: operator |= guardt &operator |= (guardt &g1, const guardt &g2) { - if(g2.is_false() || g1.is_true()) return g1; - if(g1.is_false() || g2.is_true()) { g1=g2; return g1; } + if(g2.is_false() || g1.is_true()) + return g1; + if(g1.is_false() || g2.is_true()) + { + g1=g2; + return g1; + } if(g1.id()!=ID_and || g2.id()!=ID_and) { @@ -229,7 +234,8 @@ guardt &operator |= (guardt &g1, const guardt &g2) it1=op1.erase(it1); } - if(n_op2.empty()) return g1; + if(n_op2.empty()) + return g1; // end of common prefix exprt and_expr1=conjunction(n_op1); diff --git a/src/util/guard.h b/src/util/guard.h index 7344fc10d2e..215ac58ba02 100644 --- a/src/util/guard.h +++ b/src/util/guard.h @@ -21,7 +21,7 @@ class guardt:public exprt make_true(); } - guardt& operator=(const exprt &e) + guardt &operator=(const exprt &e) { *this=static_cast(e); @@ -35,7 +35,7 @@ class guardt:public exprt add(guard); } - //exprt as_expr(guard_listt::const_iterator it) const; + // exprt as_expr(guard_listt::const_iterator it) const; exprt as_expr() const { @@ -66,8 +66,6 @@ class guardt:public exprt guard_list.swap(g.guard_list); } - friend std::ostream &operator << (std::ostream &out, const guardt &g); - size_type size() const { return guard_list.size(); diff --git a/src/util/identifier.cpp b/src/util/identifier.cpp index 52b2ba7d6c0..96074d9c43e 100644 --- a/src/util/identifier.cpp +++ b/src/util/identifier.cpp @@ -29,7 +29,8 @@ std::string identifiert::as_string() const for(componentst::const_iterator it=components.begin(); it!=components.end(); it++) { - if(it!=components.begin()) result+=ID_SEPARATOR; + if(it!=components.begin()) + result+=ID_SEPARATOR; result+=*it; } diff --git a/src/util/identifier.h b/src/util/identifier.h index 94dad2ecf13..5bcd8e9b6eb 100644 --- a/src/util/identifier.h +++ b/src/util/identifier.h @@ -17,7 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com class identifiert { public: - identifiert(const std::string &s) + explicit identifiert(const std::string &s) { parse(s); } identifiert() diff --git a/src/util/ieee_float.cpp b/src/util/ieee_float.cpp index 6ad3e417e39..5220b05885c 100644 --- a/src/util/ieee_float.cpp +++ b/src/util/ieee_float.cpp @@ -53,7 +53,8 @@ floatbv_typet ieee_float_spect::to_type() const floatbv_typet result; result.set_f(f); result.set_width(width()); - if(x86_extended) result.set(ID_x86_extended, true); + if(x86_extended) + result.set(ID_x86_extended, true); return result; } @@ -111,7 +112,8 @@ void ieee_float_spect::from_type(const floatbv_typet &type) assert(f