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

An assertion failure in TurnSwitchRangeIntoICmp #53208

Closed
kazutakahirata opened this issue Jan 14, 2022 · 1 comment
Closed

An assertion failure in TurnSwitchRangeIntoICmp #53208

kazutakahirata opened this issue Jan 14, 2022 · 1 comment

Comments

@kazutakahirata
Copy link
Contributor

The following test case triggers an assertion failure in TurnSwitchRangeIntoICmp.

For the assertion failure to occur, we must have null PHI arguments and nonnull dereferenceable(4). I don't know how valid this combination is. The test case comes from the LLVM source code compiled with AutoFDO+ThinLTO. Presumably, some inlining is partly responsible for creating this strange combination because the crash does not occur with the baseline build without AutoFDO or ThinLTO.

$ reduced.ll
define void @0(i8 %sw, i32* %p0) {
  switch i8 %sw, label %group3 [
    i8 0, label %group1
    i8 1, label %group1
    i8 2, label %group1
    i8 3, label %group1
    i8 11, label %group1
    i8 12, label %group1
    i8 13, label %group1
    i8 7, label %group1
    i8 17, label %group1
    i8 14, label %group1
    i8 15, label %group1
    i8 4, label %group2
    i8 5, label %group2
    i8 6, label %group2
    i8 8, label %group2
    i8 9, label %group2
    i8 10, label %group2
  ]

group1:
  br label %exit

group2:
  br label %exit

group3:
  br label %exit

exit:
  %phi = phi i32* [ null, %group3 ], [ %p0, %group2 ], [ null, %group1 ]
  call void @bar(i32* %phi)
  ret void
}

declare void @bar(i32* nonnull dereferenceable(4))
$ ~/rel/bin/clang -O1 -c reduced.ll
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
clang: /home/kazu/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:4850: bool (anonymous namespace)::SimplifyCFGOpt::TurnSwitchRangeIntoICmp(llvm::SwitchInst *, IRBuilder<> &): Assertion `DestA && DestB && "Single-destination switch should have been folded."' 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: /home/kazu/rel/bin/clang -O1 -c reduced.ll
1.	Optimizer
 #0 0x00007fdd94cfcb73 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/kazu/rel/bin/../lib/libLLVMSupport.so.14git+0x1b6b73)
 #1 0x00007fdd94cfa94e llvm::sys::RunSignalHandlers() (/home/kazu/rel/bin/../lib/libLLVMSupport.so.14git+0x1b494e)
 #2 0x00007fdd94c18ef3 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #3 0x00007fdd94c1909e CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x00007fdd98a43200 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13200)
 #5 0x00007fdd94650891 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:50:1
 #6 0x00007fdd9463a536 abort ./stdlib/abort.c:81:7
 #7 0x00007fdd9463a41f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #8 0x00007fdd9463a41f _nl_load_domain ./intl/loadmsgcat.c:970:34
 #9 0x00007fdd94649212 (/lib/x86_64-linux-gnu/libc.so.6+0x35212)
#10 0x00007fdd963c7d66 (anonymous namespace)::SimplifyCFGOpt::simplifySwitch(llvm::SwitchInst*, llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&) SimplifyCFG.cpp:0:0
#11 0x00007fdd963b98d6 (anonymous namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) SimplifyCFG.cpp:0:0
#12 0x00007fdd963b8554 llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef<llvm::WeakVH>) (/home/kazu/rel/bin/../lib/libLLVMTransformUtils.so.14git+0x1be554)
#13 0x00007fdd969d20ea iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#14 0x00007fdd969d1b10 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#15 0x00007fdd969d06cd simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) SimplifyCFGPass.cpp:0:0
#16 0x00007fdd969d043e llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/kazu/rel/bin/../lib/libLLVMScalarOpts.so.14git+0x33943e)
#17 0x00007fdd9372917d llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/kazu/rel/bin/../lib/../lib/libLLVMPasses.so.14git+0x10717d)
#18 0x00007fdd957b83e1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/kazu/rel/bin/../lib/libLLVMCore.so.14git+0x2863e1)
#19 0x00007fdd9835fc2d 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>&) (/home/kazu/rel/bin/../lib/libclangCodeGen.so.14git+0xe7c2d)
#20 0x00007fdd957bd07b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/kazu/rel/bin/../lib/libLLVMCore.so.14git+0x28b07b)
#21 0x00007fdd98361d2d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/kazu/rel/bin/../lib/libclangCodeGen.so.14git+0xe9d2d)
#22 0x00007fdd957b6e24 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/kazu/rel/bin/../lib/libLLVMCore.so.14git+0x284e24)
#23 0x00007fdd98359e61 (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
#24 0x00007fdd9834da55 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> >) (/home/kazu/rel/bin/../lib/libclangCodeGen.so.14git+0xd5a55)
#25 0x00007fdd986e8e7e clang::CodeGenAction::ExecuteAction() (/home/kazu/rel/bin/../lib/libclangCodeGen.so.14git+0x470e7e)
#26 0x00007fdd971d1030 clang::FrontendAction::Execute() (/home/kazu/rel/bin/../lib/libclangFrontend.so.14git+0x13c030)
#27 0x00007fdd9714297f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/kazu/rel/bin/../lib/libclangFrontend.so.14git+0xad97f)
#28 0x00007fdd98a2b4a3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/kazu/rel/bin/../lib/libclangFrontendTool.so.14git+0x44a3)
#29 0x0000000000413841 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/kazu/rel/bin/clang+0x413841)
#30 0x0000000000411240 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#31 0x00007fdd96e8d1c2 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::$_1>(long) Job.cpp:0:0
#32 0x00007fdd94c18e07 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/kazu/rel/bin/../lib/libLLVMSupport.so.14git+0xd2e07)
#33 0x00007fdd96e8cc00 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/home/kazu/rel/bin/../lib/libclangDriver.so.14git+0xb4c00)
#34 0x00007fdd96e54ee8 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/kazu/rel/bin/../lib/libclangDriver.so.14git+0x7cee8)
#35 0x00007fdd96e551b7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/home/kazu/rel/bin/../lib/libclangDriver.so.14git+0x7d1b7)
#36 0x00007fdd96e70171 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/home/kazu/rel/bin/../lib/libclangDriver.so.14git+0x98171)
#37 0x0000000000410811 main (/home/kazu/rel/bin/clang+0x410811)
#38 0x00007fdd9463b7ed __libc_start_main ./csu/../csu/libc-start.c:332:16
#39 0x000000000040e00a _start (/home/kazu/rel/bin/clang+0x40e00a)
clang-14: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 14.0.0 (https://github.com/llvm/llvm-project.git bfd0cbd4eb9fef85da96bb799038ba49a52d08f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/kazu/rel/bin
clang-14: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
zmodem pushed a commit that referenced this issue Jun 16, 2022
…le destination

TurnSwitchRangeIntoICmp crashes when given a switch with a default
destination of unreachable
Addresses issue #53208
#53208

Differential revision: https://reviews.llvm.org/D127712
@aeubanks
Copy link
Contributor

Fixed with https://reviews.llvm.org/D127712

mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
…le destination

TurnSwitchRangeIntoICmp crashes when given a switch with a default
destination of unreachable
Addresses issue #53208
llvm/llvm-project#53208

Differential revision: https://reviews.llvm.org/D127712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants