| 7 | namespace ftg { |
| 8 | |
| 9 | ParamNumberAnalyzer::ParamNumberAnalyzer( |
| 10 | const std::vector<clang::ASTUnit *> &ASTUnits, const llvm::Module &M, |
| 11 | std::set<std::string> FuncNames) { |
| 12 | std::map<std::string, const llvm::Constant *> GlobalAliasMap; |
| 13 | for (const auto &A : M.aliases()) |
| 14 | GlobalAliasMap.emplace(A.getName().str(), A.getAliasee()); |
| 15 | |
| 16 | for (auto *ASTUnit : ASTUnits) { |
| 17 | for (auto *FD : |
| 18 | util::findDefinedFunctionDecls(ASTUnit->getASTContext(), FuncNames)) { |
| 19 | if (!FD) |
| 20 | continue; |
| 21 | |
| 22 | // NOTE: Unexpected when multiple functions are matched by one clang |
| 23 | // NamedDecl. |
| 24 | const llvm::Function *F = nullptr; |
| 25 | for (auto &MangledName : util::getMangledNames(*FD)) { |
| 26 | auto FuncName = MangledName; |
| 27 | auto Iter = GlobalAliasMap.find(MangledName); |
| 28 | if (Iter != GlobalAliasMap.end() && Iter->second) |
| 29 | FuncName = Iter->second->getName(); |
| 30 | F = M.getFunction(FuncName); |
| 31 | if (F) |
| 32 | break; |
| 33 | } |
| 34 | if (!F) |
| 35 | continue; |
| 36 | |
| 37 | unsigned BeginIndex = 0; |
| 38 | if (F->hasStructRetAttr()) |
| 39 | BeginIndex += 1; |
| 40 | |
| 41 | if (llvm::isa<clang::CXXMethodDecl>(FD) && !FD->isStatic()) |
| 42 | BeginIndex += 1; |
| 43 | |
| 44 | Report.add(F->getName().str(), F->arg_size(), BeginIndex); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | std::unique_ptr<AnalyzerReport> ParamNumberAnalyzer::getReport() { |
| 50 | return std::make_unique<ParamNumberAnalysisReport>(Report); |
nothing calls this directly
no test coverage detected