Text editors can introduce spaces aligning the previous line's indentation. This crashes llvm-profdata. Added check to handle this case.
Reviewed By: snehasish
Differential Revision: https://reviews.llvm.org/D143369
ProfileIsFS = ProfileIsFSDisciminator;
FunctionSamples::ProfileIsFS = ProfileIsFS;
for (; !LineIt.is_at_eof(); ++LineIt) {
- if ((*LineIt)[(*LineIt).find_first_not_of(' ')] == '#')
+ size_t pos = LineIt->find_first_not_of(' ');
+ if (pos == LineIt->npos || (*LineIt)[pos] == '#')
continue;
// Read the header of each function.
//
--- /dev/null
+main:10:1
+ 2: 3
+
+
+ 3: inline1:5
+
+ 4: 1
+
+
--- /dev/null
+Test llvm-profdata merge can handle empty line with spaces in text format sample profile.
+
+RUN: llvm-profdata merge --sample --text %p/Inputs/sample-empty-lines.proftext | FileCheck %s
+CHECK: main:10:1
+CHECK-NEXT: 2: 3
+CHECK-NEXT: 3: inline1:5
+CHECK-NEXT: 4: 1
+