[PATCH] D143369: [llvm-profdata] Fix bug llvm-profdata crashes when reading a text sample profile with an empty line with spaces.

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 14:30:48 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84719e2f0387: [llvm-profdata] Fix bug llvm-profdata crashes when reading a text sampleā€¦ (authored by huangjd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143369/new/

https://reviews.llvm.org/D143369

Files:
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/test/tools/llvm-profdata/Inputs/sample-empty-lines.proftext
  llvm/test/tools/llvm-profdata/sample-empty-lines.test


Index: llvm/test/tools/llvm-profdata/sample-empty-lines.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profdata/sample-empty-lines.test
@@ -0,0 +1,8 @@
+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
+
Index: llvm/test/tools/llvm-profdata/Inputs/sample-empty-lines.proftext
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-profdata/Inputs/sample-empty-lines.proftext
@@ -0,0 +1,9 @@
+main:10:1
+ 2: 3
+ 
+
+ 3: inline1:5
+  
+  4: 1
+ 
+
Index: llvm/lib/ProfileData/SampleProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/SampleProfReader.cpp
+++ llvm/lib/ProfileData/SampleProfReader.cpp
@@ -328,7 +328,8 @@
   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.
     //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143369.495276.patch
Type: text/x-patch
Size: 1375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230206/ca0a8799/attachment.bin>


More information about the llvm-commits mailing list