-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLVM][Coverage][Unittest] Fix dangling reference in unittest #147118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,15 +64,18 @@ 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; | ||
|
|
||
| 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,10 @@ 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); | ||
| Data.FilenamesStorage.resize(Files.size() + 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be good to say this in a comment to make it clear the |
||
| 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()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not store the strings directly in Filenames rather than having a separate storage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filenameswill be referenced byCoverageMappingRecord::Filenames, which isArrayRef<StringRef>.llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp
Line 88 in 7ecd8e7