From: weiyu Date: Wed, 12 Feb 2020 01:24:25 +0000 (-0800) Subject: Fix bug about recursive function calls X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=e6983a4f1ce4e77f38a0d0fa90ed41cbde54e970 Fix bug about recursive function calls --- diff --git a/funcnode.cc b/funcnode.cc index ff62a527..896c60eb 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -169,7 +169,7 @@ void FuncNode::add_entry_inst(FuncInst * inst) void FuncNode::function_entry_handler(thread_id_t tid) { set_marker(tid); - set_predicate_tree_position(tid, predicate_tree_entry); + init_predicate_tree_position(tid); init_inst_act_map(tid); init_maps(tid); } @@ -187,7 +187,8 @@ void FuncNode::function_exit_handler(thread_id_t tid) exit_pred->set_exit(predicate_tree_exit); } - set_predicate_tree_position(tid, NULL); + int thread_id = id_to_int(tid); + predicate_tree_position[thread_id]->pop_back(); } /** @@ -196,6 +197,10 @@ void FuncNode::function_exit_handler(thread_id_t tid) */ void FuncNode::update_tree(ModelAction * act) { + bool should_process = act->is_read() || act->is_write(); + if (!should_process) + return; + HashTable * write_history = history->getWriteHistory(); /* build inst_list from act_list for later processing */ @@ -647,20 +652,33 @@ void FuncNode::update_loc_may_equal_map(void * new_loc, loc_set_t * old_location delete loc_it; } -void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred) +void FuncNode::init_predicate_tree_position(thread_id_t tid) { int thread_id = id_to_int(tid); - if (predicate_tree_position.size() <= (uint) thread_id) + int old_size = predicate_tree_position.size(); + + if (old_size <= thread_id + 1) { predicate_tree_position.resize(thread_id + 1); - predicate_tree_position[thread_id] = pred; + for (int i = old_size; i < thread_id + 1; i++) + predicate_tree_position[i] = new ModelVector(); + } + + predicate_tree_position[thread_id]->push_back(predicate_tree_entry); +} + +void FuncNode::set_predicate_tree_position(thread_id_t tid, Predicate * pred) +{ + int thread_id = id_to_int(tid); + ModelVector * stack = predicate_tree_position[thread_id]; + (*stack)[stack->size() - 1] = pred; } /* @return The position of a thread in a predicate tree */ Predicate * FuncNode::get_predicate_tree_position(thread_id_t tid) { int thread_id = id_to_int(tid); - return predicate_tree_position[thread_id]; + return predicate_tree_position[thread_id]->back(); } /* Make sure elements of thrd_inst_act_map are initialized properly when threads enter functions */ diff --git a/funcnode.h b/funcnode.h index ffc56119..ed2213a7 100644 --- a/funcnode.h +++ b/funcnode.h @@ -51,6 +51,7 @@ public: void add_to_val_loc_map(value_set_t * values, void * loc); void update_loc_may_equal_map(void * new_loc, loc_set_t * old_locations); + void init_predicate_tree_position(thread_id_t tid); void set_predicate_tree_position(thread_id_t tid, Predicate * pred); Predicate * get_predicate_tree_position(thread_id_t tid); @@ -123,8 +124,9 @@ private: // value_set_t * values_may_read_from; - /* Run-time position in the predicate tree for each thread */ - ModelVector predicate_tree_position; + /* Run-time position in the predicate tree for each thread + * The inner vector is used to deal with recursive functions. */ + ModelVector< ModelVector * > predicate_tree_position; PredSet predicate_leaves; ModelVector leaves_tmp_storage; diff --git a/history.cc b/history.cc index 762849bf..cb30a7de 100644 --- a/history.cc +++ b/history.cc @@ -87,8 +87,7 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) (*thrd_func_list)[id].pop_back(); } else { - model_print("trying to exit with a wrong function id\n"); - model_print("--- last_func: %d, func_id: %d\n", last_func_id, func_id); + ASSERT(false); } //model_print("thread %d exiting func %d\n", tid, func_id); }