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][ASTImporter] Implicit ctors with definition not merged could lead to crash #64171

Closed
danix800 opened this issue Jul 27, 2023 · 8 comments · Fixed by llvm/llvm-project-release-prs#597
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport release:merged

Comments

@danix800
Copy link
Member

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
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jul 27, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 27, 2023

@llvm/issue-subscribers-clang-frontend

@danix800
Copy link
Member Author

Root cause might be that FunctionDeclBitfields.NumFunctionDeclBits is not updated as needed.

See https://reviews.llvm.org/D158145

@AaronBallman
Copy link
Collaborator

Because this fixes a regression and it's a simple fix, we should probably backport this fix to Clang 17.x: https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches

@danix800
Copy link
Member Author

/cherry-pick 91c4b55

@llvmbot
Copy link
Collaborator

llvmbot commented Aug 17, 2023

/cherry-pick 91c4b55

Error: Command failed due to missing milestone.

@danix800 danix800 added this to the LLVM 17.0.X Release milestone Aug 17, 2023
@danix800
Copy link
Member Author

/cherry-pick 91c4b55

@danix800 danix800 reopened this Aug 17, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 17, 2023

/branch llvm/llvm-project-release-prs/issue64171

llvmbot pushed a commit to llvm/llvm-project-release-prs that referenced this issue Aug 17, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm/llvm-project#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145

(cherry picked from commit 91c4b55)
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 17, 2023

/pull-request llvm/llvm-project-release-prs#597

balazske pushed a commit to balazske/llvm-project that referenced this issue Aug 18, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
tru pushed a commit to llvm/llvm-project-release-prs that referenced this issue Aug 30, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm/llvm-project#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145

(cherry picked from commit 91c4b55)
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 6, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 11, 2023
NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

Fixes llvm#64171

Reviewed By: cor3ntin, balazske, aaron.ballman

Differential Revision: https://reviews.llvm.org/D158145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport release:merged
Projects
Development

Successfully merging a pull request may close this issue.

4 participants