r285868 - [index] Fix assertion hit when handling a declaration of C++'s 'operator new' function.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 2 16:42:34 PDT 2016
Author: akirtzidis
Date: Wed Nov 2 18:42:33 2016
New Revision: 285868
URL: http://llvm.org/viewvc/llvm-project?rev=285868&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/Core/index-source.cpp
Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=285868&r1=285867&r2=285868&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Wed Nov 2 18:42:33 2016
@@ -290,19 +290,9 @@ bool IndexingContext::handleDeclOccurren
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);
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=285868&r1=285867&r2=285868&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Wed Nov 2 18:42:33 2016
@@ -173,8 +173,11 @@ bool USRGenerator::ShouldGenerateLocatio
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::generateUSRForObjCPro
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);
Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=285868&r1=285867&r2=285868&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Wed Nov 2 18:42:33 2016
@@ -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 at operator new#l# | __Znwm |
+// CHECK: [[@LINE+1]]:20 | type-alias/C | size_t | {{.*}} | Ref |
+void* operator new(size_t sz);
More information about the cfe-commits
mailing list