Skip to content

Commit 8516b7f

Browse files
author
Eli Friedman
committed
[Coverage] Fix use-after free in coverage emission
Fixes regression from r320533. This fixes the undefined behavior, but I'm not sure it's really right... I think we end up with missing coverage for code in modules. Differential Revision: https://reviews.llvm.org/D41374 llvm-svn: 321052
1 parent b1e350f commit 8516b7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4289,7 +4289,11 @@ void CodeGenModule::ClearUnusedCoverageMapping(const Decl *D) {
42894289
}
42904290

42914291
void CodeGenModule::EmitDeferredUnusedCoverageMappings() {
4292-
for (const auto &Entry : DeferredEmptyCoverageMappingDecls) {
4292+
// We call takeVector() here to avoid use-after-free.
4293+
// FIXME: DeferredEmptyCoverageMappingDecls is getting mutated because
4294+
// we deserialize function bodies to emit coverage info for them, and that
4295+
// deserializes more declarations. How should we handle that case?
4296+
for (const auto &Entry : DeferredEmptyCoverageMappingDecls.takeVector()) {
42934297
if (!Entry.second)
42944298
continue;
42954299
const Decl *D = Entry.first;

0 commit comments

Comments
 (0)