<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - libclang (via Python bindings), is_definition() is different for structs on x84_64 and aarch64"
   href="http://llvm.org/bugs/show_bug.cgi?id=19759">19759</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libclang (via Python bindings), is_definition() is different for structs on x84_64 and aarch64
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.abdurachmanov@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>