Bug 277474 - clang 17 crashes with -fzero-call-used-regs when optimization is enabled
Summary: clang 17 crashes with -fzero-call-used-regs when optimization is enabled
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-04 14:03 UTC by dan-freebsd
Modified: 2024-03-28 12:31 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dan-freebsd 2024-03-04 14:03:06 UTC
Updating QEMU's upstream CI to use the latest FreBSD 13.3 gcloud images, we're seeing a SEGV in clang 17:

1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '../qobject/qobject.c'.
4.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@qobject_destroy'
 #0 0x0000000005372051 PrintStackTrace /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x00000000053703f5 RunSignalHandlers /usr/src/contrib/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x0000000005338ce5 HandleCrash /usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x0000000005338ce5 CrashRecoverySignalHandler /usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #4 0x000000082bd674af handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
 #5 0x000000082bd66a6b thr_sighandler /usr/src/lib/libthr/thread/thr_sig.c:245:1
 #6 0x00007ffffffff923 ([vdso]+0x2d3)
 #7 0x0000000004d94d71 reset /usr/src/contrib/llvm-project/llvm/include/llvm/ADT/BitVector.h:398:30
 #8 0x0000000004d94d71 insertZeroCallUsedRegs /usr/src/contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp:1291:22
 #9 0x0000000004d94d71 insertPrologEpilogCode /usr/src/contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp:1169:3
#10 0x0000000004d94d71 runOnMachineFunction /usr/src/contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp:263:5
#11 0x0000000004b630b5 runOnFunction /usr/src/contrib/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:13
#12 0x0000000004fc19eb runOnFunction /usr/src/contrib/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1435:27
#13 0x0000000004fc7804 runOnModule /usr/src/contrib/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1481:13
#14 0x0000000004fc2092 runOnModule /usr/src/contrib/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
#15 0x0000000004fc2092 run /usr/src/contrib/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:44
#16 0x0000000002f5b83e ~TimeTraceScope /usr/src/contrib/llvm-project/llvm/include/llvm/Support/TimeProfiler.h:155:9
#17 0x0000000002f5b83e RunCodegenPipeline /usr/src/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1116:3
#18 0x0000000002f5b83e EmitAssembly /usr/src/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1137:3


Although the stack trace is different, based on "insertZeroCallUsedRegs" function in frame #8 which, I'm fairly confident it'll end up being this upstream bug in clang 17:

  https://github.com/llvm/llvm-project/issues/75168

which should be fixable with

  https://github.com/llvm/llvm-project/commit/f800c1f3b207e7bcdc8b4c7192928d9a078242a0
Comment 1 Ed Maste freebsd_committer freebsd_triage 2024-03-04 14:39:44 UTC
Thanks for the analysis. It's too late to get a fix into the 13.3 release but assuming it is this upstream issue/commit we should be able to include it in a 13.3 errata update prior to 13.2 passing EOL.
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-03-04 20:32:10 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a39b3aa463f3474fabb3aedb5aecf943b54b4357

commit a39b3aa463f3474fabb3aedb5aecf943b54b4357
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-04 20:30:54 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-04 20:31:04 +0000

    Merge commit f800c1f3b207 from llvm-project (by Arthur Eubanks):

      [PEI] Don't zero out noreg operands

      A tail call may have $noreg operands.

      Fixes a crash.

      Reviewed By: xgupta

      Differential Revision: https://reviews.llvm.org/D156485

    This should fix an assertion failure building qemu, specifically those
    parts using -fzero-call-used-regs.

    Reported by:    Daniel Berrangé <dan-freebsd@berrange.com>
    PR:             277474
    MFC after:      3 days

 contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2024-03-08 08:19:48 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=fc31d474c40a50066310b3d03a8eb0724a00609d

commit fc31d474c40a50066310b3d03a8eb0724a00609d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-04 20:30:54 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-08 08:15:49 +0000

    Merge commit f800c1f3b207 from llvm-project (by Arthur Eubanks):

      [PEI] Don't zero out noreg operands

      A tail call may have $noreg operands.

      Fixes a crash.

      Reviewed By: xgupta

      Differential Revision: https://reviews.llvm.org/D156485

    This should fix an assertion failure building qemu, specifically those
    parts using -fzero-call-used-regs.

    Reported by:    Daniel Berrangé <dan-freebsd@berrange.com>
    PR:             277474
    MFC after:      3 days

    (cherry picked from commit a39b3aa463f3474fabb3aedb5aecf943b54b4357)

 contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-03-08 08:20:49 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=961271f952fc390396f967d50903291e3e6c59c6

commit 961271f952fc390396f967d50903291e3e6c59c6
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-04 20:30:54 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-03-08 08:19:10 +0000

    Merge commit f800c1f3b207 from llvm-project (by Arthur Eubanks):

      [PEI] Don't zero out noreg operands

      A tail call may have $noreg operands.

      Fixes a crash.

      Reviewed By: xgupta

      Differential Revision: https://reviews.llvm.org/D156485

    This should fix an assertion failure building qemu, specifically those
    parts using -fzero-call-used-regs.

    Reported by:    Daniel Berrangé <dan-freebsd@berrange.com>
    PR:             277474
    MFC after:      3 days

    (cherry picked from commit a39b3aa463f3474fabb3aedb5aecf943b54b4357)

 contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-03-28 05:07:21 UTC
A commit in branch releng/14.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=711422d54795fb4fbef16fd1f1afcee6ed4510f4

commit 711422d54795fb4fbef16fd1f1afcee6ed4510f4
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-04 20:30:54 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2024-03-28 03:13:14 +0000

    Merge commit f800c1f3b207 from llvm-project (by Arthur Eubanks):

      [PEI] Don't zero out noreg operands

      A tail call may have $noreg operands.

      Fixes a crash.

      Reviewed By: xgupta

      Differential Revision: https://reviews.llvm.org/D156485

    This should fix an assertion failure building qemu, specifically those
    parts using -fzero-call-used-regs.

    Reported by:    Daniel Berrangé <dan-freebsd@berrange.com>
    PR:             277474
    MFC after:      3 days
    Approved by:    so
    Security:       FreeBSD-EN-24:07.clang

    (cherry picked from commit a39b3aa463f3474fabb3aedb5aecf943b54b4357)
    (cherry picked from commit fc31d474c40a50066310b3d03a8eb0724a00609d)

 contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-03-28 07:14:49 UTC
A commit in branch releng/13.3 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=26059a4f2c14d72d114175a05f75bebe43aa6efa

commit 26059a4f2c14d72d114175a05f75bebe43aa6efa
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-04 20:30:54 +0000
Commit:     Gordon Tetlow <gordon@FreeBSD.org>
CommitDate: 2024-03-28 07:13:15 +0000

    Merge commit f800c1f3b207 from llvm-project (by Arthur Eubanks):

      [PEI] Don't zero out noreg operands

      A tail call may have $noreg operands.

      Fixes a crash.

      Reviewed By: xgupta

      Differential Revision: https://reviews.llvm.org/D156485

    This should fix an assertion failure building qemu, specifically those
    parts using -fzero-call-used-regs.

    Reported by:    Daniel Berrangé <dan-freebsd@berrange.com>
    PR:             277474
    MFC after:      3 days
    Approved by:    so
    Approved by:    re (so, implicit, appease the commit-hook)
    Security:       FreeBSD-EN-24:07.clang

    (cherry picked from commit a39b3aa463f3474fabb3aedb5aecf943b54b4357)
    (cherry picked from commit 961271f952fc390396f967d50903291e3e6c59c6)

 contrib/llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)