diff options
author | Vedant Kumar <vsk@apple.com> | 2016-06-04 00:36:28 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2016-06-04 00:36:28 +0000 |
commit | f771a050db295ab8624089db08b1ac9a764c2474 (patch) | |
tree | 8afe4743ff8466778adbd0806d3abf4bca4e08c1 /llvm/tools/llvm-profdata/llvm-profdata.cpp | |
parent | 42b1f65f03fe36c87e42d7c5c5d9fba2061180bc (diff) | |
download | bcm5719-llvm-f771a050db295ab8624089db08b1ac9a764c2474.tar.gz bcm5719-llvm-f771a050db295ab8624089db08b1ac9a764c2474.zip |
[llvm-profdata] Clean up the way we create the input filenames buffer (NFC)
Create the buffer before calling parseInputFilenamesFile(), and add a
comment explaining why this is done.
Thanks to David Li for the suggestion!
llvm-svn: 271756
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 45f348747db..b9efd2ee5cd 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -224,8 +224,7 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) { } static std::unique_ptr<MemoryBuffer> -parseInputFilenamesFile(const StringRef &InputFilenamesFile, - WeightedFileVector &WFV) { +getInputFilenamesFileBuf(const StringRef &InputFilenamesFile) { if (InputFilenamesFile == "") return {}; @@ -233,10 +232,16 @@ parseInputFilenamesFile(const StringRef &InputFilenamesFile, if (!BufOrError) exitWithErrorCode(BufOrError.getError(), InputFilenamesFile); - std::unique_ptr<MemoryBuffer> Buffer = std::move(*BufOrError); - StringRef Data = Buffer->getBuffer(); + return std::move(*BufOrError); +} + +static void parseInputFilenamesFile(MemoryBuffer *Buffer, + WeightedFileVector &WFV) { + if (!Buffer) + return; SmallVector<StringRef, 8> Entries; + StringRef Data = Buffer->getBuffer(); Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false); for (const StringRef &FileWeightEntry : Entries) { StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r"); @@ -249,8 +254,6 @@ parseInputFilenamesFile(const StringRef &InputFilenamesFile, else WFV.emplace_back(parseWeightedFile(SanitizedEntry)); } - - return Buffer; } static int merge_main(int argc, const char *argv[]) { @@ -293,7 +296,11 @@ static int merge_main(int argc, const char *argv[]) { WeightedInputs.push_back(WeightedFile(Filename, 1)); for (StringRef WeightedFilename : WeightedInputFilenames) WeightedInputs.push_back(parseWeightedFile(WeightedFilename)); - auto Buf = parseInputFilenamesFile(InputFilenamesFile, WeightedInputs); + + // Make sure that the file buffer stays alive for the duration of the + // weighted input vector's lifetime. + auto Buffer = getInputFilenamesFileBuf(InputFilenamesFile); + parseInputFilenamesFile(Buffer.get(), WeightedInputs); if (WeightedInputs.empty()) exitWithError("No input files specified. See " + |