[clang] 14a8451 - [clang][DebugInfo] Fix iterator invalidation during EmitGlobalVariable (#72415)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 09:23:53 PST 2023
Author: Michael Buch
Date: 2023-11-15T17:23:49Z
New Revision: 14a84510f5d07b05b348188c7dfbe54076fa1485
URL: https://github.com/llvm/llvm-project/commit/14a84510f5d07b05b348188c7dfbe54076fa1485
DIFF: https://github.com/llvm/llvm-project/commit/14a84510f5d07b05b348188c7dfbe54076fa1485.diff
LOG: [clang][DebugInfo] Fix iterator invalidation during EmitGlobalVariable (#72415)
Added:
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index f3de91d4a39ebee..7eeb416c70663c9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5833,8 +5833,13 @@ void CGDebugInfo::setDwoId(uint64_t Signature) {
}
void CGDebugInfo::finalize() {
- for (auto const *VD : StaticDataMemberDefinitionsToEmit) {
- assert(VD->isStaticDataMember());
+ // We can't use a for-each here because `EmitGlobalVariable`
+ // may push new decls into `StaticDataMemberDefinitionsToEmit`,
+ // which would invalidate any iterator.
+ for (size_t i = 0; i < StaticDataMemberDefinitionsToEmit.size(); ++i) {
+ auto const *VD = StaticDataMemberDefinitionsToEmit[i];
+
+ assert(VD && VD->isStaticDataMember());
if (DeclCache.contains(VD))
continue;
More information about the cfe-commits
mailing list