Bug 2262260 - clang crashes with -fzero-call-used-regs when optimization is enabled
Summary: clang crashes with -fzero-call-used-regs when optimization is enabled
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: clang
Version: 39
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Nikita Popov
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-02-01 12:39 UTC by Daniel Berrangé
Modified: 2024-02-06 01:18 UTC (History)
9 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2024-02-02 13:01:24 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Daniel Berrangé 2024-02-01 12:39:18 UTC
This demo illustrates the issue

$ cat > test.c <<EOF

struct QCryptoAkCipher {
    void (*free)(struct QCryptoAkCipher *akcipher);
};

void qcrypto_akcipher_free(struct QCryptoAkCipher *akcipher);
void qcrypto_akcipher_free(struct QCryptoAkCipher *akcipher)
{
    akcipher->free(akcipher);
}
EOF

$ clang -c  -o test  test.c -fzero-call-used-regs=all -O2
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang -c -o test /test.c -fzero-call-used-regs=all -O2
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/test.c'.
4.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@qcrypto_akcipher_free'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM-17.so      0x00007fb947feeb7a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 58
1  libLLVM-17.so      0x00007fb947fec534 llvm::sys::RunSignalHandlers() + 84
2  libLLVM-17.so      0x00007fb947f23d14
3  libc.so.6          0x00007fb947351db0
4  libLLVM-17.so      0x00007fb94855cf9f
5  libLLVM-17.so      0x00007fb9484288cc llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 828
6  libLLVM-17.so      0x00007fb948165575 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1285
7  libLLVM-17.so      0x00007fb94816c2e3 llvm::FPPassManager::runOnModule(llvm::Module&) + 51
8  libLLVM-17.so      0x00007fb948165c2d llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1085
9  libclang-cpp.so.17 0x00007fb94f7f6825 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) + 3445
10 libclang-cpp.so.17 0x00007fb94fbf3048
11 libclang-cpp.so.17 0x00007fb94e59f526 clang::ParseAST(clang::Sema&, bool, bool) + 598
12 libclang-cpp.so.17 0x00007fb9507b5c86 clang::FrontendAction::Execute() + 102
13 libclang-cpp.so.17 0x00007fb950722e40 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 752
14 libclang-cpp.so.17 0x00007fb9508366d4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 580
15 clang              0x0000000000412911 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 4097
16 clang              0x000000000040fd25
17 libclang-cpp.so.17 0x00007fb95035cbfd
18 libLLVM-17.so      0x00007fb947f23a54 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 148
19 libclang-cpp.so.17 0x00007fb95035c627 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 375
20 libclang-cpp.so.17 0x00007fb950322fee clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 878
21 libclang-cpp.so.17 0x00007fb950323257 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 167
22 libclang-cpp.so.17 0x00007fb9503405da clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 474
23 clang              0x000000000040f568 clang_main(int, char**, llvm::ToolContext const&) + 11752
24 clang              0x000000000041c036 main + 54
25 libc.so.6          0x00007fb94733ceb0
26 libc.so.6          0x00007fb94733cf60 __libc_start_main + 128
27 clang              0x000000000040c425 _start + 37
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 17.0.6 (CentOS 17.0.6-5.el9)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test-28f292.c
clang: note: diagnostic msg: /tmp/test-28f292.sh
clang: note: diagnostic msg: 

********************


Does not crash with -O0
Does not crash on non-x86 architecture
Does not crash on Fedora 38 with clang 16

This impacts ability to build QEMU (git master) with clang which now enables -fzero-call-used-regs by default

Reproducible: Always

Comment 1 Daniel Berrangé 2024-02-01 12:43:55 UTC
Switch to F39, since that has clang 17 already

Comment 2 Nikita Popov 2024-02-01 13:22:28 UTC
This sounds familiar. I believe https://github.com/llvm/llvm-project/commit/f800c1f3b207e7bcdc8b4c7192928d9a078242a0 is the fix.

Comment 3 Nikita Popov 2024-02-01 13:39:48 UTC
Confirmed that this commit fixes the issue when fixed on top the 17.x branch.

Comment 4 Nikita Popov 2024-02-01 13:44:04 UTC
Backport PR: https://src.fedoraproject.org/rpms/llvm/pull-request/189

Comment 5 Fedora Update System 2024-02-02 11:01:16 UTC
FEDORA-2024-447faac21f has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2024-447faac21f

Comment 6 Fedora Update System 2024-02-02 13:01:24 UTC
FEDORA-2024-447faac21f has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 7 Fedora Update System 2024-02-02 15:40:22 UTC
FEDORA-2024-29313e5e1e has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2024-29313e5e1e

Comment 8 Fedora Update System 2024-02-03 00:49:25 UTC
FEDORA-2024-29313e5e1e has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-29313e5e1e`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-29313e5e1e

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 9 Fedora Update System 2024-02-06 01:18:23 UTC
FEDORA-2024-29313e5e1e (llvm-17.0.6-3.fc39) has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.