This is an archive of the discontinued LLVM Phabricator instance.

Make DiagnosticsEngine::takeClient return std::unique_ptr<>
ClosedPublic

Authored by alexfh on Nov 17 2014, 9:07 AM.

Details

Summary

Make DiagnosticsEngine::takeClient return std::unique_ptr<>. Updated
callers to store conditional ownership using a pair of pointer and unique_ptr
instead of a pointer + bool. Updated code that temporarily registers clients to
use the non-owning registration (+ removed extra calls to takeClient).

Diff Detail

Event Timeline

alexfh updated this revision to Diff 16294.Nov 17 2014, 9:07 AM
alexfh retitled this revision from to Make DiagnosticsEngine::takeClient return std::unique_ptr<>.
alexfh updated this object.
alexfh edited the test plan for this revision. (Show Details)
alexfh added a reviewer: dblaikie.
alexfh added a subscriber: Unknown Object (MLST).
dblaikie accepted this revision.Nov 17 2014, 10:56 AM
dblaikie edited edge metadata.

Looks mostly like a sort-of improvement, with a bit more tidying up that could be done in follow-up patches (though I'd slightly prefer to drop the !! before committing this at least, and double-check the owner naming convention in existing cases to be consistent)

include/clang/Basic/Diagnostic.h
370

I don't think !! is idiomatic in the LLVM codebase (though I may be incorrect) & probably just (bool) or static_cast<bool> would be more consistent.

include/clang/Rewrite/Frontend/FixItRewriter.h
69

What's the naming convention for other T*+unique_ptr<T> combos like this? I think I introduced the first few of these (see the email thread on the "maybe owning" pointer semantics in llvm-dev/cfe-dev for a list of other cases) and I might've used "*Owner" rather than "Owning*" - it'd be nice to be consistent (so they're easy to find and cleanup later).

lib/Frontend/Rewrite/FixItRewriter.cpp
45

As mentioned above (hmm, should this class use the CaptureDroppedDiagnostics? I guess not (it probably does other things) - but maybe we should have a common scoped "replace the DiagnosticConsumer" device that could be used in both places? - though that's probably overkill once we fix the ownership one way or another)

lib/Frontend/VerifyDiagnosticConsumer.cpp
46

While it didn't have it before - this might deserve a comment.

This revision is now accepted and ready to land.Nov 17 2014, 10:56 AM
alexfh added inline comments.Nov 17 2014, 3:45 PM
include/clang/Basic/Diagnostic.h
370

Changed "!!" to "!= nullptr".

include/clang/Rewrite/Frontend/FixItRewriter.h
69

Renamed Owning* to *Owner or just Owner depending on wether the latter is ambiguous in the context or not.

lib/Frontend/Rewrite/FixItRewriter.cpp
45

A separate scoped diagnostic client replacer would be nice, but it's slightly out of scope for this patch.

lib/Frontend/VerifyDiagnosticConsumer.cpp
46

I'm not sure I completely understand what's going on here. I'm actually not sure if this code is even correct. I just attempted to leave the existing behavior here. So I'd refrain from writing a misleading comment until I figure this out.

alexfh closed this revision.Nov 17 2014, 3:46 PM