diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -114,7 +114,12 @@ 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]; } };