Skip to content

Clang crash: Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed. #68745

Closed
@shao-hua-li

Description

@shao-hua-li

Clang at -O2/3 crashed.

Bisected to 5d8fb47, which was committed by @elhewaty

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

% cat a.c
int a, e, g;
int *b;
static int c = 1;
static int *d = &c;
static int f;
void h() {
  e = 0;
  for (; e < 40; e++) {
    int i;
    f = 0;
    for (; (*d == 0) + *d -1 + f == 2; ++f)
      b = &i;
  }
  int **j = &d;
  if (a)
    for (;;) {
      g ^= 2;
      *j = 0;
    }
  c = 0;
}
int main() {}
%
% clang -O2 a.c
clang: /root/llvm-project/llvm/lib/IR/Value.cpp:508: void llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' 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 -O2 <source>
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x0000000003724048 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3724048)
 #1 0x0000000003721d0c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3721d0c)
 #2 0x000000000366a8b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fac0197f420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fac0144200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fac01421859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fac01421729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fac01432fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00000000031144e4 llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x31144e4)
 #9 0x0000000000c4b6f1 llvm::InstCombiner::replaceInstUsesWith(llvm::Instruction&, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc4b6f1)
#10 0x00000000032fa0a9 llvm::InstCombinerImpl::foldICmpAddConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x32fa0a9)
#11 0x0000000003315288 llvm::InstCombinerImpl::foldICmpBinOpWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3315288)
#12 0x00000000033154be llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x33154be)
#13 0x000000000331a882 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x331a882)
#14 0x0000000003284ee0 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3284ee0)
#15 0x00000000032866a2 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, bool, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#16 0x00000000032875aa llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x32875aa)
#17 0x000000000398518e llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x398518e)
#18 0x0000000000fb876d 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+0xfb876d)
#19 0x00000000030ee97e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30ee97e)
#20 0x0000000000f9cc3e 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+0xf9cc3e)
#21 0x00000000030ec97c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30ec97c)
#22 0x00000000039951d0 (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
#23 0x00000000039985b6 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) BackendUtil.cpp:0:0
#24 0x0000000003998bc9 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+0x3998bc9)
#25 0x000000000498e6af clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498e6af)
#26 0x0000000005e8b589 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5e8b589)
#27 0x000000000498d898 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498d898)
#28 0x00000000041f2209 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41f2209)
#29 0x00000000041736de clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41736de)
#30 0x00000000042d131e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42d131e)
#31 0x0000000000bef046 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbef046)
#32 0x0000000000be690a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#33 0x0000000003fcf8a9 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
#34 0x000000000366ad64 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x366ad64)
#35 0x0000000003fcfe9f 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
#36 0x0000000003f98065 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f98065)
#37 0x0000000003f98acd 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+0x3f98acd)
#38 0x0000000003fa09f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fa09f5)
#39 0x0000000000bec4ec clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbec4ec)
#40 0x0000000000ae6a11 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xae6a11)
#41 0x00007fac01423083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#42 0x0000000000be63ee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbe63ee)
%

Metadata

Metadata

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]llvm:instcombine

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions