[LLVMbugs] [Bug 18410] New: clang_equalCursors() invalid result

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 7 02:38:31 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=18410

            Bug ID: 18410
           Summary: clang_equalCursors() invalid result
           Product: clang
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lucas.soltic at orange.fr
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 11833
  --> http://llvm.org/bugs/attachment.cgi?id=11833&action=edit
The source of the program used to generate the error

Hello,

I use the C interface of libclang from trunk (revision 198681) and the visitor
API through clang_visitChildren().

In order to maintain a context for each expression (ie. this expression is in a
function which is in a namespace) I heavily rely on clang_equalCursors(). The
context is a stack containing CXCursors. I do as follow:
- I always tell libclang to visit nodes recursively
- Initially, I put the translation unit node in that context
- Each time my visitor callback is called, I look where is the parent in that
context. The parent is given by a parameter:
CXChildVisitResult visitNodeCallback(CXCursor cursor, CXCursor parent,
CXClientData client_data)
- That means that if the parent is the current context head, libclang just went
deeper in the AST
- If the parent is somewhere upper in the context, libclang went back somewhere
in the AST, in this case we remove the CXCursors in the context that are after
our found parent

This algorithm works nicely for most cases. However I have encountered a case
where it doesn't work: with a specific declaration from stl_pair.h. For some
reason, clang_equalCursors() tells that absolutely no CXCursor in the context
is the parent (not even the translation unit) which — according to my algorithm
— means that the current expression is not even in the same translation unit.

I've attached a sample programe code that reproduces the error, and the parsed
source code that generates this case.

Lucas

PS: I don't know how to add 2 attachments so here is the sample code that —
once parsed with the program given as attachment — generates the error:
template<class _T1, class _T2>
struct pair
{
    typedef _T1 first_type;    ///<  @c first_type is the first bound type
    typedef _T2 second_type;   ///<  @c second_type is the second bound type

    _T1 first;                 ///< @c first is a copy of the first object
    _T2 second;                ///< @c second is a copy of the second object

    template<class _U1, class _U2>
    pair(const pair<_U1, _U2>& __p)
    : first(__p.first), second(__p.second) { }
};

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140107/515ae5ef/attachment.html>


More information about the llvm-bugs mailing list