<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64171>64171</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang][ASTImporter] Implicit ctors with definition not merged could lead to crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          danix800
      </td>
    </tr>
</table>

<pre>
    When the first snippet
```
        struct A {
          A() : m() {}
          int m;
        };

 A foo() { A a; return a; }
        A bar() { return {}; }
```
is merged into the second one
```
        struct A {
          A() : m() {}
          int m;
        };
        A baz() { return {}; }
```
then dumping the `To` context crashes
```
#0 0x00007f2b311fcd1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:602:11
 #1 0x00007f2b311fcecb PrintStackTraceSignalHandler(void*) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:675:1
 #2 0x00007f2b311fb436 llvm::sys::RunSignalHandlers() /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Signals.cpp:104:5
 #3 0x00007f2b311fd6e5 SignalHandler(int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f2b30c5af90 (/lib/x86_64-linux-gnu/libc.so.6+0x3bf90)
 #5 0x00007f2b32b5fbf5 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::VisitFunctionDecl(clang::FunctionDecl const*) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:437:26
 #6 0x00007f2b32b5fced clang::declvisitor::Base<llvm::make_const_ptr, clang::ASTDumper, void>::VisitCXXMethodDecl(clang::CXXMethodDecl const*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/DeclNodes.inc:443:1
 #7 0x00007f2b32b5fd1d clang::declvisitor::Base<llvm::make_const_ptr, clang::ASTDumper, void>::VisitCXXConstructorDecl(clang::CXXConstructorDecl const*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/DeclNodes.inc:447:1
 #8 0x00007f2b32b5e493 clang::declvisitor::Base<llvm::make_const_ptr, clang::ASTDumper, void>::Visit(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/DeclNodes.inc:447:1
 #9 0x00007f2b32b5ddd5 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()::operator()() const /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:97:34
#10 0x00007f2b32b752c9 void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)::operator()(bool) const /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/TextNodeDumper.h:0:7
#11 0x00007f2b32b75156 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'() std::__invoke_impl<void, void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)&, bool>(std::__invoke_other, void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:61:7
#12 0x00007f2b32b750f2 std::enable_if<is_invocable_r_v<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'(), void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)&, bool>, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>::type std::__invoke_r<void, void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)&, bool>(void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/invoke.h:117:5
#13 0x00007f2b32b74f82 std::_Function_handler<void (bool), void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'())::'lambda'(bool)>::_M_invoke(std::_Any_data const&, bool&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:290:2
#14 0x00007f2b32b5cca9 std::function<void (bool)>::operator()(bool) const /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/std_function.h:591:2
#15 0x00007f2b32b5dd2a void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/TextNodeDumper.h:118:24
#16 0x00007f2b32b5db75 void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/TextNodeDumper.h:52:5
#17 0x00007f2b32b5b956 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:120:3
#18 0x00007f2b32b5e925 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::dumpDeclContext(clang::DeclContext const*) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:297:24
#19 0x00007f2b32b5df17 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()::operator()() const /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:118:7
#20 0x00007f2b32b5dbfe void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(llvm::StringRef, clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/TextNodeDumper.h:0:7
#21 0x00007f2b32b5db75 void clang::TextTreeStructure::AddChild<clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()>(clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*)::'lambda'()) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/TextNodeDumper.h:52:5
#22 0x00007f2b32b5b956 clang::ASTNodeTraverser<clang::ASTDumper, clang::TextNodeDumper>::Visit(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/clang/include/clang/AST/ASTNodeTraverser.h:120:3
#23 0x00007f2b32b56fa3 clang::Decl::dump(llvm::raw_ostream&, bool, clang::ASTDumpOutputFormat) const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/ASTDumper.cpp:222:3
#24 0x00007f2b32b56e59 clang::Decl::dump() const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/ASTDumper.cpp:206:64
#25 0x000055abce41c3eb clang::ast_matchers::ImportImplicitMethods_MergeImplicitMethodWithDefinition_Test::TestBody() /home/xxxxx/Sources/llvm-project-main/clang/unittests/AST/ASTImporterTest.cpp:3201:23
#26 0x00007f2b3436d76b void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2433:3
#27 0x00007f2b34352e07 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2488:5
#28 0x00007f2b3433b963 testing::Test::Run() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2515:3
#29 0x00007f2b3433c1ba testing::TestInfo::Run() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2687:12
#30 0x00007f2b3433c71b testing::TestSuite::Run() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2815:44
#31 0x00007f2b34344ef9 testing::internal::UnitTestImpl::RunAllTests() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:5337:24
#32 0x00007f2b34370a3b bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2433:3
#33 0x00007f2b34355247 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:2488:5
#34 0x00007f2b34344adf testing::UnitTest::Run() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/src/gtest.cc:4925:10
#35 0x00007f2b34d03d71 RUN_ALL_TESTS() /home/xxxxx/Sources/llvm-project-main/third-party/unittest/googletest/include/gtest/gtest.h:2472:3
#36 0x00007f2b34d03cb4 main /home/xxxxx/Sources/llvm-project-main/third-party/unittest/UnitTestMain/TestMain.cpp:55:3
#37 0x00007f2b30c4618a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#38 0x00007f2b30c46245 call_init ./csu/../csu/libc-start.c:128:20
#39 0x00007f2b30c46245 __libc_start_main ./csu/../csu/libc-start.c:368:5
#40 0x000055abce386221 _start (./build/tools/clang/unittests/AST/ASTTests+0x48b221)
Segmentation fault
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW99u2zrSfxrmhoghkvp7kQvFqfEVOD3fonb3nDuBIimbW1kSRCpN9ukXpKRYlN20aJvE23VgODIpjmZ-M5zhUEOqlNxWQtyA4BYEd1e007u6veG0kg-x513lNX-8-WsnKqh3AhayVRqq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