This is an archive of the discontinued LLVM Phabricator instance.

[lldb][Module] Document ModuleList::ForEach and assert nullness
ClosedPublic

Authored by Michael137 on Dec 1 2022, 1:31 AM.

Details

Summary

Currently all callsites already assume the pointer is non-null.
This patch just asserts this assumption.

This is practically enforced by ModuleList::Append
which won't add nullptrs to m_modules.

Diff Detail

Event Timeline

Michael137 created this revision.Dec 1 2022, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 1:31 AM
Michael137 requested review of this revision.Dec 1 2022, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 1:31 AM
aprantl accepted this revision.Dec 1 2022, 4:31 PM

If we assert non-null, why still pass a shared pointer? Could we have the lambda take a Module &?

This revision is now accepted and ready to land.Dec 1 2022, 4:31 PM

If we assert non-null, why still pass a shared pointer? Could we have the lambda take a Module &?

I took a stab at changing it to pass a reference but turns out there's several places where we end up storing the shared_ptr. If we changed this to a reference we'd have to call shared_from_this for those cases. Which is a bit iffy considering calling it on references that are not shared_ptr owned would throw (which can't happen currently but seems similarly awkward to the current API).