Skip to content

Compile warnings in 64-bit builds, mostly re. loss-of-data #93

Open

Description

@MaxBarraclough

I'm able to compile and run pForth for Windows/AMD64 using Visual Studio 2019. I'm seeing several compiler warnings though:

philburk-pforth-dd36def\csrc\pf_inner.c(204,69): warning C4293: '>>': shift count negative or too big, undefined behavior
philburk-pforth-dd36def\csrc\pf_save.c(410,75): warning C4244: '=': conversion from 'cell_t' to 'uint32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(412,102): warning C4267: '=': conversion from 'size_t' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(413,106): warning C4267: '=': conversion from 'size_t' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(414,41): warning C4244: '=': conversion from 'cell_t' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(438,38): warning C4244: '=': conversion from 'ExecToken' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(456,55): warning C4244: '=': conversion from 'cell_t' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(457,78): warning C4244: '=': conversion from 'cell_t' to 'uint32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(469,34): warning C4244: '=': conversion from 'cell_t' to 'int32_t', possible loss of data
philburk-pforth-dd36def\csrc\pf_save.c(476,30): warning C4244: '=': conversion from 'cell_t' to 'int32_t', possible loss of data

Regarding the possible loss of data warnings: these seem, at a glance, to be well-founded. For instance, peering through the typedefs, the conversion from 'ExecToken' to 'int32_t' boils down to a uintptr_t being converted to an int32_t.

There are also some compiler warnings on 32-bit builds, but these ones seem spurious, as all 4 of the lines are wrapped within if( sizeof(ucell_t) == 8 ) { and so will not be executed on 32-bit builds.

philburk-pforth-dd36def\csrc\pf_save.c(223,38): warning C4293: '>>': shift count negative or too big, undefined behavior
philburk-pforth-dd36def\csrc\pf_save.c(224,38): warning C4293: '>>': shift count negative or too big, undefined behavior
philburk-pforth-dd36def\csrc\pf_save.c(225,38): warning C4293: '>>': shift count negative or too big, undefined behavior
philburk-pforth-dd36def\csrc\pf_save.c(226,38): warning C4293: '>>': shift count negative or too big, undefined behavior

It's possible to get rid of these warnings using the preprocessor, following this documentation, something like this (non-Windows builds will be unaffected):

    /* 32-bit Windows builds definitely don't need the first
       sequence. This avoid spurious Visual Studio warnings. */
#if (!defined _WIN32) || (defined _WIN64)
    if( sizeof(ucell_t) == 8 )
    {
        *addr++ = (uint8_t) (data>>56);
        *addr++ = (uint8_t) (data>>48);
        *addr++ = (uint8_t) (data>>40);
        *addr++ = (uint8_t) (data>>32);
    }
#endif
    *addr++ = (uint8_t) (data>>24);
    *addr++ = (uint8_t) (data>>16);
    *addr++ = (uint8_t) (data>>8);
    *addr = (uint8_t) (data);

Activity

  1. self-assigned this
    on Mar 14, 2021
  2. added this to the Version_2.1.0 milestone on Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugbuildrelated to building

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions