[lldb] Make the NSSet formatter faster and less prone to infinite recursion
authorRaphael Isemann <teemperor@gmail.com>
Thu, 29 Apr 2021 17:13:21 +0000 (19:13 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 29 Apr 2021 17:13:43 +0000 (19:13 +0200)
commita76df78470d7994f73df0353225cbddc463cce63
tree38191cc50111c36c8f623a6d55dcffcbb4a691bb
parent5fbea826920f2ed51259093ae87b33b571833513
[lldb] Make the NSSet formatter faster and less prone to infinite recursion

Right now to get the 'NSSet *` pointer value we first derefence it and then take
the address of the result.

Beside being inefficient this potentially can cause an infinite recursion if the
`pointer` value we get is a pointer of a type that the TypeSystem can't
derefence. If the pointer is for example some form of `void *` that the dynamic
type resolution can't resolve to an actual type, then the `Derefence` call goes
back to asking the formatters how to reference it. If the NSSet formatter then
checks if it's an NSSet variation under the hood then we just end infinitely
often recursion.

In practice this seems to happen with some form of Builtin.RawPointer we get
from a NSDictionary in Swift.

FWIW, no other formatter is doing the same deref->addressOf as here and there
doesn't seem to be any specific reason to do so in the git history (it's just
part of the initial formatter commit)

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D101537
lldb/source/Plugins/Language/ObjC/NSSet.cpp