Ejemplo n.º 1
0
void SparseSolver::Print(Function &F, raw_ostream &OS) const {
  OS << "\nFUNCTION: " << F.getName() << "\n";
  for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
    if (!BBExecutable.count(BB))
      OS << "INFEASIBLE: ";
    OS << "\t";
    if (BB->hasName())
      OS << BB->getName() << ":\n";
    else
      OS << "; anon bb\n";
    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
      LatticeFunc->PrintValue(getLatticeState(I), OS);
      OS << *I << "\n";
    }

    OS << "\n";
  }
}
Ejemplo n.º 2
0
void NameBlocksPass::runOnFunction(Function* F) {

  uint64_t NameInt = 0;
  std::string Name;

  for(Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {

    if(!FI->hasName()) {

      Name.clear();
      {
	raw_string_ostream RSO(Name);
	RSO << (++NameInt);
      }
      FI->setName(Name);

    }

  }

}
Ejemplo n.º 3
0
static void ComputeNumbering(Function *F, DenseMap<Value*,unsigned> &Numbering){
  unsigned IN = 0;

  // Arguments get the first numbers.
  for (Function::arg_iterator
         AI = F->arg_begin(), AE = F->arg_end(); AI != AE; ++AI)
    if (!AI->hasName())
      Numbering[&*AI] = IN++;

  // Walk the basic blocks in order.
  for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) {
    if (!FI->hasName())
      Numbering[&*FI] = IN++;

    // Walk the instructions in order.
    for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE; ++BI)
      // void instructions don't get numbers.
      if (!BI->hasName() && !BI->getType()->isVoidTy())
        Numbering[&*BI] = IN++;
  }

  assert(!Numbering.empty() && "asked for numbering but numbering was no-op");
}
Ejemplo n.º 4
0
void ComputeSSO::HandleQueries(Module& M)
{

    for(set<QueryInput*>::iterator qit = queryinputs.begin();qit!=queryinputs.end();++qit)
    {
        bool constCheck;
        errs()<<"\n\n\n\n*******************************************************Query ";
        errs()<<"\nOperation : "<<(*qit)->operation;
        errs()<<"\nConstCheck : "<<(*qit)->constcheck;
        string operation = (*qit)->operation;
        set<string> labels = (*qit)->labels;
        set<Value*> vals = (*qit)->labVals;
        std::set<GraphNode*> taintedA;
        std::set<GraphNode*> taintedB;
        std::set<GraphNode*> intersectGraph;

        for(set<string>::iterator label = labels.begin();label != labels.end();++label)
            errs()<<" - "<<*label;
        errs()<<"\n*******************************************************\n ";

        constCheck = (*qit)->constcheck;
        if(constCheck)
        {
            for(set<Value*>::iterator val = vals.begin();val != vals.end();++val)
            {
                taintedA = taintGraphMap[*val];
            }
            intersectGraph = taintedA;
        }
        else
        {

            for(set<Value*>::iterator val = vals.begin();val != vals.end();++val)
            {
                taintedA = taintGraphMap[*val];
                ++val;
                if(val!=vals.end())
                    taintedB = taintGraphMap[*val];
            }
            if(strcmp(operation.c_str(),"intersect")==0)
            {
                //  intersectGraph = getIntersect(taintedA,taintedB);

                for(set<GraphNode*>::iterator gnode = taintedA.begin();gnode != taintedA.end();++gnode)
                {
                    if(taintedB.count(*gnode) > 0)
                    {
                        GraphNode* interNode = (*gnode)->clone();
                        intersectGraph.insert(interNode);
                    }

                }
            }
        }





        int branches =0;
        errs()<<"\n Intersect graph size :"<<intersectGraph.size();
        //print intersect graph nodes:

        //     PrintTainted(intersectGraph);

        //        for(set<GraphNode*>::iterator gnode = intersectGraph.begin();gnode != intersectGraph.end();++gnode)
        //        {
        //            errs()<<"\n Node: "<<(*gnode)->getLabel();
        //        }

        //Print appropriate vals....:
        for (Module::iterator F = M.begin(), endF = M.end(); F != endF; ++F) {
            string funcName = F->getName();
            //  errs()<<"\nTaints in function: "<<funcName;
            for (Function::iterator BB = F->begin(), endBB = F->end(); BB != endBB; ++BB) {
                string bbName ="noName";
                if(BB->hasName())
                {
                    bbName = BB->getName();
                }
                //  errs()<<" - block: "<<bbName;

                for (BasicBlock::iterator I = BB->begin(), endI = BB->end(); I
                     != endI; ++I) {
                    GraphNode* g = depGraph->findNode(I);
                    if (intersectGraph.count(g)) {
                        errs()<<"\n Node found..:";
                        I->dump();

                            errs()<<"Taint in function : "<<funcName<<"  :";
                            I->dump();

                            if (BranchInst *BI = dyn_cast<BranchInst>(I))
                            {
                                if(constCheck)
                                {
                                    Value* conditional = BI->getCondition();

                                    for (unsigned int i = 0; i < cast<User> (conditional)->getNumOperands(); i++)
                                    {
                                        Value *v1 = cast<User> (conditional)->getOperand(i);
                                        if(isa<ConstantInt>(v1))
                                        {
                                            errs()<<"Branch Inst tainted in func : "<<funcName<<"  :";
                                            BI->dump();
                                            branches++;
                                        }

                                    }

                                }
                                else
                                {
                                    //    BI->getCondition()->dump();
                                    errs()<<"Branch Inst tainted : ";
                                    BI->dump();
                                    branches++;
                                }
                            }

                    }
                }
            }
        }


        errs()<<"\n Number of conditionals tainted : " <<branches;
    }

    errs()<<"\n*******************************************************\n ";
}