LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 49218 - clang -O1 causes "PHI node has multiple entries for the same basic block with different incoming values!"
Summary: clang -O1 causes "PHI node has multiple entries for the same basic block with...
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-12.0.0
  Show dependency tree
 
Reported: 2021-02-17 01:10 PST by Haoxin Tu
Modified: 2021-03-02 20:13 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): 356cdabd3a9e f73ba0f3582b


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Haoxin Tu 2021-02-17 01:10:06 PST
Hi all.

This program make clang crash with -O1, and this problem only happens in the current trunk version of clang.

$cat small.c
#include <stdint.h>
int a, b;
int c() {
  int64_t d = b;
  if (d) {
    uint16_t e;
    for (; b;)
    f:
      for (; d;)
      g:
        if (e)
          for (;;)
            ;
    for (;;) {
      int64_t k;
      uint8_t i;
      if (k) {
      m:
        k %= i;
        goto g;
      }
    }
  }
  {
    int16_t j;
    for (;; d++) {
      int32_t l;
      if (j)
        goto f;
      if (a) {
        for (; d;)
          goto m;
        if (0 / 0)
          return a;
        for (;;)
          ;
      }
    }
  }
}

$clang -w -c -O1 small.c
PHI node has multiple entries for the same basic block with different incoming values!
  %k.2.ph = phi i64 [ poison, %for.cond9.preheader ], [ poison, %cleanup29 ], [ undef, %cleanup29 ], [ %k.0, %for.cond ]
label %cleanup29
i64 undef
i64 poison
in function c
fatal error: error in backend: Broken function found, compilation aborted!
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: clang -c -w -O1 small.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'small.c'.
4.	Running pass 'Module Verifier' on function '@c'
 #0 0x000055a24fc7567c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x33de67c)
 #1 0x000055a24fc732b4 llvm::sys::RunSignalHandlers() (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x33dc2b4)
 #2 0x000055a24fc7354b llvm::sys::CleanupOnSignal(unsigned long) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x33dc54b)
 #3 0x000055a24fbd26bf llvm::CrashRecoveryContext::HandleExit(int) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x333b6bf)
 #4 0x000055a24fc6b97e llvm::sys::Process::Exit(int, bool) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x33d497e)
 #5 0x000055a24d8ddf05 LLVMErrorHandler(void*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) cc1_main.cpp:0:0
 #6 0x000055a24fbda439 llvm::report_fatal_error(llvm::Twine const&, bool) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3343439)
 #7 0x000055a24fbda578 (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3343578)
 #8 0x000055a24f4c6083 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) Verifier.cpp:0:0
 #9 0x000055a24f441e14 llvm::FPPassManager::runOnFunction(llvm::Function&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x2baae14)
#10 0x000055a24f442959 llvm::FPPassManager::runOnModule(llvm::Module&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x2bab959)
#11 0x000055a24f441731 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x2baa731)
#12 0x000055a24ff30de0 (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#13 0x000055a24ff33f65 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x369cf65)
#14 0x000055a250b90f6b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x42f9f6b)
#15 0x000055a2516e4059 clang::ParseAST(clang::Sema&, bool, bool) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x4e4d059)
#16 0x000055a250b8fce8 clang::CodeGenAction::ExecuteAction() (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x42f8ce8)
#17 0x000055a25052df19 clang::FrontendAction::Execute() (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3c96f19)
#18 0x000055a2504c4dc9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3c2ddc9)
#19 0x000055a2505f4fa0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3d5dfa0)
#20 0x000055a24d8df054 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x1048054)
#21 0x000055a24d8db557 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#22 0x000055a250384745 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::'lambda'()>(long) Job.cpp:0:0
#23 0x000055a24fbd2592 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x333b592)
#24 0x000055a250385a8c clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (.part.185) Job.cpp:0:0
#25 0x000055a25035cfa9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3ac5fa9)
#26 0x000055a25035e157 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3ac7157)
#27 0x000055a2503704a9 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x3ad94a9)
#28 0x000055a24d80b955 main (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0xf74955)
#29 0x00007fbbac038bf7 __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0
#30 0x000055a24d8dafda _start (/media/haoxin/SeagateData/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin/clang-13+0x1043fda)
clang-13: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 13.0.0 (https://github.com/llvm/llvm-project 22f00f61dd5483a9fdaed3b7592d392c23b3646a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/dut-research/compilers/llvm-project/build-20210216/bin
clang-13: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /tmp/small-42adaf.c
clang-13: note: diagnostic msg: /tmp/small-42adaf.sh
clang-13: note: diagnostic msg: 

********************


Thanks.
Haoxin
Comment 1 Sanjay Patel 2021-02-25 13:33:52 PST
The bug occurs via -simplifycfg with a late optimization option (so it doesn't happen early in the pipeline). 

Proposal to avoid the crash:
https://reviews.llvm.org/D97495
Comment 2 Sanjay Patel 2021-02-28 06:47:30 PST
https://reviews.llvm.org/rG356cdabd3a9e
Comment 3 Roman Lebedev 2021-02-28 08:08:41 PST
Presumably it would be nice to have this in 12.x ?
Comment 4 Sanjay Patel 2021-02-28 08:23:54 PST
(In reply to Roman Lebedev from comment #3)
> Presumably it would be nice to have this in 12.x ?

Yes, reopening. 

I'm not sure where we are in the release process, but this would be a regression for 12.0 based on trying it on godbolt:
https://godbolt.org/z/4TWbsP
Comment 5 Tom Stellard 2021-03-02 20:13:27 PST
Merged: f73ba0f3582b