[LLVMbugs] [Bug 19759] New: libclang (via Python bindings), is_definition() is different for structs on x84_64 and aarch64

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 15 14:01:27 PDT 2014


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

            Bug ID: 19759
           Summary: libclang (via Python bindings), is_definition() is
                    different for structs on x84_64 and aarch64
           Product: clang
           Version: 3.4
          Hardware: Other
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david.abdurachmanov at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

We have a Python script using libclang. It walks over AST to collect
information about structures. I am porting code to aarch64 (ARMv8) and found
that script does not produce any content. This is because is_definition()
return value is different between x86_64 and aarch64.

Example:

/usr/include/time.h

### Fedora 19, AArch64 (ARMv8) ###

[2014-05-15 16:03:42,980] DEBUG: Child: <clang.cindex.Cursor object at
0x17e993b0> | timespec | timespec, kind: CursorKind.STRUCT_DECL, is_definition:
False, location: <SourceLocati
on file '/usr/include/time.h', line 120, column 8>

    118 /* POSIX.1b structure for a time value.  This is like a `struct
timeval' but
    119    has nanoseconds instead of microseconds.  */
    120 struct timespec
    121   {
    122     __time_t tv_sec;    /* Seconds.  */
    123     __syscall_slong_t tv_nsec;  /* Nanoseconds.  */
    124   };

### RHEL6, x86_64 ###

[2014-05-15 21:58:46,767] DEBUG: Child: <clang.cindex.Cursor object at
0x2468560> | timespec | timespec, kind: CursorKind.STRUCT_DECL, is_definition:
True, location: <SourceLocation file '/usr/include/time.h', line 120, column 8>
[2014-05-15 21:58:46,767] DEBUG: Found struct/class/template definition:
timespec
[2014-05-15 21:58:46,767] DEBUG: Skipping since it is an external of this
package: timespec

118 /* POSIX.1b structure for a time value.  This is like a `struct timeval'
but
119    has nanoseconds instead of microseconds.  */
120 struct timespec
121   {
122     __time_t tv_sec;            /* Seconds.  */
123     long int tv_nsec;           /* Nanoseconds.  */
124   };
125

But with clang -Xclang -ast-dump -fsyntax-only

|-RecordDecl 0x85fb030 </usr/include/time.h:120:1, line:124:3> struct timespec
definition
| |-FieldDecl 0x85fb100 <line:122:5, col:14> tv_sec '__time_t':'long'
| `-FieldDecl 0x85fb180 <line:123:5, col:23> tv_nsec '__syscall_slong_t':'long'

|-RecordDecl 0x39e1e70 </usr/include/time.h:120:1, line:124:3> struct timespec
definition
| |-FieldDecl 0x39e1f40 <line:122:5, col:14> tv_sec '__time_t':'long'
| `-FieldDecl 0x39e1fa0 <line:123:5, col:14> tv_nsec 'long'

On both machines it says "struct timespec definition".

Something like that is good enough to reproduce:

$ cat check.py
import sys
import clang.cindex

def find_typerefs(node):
    for child in node.get_children():
      print("{0} {1} {2} {3}".format(child.displayname, child.kind,
child.is_definition(), child.location))
      find_typerefs(child)

index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print 'Translation unit:', tu.spelling
find_typerefs(tu.cursor)

$ python check.py /usr/include/time.h

# x86_64 #

timespec CursorKind.STRUCT_DECL True <SourceLocation file
'/usr/include/time.h', line 120, column 8>
tv_sec CursorKind.FIELD_DECL True <SourceLocation file '/usr/include/time.h',
line 122, column 14>
__time_t CursorKind.TYPE_REF False <SourceLocation file '/usr/include/time.h',
line 122, column 5>
tv_nsec CursorKind.FIELD_DECL True <SourceLocation file '/usr/include/time.h',
line 123, column 14>

# aarch64 #

timespec CursorKind.STRUCT_DECL False <SourceLocation file
'/usr/include/time.h', line 120, column 8>
tv_sec CursorKind.FIELD_DECL True <SourceLocation file '/usr/include/time.h',
line 122, column 14>
__time_t CursorKind.TYPE_REF False <SourceLocation file '/usr/include/time.h',
line 122, column 5>
tv_nsec CursorKind.FIELD_DECL True <SourceLocation file '/usr/include/time.h',
line 123, column 23>
__syscall_slong_t CursorKind.TYPE_REF False <SourceLocation file
'/usr/include/time.h', line 123, column 5>

Is there any issues with libclang or/and python binding on aarch64?

-- 
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/20140515/d2b9b63d/attachment.html>


More information about the llvm-bugs mailing list