llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.58k stars 11.81k forks source link

Clang Crash (SegFault) #112715

Open Hubold17 opened 2 days ago

Hubold17 commented 2 days ago

Every time I run clang -o 6.exe 6.c 6.ll -Wno-override-module, where '6' is the file name, I get this error:

clang -o 6.exe 6.c 6.ll -Wno-override-module
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: /usr/local/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir 6.exe- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name 6.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises -fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises -resource-dir /usr/local/lib/clang/20 -Wno-override-module -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/6-c0a290.o -x ir 6.ll
1.      Code generation
2.      Running pass 'Function Pass Manager' on module '6.ll'.
3.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@sum_arr_llvm'
 #0 0x00005638e5e81550 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/clang-20+0x3b29550)
 #1 0x00005638e5e7ed8e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f275f82e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00005638e6fa8226 llvm::FastISel::handlePHINodesInSuccessorBlocks(llvm::BasicBlock const*) (/usr/local/bin/clang-20+0x4c50226)
 #4 0x00005638e6fad6d4 llvm::FastISel::selectInstruction(llvm::Instruction const*) (/usr/local/bin/clang-20+0x4c556d4)
 #5 0x00005638e70cc41b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/local/bin/clang-20+0x4d7441b)
 #6 0x00005638e70cddf9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/bin/clang-20+0x4d75df9)
 #7 0x00005638e70bd1fd llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/bin/clang-20+0x4d651fd)
 #8 0x00005638e528bdbf llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
 #9 0x00005638e57f2641 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/clang-20+0x349a641)
#10 0x00005638e57f2804 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/clang-20+0x349a804)
#11 0x00005638e57f327b llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/clang-20+0x349b27b)
#12 0x00005638e611028d 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>>, clang::BackendConsumer*) (/usr/local/bin/clang-20+0x3db828d)
#13 0x00005638e67951e1 clang::CodeGenAction::ExecuteAction() (/usr/local/bin/clang-20+0x443d1e1)
#14 0x00005638e6a79cc1 clang::FrontendAction::Execute() (/usr/local/bin/clang-20+0x4721cc1)
#15 0x00005638e69ecb1b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang-20+0x4694b1b)
#16 0x00005638e6b483d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang-20+0x47f03d3)
#17 0x00005638e32b721c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang-20+0xf5f21c)
#18 0x00005638e32aeee2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#19 0x00005638e32b2780 clang_main(int, char**, llvm::ToolContext const&) (/usr/local/bin/clang-20+0xf5a780)
#20 0x00005638e318ed0b main (/usr/local/bin/clang-20+0xe36d0b)
#21 0x00007f275f815d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007f275f815e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x00005638e32ae945 _start (/usr/local/bin/clang-20+0xf56945)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 20.0.0git (https://github.com/llvm/llvm-project.git e1f8f84acec05997893c305c78fbf7feecf44dd7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/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/6-8bd0d3.c
clang: note: diagnostic msg: /tmp/6-8bd0d3.sh
clang: note: diagnostic msg: 

********************
make: *** [Makefile:2: 6.exe] Error 1

The source code 6.ll I try to compile (probably wrong, ik):

define i64 @sum_arr_llvm(i64* %arr, i64 %n) {
entry:
    br label %loop_header

loop_header:
    %i = phi i64 [0, %entry], [%i_inc, %loop_header]
    %sum = phi i64 [0, %entry], [%sum_upd, %loop_header]
    %1 = icmp slt i64 %i, %n
    br i1 %1, label %loop_body, label %exit 

loop_body:
    %e_ptr = getelementptr i64, i64* %arr, i64 %i 
    %e = load i64, i64* %e_ptr
    %sum_upd = add i64 %sum, %e 
    %i_inc = add i64 %i, 1
    br label %loop_header

exit:
    ret i64 %sum
}

The mentioned files /tmp/6-8bd0d3.c:

# 1 "<built-in>"
# 1 "6.c"
long sum_arr_llvm(long *arr, long n);
long sum_arr(long *arr, long n) {
    long sum = 0;
    for (long i = 0; i < n; i++) {
        sum += arr[i];
    }
    return sum;
}

int main() {
    long arr[] = { 1, 2, 3, 4, 5 };
    __builtin_printf("array: {%ld, %ld, %ld, %ld, %ld}\n",
                     arr[0], arr[1], arr[2], arr[3], arr[4]);
    __builtin_printf("sum_arr(arr, 5)     = %ld\n", sum_arr(arr, 5));
    __builtin_printf("sum_arr_llvm(arr, 5) = %ld\n", sum_arr_llvm(arr, 5));
}

and /tmp/6-8bd0d3.sh:

# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git e1f8f84acec05997893c305c78fbf7feecf44dd7)
# Driver args: "-o" "6.exe" "6.c" "6.ll" "-Wno-override-module"
# Original command:  "/usr/local/bin/clang-20" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "6.exe-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "6.ll" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-resource-dir" "/usr/local/lib/clang/20" "-Wno-override-module" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/6-c0a290.o" "-x" "ir" "6.ll"
 "/usr/local/bin/clang-20" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "6.exe-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "6.ll" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-Wno-override-module" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "ir" "6-8bd0d3.c"
llvmbot commented 2 days ago

@llvm/issue-subscribers-backend-x86

Author: Sebastian Hubold (Hubold17)

Every time I run `clang -o 6.exe 6.c 6.ll -Wno-override-module`, where '6' is the file name, I get this error: ``` clang -o 6.exe 6.c 6.ll -Wno-override-module 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: /usr/local/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir 6.exe- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name 6.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises -fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises -resource-dir /usr/local/lib/clang/20 -Wno-override-module -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/6-c0a290.o -x ir 6.ll 1. Code generation 2. Running pass 'Function Pass Manager' on module '6.ll'. 3. Running pass 'X86 DAG->DAG Instruction Selection' on function '@sum_arr_llvm' #0 0x00005638e5e81550 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/clang-20+0x3b29550) #1 0x00005638e5e7ed8e SignalHandler(int) Signals.cpp:0:0 #2 0x00007f275f82e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x00005638e6fa8226 llvm::FastISel::handlePHINodesInSuccessorBlocks(llvm::BasicBlock const*) (/usr/local/bin/clang-20+0x4c50226) #4 0x00005638e6fad6d4 llvm::FastISel::selectInstruction(llvm::Instruction const*) (/usr/local/bin/clang-20+0x4c556d4) #5 0x00005638e70cc41b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/local/bin/clang-20+0x4d7441b) #6 0x00005638e70cddf9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/bin/clang-20+0x4d75df9) #7 0x00005638e70bd1fd llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/bin/clang-20+0x4d651fd) #8 0x00005638e528bdbf llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #9 0x00005638e57f2641 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/clang-20+0x349a641) #10 0x00005638e57f2804 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/clang-20+0x349a804) #11 0x00005638e57f327b llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/clang-20+0x349b27b) #12 0x00005638e611028d 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>>, clang::BackendConsumer*) (/usr/local/bin/clang-20+0x3db828d) #13 0x00005638e67951e1 clang::CodeGenAction::ExecuteAction() (/usr/local/bin/clang-20+0x443d1e1) #14 0x00005638e6a79cc1 clang::FrontendAction::Execute() (/usr/local/bin/clang-20+0x4721cc1) #15 0x00005638e69ecb1b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang-20+0x4694b1b) #16 0x00005638e6b483d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang-20+0x47f03d3) #17 0x00005638e32b721c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang-20+0xf5f21c) #18 0x00005638e32aeee2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #19 0x00005638e32b2780 clang_main(int, char**, llvm::ToolContext const&) (/usr/local/bin/clang-20+0xf5a780) #20 0x00005638e318ed0b main (/usr/local/bin/clang-20+0xe36d0b) #21 0x00007f275f815d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #22 0x00007f275f815e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #23 0x00005638e32ae945 _start (/usr/local/bin/clang-20+0xf56945) clang: error: unable to execute command: Segmentation fault (core dumped) clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 20.0.0git (https://github.com/llvm/llvm-project.git e1f8f84acec05997893c305c78fbf7feecf44dd7) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/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/6-8bd0d3.c clang: note: diagnostic msg: /tmp/6-8bd0d3.sh clang: note: diagnostic msg: ******************** make: *** [Makefile:2: 6.exe] Error 1 ``` The source code `6.ll` I try to compile (probably wrong, ik): ```llvm define i64 @sum_arr_llvm(i64* %arr, i64 %n) { entry: br label %loop_header loop_header: %i = phi i64 [0, %entry], [%i_inc, %loop_header] %sum = phi i64 [0, %entry], [%sum_upd, %loop_header] %1 = icmp slt i64 %i, %n br i1 %1, label %loop_body, label %exit loop_body: %e_ptr = getelementptr i64, i64* %arr, i64 %i %e = load i64, i64* %e_ptr %sum_upd = add i64 %sum, %e %i_inc = add i64 %i, 1 br label %loop_header exit: ret i64 %sum } ``` The mentioned files `/tmp/6-8bd0d3.c`: ```c # 1 "<built-in>" # 1 "6.c" long sum_arr_llvm(long *arr, long n); long sum_arr(long *arr, long n) { long sum = 0; for (long i = 0; i < n; i++) { sum += arr[i]; } return sum; } int main() { long arr[] = { 1, 2, 3, 4, 5 }; __builtin_printf("array: {%ld, %ld, %ld, %ld, %ld}\n", arr[0], arr[1], arr[2], arr[3], arr[4]); __builtin_printf("sum_arr(arr, 5) = %ld\n", sum_arr(arr, 5)); __builtin_printf("sum_arr_llvm(arr, 5) = %ld\n", sum_arr_llvm(arr, 5)); } ``` and `/tmp/6-8bd0d3.sh`: ```sh # Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git e1f8f84acec05997893c305c78fbf7feecf44dd7) # Driver args: "-o" "6.exe" "6.c" "6.ll" "-Wno-override-module" # Original command: "/usr/local/bin/clang-20" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "6.exe-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "6.ll" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-resource-dir" "/usr/local/lib/clang/20" "-Wno-override-module" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/6-c0a290.o" "-x" "ir" "6.ll" "/usr/local/bin/clang-20" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "6.exe-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "6.ll" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-fcoverage-compilation-dir=/home/sebas/compiler-design/llvmexercises" "-Wno-override-module" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "ir" "6-8bd0d3.c" ```