[ASTImporter] Fix AST import crash for a friend decl
authorVince Bridgers <vince.a.bridgers@gmail.com>
Tue, 30 Jun 2020 15:08:35 +0000 (10:08 -0500)
committereinvbri <vince.a.bridgers@ericsson.com>
Tue, 30 Jun 2020 20:57:01 +0000 (15:57 -0500)
Summary:
Running CTU testing, we found that VisitFriendDecl in
ASTImporterLookup.cpp was not handling a particular non-dependent case,
so we reached the llvm_unreachable case.

The FriendDecl and QualType not handled were:

(gdb) p D->dump()
FriendDecl 0x7ffff5cf1958
< <<srcfile>>, 'nlohmann::basic_json<std::map, std::vector,
   std::basic_string<char>, bool, long long, unsigned long long, double,
   std::allocator, adl_serializer, std::vector<unsigned char,
   std::allocator<unsigned char>>>':'nlohmann::basic_json<std::map,
   std::vector, std::basic_string<char>, bool, long long, unsigned long
   long, double, std::allocator, adl_serializer, std::vector<unsigned char,
   std::allocator<unsigned char>>>'

(gdb) p Ty->dump()
SubstTemplateTypeParmType 0x7ffff5cf0df0 'class
nlohmann::basic_json<std::map, std::vector, class
   std::basic_string<char>, _Bool, long long, unsigned long long, double,
   std::allocator, adl_serializer, class std::vector<unsigned char, class
   std::allocator<unsigned char> > >' sugar
|-TemplateTypeParmType 0x7ffff643ea40 'BasicJsonType' dependent depth 0
index 0
| `-TemplateTypeParm 0x7ffff643e9e8 'BasicJsonType'
`-RecordType 0x1012ad20 'class nlohmann::basic_json<std::map,
std::vector, class std::basic_string<char>, _Bool, long long, unsigned
long long, double, std::allocator, adl_serializer, class
std::vector<unsigned char, class std::allocator<unsigned char> > >'
  `-ClassTemplateSpecialization 0x1012ab68 'basic_json'

Reviewers: martong, a.sidorin

Reviewed By: martong

Subscribers: kristof.beyls, rnkovacs, teemperor, cfe-commits, dkrupp

Tags: #clang

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

clang/lib/AST/ASTImporterLookupTable.cpp

index 7390329..4d6fff8 100644 (file)
@@ -45,7 +45,11 @@ struct Builder : RecursiveASTVisitor<Builder> {
           LT.add(RTy->getAsCXXRecordDecl());
         else if (const auto *SpecTy = dyn_cast<TemplateSpecializationType>(Ty))
           LT.add(SpecTy->getAsCXXRecordDecl());
-        else if (isa<TypedefType>(Ty)) {
+        else if (const auto *SubstTy =
+                     dyn_cast<SubstTemplateTypeParmType>(Ty)) {
+          if (SubstTy->getAsCXXRecordDecl())
+            LT.add(SubstTy->getAsCXXRecordDecl());
+        } else if (isa<TypedefType>(Ty)) {
           // We do not put friend typedefs to the lookup table because
           // ASTImporter does not organize typedefs into redecl chains.
         } else {