@@ -2596,15 +2596,35 @@ class DISubprogram : public DILocalScope {
25962596 [](auto *N) { llvm_unreachable (" Unexpected retained node!" ); });
25972597 }
25982598
2599- // / Remove types that do not belong to the subprogram's scope from
2600- // / retainedNodes list.
2599+ // / When IR modules are merged, typically during LTO, the merged module
2600+ // / may contain several types having the same linkageName. They are
2601+ // / supposed to represent the same type included by multiple source code
2602+ // / files from a single header file.
2603+ // /
2604+ // / DebugTypeODRUniquing feature uniques (deduplicates) such types
2605+ // / based on their linkageName during metadata loading, to speed up
2606+ // / compilation and reduce debug info size.
2607+ // /
2608+ // / However, since function-local types are tracked in DISubprogram's
2609+ // / retainedNodes field, a single local type may be referenced by multiple
2610+ // / DISubprograms via retainedNodes as the result of DebugTypeODRUniquing.
2611+ // / But retainedNodes field of a DISubprogram is meant to hold only
2612+ // / subprogram's own local entities, therefore such references may
2613+ // / cause crashes.
2614+ // /
2615+ // / To address this problem, this method is called for each new subprogram
2616+ // / after module loading. It removes references to types belonging
2617+ // / to other DISubprograms from a subprogram's retainedNodes list.
2618+ // / If a corresponding IR function refers to local scopes from another
2619+ // / subprogram, emitted debug info (i.e. DWARF) should rely
2620+ // / on cross-subprogram references (and cross-CU references, as subprograms
2621+ // / may belong to different compile units). This is also a drawback:
2622+ // / when a subprogram refers to types that are local to another subprogram,
2623+ // / it is more complicated for debugger to properly discover local types
2624+ // / of a current scope for expression evaluation.
26012625 void cleanupRetainedNodes ();
26022626
2603- // / When DebugTypeODRUniquing is enabled, after multiple modules are loaded,
2604- // / some subprograms (that are from different compilation units, usually)
2605- // / may have references to the same local type in their retainedNodes lists.
2606- // /
2607- // / Clean up such references.
2627+ // / Calls SP->cleanupRetainedNodes() for a range of DISubprograms.
26082628 template <typename RangeT>
26092629 static void cleanupRetainedNodes (const RangeT &NewDistinctSPs) {
26102630 for (DISubprogram *SP : NewDistinctSPs)
0 commit comments