| 25 | } |
| 26 | |
| 27 | void TBAAVirtSolverHandler::handle(const llvm::Instruction &I) { |
| 28 | const auto *SI = dyn_cast<StoreInst>(&I); |
| 29 | if (!SI) |
| 30 | return; |
| 31 | |
| 32 | const auto *TBAA = I.getMetadata(LLVMContext::MD_tbaa); |
| 33 | if (!TBAA) |
| 34 | return; |
| 35 | |
| 36 | const auto *ValuePtr = SI->getValueOperand(); |
| 37 | assert(ValuePtr && "Unexpected LLVM API Behavior"); |
| 38 | |
| 39 | const auto *CE = |
| 40 | dyn_cast_or_null<ConstantExpr>(ValuePtr->stripPointerCasts()); |
| 41 | if (!CE || !CE->isGEPWithNoNotionalOverIndexing()) |
| 42 | return; |
| 43 | |
| 44 | const auto *VirtTableGV = dyn_cast_or_null<GlobalVariable>(CE->getOperand(0)); |
| 45 | if (!VirtTableGV || !isVirtTable(*VirtTableGV)) |
| 46 | return; |
| 47 | |
| 48 | if (!VirtTableGV->hasInitializer()) |
| 49 | return; |
| 50 | |
| 51 | const auto *Init = |
| 52 | dyn_cast_or_null<ConstantStruct>(VirtTableGV->getInitializer()); |
| 53 | if (!Init) |
| 54 | return; |
| 55 | |
| 56 | const auto *StTy = dyn_cast_or_null<StructType>(Init->getType()); |
| 57 | if (!StTy || StTy->getNumElements() != 1) |
| 58 | return; |
| 59 | |
| 60 | const auto *VirtTable = Init->getAggregateElement((unsigned)0); |
| 61 | if (!VirtTable) |
| 62 | return; |
| 63 | |
| 64 | Map[TBAA].emplace(VirtTable); |
| 65 | } |
no test coverage detected