Skip to content
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

SV-COMP 24 fixes #176

Merged
merged 6 commits into from
Oct 12, 2024
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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
AccessModifierOffset: '-2'
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'false'
Expand Down
4 changes: 2 additions & 2 deletions src/2ls/2ls_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ bool twols_parse_optionst::process_goto_program(
remove_returns(goto_model);

if(options.get_bool_option("competition-mode"))
assert_no_atexit(goto_model);
assert_no_unsupported_function_calls(goto_model);

// now do full inlining, if requested
if(options.get_bool_option("inline"))
Expand All @@ -1045,7 +1045,7 @@ bool twols_parse_optionst::process_goto_program(
}

if(options.get_bool_option("competition-mode"))
assert_no_builtin_functions(goto_model);
assert_no_unsupported_functions(goto_model);

make_scanf_nondet(goto_model);

Expand Down
4 changes: 2 additions & 2 deletions src/2ls/2ls_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class twols_parse_optionst:
void remove_dead_goto(goto_modelt &goto_model);
void memory_assert_info(goto_modelt &goto_model);
void handle_freed_ptr_compare(goto_modelt &goto_model);
void assert_no_builtin_functions(goto_modelt &goto_model);
void assert_no_atexit(goto_modelt &goto_model);
void assert_no_unsupported_functions(goto_modelt &goto_model);
void assert_no_unsupported_function_calls(goto_modelt &goto_model);
void fix_goto_targets(goto_modelt &goto_model);
void make_assertions_false(goto_modelt &goto_model);
void make_symbolic_array_indices(goto_modelt &goto_model);
Expand Down
39 changes: 33 additions & 6 deletions src/2ls/preprocessing_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Author: Peter Schrammel

#include "2ls_parse_options.h"

#define NOT_MATH_FUN(call, fun) call != fun &&call != fun "f" && call != fun "l"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space, is that enforced by clang-format?

Suggested change
#define NOT_MATH_FUN(call, fun) call != fun &&call != fun "f" && call != fun "l"
#define NOT_MATH_FUN(call, fun) call != fun && call != fun "f" && call != fun "l"


void twols_parse_optionst::inline_main(goto_modelt &goto_model)
{
irep_idt start=goto_functionst::entry_point();
Expand Down Expand Up @@ -653,9 +655,12 @@ void twols_parse_optionst::handle_freed_ptr_compare(goto_modelt &goto_model)
}
}

/// Add assertions preventing analysis of programs using GCC builtin functions
/// that are not supported and can cause false results.
void twols_parse_optionst::assert_no_builtin_functions(goto_modelt &goto_model)
/// Fail if the program contains any functions that 2LS does not currently
/// support. These include:
/// - builtin gcc functions
/// - longjmp (not supported by CBMC)
void twols_parse_optionst::assert_no_unsupported_functions(
goto_modelt &goto_model)
{
forall_goto_program_instructions(
i_it,
Expand All @@ -666,6 +671,7 @@ void twols_parse_optionst::assert_no_builtin_functions(goto_modelt &goto_model)
assert(
name.find("__builtin_")==std::string::npos &&
name.find("__CPROVER_overflow")==std::string::npos);
assert(name != "longjmp" && name != "_longjmp" && name != "siglongjmp");

if(i_it->is_assign())
{
Expand All @@ -674,9 +680,13 @@ void twols_parse_optionst::assert_no_builtin_functions(goto_modelt &goto_model)
}
}

/// Prevents usage of atexit function which is not supported, yet
/// Must be called before inlining since it will lose the calls
void twols_parse_optionst::assert_no_atexit(goto_modelt &goto_model)
/// Fail if the program contains a call to an unsupported function. These
/// include the atexit function and advanced math functions from math.h (
/// these are either not defined in CBMC at all, or defined very imprecisely,
/// e.g. the result of cos is in <-1, 1> without any further information).
/// Must be called before inlining since it will lose the calls.
void twols_parse_optionst::assert_no_unsupported_function_calls(
goto_modelt &goto_model)
{
for(const auto &f_it : goto_model.goto_functions.function_map)
{
Expand All @@ -689,6 +699,23 @@ void twols_parse_optionst::assert_no_atexit(goto_modelt &goto_model)
continue;
auto &name=id2string(to_symbol_expr(function).get_identifier());
assert(name!="atexit");
assert(
// Trigonometry
NOT_MATH_FUN(name, "cos") && NOT_MATH_FUN(name, "acos") &&
NOT_MATH_FUN(name, "sin") && NOT_MATH_FUN(name, "asin") &&
NOT_MATH_FUN(name, "tan") && NOT_MATH_FUN(name, "atan") &&
NOT_MATH_FUN(name, "atan2") &&
// Hyperbolic
NOT_MATH_FUN(name, "cosh") && NOT_MATH_FUN(name, "acosh") &&
NOT_MATH_FUN(name, "sinh") && NOT_MATH_FUN(name, "asinh") &&
NOT_MATH_FUN(name, "tanh") && NOT_MATH_FUN(name, "atanh") &&
// Exponential
NOT_MATH_FUN(name, "exp") && NOT_MATH_FUN(name, "exp2") &&
NOT_MATH_FUN(name, "expm1") && NOT_MATH_FUN(name, "log") &&
NOT_MATH_FUN(name, "log10") && NOT_MATH_FUN(name, "log2") &&
NOT_MATH_FUN(name, "log1p") &&
// Other
NOT_MATH_FUN(name, "erf"));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CPROVER_DIR = ../../lib/cbmc
# Variables you may want to override

# Enable warnings
CXXFLAGS += -Wall -Werror -Wno-long-long -Wno-sign-compare -Wno-parentheses -Wno-strict-aliasing -pedantic
CXXFLAGS += -Wall -Werror -Wno-long-long -Wno-sign-compare -Wno-parentheses -Wno-c++20-compat -Wno-strict-aliasing -pedantic

# Select optimisation or debug
#CXXFLAGS += -O2
Expand Down
9 changes: 0 additions & 9 deletions src/domains/template_generator_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ class template_generator_baset:public messaget
{
}

virtual void operator()(
unsigned _domain_number,
const local_SSAt &SSA,
bool forward=true)
{
domain_number=_domain_number;
assert(false);
}

virtual var_sett all_vars();

inline domaint *domain()
Expand Down
4 changes: 2 additions & 2 deletions src/domains/template_generator_callingcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class template_generator_callingcontextt:public template_generator_baset
{
}

virtual void operator()(
void operator()(
unsigned _domain_number,
const local_SSAt &SSA,
local_SSAt::nodest::const_iterator n_it,
local_SSAt::nodet::function_callst::const_iterator f_it,
bool forward=true);
bool forward = true);

virtual var_sett callingcontext_vars();

Expand Down
4 changes: 2 additions & 2 deletions src/domains/template_generator_ranking.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class template_generator_rankingt:public template_generator_baset
{
}

virtual void operator()(
void operator()(
unsigned _domain_number,
const local_SSAt &SSA,
bool forward=true);
bool forward = true);

protected:
void collect_variables_ranking(
Expand Down
4 changes: 2 additions & 2 deletions src/domains/template_generator_summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class template_generator_summaryt:public template_generator_baset
{
}

virtual void operator()(
void operator()(
unsigned _domain_number,
const local_SSAt &SSA,
bool forward=true);
bool forward = true);

virtual var_sett inout_vars();
virtual var_sett loop_vars();
Expand Down
Loading