Skip to content

Commit 651828d

Browse files
committed
Fail on advanced math functions
1 parent cebfcb7 commit 651828d

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/2ls/2ls_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ bool twols_parse_optionst::process_goto_program(
10231023
remove_returns(goto_model);
10241024

10251025
if(options.get_bool_option("competition-mode"))
1026-
assert_no_atexit(goto_model);
1026+
assert_no_unsupported_function_calls(goto_model);
10271027

10281028
// now do full inlining, if requested
10291029
if(options.get_bool_option("inline"))

src/2ls/2ls_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class twols_parse_optionst:
186186
void memory_assert_info(goto_modelt &goto_model);
187187
void handle_freed_ptr_compare(goto_modelt &goto_model);
188188
void assert_no_unsupported_functions(goto_modelt &goto_model);
189-
void assert_no_atexit(goto_modelt &goto_model);
189+
void assert_no_unsupported_function_calls(goto_modelt &goto_model);
190190
void fix_goto_targets(goto_modelt &goto_model);
191191
void make_assertions_false(goto_modelt &goto_model);
192192
void make_symbolic_array_indices(goto_modelt &goto_model);

src/2ls/preprocessing_util.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Author: Peter Schrammel
2222

2323
#include "2ls_parse_options.h"
2424

25+
#define NOT_MATH_FUN(call, fun) call != fun &&call != fun "f" && call != fun "l"
26+
2527
void twols_parse_optionst::inline_main(goto_modelt &goto_model)
2628
{
2729
irep_idt start=goto_functionst::entry_point();
@@ -678,9 +680,13 @@ void twols_parse_optionst::assert_no_unsupported_functions(
678680
}
679681
}
680682

681-
/// Prevents usage of atexit function which is not supported, yet
682-
/// Must be called before inlining since it will lose the calls
683-
void twols_parse_optionst::assert_no_atexit(goto_modelt &goto_model)
683+
/// Fail if the program contains a call to an unsupported function. These
684+
/// include the atexit function and advanced math functions from math.h (
685+
/// these are either not defined in CBMC at all, or defined very imprecisely,
686+
/// e.g. the result of cos is in <-1, 1> without any further information).
687+
/// Must be called before inlining since it will lose the calls.
688+
void twols_parse_optionst::assert_no_unsupported_function_calls(
689+
goto_modelt &goto_model)
684690
{
685691
for(const auto &f_it : goto_model.goto_functions.function_map)
686692
{
@@ -693,6 +699,23 @@ void twols_parse_optionst::assert_no_atexit(goto_modelt &goto_model)
693699
continue;
694700
auto &name=id2string(to_symbol_expr(function).get_identifier());
695701
assert(name!="atexit");
702+
assert(
703+
// Trigonometry
704+
NOT_MATH_FUN(name, "cos") && NOT_MATH_FUN(name, "acos") &&
705+
NOT_MATH_FUN(name, "sin") && NOT_MATH_FUN(name, "asin") &&
706+
NOT_MATH_FUN(name, "tan") && NOT_MATH_FUN(name, "atan") &&
707+
NOT_MATH_FUN(name, "atan2") &&
708+
// Hyperbolic
709+
NOT_MATH_FUN(name, "cosh") && NOT_MATH_FUN(name, "acosh") &&
710+
NOT_MATH_FUN(name, "sinh") && NOT_MATH_FUN(name, "asinh") &&
711+
NOT_MATH_FUN(name, "tanh") && NOT_MATH_FUN(name, "atanh") &&
712+
// Exponential
713+
NOT_MATH_FUN(name, "exp") && NOT_MATH_FUN(name, "exp2") &&
714+
NOT_MATH_FUN(name, "expm1") && NOT_MATH_FUN(name, "log") &&
715+
NOT_MATH_FUN(name, "log10") && NOT_MATH_FUN(name, "log2") &&
716+
NOT_MATH_FUN(name, "log1p") &&
717+
// Other
718+
NOT_MATH_FUN(name, "erf"));
696719
}
697720
}
698721
}

0 commit comments

Comments
 (0)