llvm-project
llvm-project copied to clipboard
opt-19 Segmentation fault with the pass "codegenprepare"
opt-19 Segmentation fault with the pass "codegenprepare" Compiler explorer: https://godbolt.org/z/T1jTrqbro
$cat mutant.c
char c;
__attribute__((minsize))
void
testc (void)
{
(void) __sync_fetch_and_add (&c, -1);
}
short s;
__attribute__((no_sanitize_undefined))
void
tests (void)
{
(void) __sync_fetch_and_add (&s, -1);
}
void
testc2 (void)
{
(void) __sync_val_compare_and_swap (&c, -1, -3);
}
$clang-18 -fsanitize=undefined -mllvm -disable-llvm-optzns -c -emit-llvm mutant.c -o mutant.bc
$cat mutant.bc
@c = dso_local global i8 0, align 1
@s = dso_local global i16 0, align 2
define dso_local void @testc() {
entry:
%0 = atomicrmw add ptr @c, i8 -1 seq_cst, align 1
ret void
}
define dso_local void @tests() {
entry:
%0 = atomicrmw add ptr @s, i16 -1 seq_cst, align 2
ret void
}
define dso_local void @testc2() {
entry:
%0 = cmpxchg ptr @c, i8 -1, i8 -3 seq_cst seq_cst, align 1
%1 = extractvalue { i8, i1 } %0, 0
ret void
}
$opt-18 opt-19 -passes=codegenprepare mutant.bc -o mutant.opt.bc
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: opt-19 -passes=codegenprepare mutant.bc -o mutant.opt.bc
#0 0x00007f703860d216 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xdc1216)
#1 0x00007f703860aec0 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xdbeec0)
#2 0x00007f703860d8f0 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xdc18f0)
#3 0x00007f703efb7980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
#4 0x00007f703888ac18 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x103ec18)
#5 0x00007f70388827b2 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x10367b2)
#6 0x00007f70388819f7 llvm::CodeGenPreparePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x10359f7)
#7 0x00007f703b2fe1ad (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x3ab21ad)
#8 0x00007f7038793474 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xf47474)
#9 0x00007f703a6ed7cd (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x2ea17cd)
#10 0x00007f7038796ad1 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xf4aad1)
#11 0x00007f703a6ed5fd (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0x2ea15fd)
#12 0x00007f7038792214 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.0+0xf46214)
#13 0x000055b8348a38f9 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/usr/lib/llvm-19/bin/opt+0x298f9)
#14 0x000055b834897e62 optMain (/usr/lib/llvm-19/bin/opt+0x1de62)
#15 0x00007f7036a5bc87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#16 0x000055b83489276a _start (/usr/lib/llvm-19/bin/opt+0x1876a)
Segmentation fault (core dumped)
Sorry, the opt command should be:
opt-19 -passes=codegenprepare mutant.bc -o mutant.opt.bc
The clang command should be:
clang-19 -fsanitize=undefined -mllvm -disable-llvm-optzns -c -emit-llvm mutant.c -o mutant.bc
https://github.com/llvm/llvm-project/pull/89566, there has been a discussion about this issue.
-passes='require<profile-summary>,function(codegenprepare)' opt.ll -mtriple=x86_64
It works with the above command, we need profile-summary and triple to make it work.
It seems that we can close this issue?