summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang/CXIndexDataConsumer.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-01-08 18:57:38 +0000
committerFangrui Song <maskray@google.com>2018-01-08 18:57:38 +0000
commite61045feb379ef9d17a08d3d92bbaee3785995b9 (patch)
tree33dca5a7f100af945f9ce409be043925ff54d4a1 /clang/tools/libclang/CXIndexDataConsumer.cpp
parent7dfe96ad16734766bc061224a56b576fdea0af17 (diff)
downloadbcm5719-llvm-e61045feb379ef9d17a08d3d92bbaee3785995b9.tar.gz
bcm5719-llvm-e61045feb379ef9d17a08d3d92bbaee3785995b9.zip
[index] Return when DC is null in handleReference
Summary: DC may sometimes be NULL and getContainerInfo(DC, Container) will dereference a null pointer. Default template arguments (the following example and many test files in https://github.com/nlohmann/json) may cause null pointer dereference. ```c++ template <typename> struct actor; template <template <typename> class Actor = actor> struct terminal; ``` In tools/libclang/CXIndexDataConsumer.cpp#L203 handleReference(ND, Loc, Cursor, dyn_cast_or_null<NamedDecl>(ASTNode.Parent), ASTNode.ContainerDC, ASTNode.OrigE, Kind); `dyn_cast_or_null<NamedDecl>(ASTNode.Parent)` is somehow a null pointer and in tools/libclang/CXIndexDataConsumer.cpp:935 ContainerInfo Container; getContainerInfo(DC, Container); The null DC is casted `ContInfo.cursor = getCursor(cast<Decl>(DC));` and SIGSEGV. ``` See discussions in https://github.com/jacobdufault/cquery/issues/219 https://github.com/jacobdufault/cquery/issues/192 Reviewers: akyrtzi, sammccall, yvvan Reviewed By: sammccall Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D41575 llvm-svn: 322017
Diffstat (limited to 'clang/tools/libclang/CXIndexDataConsumer.cpp')
-rw-r--r--clang/tools/libclang/CXIndexDataConsumer.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp
index 89ac23be734..0db6f0c1f07 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc
const DeclContext *DC,
const Expr *E,
CXIdxEntityRefKind Kind) {
- if (!D)
+ if (!D || !DC)
return false;
CXCursor Cursor = E ? MakeCXCursor(E, cast<Decl>(DC), CXTU)
@@ -907,7 +907,7 @@ bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc
if (!CB.indexEntityReference)
return false;
- if (!D)
+ if (!D || !DC)
return false;
if (Loc.isInvalid())
return false;
OpenPOWER on IntegriCloud