[PATCH] D141446: Fix to D139603(reverted) - moved size check to unit test so that it is cross-platform
William Junda Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 15:58:14 PST 2023
huangjd updated this revision to Diff 488407.
huangjd added a comment.
Updating D141446 <https://reviews.llvm.org/D141446>: Fix to D139603 <https://reviews.llvm.org/D139603>(reverted) - moved size check to unit test so that it is cross-platform
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D141446/new/
https://reviews.llvm.org/D141446
Files:
llvm/lib/ProfileData/SampleProfWriter.cpp
llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
Index: llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
===================================================================
--- llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
+++ llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
@@ -33,15 +33,17 @@
_Z3fooi:7711:610
1: 610)";
+static void CheckAssertFalse(std::error_code t) {
+ ASSERT_FALSE(t) << t.message().c_str();
+}
+
static SampleProfileMap ReadInput(StringRef Input) {
LLVMContext Context;
auto InputBuffer = MemoryBuffer::getMemBufferCopy(Input);
auto ReaderOrErr = SampleProfileReader::create(InputBuffer, Context);
- if (std::error_code EC = ReaderOrErr.getError())
- report_fatal_error(EC.message().c_str());
+ CheckAssertFalse(ReaderOrErr.getError());
auto Reader = std::move(ReaderOrErr.get());
- if (std::error_code EC = Reader->read())
- report_fatal_error(EC.message().c_str());
+ CheckAssertFalse(Reader->read());
return Reader->getProfiles();
}
@@ -51,22 +53,26 @@
new raw_svector_ostream(OutputBuffer));
auto WriterOrErr = SampleProfileWriter::create(
BufferStream, llvm::sampleprof::SPF_Ext_Binary);
- if (std::error_code EC = WriterOrErr.getError())
- report_fatal_error(EC.message().c_str());
+ CheckAssertFalse(WriterOrErr.getError());
return std::move(WriterOrErr.get());
}
-// Only returns the actual size of the written profile.
+// Returns the actual size of the written profile.
static size_t WriteProfile(StringRef Input, size_t SizeLimit) {
SampleProfileMap Profiles = ReadInput(Input);
SmallVector<char> OutputBuffer;
auto Writer = CreateWriter(OutputBuffer);
- if (std::error_code EC = Writer->writeWithSizeLimit(Profiles, SizeLimit))
- report_fatal_error(EC.message().c_str());
+ std::error_code EC = Writer->writeWithSizeLimit(Profiles, SizeLimit);
+ // too_large means no sample could be written because SizeLimit is too small.
+ // Otherwise any other error code indicates unexpected failure.
+ if (EC == sampleprof_error::too_large)
+ return 0;
+ else
+ CheckAssertFalse(EC);
return OutputBuffer.size();
}
TEST(TestOutputSizeLimit, TestOutputSizeLimit1) {
- for (size_t OutputSizeLimit : {489, 488, 474})
- ASSERT_LE(WriteProfile(Input1, OutputSizeLimit), OutputSizeLimit);
+ for (size_t OutputSizeLimit : {489, 488, 474, 400})
+ EXPECT_LE(WriteProfile(Input1, OutputSizeLimit), OutputSizeLimit);
}
Index: llvm/lib/ProfileData/SampleProfWriter.cpp
===================================================================
--- llvm/lib/ProfileData/SampleProfWriter.cpp
+++ llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -125,6 +125,9 @@
LLVM_DEBUG(dbgs() << "Profile originally has " << OriginalFunctionCount
<< " functions, reduced to " << ProfileMap.size() << " in "
<< IterationCount << " iterations\n");
+ // Silence warning on Release build.
+ (void)OriginalFunctionCount;
+ (void)IterationCount;
return sampleprof_error::success;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141446.488407.patch
Type: text/x-patch
Size: 3006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230111/06f44ceb/attachment.bin>
More information about the llvm-commits
mailing list