Skip to content

Commit

Permalink
unconditionally check for source functions that are UB for all execut…
Browse files Browse the repository at this point in the history
…ions, but don't error out (#991)
  • Loading branch information
regehr authored Dec 20, 2023
1 parent 4d0308a commit 5a58bf8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion llvm_util/cmd_args_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config::src_unroll_cnt = opt_unrolling_factor;
config::disable_undef_input = opt_disable_undef;
config::disable_poison_input = opt_disable_poison;
config::tgt_is_asm = opt_tgt_is_asm;
config::check_if_src_is_ub = opt_check_if_src_is_ub;
config::fail_if_src_is_ub = opt_fail_if_src_is_ub;
config::symexec_print_each_value = opt_se_verbose;
smt::set_query_timeout(to_string(opt_smt_to));
smt::set_memory_limit((uint64_t)opt_smt_max_mem * 1024 * 1024);
Expand Down
6 changes: 3 additions & 3 deletions llvm_util/cmd_args_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ llvm::cl::opt<bool> opt_disable_poison(LLVM_ARGS_PREFIX "disable-poison-input",
llvm::cl::desc("Assume inputs are not poison (default=false)"),
llvm::cl::init(false), llvm::cl::cat(alive_cmdargs));

llvm::cl::opt<bool> opt_check_if_src_is_ub(
LLVM_ARGS_PREFIX "check-src-ub",
llvm::cl::desc("Check if source function is always UB (default=false)"),
llvm::cl::opt<bool> opt_fail_if_src_is_ub(
LLVM_ARGS_PREFIX "fail-src-ub",
llvm::cl::desc("Fail if source function is always UB (default=false)"),
llvm::cl::init(false), llvm::cl::cat(alive_cmdargs));

llvm::cl::opt<bool> opt_tgt_is_asm(
Expand Down
15 changes: 11 additions & 4 deletions tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,17 @@ check_refinement(Errors &errs, const Transform &t, State &src_state,
axioms_expr = std::move(axioms)();
}

if (config::check_if_src_is_ub &&
check_expr(axioms_expr && fndom_a).isUnsat()) {
errs.add("Source function is always UB", false);
return;
if (check_expr(axioms_expr && fndom_a).isUnsat()) {
cout << "\n"
"****************************************\n"
"WARNING: Source function is always UB.\n"
"It can be refined by any target function.\n"
"Please make sure this is what you wanted.\n"
"****************************************\n\n";
if (config::fail_if_src_is_ub) {
errs.add("Source function is always UB", false);
return;
}
}

{
Expand Down
2 changes: 1 addition & 1 deletion util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ string smt_benchmark_dir;
bool disable_poison_input = false;
bool disable_undef_input = false;
bool tgt_is_asm = false;
bool check_if_src_is_ub = false;
bool fail_if_src_is_ub = false;
bool disallow_ub_exploitation = false;
bool debug = false;
unsigned src_unroll_cnt = 0;
Expand Down
2 changes: 1 addition & 1 deletion util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern bool disable_undef_input;

extern bool tgt_is_asm;

extern bool check_if_src_is_ub;
extern bool fail_if_src_is_ub;

/// This is a special mode to verify that LLVM's optimizations are not
/// exploiting UB. In particular, we disallow any UB related with arithmetic,
Expand Down

0 comments on commit 5a58bf8

Please sign in to comment.