| 285 | } |
| 286 | |
| 287 | void ArrayAnalyzer::handleUser(StackFrame &Frame, llvm::Value &User, |
| 288 | std::stack<StackFrame> &DefUseChains, |
| 289 | std::set<llvm::Value *> &VisitedNodes) { |
| 290 | Value *Def = Frame.Value; |
| 291 | ArgFlow &DefFlow = Frame.AnalysisResult; |
| 292 | auto &A = DefFlow.getLLVMArg(); |
| 293 | |
| 294 | if (auto *GEPI = dyn_cast<GetElementPtrInst>(&User)) { |
| 295 | if (GEPI->getNumIndices() > 2) |
| 296 | return; |
| 297 | |
| 298 | auto *Op0 = GEPI->getOperand(0); |
| 299 | assert(Op0 && "Unexpected Program State"); |
| 300 | auto *ST = getAsStructType(*Op0); |
| 301 | auto NumIndices = GEPI->getNumIndices(); |
| 302 | |
| 303 | if (NumIndices > 1 && !getAsArrayType(*Op0)) { |
| 304 | if (ST) { |
| 305 | assert((GEPI->getNumOperands() > NumIndices) && |
| 306 | "Unexpected Program State"); |
| 307 | |
| 308 | if (const auto *CI = |
| 309 | dyn_cast<ConstantInt>(GEPI->getOperand(NumIndices))) { |
| 310 | DefFlow.setStruct(ST); |
| 311 | auto &FieldFlow = DefFlow.getOrCreateFieldFlow(CI->getLimitedValue()); |
| 312 | FieldFlow.getFieldInfo()->Values.insert(GEPI); |
| 313 | DefUseChains.emplace(GEPI, FieldFlow); |
| 314 | return; |
| 315 | } |
| 316 | } |
| 317 | } else if (ST) { // for Struct Array |
| 318 | DefUseChains.emplace(GEPI, DefFlow); |
| 319 | } |
| 320 | |
| 321 | if (VisitedNodes.find(Op0) != VisitedNodes.end()) { |
| 322 | assert((GEPI->getNumOperands() > NumIndices) && |
| 323 | "Unexpected Program State"); |
| 324 | |
| 325 | if (const auto *CI = |
| 326 | dyn_cast<ConstantInt>(GEPI->getOperand(NumIndices))) { |
| 327 | if (CI->isZeroValue()) { |
| 328 | DefUseChains.emplace(GEPI, DefFlow); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | DefFlow.getArrIndices().insert(CI->getZExtValue()); |
| 333 | |
| 334 | auto &LI = FAM.getResult<LoopAnalysis>(*A.getParent()); |
| 335 | if (LI.getLoopFor(GEPI->getParent())) |
| 336 | DefFlow.setIsVariableLenArray(true); |
| 337 | } else |
| 338 | DefFlow.setIsVariableLenArray(true); |
| 339 | |
| 340 | if (DefFlow.isVariableLenArray()) |
| 341 | analyzeArrayLen(*GEPI, DefFlow); |
| 342 | |
| 343 | DefFlow.setIsArray(true); |
| 344 | } |
nothing calls this directly
no test coverage detected