This is an archive of the discontinued LLVM Phabricator instance.

[clang][ASTImporter] Handle UsingType in friend declarations.
ClosedPublic

Authored by balazske on Jan 26 2023, 12:59 AM.

Details

Summary

ASTImporterLookupTable did not handle correctly friend declarations
where the friend type is an UsingType (type of a declaration that
comes from an using-declaration). The problem is fixed by handling
it in the same way as a friend with TypedefType.

Diff Detail

Event Timeline

balazske created this revision.Jan 26 2023, 12:59 AM
Herald added a reviewer: shafik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
balazske requested review of this revision.Jan 26 2023, 12:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 12:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The test causes this assert if the fix is not applied:

Unhandled type of friend class
UNREACHABLE executed at /local/clang/llvm2/llvm-project/clang/lib/AST/ASTImporterLookupTable.cpp:71!
 #0 0x00007f4380b90e0a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /local/clang/llvm2/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x00007f4380b90fdb PrintStackTraceSignalHandler(void*) /local/clang/llvm2/llvm-project/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x00007f4380b8f58b llvm::sys::RunSignalHandlers() /local/clang/llvm2/llvm-project/llvm/lib/Support/Signals.cpp:103:5
 #3 0x00007f4380b91751 SignalHandler(int) /local/clang/llvm2/llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007f43840b1980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x00007f437fa40e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007f437fa427f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007f4380a132c4 /local/clang/llvm2/llvm-project/llvm/lib/Support/ErrorHandling.cpp:212:3
 #8 0x00007f438265cc05 clang::(anonymous namespace)::Builder::VisitFriendDecl(clang::FriendDecl*) /local/clang/llvm2/llvm-project/clang/lib/AST/ASTImporterLookupTable.cpp:0:11
 #9 0x00007f438265ca40 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::WalkUpFromFriendDecl(clang::FriendDecl*) /local/clang/llvm2/build/Debug/tools/clang/include/clang/AST/DeclNodes.inc:71:1
#10 0x00007f43825e2505 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseFriendDecl(clang::FriendDecl*) /local/clang/llvm2/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1550:1
#11 0x00007f43825dfa49 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseDecl(clang::Decl*) /local/clang/llvm2/build/Debug/tools/clang/include/clang/AST/DeclNodes.inc:71:1
#12 0x00007f4382648488 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseDeclContextHelper(clang::DeclContext*) /local/clang/llvm2/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1489:7
#13 0x00007f43825e7038 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseCXXRecordDecl(clang::CXXRecordDecl*) /local/clang/llvm2/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2015:1
#14 0x00007f43825dff7f clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseDecl(clang::Decl*) /local/clang/llvm2/build/Debug/tools/clang/include/clang/AST/DeclNodes.inc:295:1
#15 0x00007f4382648488 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseDeclContextHelper(clang::DeclContext*) /local/clang/llvm2/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1489:7
#16 0x00007f43825ee041 clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) /local/clang/llvm2/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1599:1
#17 0x00007f43825e084d clang::RecursiveASTVisitor<clang::(anonymous namespace)::Builder>::TraverseDecl(clang::Decl*) /local/clang/llvm2/build/Debug/tools/clang/include/clang/AST/DeclNodes.inc:645:1
#18 0x00007f43825df7d4 clang::ASTImporterLookupTable::ASTImporterLookupTable(clang::TranslationUnitDecl&) /local/clang/llvm2/llvm-project/clang/lib/AST/ASTImporterLookupTable.cpp:88:1
#19 0x0000000000655a44 std::_MakeUniq<clang::ASTImporterLookupTable>::__single_object std::make_unique<clang::ASTImporterLookupTable, clang::TranslationUnitDecl&>(clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/unique_ptr.h:821:34
#20 0x0000000000655933 clang::ASTImporterSharedState::ASTImporterSharedState(clang::TranslationUnitDecl&) /local/clang/llvm2/llvm-project/clang/include/clang/AST/ASTImporterSharedState.h:52:19
#21 0x00000000006558d1 void __gnu_cxx::new_allocator<clang::ASTImporterSharedState>::construct<clang::ASTImporterSharedState, clang::TranslationUnitDecl&>(clang::ASTImporterSharedState*, clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/ext/new_allocator.h:136:60
#22 0x00000000006555ed void std::allocator_traits<std::allocator<clang::ASTImporterSharedState>>::construct<clang::ASTImporterSharedState, clang::TranslationUnitDecl&>(std::allocator<clang::ASTImporterSharedState>&, clang::ASTImporterSharedState*, clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/alloc_traits.h:475:56
#23 0x000000000065544b std::__shared_ptr<clang::ASTImporterSharedState, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<clang::ASTImporterSharedState>, clang::TranslationUnitDecl&>(std::_Sp_make_shared_tag, std::allocator<clang::ASTImporterSharedState> const&, clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/shared_ptr_base.h:1327:4
#24 0x00000000006553ad std::shared_ptr<clang::ASTImporterSharedState>::shared_ptr<std::allocator<clang::ASTImporterSharedState>, clang::TranslationUnitDecl&>(std::_Sp_make_shared_tag, std::allocator<clang::ASTImporterSharedState> const&, clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/shared_ptr.h:345:4
#25 0x0000000000655316 std::shared_ptr<clang::ASTImporterSharedState> std::allocate_shared<clang::ASTImporterSharedState, std::allocator<clang::ASTImporterSharedState>, clang::TranslationUnitDecl&>(std::allocator<clang::ASTImporterSharedState> const&, clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/shared_ptr.h:690:14
#26 0x000000000064e6f3 std::shared_ptr<clang::ASTImporterSharedState> std::make_shared<clang::ASTImporterSharedState, clang::TranslationUnitDecl&>(clang::TranslationUnitDecl&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/shared_ptr.h:706:7
#27 0x000000000064bd3e clang::ast_matchers::ASTImporterTestBase::lazyInitSharedState(clang::TranslationUnitDecl*) /local/clang/llvm2/llvm-project/clang/unittests/AST/ASTImporterFixtures.cpp:113:22
#28 0x000000000064bf9f clang::ast_matchers::ASTImporterTestBase::lazyInitToAST(clang::TestLanguage, llvm::StringRef, llvm::StringRef) /local/clang/llvm2/llvm-project/clang/unittests/AST/ASTImporterFixtures.cpp:128:1
#29 0x000000000064c77e clang::ast_matchers::ASTImporterTestBase::getToTuDecl(llvm::StringRef, clang::TestLanguage) /local/clang/llvm2/llvm-project/clang/unittests/AST/ASTImporterFixtures.cpp:191:3
#30 0x00000000006a5a13 clang::ast_matchers::ASTImporterLookupTableTest_LookupFindsFriendClassDeclWithUsingTypeDoesNotAssert_Test::TestBody() /local/clang/llvm2/llvm-project/clang/unittests/AST/ASTImporterTest.cpp:5165:24
#31 0x00007f4380c959c4 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2433:3
#32 0x00007f4380c7b132 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2488:5
#33 0x00007f4380c63173 testing::Test::Run() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2515:3
#34 0x00007f4380c63a4d testing::TestInfo::Run() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2687:12
#35 0x00007f4380c6401c testing::TestSuite::Run() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2815:44
#36 0x00007f4380c6cde1 testing::internal::UnitTestImpl::RunAllTests() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:5337:24
#37 0x00007f4380c991e4 bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2433:3
#38 0x00007f4380c7d472 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:2488:5
#39 0x00007f4380c6c9aa testing::UnitTest::Run() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/src/gtest.cc:4925:10
#40 0x00007f43844c4d01 RUN_ALL_TESTS() /local/clang/llvm2/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:2472:3
#41 0x00007f43844c4c40 main /local/clang/llvm2/llvm-project/third-party/unittest/UnitTestMain/TestMain.cpp:55:3
#42 0x00007f437fa23c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#43 0x00000000005ee18a _start (./tools/clang/unittests/AST/ASTTests+0x5ee18a)
This revision is now accepted and ready to land.Jan 27 2023, 12:02 AM
This revision was landed with ongoing or failed builds.Jan 30 2023, 1:06 AM
This revision was automatically updated to reflect the committed changes.