[PATCH] D26317: Fix use-of-temporary with StringRef in code coverage

Jordan Rose via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 4 16:59:59 PDT 2016

jordan_rose created this revision.
jordan_rose added a reviewer: vsk.
jordan_rose added a subscriber: cfe-commits.
jordan_rose set the repository for this revision to rL LLVM.

The fixed code is basically identical to the same loop below, which might indicate an opportunity for refactoring. I just wanted to fix the use-of-temporary issue.

Caught by adding a similar check to StringRef as r283798 did for ArrayRef. I'll be upstreaming that soon.




Index: lib/CodeGen/CoverageMappingGen.cpp
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -1034,10 +1034,15 @@
     std::vector<StringRef> Filenames;
     std::vector<CounterExpression> Expressions;
     std::vector<CounterMappingRegion> Regions;
+    llvm::SmallVector<std::string, 16> FilenameStrs;
     llvm::SmallVector<StringRef, 16> FilenameRefs;
+    FilenameStrs.resize(FileEntries.size());
-    for (const auto &Entry : FileEntries)
-      FilenameRefs[Entry.second] = normalizeFilename(Entry.first->getName());
+    for (const auto &Entry : FileEntries) {
+      auto I = Entry.second;
+      FilenameStrs[I] = normalizeFilename(Entry.first->getName());
+      FilenameRefs[I] = FilenameStrs[I];
+    }
     RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames,
                                     Expressions, Regions);
     if (Reader.read())

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26317.76954.patch
Type: text/x-patch
Size: 1023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161104/b07eb5c0/attachment.bin>

More information about the cfe-commits mailing list