This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Refactor IRExecutionUnit::FindInSymbols (NFC)
ClosedPublic

Authored by JDevlieghere on Jul 30 2021, 6:45 PM.

Details

Summary

As I was trying to understand what IRExecutionUnit::FindInSymbols was doing, I couldn't help myself but refactor the code a little bit:

  • No else after return.
  • Move the lambda out of the loop.
  • Replace GetSize() == 0 with IsEmpty()
  • Eliminate pitfall of not clearing the SymbolContextList by moving it into the lexical scope of the if-clause.

And probably some other small things that bothered me.

Diff Detail

Event Timeline

JDevlieghere requested review of this revision.Jul 30 2021, 6:45 PM
JDevlieghere created this revision.
bulbazord accepted this revision.Aug 2 2021, 11:14 AM
bulbazord added a subscriber: bulbazord.

Yeah this is a lot cleaner. Thanks for taking the time to refactor this.

This revision is now accepted and ready to land.Aug 2 2021, 11:14 AM
shafik added a subscriber: shafik.Aug 2 2021, 3:41 PM

Thank you for refactoring this, besides my comment on the lambda the rest makes sense.

lldb/source/Expression/IRExecutionUnit.cpp
782

It feels like the lambda should really be a small class that tracks the state of load_address and best_internal_load_address over multiple calls and then the user can access the state.

The lambda is doing a lot of logic and there is state being carried across calls and that feels like we have crossed the boundary and a class would be better.

Convert lambda into a stateful class.

JDevlieghere marked an inline comment as done.Aug 3 2021, 4:37 PM
JDevlieghere added inline comments.
lldb/source/Expression/IRExecutionUnit.cpp
782

Thanks, I really like that idea. Updated the diff accordingly.

shafik accepted this revision.Aug 5 2021, 9:13 AM

LGTM

lldb/source/Expression/IRExecutionUnit.cpp
880

Normally I wouldn't be crazy about a reference member but since this is a localized class I think this is an ok compromise.

I guess the real question would be why IRExecutionUnit::FindInSymbols is returning a value that way and perhaps it should be returning a struct w/ addr_t and bool but that would be a different change.

This revision was landed with ongoing or failed builds.Aug 5 2021, 10:18 AM
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2021, 10:18 AM