Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MaxBarraclough opened this issue Mar 10, 2021 · 0 comments
Open

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

MaxBarraclough opened this issue Mar 10, 2021 · 0 comments
Assignees
Labels
bug build related to building
Milestone

Comments

@MaxBarraclough
Copy link
Contributor

MaxBarraclough commented Mar 10, 2021

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);
@philburk philburk added the bug label Mar 14, 2021
@philburk philburk self-assigned this Mar 14, 2021
@philburk philburk added this to the Version_2.1.0 milestone Jan 8, 2023
@philburk philburk added the build related to building label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build related to building
Projects
None yet
Development

No branches or pull requests

2 participants