Beispiel #1
0
//
// Function: getAllCallees()
//
// Description:
//  Given a DSCallSite, add to the list the functions that can be called by
//  the call site *if* it is resolvable.  Uses 'applyCallsiteFilter' to
//  only add the functions that are valid targets of this callsite.
//
void BUDataStructures::
getAllCallees(const DSCallSite &CS, FuncSet &Callees) {
  //
  // FIXME: Should we check for the Unknown flag on indirect call sites?
  //
  // Direct calls to functions that have bodies are always resolvable.
  // Indirect function calls that are for a complete call site (the analysis
  // knows everything about the call site) and do not target external functions
  // are also resolvable.
  //
  if (CS.isDirectCall()) {
    if (!CS.getCalleeFunc()->isDeclaration())
      Callees.insert(CS.getCalleeFunc());
  } else if (CS.getCalleeNode()->isCompleteNode()) {
    // Get all callees.
    if (!CS.getCalleeNode()->isExternFuncNode()) {
      // Get all the callees for this callsite
      FuncSet TempCallees;
      CS.getCalleeNode()->addFullFunctionSet(TempCallees);
      // Filter out the ones that are invalid targets with respect
      // to this particular callsite.
      applyCallsiteFilter(CS, TempCallees);
      // Insert the remaining callees (legal ones, if we're filtering)
      // into the master 'Callees' list
      Callees.insert(TempCallees.begin(), TempCallees.end());
    }
  }
}
Beispiel #2
0
static void GetAllCallees(const DSCallSite &CS,
                          std::vector<const Function*> &Callees) {
  if (CS.isDirectCall()) {
    if (!CS.getCalleeFunc()->isDeclaration())
      Callees.push_back(CS.getCalleeFunc());
  } else if (!CS.getCalleeNode()->NodeType.isIncompleteNode()) {
    // Get all callees.
    if (!CS.getCalleeNode()->NodeType.isExternFunctionNode())
      CS.getCalleeNode()->addFullFunctionList(Callees);
  }
}
// Get the arg nodes in CalleeGraph for the callee of DSCS. Like
// DSGraph::getFunctionArgumentsForCall, but for indirect calls gets the most
// non-null nodes from all functions callable from that callsite.
void CSDataRando::getArgNodesForCall(DSGraph *CalleeGraph, DSCallSite DSCS, std::vector<DSNodeHandle> &ArgNodes) {
  ArgNodes.clear();

  if (DSCS.isDirectCall()) {
    CalleeGraph->getFunctionArgumentsForCall(DSCS.getCalleeFunc(), ArgNodes);
    return;
  }

  // Handle indirect calls.
  const DSCallGraph &CG = DSA->getCallGraph();
  CallSite OriginalCS = DSCS.getCallSite();
  std::vector<DSNodeHandle> TempArgNodes;

  // Get as many non-null arg nodes as possible. We don't know what the actual
  // caller will be, and there can be some mismatch between which arguments have
  // nodes for the different functions which may be called from this callsite.
  // TODO: It should be possible to cache the result of this to use for all
  // calls within the function equivalence class.
  for (auto i = CG.callee_begin(OriginalCS), e = CG.callee_end(OriginalCS); i != e; i++) {
    TempArgNodes.clear();
    CalleeGraph->getFunctionArgumentsForCall(*i, TempArgNodes);
    for (unsigned int i = 0, e = TempArgNodes.size(); i < e; i++) {
      if (i < ArgNodes.size()) {
        if (ArgNodes[i].isNull() && (!TempArgNodes[i].isNull())) {
          ArgNodes[i] = TempArgNodes[i];
        }
      } else {
        ArgNodes.push_back(TempArgNodes[i]);
      }
    }
  }
}
Beispiel #4
0
static void GetAnyCallees(const DSCallSite &CS,
                          std::vector<const Function*> &Callees) {
  if (CS.isDirectCall()) {
    if (!CS.getCalleeFunc()->isDeclaration())
      Callees.push_back(CS.getCalleeFunc());
  } else {
    // Get all callees.
    unsigned OldSize = Callees.size();
    CS.getCalleeNode()->addFullFunctionList(Callees);
    
    // If any of the callees are unresolvable, remove them
    for (unsigned i = OldSize; i != Callees.size(); )
      if (Callees[i]->isDeclaration()) {
        Callees.erase(Callees.begin()+i);
      } else 
        ++i;
  }
}