summaryrefslogtreecommitdiffstats
path: root/clang/lib/CrossTU
diff options
context:
space:
mode:
authorBalazs Keri <1.int32@gmail.com>2019-08-06 12:10:16 +0000
committerBalazs Keri <1.int32@gmail.com>2019-08-06 12:10:16 +0000
commit4e79097dc7c30ea8e1a7e96b740113e7cd9e635d (patch)
tree176651a03cb1f9ccc2fb1df0bed6a69769eec257 /clang/lib/CrossTU
parent56bdb0c5082547229ff668405bde2ef5254ee817 (diff)
downloadbcm5719-llvm-4e79097dc7c30ea8e1a7e96b740113e7cd9e635d.tar.gz
bcm5719-llvm-4e79097dc7c30ea8e1a7e96b740113e7cd9e635d.zip
[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 llvm-svn: 368020
Diffstat (limited to 'clang/lib/CrossTU')
-rw-r--r--clang/lib/CrossTU/CrossTranslationUnit.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index f43180a2a27..bd8a022eb4d 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/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);
}
OpenPOWER on IntegriCloud