r311434 - [clang-diff] Fix getRelativeName
Johannes Altmanninger via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 01:59:13 PDT 2017
Author: krobelus
Date: Tue Aug 22 01:59:13 2017
New Revision: 311434
URL: http://llvm.org/viewvc/llvm-project?rev=311434&view=rev
Log:
[clang-diff] Fix getRelativeName
Handle the case when DeclContext is null.
Modified:
cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
Modified: cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp?rev=311434&r1=311433&r2=311434&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp (original)
+++ cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp Tue Aug 22 01:59:13 2017
@@ -372,7 +372,10 @@ int SyntaxTree::Impl::findPositionInPare
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<NamespaceDecl>(Context))
ContextPrefix = Namespace->getQualifiedNameAsString();
else if (auto *Record = dyn_cast<RecordDecl>(Context))
@@ -380,7 +383,6 @@ SyntaxTree::Impl::getRelativeName(const
else if (AST.getLangOpts().CPlusPlus11)
if (auto *Tag = dyn_cast<TagDecl>(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 *getEnclosingDe
return D->getDeclContext();
S = P.get<Stmt>();
}
- llvm_unreachable("Could not find Decl ancestor.");
+ return nullptr;
}
std::string SyntaxTree::Impl::getNodeValue(NodeId Id) const {
More information about the cfe-commits
mailing list