aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/SampleProfReader.cpp
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2015-10-21 01:22:27 +0000
committerDehao Chen <dehao@google.com>2015-10-21 01:22:27 +0000
commit100424124bf1f2845c8cac18e39333cf5f04b1ae (patch)
tree92f5b929fba79726bf7d69543d9fa218ecb27963 /llvm/lib/ProfileData/SampleProfReader.cpp
parent4c3f2b944689bdb23e929ab27815bbc87c20c035 (diff)
downloadllvm-100424124bf1f2845c8cac18e39333cf5f04b1ae.zip
llvm-100424124bf1f2845c8cac18e39333cf5f04b1ae.tar.gz
llvm-100424124bf1f2845c8cac18e39333cf5f04b1ae.tar.bz2
Tolerate negative offset when matching sample profile.
In some cases (as illustrated in the unittest), lineno can be less than the heade_lineno because the function body are included from some other files. In this case, offset will be negative. This patch makes clang still able to match the profile to IR in this situation. http://reviews.llvm.org/D13914 llvm-svn: 250873
Diffstat (limited to 'llvm/lib/ProfileData/SampleProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index d184969..899343f 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -100,6 +100,12 @@ static bool ParseHead(const StringRef &Input, StringRef &FName,
return true;
}
+
+/// \brief Returns true if line offset \p L is legal (only has 16 bits).
+static bool isOffsetLegal(unsigned L) {
+ return (L & 0xffff) == L;
+}
+
/// \brief Parse \p Input as line sample.
///
/// \param Input input line.
@@ -124,7 +130,7 @@ static bool ParseLine(const StringRef &Input, bool &IsCallsite, uint32_t &Depth,
StringRef Loc = Input.substr(Depth, n1 - Depth);
size_t n2 = Loc.find('.');
if (n2 == StringRef::npos) {
- if (Loc.getAsInteger(10, LineOffset))
+ if (Loc.getAsInteger(10, LineOffset) || !isOffsetLegal(LineOffset))
return false;
Discriminator = 0;
} else {
@@ -308,6 +314,10 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
if (std::error_code EC = LineOffset.getError())
return EC;
+ if (!isOffsetLegal(*LineOffset)) {
+ return std::error_code();
+ }
+
auto Discriminator = readNumber<uint64_t>();
if (std::error_code EC = Discriminator.getError())
return EC;