This is an archive of the discontinued LLVM Phabricator instance.

[Clang][CoverageMapping] Fix switch case counter compile time explosion
ClosedPublic

Authored by bruno on May 24 2022, 5:09 PM.

Details

Summary

After D84467, C++ generated code with huge number of switch cases chokes badly while emitting
coverage mapping, in our specific testcase (~72k cases), it won't stop after hours.

This patch makes the frontend job to finish in 4.5s and shrinks down @__covrec_
by 288k when compared to disabling simplification altogether.

There's probably no good way to create a testcase for this, but it's easy to
reproduce, just add thousands of cases in the below switch, and build with
-fprofile-instr-generate -fcoverage-mapping.

enum type : int {
 FEATURE_INVALID = 0,
 FEATURE_A = 1,
 ...
};

const char *to_string(type e) {
  switch (e) {
  case type::FEATURE_INVALID: return "FEATURE_INVALID";
  case type::FEATURE_A: return "FEATURE_A";}
  ...
  }

Diff Detail

Event Timeline

bruno created this revision.May 24 2022, 5:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 5:09 PM
bruno requested review of this revision.May 24 2022, 5:09 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 24 2022, 5:09 PM
vsk accepted this revision.May 25 2022, 4:28 PM
This revision is now accepted and ready to land.May 25 2022, 4:28 PM
This revision was landed with ongoing or failed builds.May 26 2022, 11:11 AM
This revision was automatically updated to reflect the committed changes.