Skip to content

RFC: Ranged for #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions regression/ansi-c/struct7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct S
{
int x;
int x;
};

int main()
{
struct S s;
return s.x;
}
8 changes: 8 additions & 0 deletions regression/ansi-c/struct7/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=\(64\|1\)$
^SIGNAL=0$
^file main.c line 4: duplicate member x$
^CONVERSION ERROR$
--
6 changes: 2 additions & 4 deletions src/aa-path-symex/path_symex_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ void path_symex_stept::output(std::ostream &out) const
out << "PCs:";

/*
for(pc_vectort::const_iterator p_it=s_it->pc_vector.begin();
p_it!=pc_vector.end();
p_it++)
out << " " << *p_it;
for(const auto &pc : s_it->pc_vector)
out << " " << pc;
*/
out << "\n";

Expand Down
7 changes: 2 additions & 5 deletions src/aa-path-symex/path_symex_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ void path_symex_statet::output(const threadt &thread, std::ostream &out) const
{
out << " PC: " << thread.pc << std::endl;
out << " Call stack:";
for(call_stackt::const_iterator
it=thread.call_stack.begin();
it!=thread.call_stack.end();
it++)
out << " " << it->return_location << std::endl;
for(const auto &call : thread.call_stack)
out << " " << call.return_location << std::endl;
out << std::endl;
}

Expand Down
37 changes: 11 additions & 26 deletions src/aa-symex/path_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,11 @@ void path_searcht::do_show_vcc(
std::vector<path_symex_step_reft> steps;
state.history.build_history(steps);

for(std::vector<path_symex_step_reft>::const_iterator
s_it=steps.begin();
s_it!=steps.end();
s_it++)
for(const auto &step_ref : steps)
{
if((*s_it)->guard.is_not_nil())
if(step_ref->guard.is_not_nil())
{
std::string string_value=from_expr(ns, "", (*s_it)->guard);
std::string string_value=from_expr(ns, "", step_ref->guard);
out << "{-" << count << "} " << string_value << "\n";
count++;
}
Expand Down Expand Up @@ -403,22 +400,16 @@ bool path_searcht::drop_state(const statet &state) const
// unwinding limit -- loops
if(unwind_limit!=-1 && state.get_instruction()->is_backwards_goto())
{
for(path_symex_statet::unwinding_mapt::const_iterator
it=state.unwinding_map.begin();
it!=state.unwinding_map.end();
it++)
if(it->second>unwind_limit)
for(const auto &loop_info : state.unwinding_map)
if(loop_info.second>unwind_limit)
return true;
}

// unwinding limit -- recursion
if(unwind_limit!=-1 && state.get_instruction()->is_function_call())
{
for(path_symex_statet::recursion_mapt::const_iterator
it=state.recursion_map.begin();
it!=state.recursion_map.end();
it++)
if(it->second>unwind_limit)
for(const auto &rec_info : state.recursion_map)
if(rec_info.second>unwind_limit)
return true;
}

Expand Down Expand Up @@ -500,23 +491,17 @@ Function: path_searcht::initialize_property_map
void path_searcht::initialize_property_map(
const goto_functionst &goto_functions)
{
for(goto_functionst::function_mapt::const_iterator
it=goto_functions.function_map.begin();
it!=goto_functions.function_map.end();
it++)
forall_goto_functions(it, goto_functions)
if(!it->second.is_inlined())
{
const goto_programt &goto_program=it->second.body;

for(goto_programt::instructionst::const_iterator
it=goto_program.instructions.begin();
it!=goto_program.instructions.end();
it++)
forall_goto_program_instructions(i_it, goto_program)
{
if(!it->is_assert())
if(!i_it->is_assert())
continue;

const locationt &location=it->location;
const locationt &location=i_it->location;

irep_idt property_name=location.get_property_id();

Expand Down
24 changes: 9 additions & 15 deletions src/aa-symex/symex_parseoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,12 @@ Function: symex_parseoptionst::report_properties
void symex_parseoptionst::report_properties(
const path_searcht::property_mapt &property_map)
{
for(path_searcht::property_mapt::const_iterator
it=property_map.begin();
it!=property_map.end();
it++)
for(const auto &prop_pair : property_map)
{
if(get_ui()==ui_message_handlert::XML_UI)
{
xmlt xml_result("result");
xml_result.set_attribute("claim", id2string(it->first));
xml_result.set_attribute("claim", id2string(prop_pair.first));

std::string status_string;

Expand All @@ -566,9 +563,9 @@ void symex_parseoptionst::report_properties(
}
else
{
status() << "[" << it->first << "] "
<< it->second.description << ": ";
switch(it->second.status)
status() << "[" << prop_pair.first << "] "
<< prop_pair.second.description << ": ";
switch(prop_pair.second.status)
{
case path_searcht::PASS: status() << "OK"; break;
case path_searcht::FAIL: status() << "FAILED"; break;
Expand All @@ -578,8 +575,8 @@ void symex_parseoptionst::report_properties(
}

if(cmdline.isset("show-trace") &&
it->second.status==path_searcht::FAIL)
show_counterexample(it->second.error_trace);
prop_pair.second.status==path_searcht::FAIL)
show_counterexample(prop_pair.second.error_trace);
}

if(!cmdline.isset("property"))
Expand All @@ -588,11 +585,8 @@ void symex_parseoptionst::report_properties(

unsigned failed=0;

for(path_searcht::property_mapt::const_iterator
it=property_map.begin();
it!=property_map.end();
it++)
if(it->second.status==path_searcht::FAIL)
for(const auto &prop_pair : property_map)
if(prop_pair.second.status==path_searcht::FAIL)
failed++;

status() << "** " << failed
Expand Down
34 changes: 9 additions & 25 deletions src/analyses/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ void ai_baset::output(
const goto_functionst &goto_functions,
std::ostream &out) const
{
for(goto_functionst::function_mapt::const_iterator
f_it=goto_functions.function_map.begin();
f_it!=goto_functions.function_map.end();
f_it++)
forall_goto_functions(f_it, goto_functions)
{
if(f_it->second.body_available())
{
Expand Down Expand Up @@ -175,10 +172,7 @@ Function: ai_baset::initialize

void ai_baset::initialize(const goto_functionst &goto_functions)
{
for(goto_functionst::function_mapt::const_iterator
it=goto_functions.function_map.begin();
it!=goto_functions.function_map.end();
it++)
forall_goto_functions(it, goto_functions)
initialize(it->second);
}

Expand Down Expand Up @@ -271,13 +265,8 @@ bool ai_baset::visit(

goto_program.get_successors(l, successors);

for(goto_programt::const_targetst::const_iterator
it=successors.begin();
it!=successors.end();
it++)
for(const auto &to_l : successors)
{
locationt to_l=*it;

if(to_l==goto_program.instructions.end())
continue;

Expand Down Expand Up @@ -512,10 +501,7 @@ void ai_baset::sequential_fixedpoint(
{
// do each function at least once

for(goto_functionst::function_mapt::const_iterator
it=goto_functions.function_map.begin();
it!=goto_functions.function_map.end();
it++)
forall_goto_functions(it, goto_functions)
fixedpoint(it->second.body, goto_functions, ns);
}

Expand Down Expand Up @@ -572,21 +558,19 @@ void ai_baset::concurrent_fixedpoint(
{
new_shared=false;

for(thread_wlt::const_iterator it=thread_wl.begin();
it!=thread_wl.end();
++it)
for(const auto &wl_pair : thread_wl)
{
working_sett working_set;
put_in_working_set(working_set, it->second);
put_in_working_set(working_set, wl_pair.second);

statet &begin_state=get_state(it->second);
merge(begin_state, sh_target, it->second);
statet &begin_state=get_state(wl_pair.second);
merge(begin_state, sh_target, wl_pair.second);

while(!working_set.empty())
{
goto_programt::const_targett l=get_next(working_set);

visit(l, working_set, *(it->first), goto_functions, ns);
visit(l, working_set, *(wl_pair.first), goto_functions, ns);

// the underlying domain must make sure that the final state
// carries all possible values; otherwise we would need to
Expand Down
24 changes: 8 additions & 16 deletions src/analyses/call_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ void call_grapht::output_dot(std::ostream &out) const
{
out << "digraph call_graph {\n";

for(grapht::const_iterator it=graph.begin();
it!=graph.end();
it++)
for(const auto &edge : graph)
{
out << " \"" << it->first << "\" -> "
<< "\"" << it->second << "\" "
out << " \"" << edge.first << "\" -> "
<< "\"" << edge.second << "\" "
<< " [arrowhead=\"vee\"];"
<< "\n";
}
Expand All @@ -137,12 +135,9 @@ Function: call_grapht::output

void call_grapht::output(std::ostream &out) const
{
for(grapht::const_iterator
it=graph.begin();
it!=graph.end();
it++)
for(const auto &edge : graph)
{
out << it->first << " -> " << it->second << "\n";
out << edge.first << " -> " << edge.second << "\n";
}
}

Expand All @@ -160,15 +155,12 @@ Function: call_grapht::output_xml

void call_grapht::output_xml(std::ostream &out) const
{
for(grapht::const_iterator
it=graph.begin();
it!=graph.end();
it++)
for(const auto &edge : graph)
{
out << "<call_graph_edge caller=\"";
xmlt::escape_attribute(id2string(it->first), out);
xmlt::escape_attribute(id2string(edge.first), out);
out << "\" callee=\"";
xmlt::escape_attribute(id2string(it->second), out);
xmlt::escape_attribute(id2string(edge.second), out);
out << "\">\n";
}
}
43 changes: 16 additions & 27 deletions src/analyses/cfg_dominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ void cfg_dominators_templatet<P, T, post_dom>::initialise(P &program)
cfg(program);

// initialise top element
for(typename cfgt::entry_mapt::const_iterator
e_it=cfg.entry_map.begin();
e_it!=cfg.entry_map.end(); ++e_it)
top.insert(cfg[e_it->second].PC);
for(const auto &node : cfg.entry_map)
top.insert(cfg[node.second].PC);
}

/*******************************************************************\
Expand Down Expand Up @@ -151,24 +149,18 @@ void cfg_dominators_templatet<P, T, post_dom>::fixedpoint(P &program)
bool changed=false;
typename cfgt::nodet &node=cfg[cfg.entry_map[current]];
if(node.dominators.empty())
for(typename cfgt::edgest::const_iterator
p_it=(post_dom?node.out:node.in).begin();
!changed && p_it!=(post_dom?node.out:node.in).end();
++p_it)
if(!cfg[p_it->first].dominators.empty())
for(const auto & edge : (post_dom?node.out:node.in))
if(!cfg[edge.first].dominators.empty())
{
node.dominators=cfg[p_it->first].dominators;
node.dominators=cfg[edge.first].dominators;
node.dominators.insert(current);
changed=true;
}

// compute intersection of predecessors
for(typename cfgt::edgest::const_iterator
p_it=(post_dom?node.out:node.in).begin();
p_it!=(post_dom?node.out:node.in).end();
++p_it)
for(const auto & edge : (post_dom?node.out:node.in))
{
const target_sett &other=cfg[p_it->first].dominators;
const target_sett &other=cfg[edge.first].dominators;
if(other.empty())
continue;

Expand Down Expand Up @@ -198,12 +190,9 @@ void cfg_dominators_templatet<P, T, post_dom>::fixedpoint(P &program)

if(changed) // fixed point for node reached?
{
for(typename cfgt::edgest::const_iterator
s_it=(post_dom?node.in:node.out).begin();
s_it!=(post_dom?node.in:node.out).end();
++s_it)
for(const auto & edge : (post_dom?node.in:node.out))
{
worklist.push_back(cfg[s_it->first].PC);
worklist.push_back(cfg[edge.first].PC);
}
}
}
Expand All @@ -224,21 +213,21 @@ Function: cfg_dominators_templatet::output
template <class P, class T, bool post_dom>
void cfg_dominators_templatet<P, T, post_dom>::output(std::ostream &out) const
{
for(typename cfgt::entry_mapt::const_iterator
it=cfg.entry_map.begin();
it!=cfg.entry_map.end(); ++it)
for(const auto &node : cfg.entry_map)
{
unsigned n=it->first->location_number;
unsigned n=node.first->location_number;

if(post_dom)
out << n << " post-dominated by ";
else
out << n << " dominated by ";
for(typename target_sett::const_iterator d_it=it->second.dominators.begin();
d_it!=it->second.dominators.end();)
for(typename target_sett::const_iterator
d_it=node.second.dominators.begin();
d_it!=node.second.dominators.end();
) // no d_it++
{
out << (*d_it)->location_number;
if (++d_it!=it->second.dominators.end())
if (++d_it!=node.second.dominators.end())
out << ", ";
}
out << "\n";
Expand Down
Loading