LibJSGCPluginAction.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "LibJSGCPluginAction.h"
  7. #include <clang/ASTMatchers/ASTMatchFinder.h>
  8. #include <clang/ASTMatchers/ASTMatchers.h>
  9. #include <clang/Basic/SourceManager.h>
  10. #include <clang/Frontend/CompilerInstance.h>
  11. #include <clang/Frontend/FrontendPluginRegistry.h>
  12. #include <clang/Lex/MacroArgs.h>
  13. #include <unordered_set>
  14. template<typename T>
  15. class SimpleCollectMatchesCallback : public clang::ast_matchers::MatchFinder::MatchCallback {
  16. public:
  17. explicit SimpleCollectMatchesCallback(std::string name)
  18. : m_name(std::move(name))
  19. {
  20. }
  21. void run(clang::ast_matchers::MatchFinder::MatchResult const& result) override
  22. {
  23. if (auto const* node = result.Nodes.getNodeAs<T>(m_name))
  24. m_matches.push_back(node);
  25. }
  26. auto const& matches() const { return m_matches; }
  27. private:
  28. std::string m_name;
  29. std::vector<T const*> m_matches;
  30. };
  31. static bool record_inherits_from_cell(clang::CXXRecordDecl const& record)
  32. {
  33. if (!record.isCompleteDefinition())
  34. return false;
  35. bool inherits_from_cell = record.getQualifiedNameAsString() == "JS::CellImpl";
  36. record.forallBases([&](clang::CXXRecordDecl const* base) -> bool {
  37. if (base->getQualifiedNameAsString() == "JS::CellImpl") {
  38. inherits_from_cell = true;
  39. return false;
  40. }
  41. return true;
  42. });
  43. return inherits_from_cell;
  44. }
  45. static std::vector<clang::QualType> get_all_qualified_types(clang::QualType const& type)
  46. {
  47. std::vector<clang::QualType> qualified_types;
  48. if (auto const* template_specialization = type->getAs<clang::TemplateSpecializationType>()) {
  49. auto specialization_name = template_specialization->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString();
  50. // Do not unwrap GCPtr/NonnullGCPtr/MarkedVector
  51. static std::unordered_set<std::string> gc_relevant_type_names {
  52. "JS::GCPtr",
  53. "JS::NonnullGCPtr",
  54. "JS::RawGCPtr",
  55. "JS::RawNonnullGCPtr",
  56. "JS::MarkedVector",
  57. "JS::Handle",
  58. };
  59. if (gc_relevant_type_names.contains(specialization_name)) {
  60. qualified_types.push_back(type);
  61. } else {
  62. auto const template_arguments = template_specialization->template_arguments();
  63. for (size_t i = 0; i < template_arguments.size(); i++) {
  64. auto const& template_arg = template_arguments[i];
  65. if (template_arg.getKind() == clang::TemplateArgument::Type) {
  66. auto template_qualified_types = get_all_qualified_types(template_arg.getAsType());
  67. std::move(template_qualified_types.begin(), template_qualified_types.end(), std::back_inserter(qualified_types));
  68. }
  69. }
  70. }
  71. } else {
  72. qualified_types.push_back(type);
  73. }
  74. return qualified_types;
  75. }
  76. enum class OuterType {
  77. GCPtr,
  78. RawGCPtr,
  79. Handle,
  80. Ptr,
  81. Ref,
  82. };
  83. struct QualTypeGCInfo {
  84. std::optional<OuterType> outer_type { {} };
  85. bool base_type_inherits_from_cell { false };
  86. };
  87. static std::optional<QualTypeGCInfo> validate_qualified_type(clang::QualType const& type)
  88. {
  89. if (auto const* pointer_decl = type->getAs<clang::PointerType>()) {
  90. if (auto const* pointee = pointer_decl->getPointeeCXXRecordDecl())
  91. return QualTypeGCInfo { OuterType::Ptr, record_inherits_from_cell(*pointee) };
  92. } else if (auto const* reference_decl = type->getAs<clang::ReferenceType>()) {
  93. if (auto const* pointee = reference_decl->getPointeeCXXRecordDecl())
  94. return QualTypeGCInfo { OuterType::Ref, record_inherits_from_cell(*pointee) };
  95. } else if (auto const* specialization = type->getAs<clang::TemplateSpecializationType>()) {
  96. auto template_type_name = specialization->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString();
  97. OuterType outer_type;
  98. if (template_type_name == "JS::GCPtr" || template_type_name == "JS::NonnullGCPtr") {
  99. outer_type = OuterType::GCPtr;
  100. } else if (template_type_name == "JS::RawGCPtr" || template_type_name == "JS::RawNonnullGCPtr") {
  101. outer_type = OuterType::RawGCPtr;
  102. } else if (template_type_name == "JS::Handle") {
  103. outer_type = OuterType::Handle;
  104. } else {
  105. return {};
  106. }
  107. auto template_args = specialization->template_arguments();
  108. if (template_args.size() != 1)
  109. return {}; // Not really valid, but will produce a compilation error anyway
  110. auto const& type_arg = template_args[0];
  111. auto const* record_type = type_arg.getAsType()->getAs<clang::RecordType>();
  112. if (!record_type)
  113. return {};
  114. auto const* record_decl = record_type->getAsCXXRecordDecl();
  115. if (!record_decl->hasDefinition())
  116. return {};
  117. return QualTypeGCInfo { outer_type, record_inherits_from_cell(*record_decl) };
  118. }
  119. return {};
  120. }
  121. static std::optional<QualTypeGCInfo> validate_field_qualified_type(clang::FieldDecl const* field_decl)
  122. {
  123. auto type = field_decl->getType();
  124. if (auto const* elaborated_type = llvm::dyn_cast<clang::ElaboratedType>(type.getTypePtr()))
  125. type = elaborated_type->desugar();
  126. for (auto const& qualified_type : get_all_qualified_types(type)) {
  127. if (auto error = validate_qualified_type(qualified_type))
  128. return error;
  129. }
  130. return {};
  131. }
  132. static bool decl_has_annotation(clang::Decl const* decl, std::string name)
  133. {
  134. for (auto const* attr : decl->attrs()) {
  135. if (auto const* annotate_attr = llvm::dyn_cast<clang::AnnotateAttr>(attr)) {
  136. if (annotate_attr->getAnnotation() == name)
  137. return true;
  138. }
  139. }
  140. return false;
  141. }
  142. bool LibJSGCVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* record)
  143. {
  144. using namespace clang::ast_matchers;
  145. if (!record || !record->isCompleteDefinition() || (!record->isClass() && !record->isStruct()))
  146. return true;
  147. // Cell triggers a bunch of warnings for its empty visit_edges implementation, but
  148. // it doesn't have any members anyways so it's fine to just ignore.
  149. auto qualified_name = record->getQualifiedNameAsString();
  150. if (qualified_name == "JS::CellImpl")
  151. return true;
  152. auto& diag_engine = m_context.getDiagnostics();
  153. std::vector<clang::FieldDecl const*> fields_that_need_visiting;
  154. auto record_is_cell = record_inherits_from_cell(*record);
  155. for (clang::FieldDecl const* field : record->fields()) {
  156. auto validation_results = validate_field_qualified_type(field);
  157. if (!validation_results)
  158. continue;
  159. if (decl_has_annotation(field, "serenity::ignore_gc"))
  160. continue;
  161. auto [outer_type, base_type_inherits_from_cell] = *validation_results;
  162. if (outer_type == OuterType::Ptr || outer_type == OuterType::Ref) {
  163. if (base_type_inherits_from_cell) {
  164. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "%0 to JS::CellImpl type should be wrapped in %1");
  165. auto builder = diag_engine.Report(field->getLocation(), diag_id);
  166. if (outer_type == OuterType::Ref) {
  167. builder << "reference"
  168. << "JS::NonnullGCPtr";
  169. } else {
  170. builder << "pointer"
  171. << "JS::GCPtr";
  172. }
  173. }
  174. } else if (outer_type == OuterType::GCPtr || outer_type == OuterType::RawGCPtr) {
  175. if (!base_type_inherits_from_cell) {
  176. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Specialization type must inherit from JS::CellImpl");
  177. diag_engine.Report(field->getLocation(), diag_id);
  178. } else if (outer_type == OuterType::GCPtr) {
  179. fields_that_need_visiting.push_back(field);
  180. }
  181. } else if (outer_type == OuterType::Handle) {
  182. if (record_is_cell && m_detect_invalid_function_members) {
  183. // FIXME: Change this to an Error when all of the use cases get addressed and remove the plugin argument
  184. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Warning, "Types inheriting from JS::CellImpl should not have %0 fields");
  185. auto builder = diag_engine.Report(field->getLocation(), diag_id);
  186. builder << "JS::Handle";
  187. }
  188. }
  189. }
  190. if (!record_is_cell)
  191. return true;
  192. validate_record_macros(*record);
  193. clang::DeclarationName name = &m_context.Idents.get("visit_edges");
  194. auto const* visit_edges_method = record->lookup(name).find_first<clang::CXXMethodDecl>();
  195. if (!visit_edges_method && !fields_that_need_visiting.empty()) {
  196. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "JS::Cell-inheriting class %0 contains a GC-allocated member %1 but has no visit_edges method");
  197. auto builder = diag_engine.Report(record->getLocation(), diag_id);
  198. builder << record->getName()
  199. << fields_that_need_visiting[0];
  200. }
  201. if (!visit_edges_method || !visit_edges_method->getBody())
  202. return true;
  203. // Search for a call to Base::visit_edges. Note that this also has the nice side effect of
  204. // ensuring the classes use JS_CELL/JS_OBJECT, as Base will not be defined if they do not.
  205. MatchFinder base_visit_edges_finder;
  206. SimpleCollectMatchesCallback<clang::MemberExpr> base_visit_edges_callback("member-call");
  207. auto base_visit_edges_matcher = cxxMethodDecl(
  208. ofClass(hasName(qualified_name)),
  209. functionDecl(hasName("visit_edges")),
  210. isOverride(),
  211. hasDescendant(memberExpr(member(hasName("visit_edges"))).bind("member-call")));
  212. base_visit_edges_finder.addMatcher(base_visit_edges_matcher, &base_visit_edges_callback);
  213. base_visit_edges_finder.matchAST(m_context);
  214. bool call_to_base_visit_edges_found = false;
  215. for (auto const* call_expr : base_visit_edges_callback.matches()) {
  216. // FIXME: Can we constrain the matcher above to avoid looking directly at the source code?
  217. auto const* source_chars = m_context.getSourceManager().getCharacterData(call_expr->getBeginLoc());
  218. if (strncmp(source_chars, "Base::", 6) == 0) {
  219. call_to_base_visit_edges_found = true;
  220. break;
  221. }
  222. }
  223. if (!call_to_base_visit_edges_found) {
  224. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Missing call to Base::visit_edges");
  225. diag_engine.Report(visit_edges_method->getBeginLoc(), diag_id);
  226. }
  227. // Search for uses of all fields that need visiting. We don't ensure they are _actually_ visited
  228. // with a call to visitor.visit(...), as that is too complex. Instead, we just assume that if the
  229. // field is accessed at all, then it is visited.
  230. if (fields_that_need_visiting.empty())
  231. return true;
  232. MatchFinder field_access_finder;
  233. SimpleCollectMatchesCallback<clang::MemberExpr> field_access_callback("member-expr");
  234. auto field_access_matcher = memberExpr(
  235. hasAncestor(cxxMethodDecl(hasName("visit_edges"))),
  236. hasObjectExpression(hasType(pointsTo(cxxRecordDecl(hasName(record->getName()))))))
  237. .bind("member-expr");
  238. field_access_finder.addMatcher(field_access_matcher, &field_access_callback);
  239. field_access_finder.matchAST(visit_edges_method->getASTContext());
  240. std::unordered_set<std::string> fields_that_are_visited;
  241. for (auto const* member_expr : field_access_callback.matches())
  242. fields_that_are_visited.insert(member_expr->getMemberNameInfo().getAsString());
  243. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "GC-allocated member is not visited in %0::visit_edges");
  244. for (auto const* field : fields_that_need_visiting) {
  245. if (!fields_that_are_visited.contains(field->getNameAsString())) {
  246. auto builder = diag_engine.Report(field->getBeginLoc(), diag_id);
  247. builder << record->getName();
  248. }
  249. }
  250. return true;
  251. }
  252. struct CellTypeWithOrigin {
  253. clang::CXXRecordDecl const& base_origin;
  254. LibJSCellMacro::Type type;
  255. };
  256. static std::optional<CellTypeWithOrigin> find_cell_type_with_origin(clang::CXXRecordDecl const& record)
  257. {
  258. for (auto const& base : record.bases()) {
  259. if (auto const* base_record = base.getType()->getAsCXXRecordDecl()) {
  260. auto base_name = base_record->getQualifiedNameAsString();
  261. if (base_name == "JS::CellImpl")
  262. return CellTypeWithOrigin { *base_record, LibJSCellMacro::Type::JSCell };
  263. if (base_name == "JS::Object")
  264. return CellTypeWithOrigin { *base_record, LibJSCellMacro::Type::JSObject };
  265. if (base_name == "JS::Environment")
  266. return CellTypeWithOrigin { *base_record, LibJSCellMacro::Type::JSEnvironment };
  267. if (base_name == "JS::PrototypeObject")
  268. return CellTypeWithOrigin { *base_record, LibJSCellMacro::Type::JSPrototypeObject };
  269. if (base_name == "Web::Bindings::PlatformObject")
  270. return CellTypeWithOrigin { *base_record, LibJSCellMacro::Type::WebPlatformObject };
  271. if (auto origin = find_cell_type_with_origin(*base_record))
  272. return CellTypeWithOrigin { *base_record, origin->type };
  273. }
  274. }
  275. return {};
  276. }
  277. LibJSGCVisitor::CellMacroExpectation LibJSGCVisitor::get_record_cell_macro_expectation(clang::CXXRecordDecl const& record)
  278. {
  279. auto origin = find_cell_type_with_origin(record);
  280. assert(origin.has_value());
  281. // Need to iterate the bases again to turn the record into the exact text that the user used as
  282. // the class base, since it doesn't have to be qualified (but might be).
  283. for (auto const& base : record.bases()) {
  284. if (auto const* base_record = base.getType()->getAsCXXRecordDecl()) {
  285. if (base_record == &origin->base_origin) {
  286. auto& source_manager = m_context.getSourceManager();
  287. auto char_range = source_manager.getExpansionRange({ base.getBaseTypeLoc(), base.getEndLoc() });
  288. auto exact_text = clang::Lexer::getSourceText(char_range, source_manager, m_context.getLangOpts());
  289. return { origin->type, exact_text.str() };
  290. }
  291. }
  292. }
  293. assert(false);
  294. std::unreachable();
  295. }
  296. void LibJSGCVisitor::validate_record_macros(clang::CXXRecordDecl const& record)
  297. {
  298. auto& source_manager = m_context.getSourceManager();
  299. auto record_range = record.getSourceRange();
  300. // FIXME: The current macro detection doesn't recursively search through macro expansion,
  301. // so if the record itself is defined in a macro, the JS_CELL/etc won't be found
  302. if (source_manager.isMacroBodyExpansion(record_range.getBegin()))
  303. return;
  304. auto [expected_cell_macro_type, expected_base_name] = get_record_cell_macro_expectation(record);
  305. auto file_id = m_context.getSourceManager().getFileID(record.getLocation());
  306. auto it = m_macro_map.find(file_id.getHashValue());
  307. auto& diag_engine = m_context.getDiagnostics();
  308. auto report_missing_macro = [&] {
  309. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Expected record to have a %0 macro invocation");
  310. auto builder = diag_engine.Report(record.getLocation(), diag_id);
  311. builder << LibJSCellMacro::type_name(expected_cell_macro_type);
  312. };
  313. if (it == m_macro_map.end()) {
  314. report_missing_macro();
  315. return;
  316. }
  317. std::vector<clang::SourceRange> sub_ranges;
  318. for (auto const& sub_decl : record.decls()) {
  319. if (auto const* sub_record = llvm::dyn_cast<clang::CXXRecordDecl>(sub_decl))
  320. sub_ranges.push_back(sub_record->getSourceRange());
  321. }
  322. bool found_macro = false;
  323. auto record_name = record.getDeclName().getAsString();
  324. if (record.getQualifier()) {
  325. // FIXME: There has to be a better way to get this info. getQualifiedNameAsString() gets too much info
  326. // (outer namespaces that aren't part of the class identifier), and getNameAsString() doesn't get
  327. // enough info (doesn't include parts before the namespace specifier).
  328. auto loc = record.getQualifierLoc();
  329. auto& sm = m_context.getSourceManager();
  330. auto begin_offset = sm.getFileOffset(loc.getBeginLoc());
  331. auto end_offset = sm.getFileOffset(loc.getEndLoc());
  332. auto const* file_buf = sm.getCharacterData(loc.getBeginLoc());
  333. auto prefix = std::string { file_buf, end_offset - begin_offset };
  334. record_name = prefix + "::" + record_name;
  335. }
  336. for (auto const& macro : it->second) {
  337. if (record_range.fullyContains(macro.range)) {
  338. bool macro_is_in_sub_decl = false;
  339. for (auto const& sub_range : sub_ranges) {
  340. if (sub_range.fullyContains(macro.range)) {
  341. macro_is_in_sub_decl = true;
  342. break;
  343. }
  344. }
  345. if (macro_is_in_sub_decl)
  346. continue;
  347. if (found_macro) {
  348. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Record has multiple JS_CELL-like macro invocations");
  349. diag_engine.Report(record_range.getBegin(), diag_id);
  350. }
  351. found_macro = true;
  352. if (macro.type != expected_cell_macro_type) {
  353. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Invalid JS-CELL-like macro invocation; expected %0");
  354. auto builder = diag_engine.Report(macro.range.getBegin(), diag_id);
  355. builder << LibJSCellMacro::type_name(expected_cell_macro_type);
  356. }
  357. // This is a compile error, no diagnostic needed
  358. if (macro.args.size() < 2)
  359. return;
  360. if (macro.args[0].text != record_name) {
  361. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Expected first argument of %0 macro invocation to be %1");
  362. auto builder = diag_engine.Report(macro.args[0].location, diag_id);
  363. builder << LibJSCellMacro::type_name(expected_cell_macro_type) << record_name;
  364. }
  365. if (expected_cell_macro_type == LibJSCellMacro::Type::JSPrototypeObject) {
  366. // FIXME: Validate the args for this macro
  367. } else if (macro.args[1].text != expected_base_name) {
  368. auto diag_id = diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Error, "Expected second argument of %0 macro invocation to be %1");
  369. auto builder = diag_engine.Report(macro.args[1].location, diag_id);
  370. builder << LibJSCellMacro::type_name(expected_cell_macro_type) << expected_base_name;
  371. }
  372. }
  373. }
  374. if (!found_macro)
  375. report_missing_macro();
  376. }
  377. LibJSGCASTConsumer::LibJSGCASTConsumer(clang::CompilerInstance& compiler, bool detect_invalid_function_members)
  378. : m_compiler(compiler)
  379. , m_detect_invalid_function_members(detect_invalid_function_members)
  380. {
  381. auto& preprocessor = compiler.getPreprocessor();
  382. preprocessor.addPPCallbacks(std::make_unique<LibJSPPCallbacks>(preprocessor, m_macro_map));
  383. }
  384. void LibJSGCASTConsumer::HandleTranslationUnit(clang::ASTContext& context)
  385. {
  386. LibJSGCVisitor visitor { context, m_macro_map, m_detect_invalid_function_members };
  387. visitor.TraverseDecl(context.getTranslationUnitDecl());
  388. }
  389. char const* LibJSCellMacro::type_name(Type type)
  390. {
  391. switch (type) {
  392. case Type::JSCell:
  393. return "JS_CELL";
  394. case Type::JSObject:
  395. return "JS_OBJECT";
  396. case Type::JSEnvironment:
  397. return "JS_ENVIRONMENT";
  398. case Type::JSPrototypeObject:
  399. return "JS_PROTOTYPE_OBJECT";
  400. case Type::WebPlatformObject:
  401. return "WEB_PLATFORM_OBJECT";
  402. default:
  403. __builtin_unreachable();
  404. }
  405. }
  406. void LibJSPPCallbacks::LexedFileChanged(clang::FileID curr_fid, LexedFileChangeReason reason, clang::SrcMgr::CharacteristicKind, clang::FileID, clang::SourceLocation)
  407. {
  408. if (reason == LexedFileChangeReason::EnterFile) {
  409. m_curr_fid_hash_stack.push_back(curr_fid.getHashValue());
  410. } else {
  411. assert(!m_curr_fid_hash_stack.empty());
  412. m_curr_fid_hash_stack.pop_back();
  413. }
  414. }
  415. void LibJSPPCallbacks::MacroExpands(clang::Token const& name_token, clang::MacroDefinition const&, clang::SourceRange range, clang::MacroArgs const* args)
  416. {
  417. if (auto* ident_info = name_token.getIdentifierInfo()) {
  418. static llvm::StringMap<LibJSCellMacro::Type> libjs_macro_types {
  419. { "JS_CELL", LibJSCellMacro::Type::JSCell },
  420. { "JS_OBJECT", LibJSCellMacro::Type::JSObject },
  421. { "JS_ENVIRONMENT", LibJSCellMacro::Type::JSEnvironment },
  422. { "JS_PROTOTYPE_OBJECT", LibJSCellMacro::Type::JSPrototypeObject },
  423. { "WEB_PLATFORM_OBJECT", LibJSCellMacro::Type::WebPlatformObject },
  424. };
  425. auto name = ident_info->getName();
  426. if (auto it = libjs_macro_types.find(name); it != libjs_macro_types.end()) {
  427. LibJSCellMacro macro { range, it->second, {} };
  428. for (size_t arg_index = 0; arg_index < args->getNumMacroArguments(); arg_index++) {
  429. auto const* first_token = args->getUnexpArgument(arg_index);
  430. auto stringified_token = clang::MacroArgs::StringifyArgument(first_token, m_preprocessor, false, range.getBegin(), range.getEnd());
  431. // The token includes leading and trailing quotes
  432. auto len = strlen(stringified_token.getLiteralData());
  433. std::string arg_text { stringified_token.getLiteralData() + 1, len - 2 };
  434. macro.args.push_back({ arg_text, first_token->getLocation() });
  435. }
  436. assert(!m_curr_fid_hash_stack.empty());
  437. auto curr_fid_hash = m_curr_fid_hash_stack.back();
  438. if (m_macro_map.find(curr_fid_hash) == m_macro_map.end())
  439. m_macro_map[curr_fid_hash] = {};
  440. m_macro_map[curr_fid_hash].push_back(macro);
  441. }
  442. }
  443. }
  444. static clang::FrontendPluginRegistry::Add<LibJSGCPluginAction> X("libjs_gc_scanner", "analyze LibJS GC usage");