llvm / llvm-project

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

`clang-17`: Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' failed. #63762

Open wierton opened 1 year ago

wierton commented 1 year ago

Below is the testing program:

#define C(a, b) if (a > b) return; if (a < b)  return;

#define C4(x, b) C((x)[0], b) C((x)[1], b) C((x)[2], b) C((x)[3], b)
#define C16(x, y) C4(x, (y)[0]) C4(x, (y)[1]) C4(x, (y)[2]) C4(x, (y)[3])
#define C64(x, y) C16(x, y) C16(x + 4, y) C16(x + 8, y) C16(x + 12, y)
#define C256(x, y) C64(x, y) C64(x, y + 4) C64(x, y + 8) C64(x, y + 12)
#define C1024(x, y) C256(x, y) C256(x + 16, y) C256(x + 32, y) C256(x + 48, y)

void foo(int x[64], int y[64]) {
  C1024(x, y);
}

When compiling it using Clang with option clang-17 -O1 small.c, Clang triggers an assertion failure:

clang: /root/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:240: bool iterativelySimplifyCFG(llvm::Function&, const llvm::TargetTransformInfo&, llvm::DomTreeUpdater*, const llvm::SimplifyCFGOptions&): Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O1 <source>
1.  <eof> parser at end of file
2.  Optimizer
 #0 0x00005608a752423f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c4223f)
 #1 0x00005608a7521fac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c3ffac)
 #2 0x00005608a746c608 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fd080814420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fd0802e100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fd0802c0859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fd0802c0729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fd0802d1fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005608a74015b4 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
 #9 0x00005608a7402cf0 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#10 0x00005608a7403495 simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#11 0x00005608a740362a llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b2162a)
#12 0x00005608a555f7c6 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1c7d7c6)
#13 0x00005608a4da8c4d 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>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x14c6c4d)
#14 0x00005608a6ed2acd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35f0acd)
#15 0x00005608a4d8c476 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x14aa476)
#16 0x00005608a6ed0a4d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35eea4d)
#17 0x00005608a77a1837 (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
#18 0x00005608a77a4899 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>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ec2899)
#19 0x00005608a87ad6fd clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ecb6fd)
#20 0x00005608a9cd7279 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x63f5279)
#21 0x00005608a87abeb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ec9eb8)
#22 0x00005608a7fee2f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x470c2f9)
#23 0x00005608a7f735d6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46915d6)
#24 0x00005608a80d3646 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47f1646)
#25 0x00005608a49f48b4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11128b4)
#26 0x00005608a49f05da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00005608a7dcd53d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#28 0x00005608a746cb10 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b8ab10)
#29 0x00005608a7dcdb5f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#30 0x00005608a7d9473c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b273c)
#31 0x00005608a7d951cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b31cd)
#32 0x00005608a7d9d2ad clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44bb2ad)
#33 0x00005608a49f2b2a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1110b2a)
#34 0x00005608a48f8625 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1016625)
#35 0x00007fd0802c2083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#36 0x00005608a49eb3be _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11093be)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)

The version of testing clang (associated with 9e362e5e3fe0b7f85160c3a06e9c646e1c75e8e0):

clang version 17.0.0 (https://github.com/llvm/llvm-project.git 9e362e5e3fe0b7f85160c3a06e9c646e1c75e8e0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin

The behavior mentioned above can be verified at link https://gcc.godbolt.org/z/54f6vhhKq

jshtuazon2 commented 1 year ago

Below is the testing program:

#define C(a, b) if (a > b) return; if (a < b)  return;

#define C4(x, b) C((x)[0], b) C((x)[1], b) C((x)[2], b) C((x)[3], b)
#define C16(x, y) C4(x, (y)[0]) C4(x, (y)[1]) C4(x, (y)[2]) C4(x, (y)[3])
#define C64(x, y) C16(x, y) C16(x + 4, y) C16(x + 8, y) C16(x + 12, y)
#define C256(x, y) C64(x, y) C64(x, y + 4) C64(x, y + 8) C64(x, y + 12)
#define C1024(x, y) C256(x, y) C256(x + 16, y) C256(x + 32, y) C256(x + 48, y)

void foo(int x[64], int y[64]) {
  C1024(x, y);
}

When compiling it using Clang with option clang-17 -O1 small.c, Clang triggers an assertion failure:

clang: /root/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:240: bool iterativelySimplifyCFG(llvm::Function&, const llvm::TargetTransformInfo&, llvm::DomTreeUpdater*, const llvm::SimplifyCFGOptions&): Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O1 <source>
1.    <eof> parser at end of file
2.    Optimizer
 #0 0x00005608a752423f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c4223f)
 #1 0x00005608a7521fac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c3ffac)
 #2 0x00005608a746c608 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fd080814420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fd0802e100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fd0802c0859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fd0802c0729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fd0802d1fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005608a74015b4 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
 #9 0x00005608a7402cf0 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#10 0x00005608a7403495 simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#11 0x00005608a740362a llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b2162a)
#12 0x00005608a555f7c6 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1c7d7c6)
#13 0x00005608a4da8c4d 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>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x14c6c4d)
#14 0x00005608a6ed2acd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35f0acd)
#15 0x00005608a4d8c476 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x14aa476)
#16 0x00005608a6ed0a4d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35eea4d)
#17 0x00005608a77a1837 (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
#18 0x00005608a77a4899 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>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ec2899)
#19 0x00005608a87ad6fd clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ecb6fd)
#20 0x00005608a9cd7279 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x63f5279)
#21 0x00005608a87abeb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ec9eb8)
#22 0x00005608a7fee2f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x470c2f9)
#23 0x00005608a7f735d6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46915d6)
#24 0x00005608a80d3646 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47f1646)
#25 0x00005608a49f48b4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11128b4)
#26 0x00005608a49f05da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00005608a7dcd53d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#28 0x00005608a746cb10 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b8ab10)
#29 0x00005608a7dcdb5f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#30 0x00005608a7d9473c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b273c)
#31 0x00005608a7d951cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b31cd)
#32 0x00005608a7d9d2ad clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44bb2ad)
#33 0x00005608a49f2b2a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1110b2a)
#34 0x00005608a48f8625 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1016625)
#35 0x00007fd0802c2083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#36 0x00005608a49eb3be _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11093be)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)

The version of testing clang (associated with 9e362e5):

clang version 17.0.0 (https://github.com/llvm/llvm-project.git 9e362e5e3fe0b7f85160c3a06e9c646e1c75e8e0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin

The behavior mentioned above can be verified at link https://gcc.godbolt.org/z/54f6vhhKq