Change the return type of Predicate::evaluate
authorweiyu <weiyuluo1232@gmail.com>
Mon, 30 Sep 2019 18:05:30 +0000 (11:05 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 30 Sep 2019 18:05:30 +0000 (11:05 -0700)
Makefile
classlist.h
concretepredicate.cc
concretepredicate.h
funcnode.cc
newfuzzer.cc
predicate.cc
predicate.h

index edff29b..6a57d4a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,8 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \
           datarace.o impatomic.o cmodelint.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o conditionvariable.o \
           context.o execution.o libannotate.o plugins.o pthread.o futex.o fuzzer.o \
-          sleeps.o history.o funcnode.o funcinst.o predicate.o printf.o newfuzzer.o
+          sleeps.o history.o funcnode.o funcinst.o predicate.o printf.o newfuzzer.o \
+          concretepredicate.o
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic -lpthread
index 65ac08d..4cd97b3 100644 (file)
@@ -19,6 +19,7 @@ class NewFuzzer;
 class FuncNode;
 class FuncInst;
 class Predicate;
+class ConcretePredicate;
 
 struct model_snapshot_members;
 struct bug_message;
index e3cbcac..9633e6c 100644 (file)
@@ -1,7 +1,7 @@
 #include "concretepredicate.h"
 
-ConcretePredicate::ConcretePredicate(void * loc) :
-       location(loc),
+ConcretePredicate::ConcretePredicate(thread_id_t tid) :
+       tid(tid),
        expressions()
 {}
 
index 2ec4e85..6319a2e 100644 (file)
@@ -2,12 +2,13 @@
 #define __CONCRETE_PREDICATE_H__
 
 #include <inttypes.h>
+#include "modeltypes.h"
 #include "classlist.h"
 #include "predicatetypes.h"
 
 class ConcretePredicate {
 public:
-       ConcretePredicate(void * loc);
+       ConcretePredicate(thread_id_t tid);
        ~ConcretePredicate();
 
        void add_expression(token_t token, uint64_t value, bool equality);
@@ -16,6 +17,7 @@ public:
 
        SNAPSHOTALLOC
 private:
+       thread_id_t tid;
        void * location;
        SnapVector<struct concrete_pred_expr> expressions;
 };
index d328a4c..8cd8142 100644 (file)
@@ -1,4 +1,6 @@
+#include "history.h"
 #include "funcnode.h"
+#include "concretepredicate.h"
 
 FuncNode::FuncNode(ModelHistory * history) :
        history(history),
@@ -331,9 +333,10 @@ bool FuncNode::follow_branch(Predicate ** curr_pred, FuncInst * next_inst, Model
                        unset_predicates->push_back(branch);
                }
 
-               SnapVector<struct concrete_pred_expr> concrete_exprs = branch->evaluate(inst_act_map);
-               for (uint i = 0; i < concrete_exprs.size(); i++) {
-                       struct concrete_pred_expr concrete = concrete_exprs[i];
+               ConcretePredicate * concrete_pred = branch->evaluate(inst_act_map, next_act->get_tid());
+               SnapVector<struct concrete_pred_expr> * concrete_exprs = concrete_pred->getExpressions();
+               for (uint i = 0; i < concrete_exprs->size(); i++) {
+                       struct concrete_pred_expr concrete = (*concrete_exprs)[i];
                        uint64_t next_read;
                        bool equality;
 
index 1fdc7d8..eefd553 100644 (file)
@@ -3,6 +3,7 @@
 #include "model.h"
 #include "action.h"
 #include "execution.h"
+#include "history.h"
 #include "funcnode.h"
 #include "schedule.h"
 #include "concretepredicate.h"
@@ -149,15 +150,17 @@ bool NewFuzzer::prune_writes(thread_id_t tid, Predicate * pred,
 
        bool pruned = false;
        uint index = 0;
-       SnapVector<struct concrete_pred_expr> concrete_exprs = pred->evaluate(inst_act_map);
+
+       ConcretePredicate * concrete_pred = pred->evaluate(inst_act_map, tid);
+       SnapVector<struct concrete_pred_expr> * concrete_exprs = concrete_pred->getExpressions();
 
        while ( index < rf_set->size() ) {
                ModelAction * write_act = (*rf_set)[index];
                uint64_t write_val = write_act->get_write_value();
                bool satisfy_predicate = true;
 
-               for (uint i = 0; i < concrete_exprs.size(); i++) {
-                       struct concrete_pred_expr concrete = concrete_exprs[i];
+               for (uint i = 0; i < concrete_exprs->size(); i++) {
+                       struct concrete_pred_expr concrete = (*concrete_exprs)[i];
                        bool equality;
 
                        switch (concrete.token) {
index a5ba11c..94eedfd 100644 (file)
@@ -1,4 +1,5 @@
 #include "predicate.h"
+#include "concretepredicate.h"
 
 Predicate::Predicate(FuncInst * func_inst, bool is_entry) :
        func_inst(func_inst),
@@ -59,9 +60,9 @@ void Predicate::copy_predicate_expr(Predicate * other)
 }
 
 /* Evaluate predicate expressions against the given inst_act_map */
-SnapVector<struct concrete_pred_expr> Predicate::evaluate(inst_act_map_t * inst_act_map)
+ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
 {
-       SnapVector<struct concrete_pred_expr> concrete_exprs;
+       ConcretePredicate * concrete = new ConcretePredicate(tid);
        PredExprSetIter * it = pred_expressions.iterator();
 
        while (it->hasNext()) {
@@ -85,12 +86,13 @@ SnapVector<struct concrete_pred_expr> Predicate::evaluate(inst_act_map_t * inst_
                                break;
                }
 
-               concrete_exprs.push_back(concrete_pred_expr(ptr->token, value, ptr->value));
+               concrete->add_expression(ptr->token, value, ptr->value);
        }
 
-       return concrete_exprs;
+       return concrete;
 }
 
+
 void Predicate::print_predicate()
 {
        model_print("\"%p\" [shape=box, label=\"\n", this);
index 4bb3039..1600cc8 100644 (file)
@@ -4,6 +4,7 @@
 #include "funcinst.h"
 #include "hashset.h"
 #include "predicatetypes.h"
+#include "classlist.h"
 
 unsigned int pred_expr_hash (struct pred_expr *);
 bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
@@ -35,7 +36,7 @@ public:
        bool is_write() { return does_write; }
        void set_write(bool is_write) { does_write = is_write; }
 
-       SnapVector<struct concrete_pred_expr> evaluate(inst_act_map_t * inst_act_map);
+       ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
 
        void print_predicate();
        void print_pred_subtree();