From 2298981669bf3bd63335a4be179bc0f96823a8f4 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 20 Aug 2019 20:50:49 +0000 Subject: Vendor import of stripped clang trunk r366426 (just before the release_90 branch point): https://llvm.org/svn/llvm-project/cfe/trunk@366426 --- lib/AST/ASTImporterLookupTable.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib/AST/ASTImporterLookupTable.cpp') diff --git a/lib/AST/ASTImporterLookupTable.cpp b/lib/AST/ASTImporterLookupTable.cpp index fbcd4f5cb3417..7390329d4ed8d 100644 --- a/lib/AST/ASTImporterLookupTable.cpp +++ b/lib/AST/ASTImporterLookupTable.cpp @@ -1,9 +1,8 @@ //===- ASTImporterLookupTable.cpp - ASTImporter specific lookup -----------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -27,17 +26,30 @@ struct Builder : RecursiveASTVisitor { LT.add(D); return true; } + // In most cases the FriendDecl contains the declaration of the befriended + // class as a child node, so it is discovered during the recursive + // visitation. However, there are cases when the befriended class is not a + // child, thus it must be fetched explicitly from the FriendDecl, and only + // then can we add it to the lookup table. bool VisitFriendDecl(FriendDecl *D) { if (D->getFriendType()) { QualType Ty = D->getFriendType()->getType(); - // FIXME Can this be other than elaborated? - QualType NamedTy = cast(Ty)->getNamedType(); - if (!NamedTy->isDependentType()) { - if (const auto *RTy = dyn_cast(NamedTy)) + if (isa(Ty)) + Ty = cast(Ty)->getNamedType(); + // A FriendDecl with a dependent type (e.g. ClassTemplateSpecialization) + // always has that decl as child node. + // However, there are non-dependent cases which does not have the + // type as a child node. We have to dig up that type now. + if (!Ty->isDependentType()) { + if (const auto *RTy = dyn_cast(Ty)) LT.add(RTy->getAsCXXRecordDecl()); - else if (const auto *SpecTy = - dyn_cast(NamedTy)) { + else if (const auto *SpecTy = dyn_cast(Ty)) LT.add(SpecTy->getAsCXXRecordDecl()); + else if (isa(Ty)) { + // We do not put friend typedefs to the lookup table because + // ASTImporter does not organize typedefs into redecl chains. + } else { + llvm_unreachable("Unhandled type of friend class"); } } } -- cgit v1.2.3