summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2017-07-12 22:05:30 +0000
committerBen Langmuir <blangmuir@apple.com>2017-07-12 22:05:30 +0000
commit2d77c354f16dda7be663553232555b0d61eab112 (patch)
treea33bc816d5f76652a5350f16e129dbc6764157f1 /lib
parentf3ab09d9a0924b533b587e03b665fe6b4204b4ad (diff)
[index] Don't add relation to a NamedDecl with no name
Unless it's one of the special cases (tag, category) that we can handle. This syncs up the check between handling a decl and handling a relation. This would cause invalid nameless decls to end up in relations despite having no name or USR. rdar://problem/32474406 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Index/IndexingContext.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp
index 754bc84ff4..c4aa51d62f 100644
--- a/lib/Index/IndexingContext.cpp
+++ b/lib/Index/IndexingContext.cpp
@@ -229,6 +229,12 @@ static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, AST
return false;
}
+/// Whether the given NamedDecl should be skipped because it has no name.
+static bool shouldSkipNamelessDecl(const NamedDecl *ND) {
+ return ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
+ !isa<ObjCCategoryDecl>(ND);
+}
+
static const Decl *adjustParent(const Decl *Parent) {
if (!Parent)
return nullptr;
@@ -243,8 +249,8 @@ static const Decl *adjustParent(const Decl *Parent) {
} else if (auto RD = dyn_cast<RecordDecl>(Parent)) {
if (RD->isAnonymousStructOrUnion())
continue;
- } else if (auto FD = dyn_cast<FieldDecl>(Parent)) {
- if (FD->getDeclName().isEmpty())
+ } else if (auto ND = dyn_cast<NamedDecl>(Parent)) {
+ if (shouldSkipNamelessDecl(ND))
continue;
}
return Parent;
@@ -315,9 +321,7 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc,
const DeclContext *ContainerDC) {
if (D->isImplicit() && !isa<ObjCMethodDecl>(D))
return true;
- if (!isa<NamedDecl>(D) ||
- (cast<NamedDecl>(D)->getDeclName().isEmpty() &&
- !isa<TagDecl>(D) && !isa<ObjCCategoryDecl>(D)))
+ if (!isa<NamedDecl>(D) || shouldSkipNamelessDecl(cast<NamedDecl>(D)))
return true;
SourceManager &SM = Ctx->getSourceManager();