Author: maskray Date: Mon Jan 8 10:57:38 2018 New Revision: 322017 URL: http://llvm.org/viewvc/llvm-project?rev=322017&view=rev Log: [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 Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=322017&r1=322016&r2=322017&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original) +++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Mon Jan 8 10:57:38 2018 @@ -890,7 +890,7 @@ bool CXIndexDataConsumer::handleReferenc 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::handleReferenc if (!CB.indexEntityReference) return false; - if (!D) + if (!D || !DC) return false; if (Loc.isInvalid()) return false; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits