diff --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp --- a/llvm/lib/ProfileData/RawMemProfReader.cpp +++ b/llvm/lib/ProfileData/RawMemProfReader.cpp @@ -325,7 +325,8 @@ continue; } - for (size_t I = 0; I < DI.getNumberOfFrames(); I++) { + for (size_t I = 0, NumFrames = DI.getNumberOfFrames(); I < NumFrames; + I++) { const auto &Frame = DI.getFrame(I); LLVM_DEBUG( // Print out the name to guid mapping for debugging. @@ -340,8 +341,8 @@ // these suffixes will not be present. Function::getGUID(trimSuffix(Frame.FunctionName)), Frame.Line - Frame.StartLine, Frame.Column, - // Only the first entry is not an inlined location. - I != 0); + // Only the last entry is not an inlined location. + I != NumFrames - 1); } } diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp --- a/llvm/unittests/ProfileData/MemProfTest.cpp +++ b/llvm/unittests/ProfileData/MemProfTest.cpp @@ -169,13 +169,13 @@ EXPECT_EQ(Records[0].Info.getAllocCount(), 1U); EXPECT_EQ(Records[1].Info.getAllocCount(), 2U); - EXPECT_THAT(Records[0].CallStack[0], FrameContains("foo", 5U, 30U, false)); - EXPECT_THAT(Records[0].CallStack[1], FrameContains("bar", 51U, 20U, true)); + EXPECT_THAT(Records[0].CallStack[0], FrameContains("foo", 5U, 30U, true)); + EXPECT_THAT(Records[0].CallStack[1], FrameContains("bar", 51U, 20U, false)); - EXPECT_THAT(Records[1].CallStack[0], FrameContains("baz", 5U, 30U, false)); - EXPECT_THAT(Records[1].CallStack[1], FrameContains("qux", 5U, 10U, true)); - EXPECT_THAT(Records[1].CallStack[2], FrameContains("foo", 5U, 30U, false)); - EXPECT_THAT(Records[1].CallStack[3], FrameContains("bar", 51U, 20U, true)); + EXPECT_THAT(Records[1].CallStack[0], FrameContains("baz", 5U, 30U, true)); + EXPECT_THAT(Records[1].CallStack[1], FrameContains("qux", 5U, 10U, false)); + EXPECT_THAT(Records[1].CallStack[2], FrameContains("foo", 5U, 30U, true)); + EXPECT_THAT(Records[1].CallStack[3], FrameContains("bar", 51U, 20U, false)); } TEST(MemProf, PortableWrapper) {