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

[18 regression] PHINode should have one entry for each predecessor of its parent basic block! #85552

Open
berolinux opened this issue Mar 16, 2024 · 4 comments

Comments

@berolinux
Copy link

$ clang++ -o test.o -c test.cc -O1
PHINode should have one entry for each predecessor of its parent basic block!
  %2 = phi ptr [ poison, <null operand!> ], [ null, %dynamic_cast.null ]
fatal error: error in backend: Broken module found, compilation aborted!
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: clang++ -Wno-unused-value -o test.o -c test.cc -O1
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x00007f390239a576 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib64/libLLVM.so.18.1+0x459a576)
 #1 0x00007f39023991ea llvm::sys::RunSignalHandlers() (/usr/lib64/libLLVM.so.18.1+0x45991ea)
 #2 0x00007f39022b119d (/usr/lib64/libLLVM.so.18.1+0x44b119d)
 #3 0x00007f39022b10ad llvm::CrashRecoveryContext::HandleExit(int) (/usr/lib64/libLLVM.so.18.1+0x44b10ad)
 #4 0x00007f39023928bb (/usr/lib64/libLLVM.so.18.1+0x45928bb)
 #5 0x0000556cde35771a (/usr/bin/clang-18+0x1771a)
 #6 0x00007f39022c7747 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib64/libLLVM.so.18.1+0x44c7747)
 #7 0x00007f39022c7606 (/usr/lib64/libLLVM.so.18.1+0x44c7606)
 #8 0x00007f39026f6c17 (/usr/lib64/libLLVM.so.18.1+0x48f6c17)
 #9 0x00007f390a7a0c8f (/usr/lib64/libclang-cpp.so.18.1+0x2da0c8f)
#10 0x00007f3902685407 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib64/libLLVM.so.18.1+0x4885407)
#11 0x00007f390a79345a (/usr/lib64/libclang-cpp.so.18.1+0x2d9345a)
#12 0x00007f390a78bd7b 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>>, clang::BackendConsumer*) (/usr/lib64/libclang-cpp.so.18.1+0x2d8bd7b)
#13 0x00007f390ac1a68f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib64/libclang-cpp.so.18.1+0x321a68f)
#14 0x00007f3909245246 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib64/libclang-cpp.so.18.1+0x1845246)
#15 0x00007f390b78285b clang::FrontendAction::Execute() (/usr/lib64/libclang-cpp.so.18.1+0x3d8285b)
#16 0x00007f390b6e6b09 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib64/libclang-cpp.so.18.1+0x3ce6b09)
#17 0x00007f390b801daa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib64/libclang-cpp.so.18.1+0x3e01daa)
#18 0x0000556cde357036 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-18+0x17036)
#19 0x0000556cde352cef (/usr/bin/clang-18+0x12cef)
#20 0x00007f390b2c236b (/usr/lib64/libclang-cpp.so.18.1+0x38c236b)
#21 0x00007f39022b1033 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib64/libLLVM.so.18.1+0x44b1033)
#22 0x00007f390b2c2253 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib64/libclang-cpp.so.18.1+0x38c2253)
#23 0x00007f390b27aec7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib64/libclang-cpp.so.18.1+0x387aec7)
#24 0x00007f390b27b3de clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib64/libclang-cpp.so.18.1+0x387b3de)
#25 0x00007f390b2bd91f clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib64/libclang-cpp.so.18.1+0x38bd91f)
#26 0x0000556cde352265 clang_main(int, char**, llvm::ToolContext const&) (/usr/bin/clang-18+0x12265)
#27 0x0000556cde361f36 main (/usr/bin/clang-18+0x21f36)
#28 0x00007f38fd83dc0a (/usr/lib64/libc.so.6+0x29c0a)
#29 0x00007f38fd83dcc5 __libc_start_main (/usr/lib64/libc.so.6+0x29cc5)
#30 0x0000556cde34ee71 _start (/usr/bin/clang-18+0xee71)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)

Reduced test case:

struct a {
  virtual void b();
};
struct c {
  a *operator*();
  bool operator!=(c);
  void operator++();
  c begin();
  c end();
} d;
template <typename e> void g() {
  for (a *f : d)
    dynamic_cast<e *>(f);
}
struct h final : protected a {};
void i() { g<h>; }
@Sirraide
Copy link
Member

The issue appears to still exist on trunk.

@Sirraide
Copy link
Member

At a glance, the IR that codegen produces for -O0 at least looks fine, so this is probably an LLVM bug.

@dtcxzyw
Copy link
Member

dtcxzyw commented Mar 17, 2024

This is a clang codegen bug.

*** IR Dump At Start ***
; ModuleID = 'test.cpp'
source_filename = "test.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.c = type { i8 }

$_Z1gI1hEvv = comdat any

@d = dso_local global %struct.c zeroinitializer, align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z1iv() #0 {
entry:
  ret void
}

; Function Attrs: mustprogress uwtable
define linkonce_odr dso_local void @_Z1gI1hEvv() #1 comdat {
entry:
  %__range1 = alloca ptr, align 8
  %__begin1 = alloca %struct.c, align 1
  %undef.agg.tmp = alloca %struct.c, align 1
  %__end1 = alloca %struct.c, align 1
  %undef.agg.tmp1 = alloca %struct.c, align 1
  %agg.tmp = alloca %struct.c, align 1
  %f = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %__range1) #4
  store ptr @d, ptr %__range1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %__begin1) #4
  call void @_ZN1c5beginEv(ptr noundef nonnull align 1 dereferenceable(1) @d)
  call void @llvm.lifetime.start.p0(i64 1, ptr %__end1) #4
  call void @_ZN1c3endEv(ptr noundef nonnull align 1 dereferenceable(1) @d)
  br label %for.cond

for.cond:                                         ; preds = %for.inc, %entry
  %call = call noundef zeroext i1 @_ZN1cneES_(ptr noundef nonnull align 1 dereferenceable(1) %__begin1)
  br i1 %call, label %for.body, label %for.cond.cleanup

for.cond.cleanup:                                 ; preds = %for.cond
  call void @llvm.lifetime.end.p0(i64 1, ptr %__end1) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %__begin1) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %__range1) #4
  br label %for.end

for.body:                                         ; preds = %for.cond
  call void @llvm.lifetime.start.p0(i64 8, ptr %f) #4
  %call2 = call noundef ptr @_ZN1cdeEv(ptr noundef nonnull align 1 dereferenceable(1) %__begin1)
  store ptr %call2, ptr %f, align 8, !tbaa !5
  %0 = load ptr, ptr %f, align 8, !tbaa !5
  %1 = icmp eq ptr %0, null
  br i1 %1, label %dynamic_cast.null, label %dynamic_cast.notnull

dynamic_cast.notnull:                             ; preds = %for.body
  br label %dynamic_cast.null

dynamic_cast.null:                                ; preds = %dynamic_cast.notnull, %for.body
  br label %dynamic_cast.end

dynamic_cast.end:                                 ; preds = %dynamic_cast.null
  %2 = phi ptr [ poison, <null operand!> ], [ null, %dynamic_cast.null ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %f) #4
  br label %for.inc

for.inc:                                          ; preds = %dynamic_cast.end
  call void @_ZN1cppEv(ptr noundef nonnull align 1 dereferenceable(1) %__begin1)
  br label %for.cond

for.end:                                          ; preds = %for.cond.cleanup
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare void @_ZN1c5beginEv(ptr noundef nonnull align 1 dereferenceable(1)) #3

declare void @_ZN1c3endEv(ptr noundef nonnull align 1 dereferenceable(1)) #3

declare noundef zeroext i1 @_ZN1cneES_(ptr noundef nonnull align 1 dereferenceable(1)) #3

declare noundef ptr @_ZN1cdeEv(ptr noundef nonnull align 1 dereferenceable(1)) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare void @_ZN1cppEv(ptr noundef nonnull align 1 dereferenceable(1)) #3

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.0.0git"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
PHINode should have one entry for each predecessor of its parent basic block!
  %2 = phi ptr [ poison, <null operand!> ], [ null, %dynamic_cast.null ]
fatal error: error in backend: Broken module found, compilation aborted!

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 17, 2024

@llvm/issue-subscribers-clang-codegen

Author: Bernhard Rosenkraenzer (berolinux)

``` $ clang++ -o test.o -c test.cc -O1 PHINode should have one entry for each predecessor of its parent basic block! %2 = phi ptr [ poison, <null operand!> ], [ null, %dynamic_cast.null ] fatal error: error in backend: Broken module found, compilation aborted! 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: clang++ -Wno-unused-value -o test.o -c test.cc -O1 1. <eof> parser at end of file 2. Optimizer #0 0x00007f390239a576 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib64/libLLVM.so.18.1+0x459a576) #1 0x00007f39023991ea llvm::sys::RunSignalHandlers() (/usr/lib64/libLLVM.so.18.1+0x45991ea) #2 0x00007f39022b119d (/usr/lib64/libLLVM.so.18.1+0x44b119d) #3 0x00007f39022b10ad llvm::CrashRecoveryContext::HandleExit(int) (/usr/lib64/libLLVM.so.18.1+0x44b10ad) #4 0x00007f39023928bb (/usr/lib64/libLLVM.so.18.1+0x45928bb) #5 0x0000556cde35771a (/usr/bin/clang-18+0x1771a) #6 0x00007f39022c7747 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib64/libLLVM.so.18.1+0x44c7747) #7 0x00007f39022c7606 (/usr/lib64/libLLVM.so.18.1+0x44c7606) #8 0x00007f39026f6c17 (/usr/lib64/libLLVM.so.18.1+0x48f6c17) #9 0x00007f390a7a0c8f (/usr/lib64/libclang-cpp.so.18.1+0x2da0c8f) #10 0x00007f3902685407 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib64/libLLVM.so.18.1+0x4885407) #11 0x00007f390a79345a (/usr/lib64/libclang-cpp.so.18.1+0x2d9345a) #12 0x00007f390a78bd7b 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>>, clang::BackendConsumer*) (/usr/lib64/libclang-cpp.so.18.1+0x2d8bd7b) #13 0x00007f390ac1a68f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib64/libclang-cpp.so.18.1+0x321a68f) #14 0x00007f3909245246 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib64/libclang-cpp.so.18.1+0x1845246) #15 0x00007f390b78285b clang::FrontendAction::Execute() (/usr/lib64/libclang-cpp.so.18.1+0x3d8285b) #16 0x00007f390b6e6b09 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib64/libclang-cpp.so.18.1+0x3ce6b09) #17 0x00007f390b801daa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib64/libclang-cpp.so.18.1+0x3e01daa) #18 0x0000556cde357036 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-18+0x17036) #19 0x0000556cde352cef (/usr/bin/clang-18+0x12cef) #20 0x00007f390b2c236b (/usr/lib64/libclang-cpp.so.18.1+0x38c236b) #21 0x00007f39022b1033 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib64/libLLVM.so.18.1+0x44b1033) #22 0x00007f390b2c2253 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/lib64/libclang-cpp.so.18.1+0x38c2253) #23 0x00007f390b27aec7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib64/libclang-cpp.so.18.1+0x387aec7) #24 0x00007f390b27b3de clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/lib64/libclang-cpp.so.18.1+0x387b3de) #25 0x00007f390b2bd91f clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/lib64/libclang-cpp.so.18.1+0x38bd91f) #26 0x0000556cde352265 clang_main(int, char**, llvm::ToolContext const&) (/usr/bin/clang-18+0x12265) #27 0x0000556cde361f36 main (/usr/bin/clang-18+0x21f36) #28 0x00007f38fd83dc0a (/usr/lib64/libc.so.6+0x29c0a) #29 0x00007f38fd83dcc5 __libc_start_main (/usr/lib64/libc.so.6+0x29cc5) #30 0x0000556cde34ee71 _start (/usr/bin/clang-18+0xee71) clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation) ```

Reduced test case:

struct a {
  virtual void b();
};
struct c {
  a *operator*();
  bool operator!=(c);
  void operator++();
  c begin();
  c end();
} d;
template &lt;typename e&gt; void g() {
  for (a *f : d)
    dynamic_cast&lt;e *&gt;(f);
}
struct h final : protected a {};
void i() { g&lt;h&gt;; }

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

4 participants