This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][NFC] Use unique_ptrs for PathDiagnosticConsumers
AbandonedPublic

Authored by steakhal on Jul 5 2023, 12:34 AM.

Details

Summary

Due to lazy initialization on AnalysisConsumer, that needs to smuggle analysis consumers from its ctor to the initialize function; hence we need the TempPathConsumers.
The consumers are usually populated by DigestAnalyzerOptions from the ctor.

At least now, we only have a single place storing pointers to the consumers - unlike in the past where you could call the virtual addDiagnosticConsumer on AnalysisConsumer and end up pushing to the "stale" vector of consumers without observing any effects - except for leaking memory.
Now, it's gone. And pushing back there would push back to the AnalysisManager (who owns the consumers) - and behave as expected.

Note that the code quality begs for refactoring how consumers passed across, but I'm not intending to fix that.

Diff Detail

Event Timeline

steakhal created this revision.Jul 5 2023, 12:34 AM
Herald added a reviewer: njames93. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
steakhal requested review of this revision.Jul 5 2023, 12:34 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 5 2023, 12:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
xazax.hun accepted this revision.Jul 5 2023, 3:05 AM

Thanks!

This revision is now accepted and ready to land.Jul 5 2023, 3:05 AM
steakhal planned changes to this revision.Jul 5 2023, 3:35 AM

Hm, it seems like it broke some CSA unittests. I'll look into that once I have some time.

steakhal abandoned this revision.Jul 7 2023, 5:27 AM

Okay, I'm done. It's just a complete mess.
I'll come back to this once I have some time, but not now.

Here is what I found:
Unittests call AnalysisConsumer->addDiagnosticConsumer() after the AnalysisConsumer is constructed, but before AnalysisConsumer::Initialize(ASTContext &Context) is called - because the AST consumer is not yet invoked.
The AnalysisConsumer::Initialize(ASTContext &Context) supposed to construct the CheckerManager and AnalysisManager using the given ASTContext.

The ASTContext would be available even at the construction of AnalysisConsumer via the CompilerInstance - and that should work. So, I moved this lazy initialization to the ctor init list. - Works great, however, CheckerManager will do some checking for the checker dependencies, hence it needs all checkers to be configured at that point, which means that we should remove AnalysisConsumer::AddCheckerRegistrationFn() to make that happen. This implies that the construction of AnalysisConsumer would need to have all the checkers we need to configure upfront.
It's likely we can make it work, but would require some engineering on the unittests, which could this patch pump up even more.
And, I'd say, it's likely we can do something better overall if we just step back and redesign how things are getting constructed etc. And avoiding lazy initialization altogether.

I have a pretty good understanding of how things work now, so I might come back once I feel empowered.