From ce7e9f1524037ca01fa3c5d395dcde87beb25dba Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 22 Aug 2017 08:59:13 +0000 Subject: [PATCH] [clang-diff] Fix getRelativeName Handle the case when DeclContext is null. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311434 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/ASTDiff/ASTDiff.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Tooling/ASTDiff/ASTDiff.cpp b/lib/Tooling/ASTDiff/ASTDiff.cpp index 2dcd1a2856..747c67ecdc 100644 --- a/lib/Tooling/ASTDiff/ASTDiff.cpp +++ b/lib/Tooling/ASTDiff/ASTDiff.cpp @@ -372,7 +372,10 @@ int SyntaxTree::Impl::findPositionInParent(NodeId Id, bool Shifted) const { std::string SyntaxTree::Impl::getRelativeName(const NamedDecl *ND, const DeclContext *Context) const { + std::string Val = ND->getQualifiedNameAsString(); std::string ContextPrefix; + if (!Context) + return Val; if (auto *Namespace = dyn_cast(Context)) ContextPrefix = Namespace->getQualifiedNameAsString(); else if (auto *Record = dyn_cast(Context)) @@ -380,7 +383,6 @@ SyntaxTree::Impl::getRelativeName(const NamedDecl *ND, else if (AST.getLangOpts().CPlusPlus11) if (auto *Tag = dyn_cast(Context)) ContextPrefix = Tag->getQualifiedNameAsString(); - std::string Val = ND->getQualifiedNameAsString(); // Strip the qualifier, if Val refers to somthing in the current scope. // But leave one leading ':' in place, so that we know that this is a // relative path. @@ -404,7 +406,7 @@ static const DeclContext *getEnclosingDeclContext(ASTContext &AST, return D->getDeclContext(); S = P.get(); } - llvm_unreachable("Could not find Decl ancestor."); + return nullptr; } std::string SyntaxTree::Impl::getNodeValue(NodeId Id) const { -- 2.40.0