Issue 63791
Summary Clang crash: UNREACHABLE executed at /llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:1102!
Labels new issue
Assignees
Reporter shao-hua-li
    Clang at -O2 crash on the following test case.

Compiler explorer: https://godbolt.org/z/cP3G3b1jG

```console
% cat a.c
int b, k, c;
static int j = 4;
static int l = 4;
short m, o;
static int n = -1020499714;
static int *p = &l, *s = &k;
long r;
static long t;
int u() {
  b = b & 3;
  if (b)
    return 4;
  return 8;
}
int w(int e) {
  int f[] = {e, 66, e, e, 9, e};
  int g, h, a = 0, i;
  h = 1;
  for (; h < 41; g++, h *= 2) {
    if (f[g] > 0) {
      a += f[g];
      if (a > 2)
        i = a;
    }
 if (a == 41)
      break;
  }
  return i;
}
static long x(unsigned v) {
  if (v)
    for (;;)
      for (; u() + n + *s - 1020499706 + r;) {
        o = 2;
        for (; w(*s - 41) + n + *s - -1020499635 + o >= 0; o--)
          for (; t <= 2; t++)
 ;
        for (; m;) {
          char *q;
          ++*q++;
 }
      }
  n = 6;
  return 1;
}
void y() {
  int *d = &j;
  s = d;
  c = *p;
  x(c);
}
int main() {}
%
% clang-tk -O2 a.c
Got unexpected user - out of sync with canFreelyInvertAllUsersOf() ?
UNREACHABLE executed at /zdata/shaoli/compilers/ccbuilder-repos/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:1102!
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: /zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name crash_0_reduced.c -mrelocation-model pic -pic-level 2 -pic-is-pie -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 -resource-dir /zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/lib/clang/17 -internal-isystem /zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/lib/clang/17/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 -O2 -fdebug-compilation-dir=/zdata/shaoli/realsmith -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/crash_0_reduced-e1a63c.o -x c work115/work/wrong/crash_0_reduced.c
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x000055e1e9e07b1f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3ba9b1f)
 #1 0x000055e1e9e05274 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f2f28f06420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f2f2895700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f2f28936859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x000055e1e9d5b34e (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3afd34e)
 #6 0x000055e1e992d789 llvm::InstCombinerImpl::freelyInvertAllUsersOf(llvm::Value*, llvm::Value*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36cf789)
 #7 0x000055e1e996bcf1 llvm::InstCombinerImpl::sinkNotIntoLogicalOp(llvm::Instruction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x370dcf1)
 #8 0x000055e1e99763cd llvm::InstCombinerImpl::foldNot(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x37183cd)
 #9 0x000055e1e99827b4 llvm::InstCombinerImpl::visitXor(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x37247b4)
#10 0x000055e1e993f510 llvm::InstCombinerImpl::run() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36e1510)
#11 0x000055e1e9941f1b combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#12 0x000055e1e9942dae llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36e4dae)
#13 0x000055e1ea073e46 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3e15e46)
#14 0x000055e1e769056d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x143256d)
#15 0x000055e1e97b638d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x355838d)
#16 0x000055e1e7674006 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x1416006)
#17 0x000055e1e97b430d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x355630d)
#18 0x000055e1ea084ff6 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) BackendUtil.cpp:0:0
#19 0x000055e1ea088069 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>>) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3e2a069)
#20 0x000055e1eb090a6d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4e32a6d)
#21 0x000055e1ec23c419 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x5fde419)
#22 0x000055e1eb08f228 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4e31228)
#23 0x000055e1ea8d1979 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4673979)
#24 0x000055e1ea856906 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x45f8906)
#25 0x000055e1ea9b6ae6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4758ae6)
#26 0x000055e1e72dcae4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x107eae4)
#27 0x000055e1e72d880a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000055e1e72d9ddc clang_main(int, char**, llvm::ToolContext const&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x107bddc)
#29 0x000055e1e71ee1d5 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0xf901d5)
#30 0x00007f2f28938083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x000055e1e72d35ee _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x10755ee)
clang-tk: error: unable to execute command: Aborted
clang-tk: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 99074aafc31593c9935da483edab1333d6ce5a5b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
%
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to