sighingnow / libclang

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

Issue/Oddity with std::bitset and 'Unknown template argument kind 280' #25

Closed g40 closed 2 years ago

g40 commented 2 years ago

First of all many thanks for this work, it is an extremely helpful resource.

Core error is using ValueError: Unknown template argument kind 280

At first sight this looks like a mismatch between the cursor kind enumerations here

which are in turn different to those defined here

and those specified in the Python interface here

but, oddly, this error is only triggered if <bit> is included.

I'm stuck with clang 10 on my Ubuntu machine so cannot test there (no member named 'bit_cast' in namespace 'std')

How best to proceed?

Many thanks

Jerry

// minimal test case https://en.cppreference.com/w/cpp/numeric/bit_cast
#include <cstdint>
// this works until <bit> is included
// uncomment to see libclang error
// #include <bit>

constexpr double f64v = 19880124.0; 
constexpr auto u64v = std::bit_cast<std::uint64_t>(f64v);
static_assert( std::bit_cast<double>(u64v) == f64v ); // round-trip

constexpr std::uint64_t u64v2 = 0x3fe9000000000000ull;
constexpr auto f64v2 = std::bit_cast<double>(u64v2);
static_assert( std::bit_cast<std::uint64_t>(f64v2) == u64v2 ); // round-trip

int main()
{
    return 0;
}

Stack traceback with #include <bit>

python cindex-dump.py test.cpp -std=c++20
('diags', [])
Traceback (most recent call last):
  File "cindex-dump.py", line 86, in <module>
    main()
  File "cindex-dump.py", line 83, in main
    pprint(('nodes', get_info(tu.cursor)))
  File "cindex-dump.py", line 43, in get_info
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in <listcomp>
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in get_info
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in <listcomp>
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in get_info
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in <listcomp>
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in get_info
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in <listcomp>
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in get_info
    for c in node.get_children()]
  File "cindex-dump.py", line 43, in <listcomp>
    for c in node.get_children()]
  File "cindex-dump.py", line 45, in get_info
    'kind' : node.kind,
  File "R:\apps\python3\lib\site-packages\clang\cindex.py", line 1541, in kind
    return CursorKind.from_id(self._kind_id)
  File "R:\apps\python3\lib\site-packages\clang\cindex.py", line 650, in from_id
    raise ValueError('Unknown template argument kind %d' % id)
ValueError: Unknown template argument kind 280

System details (Windows 10 FWIW):


clang -v
clang version 13.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: r:\apps\llvm\bin

pip show libclang
Name: libclang
Version: 13.0.0
Summary: Clang Python Bindings, mirrored from the official LLVM repo: https://github.com/llvm/llvm-project/tree/main/clang/bindings/python, to make the installation process easier.
Home-page: https://github.com/sighingnow/libclang
Author: Tao He
Author-email: sighingnow@gmail.com
License: Apache License 2.0
Location: r:\apps\python3\lib\site-packages
sighingnow commented 2 years ago

I could submit patch to the upstream LLVM.

Thanks for reporting!

sighingnow commented 2 years ago

FYI: https://reviews.llvm.org/D122409

g40 commented 2 years ago

@sighingnow - thanks and I can see the upstream submission. Thank you for your continued efforts.

g40 commented 2 years ago

@sighingnow seems jammed: https://reviews.llvm.org/D122409

sighingnow commented 2 years ago

@sighingnow seems jammed: https://reviews.llvm.org/D122409

There's no response about this patch. I have applied the diff to this repo and will be included in the v14.0.1 release today.