Jextract failure on llvm 17.0.1 with sdl

Jorn Vernee jorn.vernee at oracle.com
Mon Oct 16 21:06:21 UTC 2023


Hi,

This exception comes from the following section in 
TypeMaker::makeTypeInternal:"

             case Unexposed:
             case Elaborated:
                 org.openjdk.jextract.clang.Type canonical = 
t.canonicalType();
                 if (canonical.equalType(t)) {
                     throw new TypeException("Unknown type with same 
canonical type: " + t.spelling());
                 }
                 return makeType(canonical);

I think in this case we're looking at an 'Unexposed' type, which means 
that libclang (the C interface of clang) does not support this type [1]. 
Looking at the implementation of `GetTypeKind` in libclang [2], it 
delegates to `GetBuiltinTypeKind` [3] for builtin types, and this 
doesn't have a case for BFloat16, so instead it returns 
`CXType_Unexposed`. i.e. this seems to be an issue that needs to be 
fixed in libclang itself. There might be other changes that are needed 
to fully support this type, but I can't say off the top of my head.

As a workaround, we might be able to specifically detect __bf16 based on 
its name/spelling, and then return an instance of Type.Primitive from 
TypeMaker::makeTypeInternal, that is later filtered out in 
`UnsupportedLayouts`. That would allow jextract to continue and generate 
something, but wouldn't work for cases where the __bf16 type is actually 
required since we would just omit any function/variable that used this 
type in its declaration.

Jorn

[1]: 
https://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#gaad39de597b13a18882c21860f92b095a
[2]: 
https://github.com/llvm/llvm-project/blob/llvmorg-17.0.1/clang/tools/libclang/CXType.cpp#L94
[3]: 
https://github.com/llvm/llvm-project/blob/llvmorg-17.0.1/clang/tools/libclang/CXType.cpp#L29

On 16/10/2023 20:15, Clayton Walker wrote:
> Hello,
>
> I've been working on creating a set of bindings against sdl2, and have 
> encountered the following issue:
>
> Unknown type with same canonical type: __bf16
>
> I wasn't sure what needed to be fixed, perhaps a missing declaration 
> or mapping in jextract, but after a bit of digging I tried adding the 
> clang BFloat16 data type but had no luck. 
> https://github.com/openjdk/jextract/compare/jdk21...Sineaggi:jextract:jdk-21-bf16
>


More information about the panama-dev mailing list