@@ -296,6 +296,24 @@ std::string GetNumAsString(llvm::APFloat value) {
296296bool IsUserDefinedDecl (const clang::Decl *decl) {
297297 const auto &ctx = decl->getASTContext ();
298298 const auto &src_mgr = ctx.getSourceManager ();
299+ if (auto fn = llvm::dyn_cast<clang::FunctionDecl>(decl)) {
300+ if (const clang::FunctionDecl *definition = nullptr ;
301+ fn->isDefined (definition)) {
302+ decl = definition;
303+ } else if (llvm::any_of (fn->redecls (), [&](auto redecl) {
304+ return src_mgr.isInSystemHeader (redecl->getLocation ());
305+ })) {
306+ return false ;
307+ }
308+ } else if (auto var = llvm::dyn_cast<clang::VarDecl>(decl)) {
309+ if (auto definition = var->getDefinition ()) {
310+ decl = definition;
311+ } else if (llvm::any_of (var->redecls (), [&](auto redecl) {
312+ return src_mgr.isInSystemHeader (redecl->getLocation ());
313+ })) {
314+ return false ;
315+ }
316+ }
299317 auto src_loc = decl->getLocation ();
300318 if (auto *spec =
301319 clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl);
@@ -822,12 +840,25 @@ static std::string GetParamSignature(const clang::Decl *decl) {
822840 return args;
823841}
824842
843+ static clang::ASTNameGenerator *name_generator = nullptr ;
844+
845+ void SetNameGenerator (clang::ASTNameGenerator *generator) {
846+ name_generator = generator;
847+ }
848+
849+ clang::ASTNameGenerator *GetNameGenerator () { return name_generator; }
850+
851+ static std::string GetMangledName (const clang::Decl *decl) {
852+ assert (name_generator);
853+ return name_generator->getName (decl);
854+ }
855+
825856static std::string GetLexicalSpecializationID (const clang::Decl *decl) {
826857 auto &ctx = decl->getASTContext ();
827858 std::string id;
828859 if (const auto *var =
829860 clang::dyn_cast<clang::VarTemplateSpecializationDecl>(decl)) {
830- id += clang::ASTNameGenerator (var-> getASTContext ()). getName (var);
861+ id += GetMangledName (var);
831862 }
832863 if (const auto *self =
833864 clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl)) {
@@ -846,7 +877,7 @@ static std::string GetLexicalSpecializationID(const clang::Decl *decl) {
846877 }
847878 if (const auto *fn = clang::dyn_cast<clang::FunctionDecl>(dc);
848879 fn && fn->getTemplateSpecializationArgs ()) {
849- id += clang::ASTNameGenerator (fn-> getASTContext ()). getName (fn);
880+ id += GetMangledName (fn);
850881 }
851882 }
852883 return id;
@@ -919,9 +950,7 @@ std::string DisambiguateAnonymousTag(const clang::TagDecl *tag) {
919950static std::unordered_map<std::string, size_t > type_mapping;
920951
921952static size_t GetDeclId (const clang::NamedDecl *decl, bool internal) {
922- std::string key =
923- clang::ASTNameGenerator (decl->getASTContext ()).getName (decl) +
924- GetParamSignature (decl);
953+ std::string key = GetMangledName (decl) + GetParamSignature (decl);
925954 if (internal) {
926955 key += GetLocationID (decl);
927956 }
@@ -982,9 +1011,11 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) {
9821011 target = record;
9831012 }
9841013 }
1014+ auto *record = clang::dyn_cast<clang::CXXRecordDecl>(target);
9851015 return std::format (
986- " anon_{}" , type_mapping.try_emplace (GetID (target), type_mapping.size ())
987- .first ->second );
1016+ " {}_{}" , record && record->isLambda () ? " lambda" : " anon" ,
1017+ type_mapping.try_emplace (GetID (target), type_mapping.size ())
1018+ .first ->second );
9881019 }
9891020
9901021 std::optional<size_t > id;
@@ -1346,21 +1377,6 @@ clang::QualType GetDeclRefType(const clang::FunctionDecl *fn,
13461377 return field ? field->getType () : decl->getType ();
13471378}
13481379
1349- bool HasStaticLocal (const clang::Stmt *stmt) {
1350- if (!stmt) {
1351- return false ;
1352- }
1353- if (auto decl_stmt = clang::dyn_cast<clang::DeclStmt>(stmt)) {
1354- for (auto decl : decl_stmt->decls ()) {
1355- if (auto var = clang::dyn_cast<clang::VarDecl>(decl);
1356- var && var->isStaticLocal ()) {
1357- return true ;
1358- }
1359- }
1360- }
1361- return llvm::any_of (stmt->children (), HasStaticLocal);
1362- }
1363-
13641380bool IsUserOperatorCall (const clang::CXXOperatorCallExpr *expr) {
13651381 const auto *callee = expr->getDirectCallee ();
13661382 if (!callee || AsLambdaOperatorCall (callee)) {
0 commit comments