sighingnow / libclang

(Unofficial) Release libclang (clang.cindex) on pypi.
https://pypi.org/project/libclang
Other
81 stars 21 forks source link

size_t getting TypeKind.INT instead of TypeKind.ULONG #53

Closed Victorious3 closed 1 year ago

Victorious3 commented 1 year ago

For the case of libc's malloc function I get the tokens:

['extern', 'void', '*', 'malloc', '(', 'size_t', '__size', ')', '__THROW', '__attribute_malloc__']

and the parameter has the tokens:

['size_t', '__size']

However when I look at the type of the parameter with param.type I get TypeKind.INT instead of something resembling size_t.

sighingnow commented 1 year ago

Cannot reproduce. size_t itself is a TypeKind.TYPEDEF, whose canonical type's kind is TypeKind.ULONG, not TypeKind.INT.

You could check TranslationUnit.diagnostics to see if there are compilation errors during parsing (missing include or something like that).

sighingnow commented 1 year ago

Closing as answered. Feel free to reopen if you could provide minimal example that can reproduce this issue.

tregua87 commented 10 months ago

I am encountering the same problem. For some files/headers, the library misinterpret size_t type.

I am in an Ubuntu 20.04 (Dockerized) with libclang==14.0.6 (installed from pip).

$ uname -a
Linux d3718923266e 5.15.0-73-generic #80~20.04.1-Ubuntu SMP Wed May 17 14:58:14 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

I made a minimal example here: libclang.zip You should just unzip and run ./sizet_error.py

To note that clang-12 seems to get the correct AST.

$ clang-12 --version
Ubuntu clang version 12.0.0-3ubuntu1~20.04.5
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ clang-12 -I. -Xclang -ast-dump -fsyntax-only min.cc | grep aom_uleb_encode_fixed_size
| | | `-FunctionDecl 0x20ae310 <line:60:1, line:62:50> line:60:5 aom_uleb_encode_fixed_size 'int (uint64_t, size_t, size_t, uint8_t *, size_t *)'
tregua87 commented 10 months ago

@sighingnow do you prefer I open a new issue?