oydale added a comment.

My understanding of the issue is that clang emits incorrect IR. Without my fix 
and when disabling the assertion mentioned in the commit message by commenting 
it out, llvm-lit gives the following output when executed against the minimal 
test case in the current version of the commit:
  + /home/maestro/llvm/llvm-project/build/bin/clang -cc1 -internal-isystem 
/home/maestro/llvm/llvm-project/build/lib/clang/9.0.0/include -nostdsysteminc 
-emit-obj --std=c++17 -fcxx-exceptions -fexceptions 
/home/maestro/llvm/llvm-project/clang/test/CodeGenCXX/pr40771-ctad-with-lambda-copy-capture.cpp
  Instruction referencing instruction not embedded in a basic block!
    %cleanup.isactive = alloca i1, align 1
    store i1 true, i1* %cleanup.isactive, align 1
  in function __cxx_global_var_init.1
  fatal error: error in backend: Broken function found, compilation aborted!

This is what makes me assume that the IR output is incorrect.

Without my fix and with the assertion still commented out, disabling the LLVM 
verification, and enabling optimizations with -O1, the debug build of clang 
yields a similar crash as what can be observed in release builds such as on 
godbolt:

  ~/llvm/llvm-project/build/bin/clang-9 -cc1 -triple x86_64-pc-linux-gnu 
-emit-obj -disable-free -disable-llvm-verifier -std=c++17 -fexceptions -O1 
-fcxx-exceptions minimal.cpp
  Stack dump:
  0.    Program arguments: /home/maestro/llvm/llvm-project/build/bin/clang-9 
-cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier 
-std=c++17 -fexceptions -O1 -fcxx-exceptions minimal.cpp 
  1.    <eof> parser at end of file
  2.    Per-function optimization
  3.    Running pass 'SROA' on function '@__cxx_global_var_init.1'
   #0 0x00007f2309f7b7a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
   #1 0x00007f2309f7b83a PrintStackTraceSignalHandler(void*) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:555:1
   #2 0x00007f2309f79834 llvm::sys::RunSignalHandlers() 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Signals.cpp:68:20
   #3 0x00007f2309f7b1fd SignalHandler(int) 
/home/maestro/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
   #4 0x00007f230929e4d0 __restore_rt (/usr/lib/libpthread.so.0+0x124d0)
   #5 0x00007f230be28fda llvm::PointerIntPair<llvm::ilist_node_base<true>*, 1u, 
unsigned int, llvm::PointerLikeTypeTraits<llvm::ilist_node_base<true>*>, 
llvm::PointerIntPairInfo<llvm::ilist_node_base<true>*, 1u, 
llvm::PointerLikeTypeTraits<llvm::ilist_node_base<true>*> > 
>::setPointer(llvm::ilist_node_base<true>*) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:63:32
   #6 0x00007f230be267cb 
llvm::ilist_node_base<true>::setPrev(llvm::ilist_node_base<true>*) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_node_base.h:40:75
   #7 0x00007f230be3748b 
llvm::ilist_base<true>::removeImpl(llvm::ilist_node_base<true>&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_base.h:34:5
   #8 0x00007f230be37725 void 
llvm::ilist_base<true>::remove<llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Instruction,
 true, false, void> > 
>(llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Instruction, 
true, false, void> >&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist_base.h:80:64
   #9 0x00007f230be37166 
llvm::simple_ilist<llvm::Instruction>::remove(llvm::Instruction&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/simple_ilist.h:183:77
  #10 0x00007f230be36aa2 
llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction>, 
llvm::SymbolTableListTraits<llvm::Instruction> 
>::remove(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
 true, false, void>, false, false>&) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist.h:253:12
  #11 0x00007f230be35bf1 
llvm::iplist_impl<llvm::simple_ilist<llvm::Instruction>, 
llvm::SymbolTableListTraits<llvm::Instruction> 
>::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction,
 true, false, void>, false, false>) 
/home/maestro/llvm/llvm-project/llvm/include/llvm/ADT/ilist.h:266:5
  #12 0x00007f230bf7bb5d llvm::Instruction::eraseFromParent() 
/home/maestro/llvm/llvm-project/llvm/lib/IR/Instruction.cpp:69:1
  #13 0x00007f230a611a47 
llvm::SROA::deleteDeadInstructions(llvm::SmallPtrSetImpl<llvm::AllocaInst*>&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4520:13
  #14 0x00007f230a611df1 llvm::SROA::runImpl(llvm::Function&, 
llvm::DominatorTree&, llvm::AssumptionCache&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4564:15
  #15 0x00007f230a62979e 
llvm::sroa::SROALegacyPass::runOnFunction(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:4620:31
  #16 0x00007f230bfc820a llvm::FPPassManager::runOnFunction(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1648:20
  #17 0x00007f230bfc7e2c 
llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1585:13
  #18 0x00007f230bfc7a14 
llvm::legacy::FunctionPassManager::run(llvm::Function&) 
/home/maestro/llvm/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1511:1
  #19 0x00007f2307ff5d67 (anonymous 
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, 
std::unique_ptr<llvm::raw_pwrite_stream, 
std::default_delete<llvm::raw_pwrite_stream> >) 
/home/maestro/llvm/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:885:25
  #20 0x00007f2307ffa457 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> >) 
/home/maestro/llvm/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1516:27
  #21 0x00007f230845c506 
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) 
/home/maestro/llvm/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:303:24
  #22 0x00007f2302b1f7c3 clang::ParseAST(clang::Sema&, bool, bool) 
/home/maestro/llvm/llvm-project/clang/lib/Parse/ParseAST.cpp:178:14
  #23 0x00007f2307749f4f clang::ASTFrontendAction::ExecuteAction() 
/home/maestro/llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1041:11
  #24 0x00007f2308458e65 clang::CodeGenAction::ExecuteAction() 
/home/maestro/llvm/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1060:1
  #25 0x00007f23077498b0 clang::FrontendAction::Execute() 
/home/maestro/llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:938:38
  #26 0x00007f23076d1d84 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
/home/maestro/llvm/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:944:42
  #27 0x00007f230736f70f 
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
/home/maestro/llvm/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:291:38
  #28 0x00005583d3c15863 cc1_main(llvm::ArrayRef<char const*>, char const*, 
void*) /home/maestro/llvm/llvm-project/clang/tools/driver/cc1_main.cpp:249:40
  #29 0x00005583d3c0af31 ExecuteCC1Tool(llvm::ArrayRef<char const*>, 
llvm::StringRef) 
/home/maestro/llvm/llvm-project/clang/tools/driver/driver.cpp:309:64
  #30 0x00005583d3c0b60f main 
/home/maestro/llvm/llvm-project/clang/tools/driver/driver.cpp:381:26
  #31 0x00007f2306860ce3 __libc_start_main (/usr/lib/libc.so.6+0x23ce3)
  #32 0x00005583d3c096ee _start 
(/home/maestro/llvm/llvm-project/build/bin/clang-9+0x426ee)
  [1]    23467 segmentation fault (core dumped)  
~/llvm/llvm-project/build/bin/clang-9 -cc1 -triple x86_64-pc-linux-gnu 

With my patch (and the assert not commented out), the test case passes, and 
there is no segfault in the SROA pass either using the command from the latter 
code block. With my patch applied, I'm also able to compile and execute the 
original test input I had with CTAD and lambdas using copy capture and get the 
expected output.

I wholeheartedly agree that there's two distinct issues at play here, one being 
the incorrect IR output from clang and the other being the crash in the SROA 
pass. My patch merely fixes the IR output from clang, making it less likely to 
trigger the crash in the SROA pass. The crash in the SROA pass should also be 
fixed, I personally would prefer to keep that separate from this commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64656/new/

https://reviews.llvm.org/D64656



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to