Skip to content

Commit

Permalink
[clang][CodeGenPGO] Don't use an invalid index when region counts dis…
Browse files Browse the repository at this point in the history
…agree

If we're using an old instrprof profile and the user passes we can get
Decls with children decl counts not matching the what the profile was
written against. In a particular case I was debugging we have 24 decls
in the AST and 22 decls in the profile. Avoid crashing in this case.

Differential Revision: https://reviews.llvm.org/D149504
  • Loading branch information
lanza committed May 11, 2023
1 parent 9a35c0c commit 220e77a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clang/lib/CodeGen/CodeGenPGO.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ class CodeGenPGO {
return 0;
if (!haveRegionCounts())
return 0;
return RegionCounts[(*RegionCounterMap)[S]];
// With profiles from a differing version of clang we can have mismatched
// decl counts. Don't crash in such a case.
auto Index = (*RegionCounterMap)[S];
if (Index >= RegionCounts.size())
return 0;
return RegionCounts[Index];
}
};

Expand Down

0 comments on commit 220e77a

Please sign in to comment.