This fixes a regression introduced by a cosmetic change
The cosmetic change in the link above introduces a scenario where
calling getPSI() may dereference a NULL pointer (namely if the PSI
member of ProfileSummaryInfo is NULL).
When compiling with clang-9 with -O2, calls to getPSI are inlined.
The compiler sees the nullptr dereference (which is undefined behavior)
and is entitled to remove any nullptr check.
This causes snippets like this to crash:
// The following call to getPSI is inlined, and it contains a pointer // dereference. auto *PSI = &Stuff.getPSI(); // This check is assumed to be always true, because if it was false // the following line would summon undefined behavior. // So the compiler emits the code for `if (true)` if (PSI) PSI->call_any_method(); // This dereferences PSI which is nullptr
This commit changes the APIs of ProfileSummaryInfo to return naked
pointers instead of dereferencing a possibly null pointer.
In this way, the pointer (null or not) is never dereferenced, and the
compiler is not entitled to remove the if (PSI) check.