MSYS2-packages/llvm/0008-LLVM-Coverage-Unittest-Fix-dangling-reference-in-uni.patch
jeremyd2019 45f860c0dc
llvm: backport fixes, fix 32-bit (#5630)
* --disable-high-entropy-va is not accepted on 32-bit ld, it should be added only on 64-bit.

* New Cygwin linker driver was not passing --large-address-aware on 32-bit

* Microsoft-style calling convention name mangling (such as stdcall Name@N) was disabled on Cygwin, regression from 21.1.  This would have been an issue on x86_64 as well with vectorcall I think
2025-09-14 12:38:25 -07:00

74 lines
3.3 KiB
Diff

From 03731bf1dc4a9ab97a03bf4a5d6e33487ccb6845 Mon Sep 17 00:00:00 2001
From: Tomohiro Kashiwada <kikairoya@gmail.com>
Date: Fri, 12 Sep 2025 05:12:54 +0900
Subject: [PATCH] [LLVM][Coverage][Unittest] Fix dangling reference in unittest
(#147118)
In loop of `writeAndReadCoverageRegions`, `OutputFunctions[I].Filenames`
references to contents of `Filenames` after returning from
`readCoverageRegions` but `Filenames` will be cleared in next call of
`readCoverageRegions`, causes dangling reference.
The lifetime of the contents of `Filenames` must be equal or longer than
`OutputFunctions[I]`, thus it has been moved into `OutputFunctions[I]`
(typed `OutputFunctionCoverageData`).
(cherry picked from commit ca09801bd03579f28edac60077a164fab0474eb4)
---
.../ProfileData/CoverageMappingTest.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index ec81e5f274..b268aa7cdd 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -64,6 +64,7 @@ namespace {
struct OutputFunctionCoverageData {
StringRef Name;
uint64_t Hash;
+ std::vector<std::string> FilenamesStorage;
std::vector<StringRef> Filenames;
std::vector<CounterMappingRegion> Regions;
std::vector<CounterExpression> Expressions;
@@ -71,8 +72,10 @@ struct OutputFunctionCoverageData {
OutputFunctionCoverageData() : Hash(0) {}
OutputFunctionCoverageData(OutputFunctionCoverageData &&OFCD)
- : Name(OFCD.Name), Hash(OFCD.Hash), Filenames(std::move(OFCD.Filenames)),
- Regions(std::move(OFCD.Regions)) {}
+ : Name(OFCD.Name), Hash(OFCD.Hash),
+ FilenamesStorage(std::move(OFCD.FilenamesStorage)),
+ Filenames(std::move(OFCD.Filenames)), Regions(std::move(OFCD.Regions)) {
+ }
OutputFunctionCoverageData(const OutputFunctionCoverageData &) = delete;
OutputFunctionCoverageData &
@@ -135,7 +138,6 @@ struct InputFunctionCoverageData {
struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {
bool UseMultipleReaders;
StringMap<unsigned> Files;
- std::vector<std::string> Filenames;
std::vector<InputFunctionCoverageData> InputFunctions;
std::vector<OutputFunctionCoverageData> OutputFunctions;
@@ -233,13 +235,11 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {
void readCoverageRegions(const std::string &Coverage,
OutputFunctionCoverageData &Data) {
- // We will re-use the StringRef in duplicate tests, clear it to avoid
- // clobber previous ones.
- Filenames.clear();
- Filenames.resize(Files.size() + 1);
+ // +1 here since `Files` (filename to index map) uses 1-based index.
+ Data.FilenamesStorage.resize(Files.size() + 1);
for (const auto &E : Files)
- Filenames[E.getValue()] = E.getKey().str();
- ArrayRef<std::string> FilenameRefs = llvm::ArrayRef(Filenames);
+ Data.FilenamesStorage[E.getValue()] = E.getKey().str();
+ ArrayRef<std::string> FilenameRefs = llvm::ArrayRef(Data.FilenamesStorage);
RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames,
Data.Expressions, Data.Regions);
EXPECT_THAT_ERROR(Reader.read(), Succeeded());
--
2.51.0.windows.1