コード例 #1
0
ファイル: unified_diff.cpp プロジェクト: dcattaruzza/cbmc
bool unified_difft::operator()()
{
  typedef std::map<irep_idt,
                   goto_functionst::function_mapt::const_iterator>
                     function_mapt;

  function_mapt old_funcs, new_funcs;

  forall_goto_functions(it, old_goto_functions)
    old_funcs.insert(std::make_pair(it->first, it));
  forall_goto_functions(it, new_goto_functions)
    new_funcs.insert(std::make_pair(it->first, it));

  goto_programt empty;

  function_mapt::const_iterator ito=old_funcs.begin();
  for(function_mapt::const_iterator itn=new_funcs.begin();
      itn!=new_funcs.end();
      ++itn)
  {
    for( ;
        ito!=old_funcs.end() && ito->first<itn->first;
        ++ito)
      unified_diff(ito->first, ito->second->second.body, empty);

    if(ito==old_funcs.end() || itn->first<ito->first)
      unified_diff(itn->first, empty, itn->second->second.body);
    else
    {
      assert(ito->first==itn->first);
      unified_diff(
        itn->first,
        ito->second->second.body,
        itn->second->second.body);
      ++ito;
    }
  }
  for( ; ito!=old_funcs.end(); ++ito)
    unified_diff(ito->first, ito->second->second.body, empty);

  return !differences_map.empty();
}
コード例 #2
0
ファイル: loop_ids.cpp プロジェクト: lihaol/cbmc
void show_loop_ids(
  ui_message_handlert::uit ui,
  const goto_functionst &goto_functions)
{
  switch(ui)
  {
    case ui_message_handlert::PLAIN:
    case ui_message_handlert::XML_UI:
      forall_goto_functions(it, goto_functions)
        show_loop_ids(ui, it->second.body);
      break;
    case ui_message_handlert::JSON_UI:
      json_objectt json_result;
      json_arrayt &loops=json_result["loops"].make_array();

      forall_goto_functions(it, goto_functions)
        show_loop_ids_json(ui, it->second.body, loops);

      std::cout << ",\n" << json_result;
      break;
  }
}
コード例 #3
0
ファイル: is_threaded.cpp プロジェクト: lihaol/cbmc
void is_threadedt::compute(const goto_functionst &goto_functions)
{
  // the analysis doesn't actually use the namespace, fake one
  symbol_tablet symbol_table;
  const namespacet ns(symbol_table);

  ait<is_threaded_domaint> is_threaded_analysis;

  is_threaded_analysis(goto_functions, ns);

  forall_goto_functions(f_it, goto_functions)
    forall_goto_program_instructions(i_it, f_it->second.body)
      if(is_threaded_analysis[i_it].is_threaded)
        is_threaded_set.insert(i_it);
}
コード例 #4
0
remove_function_pointerst::remove_function_pointerst(
  symbol_tablet &_symbol_table,
  bool _add_safety_assertion,
  const goto_functionst &goto_functions):
  ns(_symbol_table),
  symbol_table(_symbol_table),
  add_safety_assertion(_add_safety_assertion)
{
  compute_address_taken_in_symbols(address_taken);
  compute_address_taken_functions(goto_functions, address_taken);

  // build type map
  forall_goto_functions(f_it, goto_functions)
    type_map[f_it->first]=f_it->second.type;
}
コード例 #5
0
remove_function_pointerst::remove_function_pointerst(
  message_handlert &_message_handler,
  symbol_tablet &_symbol_table,
  bool _add_safety_assertion, bool only_resolve_const_fps,
  const goto_functionst &goto_functions):
  messaget(_message_handler),
  ns(_symbol_table),
  symbol_table(_symbol_table),
  add_safety_assertion(_add_safety_assertion),
  only_resolve_const_fps(only_resolve_const_fps)
{
  compute_address_taken_in_symbols(address_taken);
  compute_address_taken_functions(goto_functions, address_taken);

  // build type map
  forall_goto_functions(f_it, goto_functions)
    type_map[f_it->first]=f_it->second.type;
}
コード例 #6
0
ファイル: prepare.cpp プロジェクト: olivo/BP
int preparet::get_async_modules()
{
  if(goto_functions.function_map.empty())
  {
    // see if we have a "main"

    if(context.symbols.find("main")==context.symbols.end())
    {
      error("failed to find entry point -- please provide a model");
      return 1;
    }

    status("Generating GOTO Program");

    goto_convert(
        context,
        goto_functions,
        get_message_handler());
  }

  // we no longer need any parse trees or language files
  clear_parse();

  // finally add the library
  status("Adding CPROVER library");      
  link_to_library(
      context, goto_functions, get_message_handler());

  if(cmdline.isset("show-goto-functions"))
  {
    goto_functions.output(ns, std::cout);
    return 0;
  }

  unsigned functions=goto_functions.function_map.size();
  unsigned instructions=0;
  forall_goto_functions(it, goto_functions)
    instructions+=it->second.body.instructions.size();

  status(i2string(functions)+" functions, "+
      i2string(instructions)+" instructions.");

  if(cmdline.isset("string-abstraction"))
    string_instrumentation(
        context, get_message_handler(), goto_functions);

  status("Removing function pointers");
  remove_function_pointers(ns, goto_functions, cmdline.isset("pointer-check"));

  status("Removing unused functions");
  remove_unused_functions(
      goto_functions, get_message_handler());

  // Boom requies full inlining.
  bool boom=
    !cmdline.isset("modelchecker") ||
    std::string(cmdline.getval("modelchecker"))=="boom";

  // OSWALDO
  if(cmdline.isset("full-inlining") || boom)
  {
    status("Full inlining");

    satabs_inline(
        goto_functions,
        ns,
        get_message_handler());
  }
  else
  {
    // partially inline functions
    status("Partial inlining");

    satabs_partial_inline(
        goto_functions,
        ns,
        get_message_handler());

    // we do this again, to remove all the functions that are inlined now
    remove_unused_functions(
        goto_functions, get_message_handler());

    status("Adjusting functions");
    prepare_functions(
        context,
        goto_functions,
        get_message_handler());

    // show it?
    if(cmdline.isset("show-adjusted-functions"))
    {
      goto_functions.output(ns, std::cout);
      return 0;
    }
  }

  // add loop ids
  goto_functions.compute_loop_numbers();

  add_failed_symbols(context);

  // add generic checks
  goto_check(ns, options, goto_functions);

  if(cmdline.isset("string-abstraction"))
  {
    status("String Abstraction");
    string_abstraction(
        context,
        get_message_handler(),
        goto_functions);
  }  

  goto_functions.compute_location_numbers();

  #if 0
  // obsoleted by goto_check
  if(cmdline.isset("pointer-check") ||
      cmdline.isset("show-value-sets"))
  {
    status("Pointer Analysis");
    value_set_analysist value_set_analysis(ns);
    value_set_analysis(goto_functions);

    // show it?
    if(cmdline.isset("show-value-sets"))
    {
      show_value_sets(get_ui(), goto_functions, value_set_analysis);
      return 0;
    }

    if(cmdline.isset("pointer-check"))
    {
      status("Adding Pointer Checks");

      // add pointer checks
      pointer_checks(
          goto_functions, context, options, value_set_analysis);
    }
  }
  #endif

  goto_functions.compute_location_numbers();

  // label claims
  label_claims(goto_functions);

  // set claim
  if(cmdline.isset("claim"))
    set_claims(
        goto_functions,
        cmdline.get_values("claim"));

  // reachability slice?
  if(!cmdline.isset("no-slicing"))
    reachability_slicer(goto_functions);

  // show it?

  if(cmdline.isset("show-final-program"))
  {
    goto_functions.output(ns, std::cout);
    return 0;
  }

  return -1; // proceed!
}
コード例 #7
0
ファイル: prepare.cpp プロジェクト: olivo/BP
int preparet::get_async_modules()
{
  if(goto_functions.function_map.empty())
  {
    // see if we have a "main"

    if(context.symbols.find("main")==context.symbols.end())
    {
      error("failed to find entry point -- please provide a model");
      return 1;
    }

    status("Generating GOTO Program");

    goto_convert(
      context,
      options,
      goto_functions,
      get_message_handler());
  }
    
  if(cmdline.isset("show-goto-functions"))
  {
    goto_functions.output(ns, std::cout);
    return 0;
  }
  
  unsigned functions=goto_functions.function_map.size();
  unsigned instructions=0;
  forall_goto_functions(it, goto_functions)
    instructions+=it->second.body.instructions.size();
  
  status(i2string(functions)+" functions, "+
         i2string(instructions)+" instructions.");
  
  if(cmdline.isset("string-abstraction"))
    string_instrumentation(
      context, get_message_handler(), goto_functions);

  status("Removing function pointers");
  remove_function_pointers(ns, goto_functions);

  status("Removing unused functions");
  remove_unused_functions(
    goto_functions, get_message_handler());

  if(cmdline.isset("full-inlining"))
  {
    status("Full inlining");

    satabs_inline(
      goto_functions,
      ns,
      get_message_handler());
  }
  else
  {
    // partially inline functions
    status("Partial inlining");

    satabs_partial_inline(
      goto_functions,
      ns,
      get_message_handler());
  
    // we do this again, to remove all the functions that are inlined now
    remove_unused_functions(
      goto_functions, get_message_handler());

    status("Adjusting functions");
    prepare_functions(
      context,
      goto_functions,
      get_message_handler());

    // show it?
    if(cmdline.isset("show-adjusted-functions"))
    {
      goto_functions.output(ns, std::cout);
      return 0;
    }
  }
  
  // add loop ids
  goto_functions.compute_loop_numbers();

  // show it?
  if(cmdline.isset("show-loops"))
  {
    show_loop_numbers(get_ui(), goto_functions);
    return 0;
  }

  add_failed_symbols(context);

  // add generic checks
  goto_check(ns, options, goto_functions);

  if(cmdline.isset("string-abstraction"))
  {
    status("String Abstraction");
    string_abstraction(
      context,
      get_message_handler(),
      goto_functions);
  }  
  
  goto_functions.compute_location_numbers();

  if(cmdline.isset("pointer-check") ||
     cmdline.isset("show-value-sets") ||
     cmdline.isset("data-race-check"))
  {
    status("Pointer Analysis");
    value_set_analysist value_set_analysis(ns);
    value_set_analysis(goto_functions);

    // show it?
    if(cmdline.isset("show-value-sets"))
    {
      show_value_sets(get_ui(), goto_functions, value_set_analysis);
      return 0;
    }

    if(cmdline.isset("pointer-check"))
    {
      status("Adding Pointer Checks");

      // add pointer checks
      pointer_checks(
        goto_functions, context, options, value_set_analysis);
    }

    if(cmdline.isset("data-race-check"))
    {
      status("Adding Data Race Checks");

      add_race_assertions(
        value_set_analysis,
        context,
        goto_functions);

      value_set_analysis.
        update(goto_functions);
    }
  }
  
  goto_functions.compute_location_numbers();

  #if 0  
  // do invariant propagation
  if(!cmdline.isset("no-invariant-sets"))
  {
    status("Invariant Propagation");
    invariant_propagation(
      goto_functions);
  }
  else
    invariant_propagation.initialize(
      goto_functions);

  if(cmdline.isset("show-invariant-sets"))
  {
    invariant_propagation.output(
      goto_functions, std::cout);
    return 0;
  }

  // simplify
  if(!cmdline.isset("no-invariant-sets"))
    invariant_propagation.simplify(
      goto_functions);
  #endif

  // set claim
  if(cmdline.isset("claim"))
    set_claims(
      goto_functions,
      cmdline.get_values("claim"));
      
  // slice
  if(!cmdline.isset("no-slicing"))
    slicer(goto_functions);

  // show it?

  if(cmdline.isset("show-final-program"))
  {
    goto_functions.output(ns, std::cout);
    return 0;
  }

  return -1; // proceed!
}
コード例 #8
0
ファイル: horn_encoding.cpp プロジェクト: viktormalik/2ls
void horn_encodingt::operator()()
{
  forall_goto_functions(f_it, goto_functions)
    translate(f_it);
}
コード例 #9
0
ファイル: all_properties.cpp プロジェクト: danpoe/cbmc
safety_checkert::resultt bmc_all_propertiest::operator()()
{
  status() << "Passing problem to " << solver.decision_procedure_text() << eom;

  solver.set_message_handler(get_message_handler());

  // stop the time
  absolute_timet sat_start=current_time();

  bmc.do_conversion();

  // Collect _all_ goals in `goal_map'.
  // This maps property IDs to 'goalt'
  forall_goto_functions(f_it, goto_functions)
    forall_goto_program_instructions(i_it, f_it->second.body)
      if(i_it->is_assert())
        goal_map[i_it->source_location.get_property_id()]=goalt(*i_it);

  // get the conditions for these goals from formula
  // collect all 'instances' of the properties
  for(symex_target_equationt::SSA_stepst::iterator
      it=bmc.equation.SSA_steps.begin();
      it!=bmc.equation.SSA_steps.end();
      it++)
  {
    if(it->is_assert())
    {
      irep_idt property_id;

      if(it->source.pc->is_assert())
        property_id=it->source.pc->source_location.get_property_id();
      else if(it->source.pc->is_goto())
      {
        // this is likely an unwinding assertion
        property_id=id2string(
          it->source.pc->source_location.get_function())+".unwind."+
          std::to_string(it->source.pc->loop_number);
        goal_map[property_id].description=it->comment;
      }
      else
        continue;

      goal_map[property_id].instances.push_back(it);
    }
  }

  do_before_solving();

  cover_goalst cover_goals(solver);

  cover_goals.set_message_handler(get_message_handler());
  cover_goals.register_observer(*this);

  for(const auto &g : goal_map)
  {
    // Our goal is to falsify a property, i.e., we will
    // add the negation of the property as goal.
    literalt p=!solver.convert(g.second.as_expr());
    cover_goals.add(p);
  }

  status() << "Running " << solver.decision_procedure_text() << eom;

  bool error=false;

  decision_proceduret::resultt result=cover_goals();

  if(result==decision_proceduret::resultt::D_ERROR)
  {
    error=true;
    for(auto &g : goal_map)
      if(g.second.status==goalt::statust::UNKNOWN)
        g.second.status=goalt::statust::ERROR;
  }
  else
  {
    for(auto &g : goal_map)
      if(g.second.status==goalt::statust::UNKNOWN)
        g.second.status=goalt::statust::SUCCESS;
  }

  // output runtime

  {
    absolute_timet sat_stop=current_time();
    status() << "Runtime decision procedure: "
             << (sat_stop-sat_start) << "s" << eom;
  }

  // report
  report(cover_goals);

  if(error)
    return safety_checkert::resultt::ERROR;

  bool safe=(cover_goals.number_covered()==0);

  if(safe)
    bmc.report_success(); // legacy, might go away
  else
    bmc.report_failure(); // legacy, might go away

  return safe?safety_checkert::resultt::SAFE:safety_checkert::resultt::UNSAFE;
}