Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang crash: Assertion `isReg() && "This is not a register operand!"' failed. #71178

Closed
shao-hua-li opened this issue Nov 3, 2023 · 1 comment · Fixed by #79820 · May be fixed by #73519
Closed

Clang crash: Assertion `isReg() && "This is not a register operand!"' failed. #71178

shao-hua-li opened this issue Nov 3, 2023 · 1 comment · Fixed by #79820 · May be fixed by #73519
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:codegen

Comments

@shao-hua-li
Copy link

Clang at -O1 crashes on the test case.

Bisected to 2cdc6f2, which was committed by @djtodoro

Compiler explorer: https://godbolt.org/z/74MTEPh36

% cat a.c
long a, b, e, g;
int c;
short d;
int *f;
int h() {
  long i;
j:
  if (e) {
    int k;
    g = b && -1 / a;
    k = *f;
    if (k) {
      i |= 0 <= 0;
      if (c)
        goto j;
    } else {
      d = 0;
      return 0;
    }
  } else {
    int l;
    for (; d;) {
      e = 9166129423;
      goto j;
    }
    return *f;
  }
  return 0;
}
int main() {}
%
% clang -O1 a.c
clang-14: /tmp/tmp3wrk7acr/tmpxyxr54it/llvm/include/llvm/CodeGen/MachineOperand.h:361: llvm::Register llvm::MachineOperand::getReg() const: Assertion `isReg() && "This is not a register operand!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/clang-14 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name reduced.c -mrelocation-model static -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_7TTZKO7D -resource-dir /zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/lib/clang/14.0.0 -internal-isystem /zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O1 -fdebug-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_7TTZKO7D -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/reduced-b68b25.o -x c a.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'a.c'.
4.      Running pass 'Simple Register Coalescing' on function '@h'
 #0 0x00007fd79170c704 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007fd791709e2e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fd790ae8090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
 #3 0x00007fd790ae800b raise /build/glibc-BHL3KM/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007fd790ac7859 abort /build/glibc-BHL3KM/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007fd790ac7729 get_sysdep_segment_value /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007fd790ac7729 _nl_load_domain /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007fd790ad8fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00007fd791d8fadd isMoveInstr(llvm::TargetRegisterInfo const&, llvm::MachineInstr const*, llvm::Register&, llvm::Register&, unsigned int&, unsigned int&) (.constprop.0) RegisterCoalescer.cpp:0:0
 #9 0x00007fd791d95ada llvm::CoalescerPair::setRegisters(llvm::MachineInstr const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libLLVM-14git.so+0xec2ada)
#10 0x00007fd791da10ac (anonymous namespace)::RegisterCoalescer::joinCopy(llvm::MachineInstr*, bool&) (.constprop.0) RegisterCoalescer.cpp:0:0
#11 0x00007fd791da38cf (anonymous namespace)::RegisterCoalescer::copyCoalesceWorkList(llvm::MutableArrayRef<llvm::MachineInstr*>) RegisterCoalescer.cpp:0:0
#12 0x00007fd791da70d5 (anonymous namespace)::RegisterCoalescer::runOnMachineFunction(llvm::MachineFunction&) RegisterCoalescer.cpp:0:0
#13 0x00007fd791bb2a38 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libLLVM-14git.so+0xcdfa38)
#14 0x00007fd7918a12c5 llvm::FPPassManager::runOnFunction(llvm::Function&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libLLVM-14git.so+0x9ce2c5)
#15 0x00007fd7918a1509 llvm::FPPassManager::runOnModule(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libLLVM-14git.so+0x9ce509)
#16 0x00007fd7918a25f2 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libLLVM-14git.so+0x9cf5f2)
#17 0x00007fd7970948a3 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x1bef8a3)
#18 0x00007fd797472353 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x1fcd353)
#19 0x00007fd795e300d9 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x98b0d9)
#20 0x00007fd797470ce8 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x1fcbce8)
#21 0x00007fd797ef89a9 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x2a539a9)
#22 0x00007fd797e8238e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x29dd38e)
#23 0x00007fd797f8c223 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/../lib/libclang-cpp.so.14git+0x2ae7223)
#24 0x000055efe3794127 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/clang-14+0x15127)
#25 0x000055efe3790778 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x000055efe378d361 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/clang-14+0xe361)
#27 0x00007fd790ac9083 __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:342:3
#28 0x000055efe37902ee _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin/clang-14+0x112ee)
clang-14: error: unable to execute command: Aborted
clang-14: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers/clang-2cdc6f2ca62e83fec445114fbbe6276e9ab2a7d0/bin
clang-14: note: diagnostic msg:
********************
%
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 3, 2023
@djolertrk
Copy link
Contributor

I will take a look. Thanks.

@EugeneZelenko EugeneZelenko added llvm:optimizations crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Nov 3, 2023
vvuksanovic added a commit to vvuksanovic/llvm-project that referenced this issue Nov 27, 2023
If a pointer gets recycled while it is already in a work list, it can
cause duplicates in the work lists. In that case the same instruction
may be processed twice. If it is coalesced the first time, processing
it again would read deallocated memory. This is fixed by removing the
first occurrence from the work lists when we detect a pointer was
recycled.

Fixes llvm#71178
DianQK added a commit that referenced this issue Feb 9, 2024
… but erased (#79820)

Fixes #79718. Fixes #71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 9, 2024
… but erased (llvm#79820)

Fixes llvm#79718. Fixes llvm#71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.

(cherry picked from commit 95b14da)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 9, 2024
… but erased (llvm#79820)

Fixes llvm#79718. Fixes llvm#71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.

(cherry picked from commit 95b14da)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
… but erased (llvm#79820)

Fixes llvm#79718. Fixes llvm#71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.

(cherry picked from commit 95b14da)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
… but erased (llvm#79820)

Fixes llvm#79718. Fixes llvm#71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.

(cherry picked from commit 95b14da)
tstellar pushed a commit to tstellar/llvm-project that referenced this issue Feb 14, 2024
… but erased (llvm#79820)

Fixes llvm#79718. Fixes llvm#71178.

The same instructions may exist in an iteration. We cannot immediately
delete instructions in `ErasedInstrs`.

(cherry picked from commit 95b14da)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] llvm:codegen
Projects
None yet
4 participants