c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

c2hs confused by clang headers on the Windows platform

Open Kleidukos opened this issue 2 years ago • 5 comments

Symptoms described at https://github.com/vmchale/libarchive/pull/34

This is presumably because starting from 9.4 GHC uses clang instead of gcc on Windows, thus different headers, which c2hs is incapable to deal with.

Kleidukos avatar Nov 09 '23 09:11 Kleidukos

Here is the bit of the header it chokes on:

static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CAST
_castf64_u64(double __A) {
  return __builtin_bit_cast(unsigned long long, __A);
}
Error: p/ghc/9.4.7/mingw/lib/clang/14.0.6/include/ia32intrin.h:222: (column 29) [ERROR]  >>> Syntax error !
  The symbol `unsigned' does not fit here.

wz1000 avatar Nov 09 '23 14:11 wz1000

It seems like __builtin_bit_cast is a C++ construct, so it is not surprising that c2hs chokes on it.

wz1000 avatar Nov 09 '23 15:11 wz1000

Maybe, but basically it seems c2hs is dysfunctional on Windows since GHC 9.4, whatever you do. It would be nice to fix it, even if in ad-hoc way.

Bodigrim avatar Nov 12 '23 17:11 Bodigrim

I don't have access to Windows machine at the moment but can you try invoking c2hs like this:

c2hs -C -D"__builtin_bit_cast(A,B)=((A)B)" <file.chs>

The double quotes escape their contents on zsh, for sh you probably need single quotes:

c2hs -C -D'__builtin_bit_cast(A,B)=((A)B)' <file.chs>

This will just parse __builtin_bit_cast(unsigned long long, __A) as ((unsigned long long) __A).

deech avatar Nov 12 '23 18:11 deech

I have addressed this in https://github.com/visq/language-c/pull/96

bgamari avatar Nov 16 '23 19:11 bgamari