[clang] 220e77a - [clang][CodeGenPGO] Don't use an invalid index when region counts disagree
Nathan Lanza via cfe-commits
cfe-commits at lists.llvm.org
Wed May 10 20:00:29 PDT 2023
Author: Nathan Lanza
Date: 2023-05-10T22:53:53-04:00
New Revision: 220e77a83af19b3f6c47472596fdaaef8e305927
URL: https://github.com/llvm/llvm-project/commit/220e77a83af19b3f6c47472596fdaaef8e305927
DIFF: https://github.com/llvm/llvm-project/commit/220e77a83af19b3f6c47472596fdaaef8e305927.diff
LOG: [clang][CodeGenPGO] Don't use an invalid index when region counts disagree
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
Added:
Modified:
clang/lib/CodeGen/CodeGenPGO.h
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h
index 66c93cba4bb0..392ec5a144fe 100644
--- a/clang/lib/CodeGen/CodeGenPGO.h
+++ b/clang/lib/CodeGen/CodeGenPGO.h
@@ -114,7 +114,12 @@ class CodeGenPGO {
return 0;
if (!haveRegionCounts())
return 0;
- return RegionCounts[(*RegionCounterMap)[S]];
+ // With profiles from a
diff ering 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];
}
};
More information about the cfe-commits
mailing list