diff options
author | Dehao Chen <dehao@google.com> | 2015-10-21 01:22:27 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2015-10-21 01:22:27 +0000 |
commit | 491ae53e26e5d7f615d25e2e79f1fe2f29c26241 (patch) | |
tree | 96f688abc3f0c85826deecbdebee7a0c8d42d4cd /lib/ProfileData/SampleProfReader.cpp | |
parent | c75a25368946ce7dda69b34ee71ff79467de7afd (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250873 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ProfileData/SampleProfReader.cpp')
-rw-r--r-- | lib/ProfileData/SampleProfReader.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/ProfileData/SampleProfReader.cpp b/lib/ProfileData/SampleProfReader.cpp index d184969e046..899343f72f7 100644 --- a/lib/ProfileData/SampleProfReader.cpp +++ b/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; |