Fix bug about recursive function calls
authorweiyu <weiyuluo1232@gmail.com>
Wed, 12 Feb 2020 01:24:25 +0000 (17:24 -0800)
committerweiyu <weiyuluo1232@gmail.com>
Wed, 12 Feb 2020 01:24:25 +0000 (17:24 -0800)
funcnode.cc
funcnode.h
history.cc

index ff62a527648f156dc7723025abda08757daac44c..896c60ebb4b8049f6d366fa20e615d55863a6354 100644 (file)
@@ -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<void *, value_set_t *, uintptr_t, 0> * 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 *>();
+       }
+
+       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<Predicate *> * 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 */
index ffc56119d4897179066b1b72e97d16bcce4e88b3..ed2213a73382e40d0e799aea9c976da3863613a2 100644 (file)
@@ -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 *> 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 *> * > predicate_tree_position;
 
        PredSet predicate_leaves;
        ModelVector<Predicate *> leaves_tmp_storage;
index 762849bf1fb92a8d3a93df7133ecab65da6a00cb..cb30a7deeb9e047cf27034d5bcdb2d5964aa8ab5 100644 (file)
@@ -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);
 }