This is an archive of the discontinued LLVM Phabricator instance.

[clang] Cleanup ASTContext before output files in crash recovery for modules
ClosedPublic

Authored by benlangmuir on Jul 6 2022, 11:57 AM.

Details

Summary

When we recover from a crash in a module compilation thread, we need to ensure any output streams owned by the ASTConsumer (e.g. in RawPCHContainerGenerator) are deleted before we call clearOutputFiles(). This has the same theoretical issues with proxy streams that Duncan discusses in the commit 2d133867833fe8eb. In practice, this was observed as a use-after-free crash on a downstream branch that uses such a proxy stream in this code path.

Diff Detail

Event Timeline

benlangmuir created this revision.Jul 6 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2022, 11:57 AM
benlangmuir requested review of this revision.Jul 6 2022, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2022, 11:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
akyrtzi accepted this revision.Jul 6 2022, 1:55 PM
This revision is now accepted and ready to land.Jul 6 2022, 1:55 PM

Updated per out-of-band feedback from @steven_wu :

  • Added an assert to clearOutputFiles that the ASTConsumer is removed. Normally this would be done in FrontendAction::EndSourceFile. This should help avoid regressions and also means it is covered by existing tests.
  • Updated FailureCleanup in FrontendAction::BeginSourceFile to reset the ASTConsumer. This is needed due to the assertion, but I don't think it changes much in practice since there would also be no output files at this stage.
steven_wu accepted this revision.Jul 7 2022, 10:06 AM

LGTM. Thanks!

This revision was landed with ongoing or failed builds.Jul 7 2022, 10:24 AM
This revision was automatically updated to reflect the committed changes.