Issue 136435
Summary clang_equalCursors not work as expect
Labels new issue
Assignees
Reporter neko-para
    I'm using my own nodejs binding of libclang to parse my source to generate a simplified ast.

```typescript
// dfs logic, using cursors as a stack
function parseAnnotate(tu: CTranslationUnit) {
 const root = tu.cursor
    const cursors: CCursor[] = [root]
 tu.cursor.visitChildren((cursor, parent) => {
        while (cursors.length > 0 && !cursors[0].equal(parent)) {
            cursors.shift()
        }
 if (cursors.length === 0) {
            console.warn('jump out root', cursor, parent)
        }
        cursors.unshift(cursor)

 console.log('  '.repeat(cursors.length - 2), cursor.spelling, cursor.kindStr)
        return CXChildVisitResult.Recurse
 })
}
```

The code above works quite well, but when parsing the code below, the cursors that should be equal become different.

```
 _Const_lvalue_cond_oper ClassTemplatePartialSpecialization
       _Ty1 TemplateTypeParameter
       _Ty2 TemplateTypeParameter
 RequiresExpr
> Here should be a TemplateRef with parent of RequiresExpr, but my program crashed
```

![Image](https://github.com/user-attachments/assets/f7e2ee62-51ba-449d-93af-6c4d4c563424)

https://github.com/microsoft/STL/blob/5762e6bcaf7f5f8b5dba0a9aabf0acbd0e335e80/stl/inc/type_traits#L1288

**After dumping the CXCursor data, it shows that the parent.data[0] is non-zero, while cursors[0].data[0] (previously stored one) is zero, causing clang_equalCursors return false.**

I think there should be some problem either on my binding code or the way I use libclang, but I'm not sure.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to