[PATCH] D41374: [Coverage] Fix use-after free in coverage emission

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 17:35:46 PST 2017

efriedma created this revision.
efriedma added reviewers: vsk, davidxl.
efriedma added a project: clang.

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.

  rC Clang



Index: lib/CodeGen/CodeGenModule.cpp
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4289,7 +4289,11 @@
 void CodeGenModule::EmitDeferredUnusedCoverageMappings() {
-  for (const auto &Entry : DeferredEmptyCoverageMappingDecls) {
+  // We call takeVector() here to avoid use-after-free.
+  // FIXME: DeferredEmptyCoverageMappingDecls is getting mutated because
+  // we deserialize function bodies to emit coverage info for them, and that
+  // deserializes more declarations. How should we handle that case?
+  for (const auto &Entry : DeferredEmptyCoverageMappingDecls.takeVector()) {
     if (!Entry.second)
     const Decl *D = Entry.first;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41374.127440.patch
Type: text/x-patch
Size: 758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171219/20b291f7/attachment-0001.bin>

More information about the cfe-commits mailing list