[llvm] c987950 - [NFC][SampleFDO] Re-apply "In text sample prof reader, report more concrete parsing errors for different line types" (#155124)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 23 17:49:14 PDT 2025


Author: Mingming Liu
Date: 2025-08-23T17:49:11-07:00
New Revision: c987950fad8d80182705673b404e4b151669ddff

URL: https://github.com/llvm/llvm-project/commit/c987950fad8d80182705673b404e4b151669ddff
DIFF: https://github.com/llvm/llvm-project/commit/c987950fad8d80182705673b404e4b151669ddff.diff

LOG: [NFC][SampleFDO] Re-apply "In text sample prof reader, report more concrete parsing errors for different line types" (#155124)

Re-apply https://github.com/llvm/llvm-project/pull/154885 with a fix to initialize `LineTy` before calling `ParseLine`.

Added: 
    

Modified: 
    llvm/lib/ProfileData/SampleProfReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index d147222fe2ce6..12769a391286c 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -375,16 +375,23 @@ std::error_code SampleProfileReaderText::readImpl() {
       StringRef FName;
       DenseMap<StringRef, uint64_t> TargetCountMap;
       uint32_t Depth, LineOffset, Discriminator;
-      LineType LineTy;
+      LineType LineTy = LineType::BodyProfile;
       uint64_t FunctionHash = 0;
       uint32_t Attributes = 0;
       bool IsFlat = false;
       if (!ParseLine(*LineIt, LineTy, Depth, NumSamples, LineOffset,
                      Discriminator, FName, TargetCountMap, FunctionHash,
                      Attributes, IsFlat)) {
-        reportError(LineIt.line_number(),
-                    "Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " +
-                        *LineIt);
+        switch (LineTy) {
+        case LineType::Metadata:
+          reportError(LineIt.line_number(),
+                      "Cannot parse metadata: " + *LineIt);
+          break;
+        default:
+          reportError(LineIt.line_number(),
+                      "Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " +
+                          *LineIt);
+        }
         return sampleprof_error::malformed;
       }
       if (LineTy != LineType::Metadata && Depth == DepthMetadata) {


        


More information about the llvm-commits mailing list