This is an archive of the discontinued LLVM Phabricator instance.

[SBAPI] Don't check IsValid in constructor
ClosedPublic

Authored by JDevlieghere on Mar 4 2019, 6:01 PM.

Details

Summary

When running the test suite with the instrumentation macros, I noticed two lldb-mi tests regressed. The issue was the copy constructor of SBLineEntry. Without the macros the returned value would be elided, but with the macros the copy constructor was called. The latter used IsValid to determine whether the underlying opaque pointer should be set. This is likely a remnant of when IsValid would only check the validity of the smart pointer. In SBLineEntry however, it actually forwards to LineEntry::IsValid().

So what happened here was that because of the macros the copy constructor was called. The opaque pointer was valid but the LineEntry didn't consider itself valid. So the copied-to object was default initialized.

This patch replaces all checks for IsValid in copy (assignment) constructors with checks for the opaque pointer itself.

Diff Detail

Repository
rL LLVM

Event Timeline

JDevlieghere created this revision.Mar 4 2019, 6:01 PM
labath added a comment.Mar 5 2019, 4:28 AM

The copy constructors and assignment operators are very repetitive. What would you say to a function like

template<typename T>
void clone(std::unique_ptr<T> &dest, const std::unique_ptr<T> &src) {
if (&dest == &src)
  return;
if (src)
  dest = llvm::make_unique<T>(*src);
else
  dest.reset();
}

(and a similar one for shared_ptrs)? Then both copy constructors and assignment operators could be just implemented as clone(m_whatever, rhs.m_whatever);. (Assuming we don't care about pessimizing the self-assignment case this could even be m_whatever = clone(rhs.m_whatever);)

clayborg accepted this revision.Mar 5 2019, 7:49 AM
clayborg added a subscriber: clayborg.

lgtm

This revision is now accepted and ready to land.Mar 5 2019, 7:49 AM
  • Add clone utility.
  • Updated other SB classes to make use of the clone function as well.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2019, 4:07 PM