-
Notifications
You must be signed in to change notification settings - Fork 162
Crash on code using default argument for template template parameter #219
Comments
I am using
|
Reduced code example that triggers the crash:
If the default template argument is removed, the crash goes away. |
I can reproduce this:
, after which:
Building the file itself just went fine:
|
I can reproduce with HighCommander4's example too. If you uncomment 1880
clang_toggleCrashRecovery(0); /////// uncomment this statement
// |index_result| is a CXErrorCode instance.
int index_result = clang_indexTranslationUnit( It reveals this is a bug on libclang's side (--bundled-clang=5.0.1), probably similar to #192 Linking cquery with Before we get a new release on releases.llvm.org, you may consider linking cquery against clang+llvm built from the source: CXXFLAGS="-g -I$HOME/Dev/llvm/tools/clang/include" ./waf configure --variant=my-clang-release --use-system-clang --llvm-config=$HOME/Dev/llvm/release/bin/llvm-config |
May be a race in libclang.
|
I can confirm that the workaround described in the previous comment prevents the crash. @MaskRay, out of curiosity, how do you come up with a binary patch like this? Do you start with a source change to libclang, and take a diff of the resulting binaries? Or do you somehow debug the binary directly? |
I leave some notes in https://maskray.me/blog/2017-12-25-cquery-updates-and-libclang-one-byte-patch (sorry, in Chinese). |
@HighCommander4 He... participated in DEFCON CTF Contest... His team won World No.5. Binary manipulation is no less familiar to him than cplusplus. |
Impressive :) IIUC (I ran the blog post through Google Translate), it starts with a desired source change, but additional cleverness is required to find a way to express the source change as a binary change of only 1 byte. Anyways, what I really wanted to ask is, do you know the source change in this case? If so, could you share it? |
Just translated most part of that article.... And the patch is sent for review at https://reviews.llvm.org/D41575 |
Oh, I just noticed it's the same change as in #192 (adding a null check). |
The libclang |
Mark as resolved as the hack is commited #226 in There is still no response from the clang upstream https://reviews.llvm.org/D41575 . What a high threshold for newcomers. There are definitely duplicated efforts spending on cquery and clangd. I'm still unclear what will happen. #63 |
Perhaps you could submit the patch to their Review Corner? |
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 jacobdufault/cquery#219 jacobdufault/cquery#192 Reviewers: akyrtzi, sammccall, yvvan Reviewed By: sammccall Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D41575 git-svn-id: http://llvm.org/svn/llvm-project/cfe/trunk@322017 91177308-0d34-0410-b5e6-96231b3b80d8
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 jacobdufault/cquery#219 jacobdufault/cquery#192 Reviewers: akyrtzi, sammccall, yvvan Reviewed By: sammccall Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D41575 llvm-svn=322017
Thanks for the pointer! I'll use that if there is a bug next time :) Commited in https://reviews.llvm.org/rC322017 |
@MaskRay Will the binary patch work for |
When indexing a project containing a single code file containing just the following include:
the indexer crashes with:
If I remove the include, there is no crash. I'm using Boost 1.63.
The text was updated successfully, but these errors were encountered: