/*! * Whether a location set is a pointer type or not */ bool ObjTypeInfo::isNonPtrFieldObj(const LocationSet& ls) { if (isHeap() || isStaticObj()) return false; llvm::Type* ety = getLLVMType(); while (const ArrayType *AT= dyn_cast<ArrayType>(ety)) { ety = AT->getElementType(); } if (isa<StructType>(ety) || isa<ArrayType>(ety)) { bool hasIntersection = false; const vector<FieldInfo> &infovec = SymbolTableInfo::Symbolnfo()->getFlattenFieldInfoVec(ety); vector<FieldInfo>::const_iterator it = infovec.begin(); vector<FieldInfo>::const_iterator eit = infovec.end(); for (; it != eit; ++it) { const FieldInfo& fieldLS = *it; if (ls.intersects(LocationSet(fieldLS))) { hasIntersection = true; if (fieldLS.getFlattenElemTy()->isPointerTy()) return false; } } assert(hasIntersection && "cannot find field of specified offset"); return true; } else { if (isStaticObj() || isHeap()) { // TODO: Objects which cannot find proper field for a certain offset including // arguments in main(), static objects allocated before main and heap // objects. Right now they're considered to have infinite fields and we // treat each field as pointers conservatively. // Try to model static and heap objects more accurately in the future. return false; } else { // TODO: Using new memory model (locMM) may create objects with spurious offset // as we simply return new offset by mod operation without checking its // correctness in LocSymTableInfo::getModulusOffset(). So the following // assertion may fail. Try to refine the new memory model. assert(ls.getOffset() == 0 && "cannot get a field from a non-struct type"); return (hasPtrObj() == false); } } }
/*! * Get modulus offset given the type information */ LocationSet SymbolTableInfo::getModulusOffset(ObjTypeInfo* tyInfo, const LocationSet& ls) { /// if the offset is negative, it's possible that we're looking for an obj node out of range /// of current struct. Make the offset positive so we can still get a node within current /// struct to represent this obj. Size_t offset = ls.getOffset(); if(offset < 0) { wrnMsg("try to create a gep node with negative offset."); offset = abs(offset); } u32_t maxOffset = tyInfo->getMaxFieldOffsetLimit(); if (maxOffset != 0) offset = offset % maxOffset; else offset = 0; return LocationSet(offset); }