| 25 | } |
| 26 | |
| 27 | LocIndex LocIndex::of(const llvm::AllocaInst &AI) { |
| 28 | const auto *F = AI.getFunction(); |
| 29 | assert(F && "Unexpected Program State"); |
| 30 | |
| 31 | for (auto &IterB : *F) |
| 32 | for (auto &IterI : IterB) { |
| 33 | const auto *CB = llvm::dyn_cast<llvm::CallBase>(&IterI); |
| 34 | if (!CB) |
| 35 | continue; |
| 36 | |
| 37 | const auto *CF = CB->getCalledFunction(); |
| 38 | if (!CF || !CF->isIntrinsic() || CF->getName() != "llvm.dbg.declare") |
| 39 | continue; |
| 40 | |
| 41 | assert(CB->getNumArgOperands() > 0 && "Unexpected Program State"); |
| 42 | |
| 43 | const auto *M1 = |
| 44 | llvm::dyn_cast_or_null<llvm::MetadataAsValue>(CB->getArgOperand(0)); |
| 45 | if (!M1) |
| 46 | continue; |
| 47 | |
| 48 | const auto *M2 = |
| 49 | llvm::dyn_cast_or_null<llvm::LocalAsMetadata>(M1->getMetadata()); |
| 50 | if (!M2 || M2->getValue() != &AI) |
| 51 | continue; |
| 52 | |
| 53 | const auto &Loc = CB->getDebugLoc(); |
| 54 | if (Loc.get()) |
| 55 | return LocIndex(getFullPath(CB->getDebugLoc()), Loc.getLine(), |
| 56 | Loc.getCol()); |
| 57 | } |
| 58 | throw std::runtime_error("DebugLoc Not Found"); |
| 59 | } |
| 60 | |
| 61 | LocIndex LocIndex::of(const llvm::Instruction &I) { |
| 62 | if (auto *AI = llvm::dyn_cast<llvm::AllocaInst>(&I)) |
nothing calls this directly
no test coverage detected