diff options
author | Balazs Keri <1.int32@gmail.com> | 2019-08-06 12:10:16 +0000 |
---|---|---|
committer | Balazs Keri <1.int32@gmail.com> | 2019-08-06 12:10:16 +0000 |
commit | 7d8e55c8bbf7a15c9738a1b029717af1e5a2fb48 (patch) | |
tree | 8fdb901018966cf5aab5c99cc6c3b03d6633728e /lib/CrossTU | |
parent | af48556a120a9b832b0460edd2d0dffcbed41ffd (diff) | |
download | clang-7d8e55c8bbf7a15c9738a1b029717af1e5a2fb48.tar.gz |
[CrossTU] Handle case when no USR could be generated during Decl search.
Summary:
When searching for a declaration to be loaded the "lookup name" for every
other Decl is computed. If the USR can not be determined here should be
not an assert, instead skip this Decl.
Reviewers: martong
Reviewed By: martong
Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65445
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CrossTU')
-rw-r--r-- | lib/CrossTU/CrossTranslationUnit.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/CrossTU/CrossTranslationUnit.cpp b/lib/CrossTU/CrossTranslationUnit.cpp index f43180a2a2..bd8a022eb4 100644 --- a/lib/CrossTU/CrossTranslationUnit.cpp +++ b/lib/CrossTU/CrossTranslationUnit.cpp @@ -193,12 +193,13 @@ CrossTranslationUnitContext::CrossTranslationUnitContext(CompilerInstance &CI) CrossTranslationUnitContext::~CrossTranslationUnitContext() {} -std::string CrossTranslationUnitContext::getLookupName(const NamedDecl *ND) { +llvm::Optional<std::string> +CrossTranslationUnitContext::getLookupName(const NamedDecl *ND) { SmallString<128> DeclUSR; bool Ret = index::generateUSRForDecl(ND, DeclUSR); - (void)Ret; - assert(!Ret && "Unable to generate USR"); - return DeclUSR.str(); + if (Ret) + return {}; + return std::string(DeclUSR.str()); } /// Recursively visits the decls of a DeclContext, and returns one with the @@ -218,7 +219,8 @@ CrossTranslationUnitContext::findDefInDeclContext(const DeclContext *DC, const T *ResultDecl; if (!ND || !hasBodyOrInit(ND, ResultDecl)) continue; - if (getLookupName(ResultDecl) != LookupName) + llvm::Optional<std::string> ResultLookupName = getLookupName(ResultDecl); + if (!ResultLookupName || *ResultLookupName != LookupName) continue; return ResultDecl; } @@ -233,12 +235,12 @@ llvm::Expected<const T *> CrossTranslationUnitContext::getCrossTUDefinitionImpl( assert(!hasBodyOrInit(D) && "D has a body or init in current translation unit!"); ++NumGetCTUCalled; - const std::string LookupName = getLookupName(D); - if (LookupName.empty()) + const llvm::Optional<std::string> LookupName = getLookupName(D); + if (!LookupName) return llvm::make_error<IndexError>( index_error_code::failed_to_generate_usr); llvm::Expected<ASTUnit *> ASTUnitOrError = - loadExternalAST(LookupName, CrossTUDir, IndexName, DisplayCTUProgress); + loadExternalAST(*LookupName, CrossTUDir, IndexName, DisplayCTUProgress); if (!ASTUnitOrError) return ASTUnitOrError.takeError(); ASTUnit *Unit = *ASTUnitOrError; @@ -294,7 +296,7 @@ llvm::Expected<const T *> CrossTranslationUnitContext::getCrossTUDefinitionImpl( } TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); - if (const T *ResultDecl = findDefInDeclContext<T>(TU, LookupName)) + if (const T *ResultDecl = findDefInDeclContext<T>(TU, *LookupName)) return importDefinition(ResultDecl, Unit); return llvm::make_error<IndexError>(index_error_code::failed_import); } |