diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2016-11-02 23:42:33 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2016-11-02 23:42:33 +0000 |
| commit | f12918d218b76ce442cd7e0c6b65620bf2d35805 (patch) | |
| tree | 14626f62f0db0d6e7d8ddc767e14e21708113e58 /clang | |
| parent | 80b64f0861e1e7370bca2ccc9b95a848b7e1e815 (diff) | |
| download | bcm5719-llvm-f12918d218b76ce442cd7e0c6b65620bf2d35805.tar.gz bcm5719-llvm-f12918d218b76ce442cd7e0c6b65620bf2d35805.zip | |
[index] Fix assertion hit when handling a declaration of C++'s 'operator new' function.
Part of this is to allow creating a USR for the canonical decl of that which is implicit and does
not have a source location.
rdar://28978992
llvm-svn: 285868
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Index/USRGeneration.cpp | 11 | ||||
| -rw-r--r-- | clang/test/Index/Core/index-source.cpp | 6 |
3 files changed, 14 insertions, 13 deletions
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index bcc367c6626..21869d88a57 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -290,19 +290,9 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, Roles |= (unsigned)SymbolRole::Declaration; D = getCanonicalDecl(D); - if (D->isImplicit() && !isa<ObjCMethodDecl>(D) && - !(isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->getBuiltinID())) { - // operator new declarations will link to the implicit one as canonical. - return true; - } Parent = adjustParent(Parent); if (Parent) Parent = getCanonicalDecl(Parent); - assert((!Parent || !Parent->isImplicit() || - (isa<FunctionDecl>(Parent) && - cast<FunctionDecl>(Parent)->getBuiltinID()) || - isa<ObjCInterfaceDecl>(Parent) || isa<ObjCMethodDecl>(Parent)) && - "unexpected implicit parent!"); SmallVector<SymbolRelation, 6> FinalRelations; FinalRelations.reserve(Relations.size()+1); diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index 6a114f934a9..bec777ddf4f 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -173,8 +173,11 @@ bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) { return false; if (D->getParentFunctionOrMethod()) return true; + SourceLocation Loc = D->getLocation(); + if (Loc.isInvalid()) + return false; const SourceManager &SM = Context->getSourceManager(); - return !SM.isInSystemHeader(D->getLocation()); + return !SM.isInSystemHeader(Loc); } void USRGenerator::VisitDeclContext(const DeclContext *DC) { @@ -874,9 +877,11 @@ void clang::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS) { bool clang::index::generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf) { - // Don't generate USRs for things with invalid locations. - if (!D || D->getLocStart().isInvalid()) + if (!D) return true; + // We don't ignore decls with invalid source locations. Implicit decls, like + // C++'s operator new function, can have invalid locations but it is fine to + // create USRs that can identify them. USRGenerator UG(&D->getASTContext(), Buf); UG.Visit(D); diff --git a/clang/test/Index/Core/index-source.cpp b/clang/test/Index/Core/index-source.cpp index c4e12903f6c..11ac89529dd 100644 --- a/clang/test/Index/Core/index-source.cpp +++ b/clang/test/Index/Core/index-source.cpp @@ -19,3 +19,9 @@ class BT { return { .idx = 0 }; // Make sure this doesn't trigger a crash. } }; + +// CHECK: [[@LINE+1]]:23 | type-alias/C | size_t | +typedef unsigned long size_t; +// CHECK: [[@LINE+2]]:7 | function/C | operator new | c:@F@operator new#l# | __Znwm | +// CHECK: [[@LINE+1]]:20 | type-alias/C | size_t | {{.*}} | Ref | +void* operator new(size_t sz); |

