/*! * Get a base pointer given a pointer * Return the source node of its connected gep edge if this pointer has * Otherwise return the node id itself */ NodeID PAG::getBaseValNode(NodeID nodeId) { PAGNode* node = getPAGNode(nodeId); if (node->hasIncomingEdges(PAGEdge::NormalGep) || node->hasIncomingEdges(PAGEdge::VariantGep)) { PAGEdge::PAGEdgeSetTy& ngeps = node->getIncomingEdges(PAGEdge::NormalGep); PAGEdge::PAGEdgeSetTy& vgeps = node->getIncomingEdges(PAGEdge::VariantGep); assert(((ngeps.size()+vgeps.size())==1) && "one node can only be connected by at most one gep edge!"); PAGNode::iterator it; if(!ngeps.empty()) it = ngeps.begin(); else it = vgeps.begin(); assert(isa<GepPE>(*it) && "not a gep edge??"); return (*it)->getSrcID(); } else return nodeId; }
/*! * Get a base PAGNode given a pointer * Return the source node of its connected normal gep edge * Otherwise return the node id itself * Size_t offset : gep offset */ LocationSet PAG::getLocationSetFromBaseNode(NodeID nodeId) { PAGNode* node = getPAGNode(nodeId); PAGEdge::PAGEdgeSetTy& geps = node->getIncomingEdges(PAGEdge::NormalGep); /// if this node is already a base node if(geps.empty()) return LocationSet(0); assert(geps.size()==1 && "one node can only be connected by at most one gep edge!"); PAGNode::iterator it = geps.begin(); const PAGEdge* edge = *it; assert(isa<NormalGepPE>(edge) && "not a get edge??"); const NormalGepPE* gepEdge = cast<NormalGepPE>(edge); return gepEdge->getLocationSet(); }
/*! * Stat null pointers */ void AndersenStat::statNullPtr() { _NumOfNullPtr = 0; for (PAG::iterator iter = pta->getPAG()->begin(), eiter = pta->getPAG()->end(); iter != eiter; ++iter) { NodeID pagNodeId = iter->first; PAGNode* pagNode = iter->second; PAGEdge::PAGEdgeSetTy& inComingStore = pagNode->getIncomingEdges(PAGEdge::Store); PAGEdge::PAGEdgeSetTy& outGoingLoad = pagNode->getOutgoingEdges(PAGEdge::Load); if (inComingStore.empty()==false || outGoingLoad.empty()==false) { ///TODO: change the condition here to fetch the points-to set PointsTo& pts = pta->getPts(pagNodeId); if(pta->containBlackHoleNode(pts)) { _NumOfConstantPtr++; } if(pta->containConstantNode(pts)) { _NumOfBlackholePtr++; } if(pts.empty()) { std::string str; raw_string_ostream rawstr(str); if (!isa<DummyValPN>(pagNode) && !isa<DummyObjPN>(pagNode) ) { // if a pointer is in dead function, we do not care if(isPtrInDeadFunction(pagNode->getValue()) == false) { _NumOfNullPtr++; rawstr << "##Null Pointer : (NodeID " << pagNode->getId() << ") PtrName:" << pagNode->getValue()->getName(); wrnMsg(rawstr.str()); //pagNode->getValue()->dump(); } } else { _NumOfNullPtr++; rawstr << "##Null Pointer : (NodeID " << pagNode->getId(); wrnMsg(rawstr.str()); } } } } }