void GraphBuilder::visitIntToPtrInst(IntToPtrInst &I) { DSNode *N = createNode(); if(I.hasOneUse()) { if(isa<ICmpInst>(*(I.use_begin()))) { NumBoringIntToPtr++; return; } } else { N->setIntToPtrMarker(); N->setUnknownMarker(); } setDestTo(I, N); }
/// /// getValueDest - Return the DSNode that the actual value points to. /// DSNodeHandle GraphBuilder::getValueDest(Value* V) { if (isa<Constant>(V) && cast<Constant>(V)->isNullValue()) return 0; // Null doesn't point to anything, don't add to ScalarMap! DSNodeHandle &NH = G.getNodeForValue(V); if (!NH.isNull()) return NH; // Already have a node? Just return it... // Otherwise we need to create a new node to point to. // Check first for constant expressions that must be traversed to // extract the actual value. DSNode* N; if (Function * F = dyn_cast<Function > (V)) { // Create a new global node for this function. N = createNode(); N->addFunction(F); if (F->isDeclaration()) N->setExternFuncMarker(); } else if (GlobalValue * GV = dyn_cast<GlobalValue > (V)) { // Create a new global node for this global variable. N = createNode(); N->addGlobal(GV); if (GV->isDeclaration()) N->setExternGlobalMarker(); } else if (Constant *C = dyn_cast<Constant>(V)) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { if (CE->isCast()) { if (isa<PointerType>(CE->getOperand(0)->getType())) NH = getValueDest(CE->getOperand(0)); else NH = createNode()->setUnknownMarker(); } else if (CE->getOpcode() == Instruction::GetElementPtr) { visitGetElementPtrInst(*CE); assert(G.hasNodeForValue(CE) && "GEP didn't get processed right?"); NH = G.getNodeForValue(CE); } else { // This returns a conservative unknown node for any unhandled ConstExpr NH = createNode()->setUnknownMarker(); } if (NH.isNull()) { // (getelementptr null, X) returns null G.eraseNodeForValue(V); return 0; } return NH; } else if (isa<UndefValue>(C)) { G.eraseNodeForValue(V); return 0; } else if (isa<GlobalAlias>(C)) { // XXX: Need more investigation // According to Andrew, DSA is broken on global aliasing, since it does // not handle the aliases of parameters correctly. Here is only a quick // fix for some special cases. NH = getValueDest(cast<GlobalAlias>(C)->getAliasee()); return NH; } else if (isa<BlockAddress>(C)) { // // FIXME: This may not be quite right; we should probably add a // BlockAddress flag to the DSNode instead of using the unknown flag. // N = createNode(); N->setUnknownMarker(); } else { errs() << "Unknown constant: " << *C << "\n"; assert(0 && "Unknown constant type!"); } N = createNode(); // just create a shadow node } else { // Otherwise just create a shadow node N = createNode(); } NH.setTo(N, 0); // Remember that we are pointing to it... return NH; }