This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by huangjd on Feb 5 2023, 11:13 PM.

Details

Summary

Text editors can introduce spaces aligning the previous line's indentation. This crashes llvm-profdata. Added check to handle this case.

Diff Detail

Event Timeline

huangjd created this revision.Feb 5 2023, 11:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2023, 11:13 PM
huangjd requested review of this revision.Feb 5 2023, 11:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2023, 11:13 PM
This revision is now accepted and ready to land.Feb 6 2023, 10:28 AM
This revision was landed with ongoing or failed builds.Feb 6 2023, 2:30 PM
This revision was automatically updated to reflect the committed changes.
ro added a subscriber: ro.Apr 24 2023, 5:06 AM

A reghunt just determined that this patch broke a considerable number (30+) of profile-related tests on Solaris/sparcv9. E.g.

+  LLVM :: Other/new-pm-thinlto-prelink-samplepgo-inline-threshold.ll

/vol/llvm/src/llvm-project/dist/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-inline-threshold.ll:74:10: error: CHECK: expected string not found in input
; CHECK: call i32 @_Z4sum1ii
         ^

I just noticed this again when switching host compiler of the 1-stage clang-solaris-sparcv9 buildbot from llvm 15.0.0 to 16.0.0.

Should we discuss this here or is it better to file an Issue?

In D143369#4292062, @ro wrote:

A reghunt just determined that this patch broke a considerable number (30+) of profile-related tests on Solaris/sparcv9. E.g.

+  LLVM :: Other/new-pm-thinlto-prelink-samplepgo-inline-threshold.ll

/vol/llvm/src/llvm-project/dist/llvm/test/Other/new-pm-thinlto-prelink-samplepgo-inline-threshold.ll:74:10: error: CHECK: expected string not found in input
; CHECK: call i32 @_Z4sum1ii
         ^

I just noticed this again when switching host compiler of the 1-stage clang-solaris-sparcv9 buildbot from llvm 15.0.0 to 16.0.0.

Should we discuss this here or is it better to file an Issue?

Could you discuss this with more detail? This patch is very simple to understand so I am surprised that it's causing such a bug

ro added a comment.Apr 25 2023, 3:45 AM

I've taken the smallest failing testcase (LLVM :: tools/llvm-profdata/sample-remap.test) and reduced it further to

$ cat in
main:184019:0
 4: 534
 4.2: 534
$ llvm-profdata merge -sample -text in -o out

Without your patch, the output is identical to the input, with it, I get

main:184019:0
 4: 1068

instead. I'm completely unfamiliar with both the input format and the code, so I've not yet tried looking deeper.

huangjd added a comment.EditedApr 25 2023, 2:10 PM
In D143369#4295219, @ro wrote:

I've taken the smallest failing testcase (LLVM :: tools/llvm-profdata/sample-remap.test) and reduced it further to

$ cat in
main:184019:0
 4: 534
 4.2: 534
$ llvm-profdata merge -sample -text in -o out

Without your patch, the output is identical to the input, with it, I get

main:184019:0
 4: 1068

instead. I'm completely unfamiliar with both the input format and the code, so I've not yet tried looking deeper.

I ran it on x86-64 linux and couldn't replicate it, so it seems like an issue specific to Solaris/sparcv9. It doesn't look like the line with 4.2 is skipped due to this patch, but instead it's parsed but being merged with the line with 4, which indicates a bug somewhere else.

ro added a comment.Apr 25 2023, 2:16 PM

What system are you running this on? I ran it on x86-64 linux and couldn't replicate it. It doesn't look like the line with 4.2 is skipped due to this patch, but instead it's parsed but being merged with the line with 4, which indicates a bug somewhere else.

This is Solaris/sparcv9 (sparcv9-sun-solaris2.11) and can also be seen on the corresponding buildbot. I'm currently running both a debug build to be able to investigate more and a Linux/sparc64 build to see if the issue occurs there, too. Unfortunately, those Debug builds are dog slow...

I've also reverted your patch on main locally: all the failures seen in the buildbot vanish then.

In D143369#4296705, @ro wrote:

What system are you running this on? I ran it on x86-64 linux and couldn't replicate it. It doesn't look like the line with 4.2 is skipped due to this patch, but instead it's parsed but being merged with the line with 4, which indicates a bug somewhere else.

This is Solaris/sparcv9 (sparcv9-sun-solaris2.11) and can also be seen on the corresponding buildbot. I'm currently running both a debug build to be able to investigate more and a Linux/sparc64 build to see if the issue occurs there, too. Unfortunately, those Debug builds are dog slow...

I've also reverted your patch on main locally: all the failures seen in the buildbot vanish then.

Any leads on why it is crashing with debug build?