llvm-project
90bac1bb - [MemProf] Match call sites with line 0 (C++ non-virtual thunks) (#229919)

Commit
44 days ago
[MemProf] Match call sites with line 0 (C++ non-virtual thunks) (#229919) The forwarding call in a C++ non-virtual thunk (`_ZThn...`, a DISubprogram with DIFlagThunk at the method's line L) has a DILocation with line 0. The profiler records that frame with line offset 0, but MemProfUse computed the offset as `(0 - L) & 0xffff`, so the call site never matched and the thunk got no `!callsite` metadata. Once the method is inlined into the thunk, the thunk's private copy of the call chain can no longer be redirected to a cold clone during context disambiguation. For example: ```c++ struct A { virtual ~A(); virtual void f(); long a; }; struct B { virtual ~B(); virtual void g(); long b; }; struct C : A, B { void f() override; void g() override; }; void C::g() { b = (long)new char[10]; } void viaB(B *p) { p->g(); } // -> _ZThn16_N1C1gEv -> C::g(), cold int main() { C c; c.g(); ... } // -> C::g() directly, not cold ``` The allocation in `C::g()` is cold only through the thunk, so it needs a clone, but the thunk's inlined copy of `C::g()` keeps the not-cold allocation. Factor the three identical `GetOffset` lambdas into `getLineOffset()` and make it return 0 when the location's line is below the subprogram's start line, and apply the same clamp in `RawMemProfReader` (where the `uint32_t` subtraction wrapped). Stack ids change only for frames that could never match before.
Author
Parents
Loading