gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bootstrapping failures on Win64 (11; x86_64) due to pointer casts


From: Alcor
Subject: Bootstrapping failures on Win64 (11; x86_64) due to pointer casts
Date: Sat, 20 Jul 2024 15:31:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hi All,

I have tried to get GM2 to compile under Win11 x86_64. Unfortunately, I
have discovered that bootstrapping fails when compiling mc-boot/ due to
portability issues with pointer casts.

The salient error message is the following:

../../gcc-14.1.0/gcc/m2/mc-boot/Gdecl.cc: In function 'void out1(const char*, 
unsigned int, decl_node)':
../../gcc-14.1.0/gcc/m2/mc-boot/Gdecl.cc:8240:28: error: cast from 'decl_node' 
{aka 'decl_nodeRec_r*'} to 'long unsigned int' loses precision [-fpermissive]
 8240 |       d = (unsigned int ) ((long unsigned int ) (s));
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~
../../gcc-14.1.0/gcc/m2/mc-boot/Gdecl.cc: In function 
'DynamicStrings_stringRecord* gen(decl_node)':
../../gcc-14.1.0/gcc/m2/mc-boot/Gdecl.cc:19798:24: error: cast from 'decl_node' 
{aka 'decl_nodeRec_r*'} to 'long unsigned int' loses precision [-fpermissive]
19798 |   d = (unsigned int ) ((long unsigned int ) (n));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~

The above code compiles without issue on Linux x86_64 as
sizeof(void*) == sizeof(long unsigned int) == 8.

On Win64, sizeof(void*) == 8 and sizeof(long unsigned int) == 4, thus
the above error.

A quick fix would be changing the cast to

  `d = (unsigned int ) ((long long unsigned int ) (s));'

as sizeof(long long unsigned int) == 8 on Win64. Or, if using C99 is an
option, casting through an uintptr_t (C99) e.g.

  `d = (unsigned int ) ((uintptr_t ) (s));'

which is guaranteed to portably work, as the C99 defines (u)intptr_t to
be a (un)signed integer with _at least_ as many bits as a pointer.

For now, I will try patching the mc-boot/ files manually to see if the build
proceeds (if they are not many). But ideally the correct solution would
be to modify the `mc' bootstrap compiler to either 1) #include
<stdint.h> and perform pointer-to-integer casts through (u)intptr_t or
2) to check for Win64/MinGW64 and to cast through
`long long unsigned int' instead.

Cheers,
-A.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]