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

clang -O1 causes "PHI node has multiple entries for the same basic block with different incoming values!" #48562

Closed
haoxintu opened this issue Feb 17, 2021 · 5 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@haoxintu
Copy link

Bugzilla Link 49218
Resolution FIXED
Resolved on Mar 02, 2021 20:13
Version trunk
OS Linux
Blocks #48246
CC @LebedevRI,@rotateright
Fixed by commit(s) 356cdab f73ba0f

Extended Description

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. 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, std::allocator > 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_deletellvm::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_deletellvm::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::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, 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::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, 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 22f00f6)
    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

@rotateright
Copy link
Contributor

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

@rotateright
Copy link
Contributor

@LebedevRI
Copy link
Member

Presumably it would be nice to have this in 12.x ?

@rotateright
Copy link
Contributor

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

@tstellar
Copy link
Collaborator

tstellar commented Mar 3, 2021

Merged: f73ba0f

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

4 participants