// 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]);
      }
    }
  }
}
Example #2
0
//
// Function: applyCallsiteFilter
//
// Description:
//  Given a DSCallSite, and a list of functions, filter out the ones
//  that aren't callable from the given Callsite.
//
//  Does no filtering if 'filterCallees' is set to false.
//
void BUDataStructures::
applyCallsiteFilter(const DSCallSite &DCS, FuncSet &Callees) {

  if (!filterCallees) return;

  FuncSet::iterator I = Callees.begin();
  CallSite CS = DCS.getCallSite();
  while (I != Callees.end()) {
    if (functionIsCallable(CS, *I)) {
      ++I;
    } else {
      I = Callees.erase(I);
    }
  }
}