This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix serialized diagnostics edge-cases
ClosedPublic

Authored by jansvoboda11 on Jan 25 2022, 8:03 AM.

Details

Summary

The Clang frontend sometimes fails on the following assertion when launched with -serialize-diagnostic-file <x>:

Assertion failed: (BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance"), function ~BitstreamWriter, file BitstreamWriter.h, line 125.

This was first noticed when passing an unknown command-line argument to -cc1.

It turns out the DiagnosticConsumer::finish() function should be called as soon as processing of all source files ends, but there are some code paths where that doesn't happen:

  1. when command line parsing fails in cc1_main(),
  2. when !Act.PrepareToExecute(*this) or !createTarget() evaluate to true in CompilerInstance::ExecuteAction and the function returns early.

This patch ensures finish() is called in all those code paths.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Jan 25 2022, 8:03 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 8:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jansvoboda11 edited the summary of this revision. (Show Details)Jan 25 2022, 8:04 AM
jansvoboda11 added inline comments.Jan 25 2022, 8:08 AM
clang/test/Misc/serialized-diags-emit-header-module-misconfig.c
3

This combination of command-line arguments causes GenerateHeaderModuleAction::PrepareToExecuteAction to return false and !Act.PrepareToExecute(*this) == true.

This revision is now accepted and ready to land.Jan 25 2022, 1:32 PM
This revision was landed with ongoing or failed builds.Jan 26 2022, 2:22 AM
This revision was automatically updated to reflect the committed changes.