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

bignum.cpp: Avoid long to double conversion under conditional test #3845

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spchamp
Copy link

@spchamp spchamp commented Dec 31, 2021

This patch adds an additional cast for a conditional test form, in the definition of Bignum::from_double in machine/class/bignum.cpp

The cast should serve to ensure that the local variable value will be evaluated as being of a long type, within the left hand expression in the conditional test form. clang++ 11 has detected a potential type incompatibility, in this expression.

The value is already being cast to long, in the right hand expression in the test form, i.e 0 != (long)value.

Previous to the patch, compiling with clang++ 11 on FreeBSD 11.1

2: CXX machine/class/bignum.cpp
4: CXX machine/class/block_as_method.cpp
machine/class/bignum.cpp:1112:32: error: implicit conversion from 'long' to 'double' changes value from 4611686018427387903 to 4611686018427387904 [-Werror,-Wimplicit-const-int-float-convers>
    while(!(value <= (LONG_MAX >> 1)) || 0 != (long)value) {
                  ~~  ~~~~~~~~~^~~~
3: CXX machine/class/block_environment.cpp
1 error generated.
Error: /usr/local/bin/clang++11 -I/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/machine -I/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/mach>
/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:69:in `command': Error compiling (RuntimeError)
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:235:in `cxx_compile'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:222:in `compile'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:438:in `build'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:958:in `block (2 levels) in perform_tasks'

  1. Is this pull-request complete?
  • Yes, this pull-request is ready to be reviewed and merged.
  • No, this pull-request is a work-in-progress.
  1. Does this pull request fix an issue with an existing feature or introduce a new feature?
  • It fixes an issue with an existing features.
  • It introduces a new feature.
  1. Does this pull-request include tests?
  • Yes, it includes tests.
  • No, it does not include tests because the tests already exist.
  • No, it does not include tests because tests are too difficult to write.
  • No, it does not include tests because ...

This patch adds an additional cast for a conditional test form, in the
definition of Bignum::from_double in machine/class/bignum.cpp

The cast should serve to ensure that the local variable 'value' will be
evaluated as being of a long type, within the left hand expresesion in
the conditional test form. clang++ 11 has detected a potential type
incompatibility, in this expression.

The value is already being cast to long, in the right hand expression of
the test form, i.e `0 != (long)value`.

Previous to the patch, compiling with clang++ 11 on FreeBSD 11.1
~~~~
2: CXX machine/class/bignum.cpp
4: CXX machine/class/block_as_method.cpp
machine/class/bignum.cpp:1112:32: error: implicit conversion from 'long' to 'double' changes value from 4611686018427387903 to 4611686018427387904 [-Werror,-Wimplicit-const-int-float-convers>
    while(!(value <= (LONG_MAX >> 1)) || 0 != (long)value) {
                  ~~  ~~~~~~~~~^~~~
3: CXX machine/class/block_environment.cpp
1 error generated.
Error: /usr/local/bin/clang++11 -I/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/machine -I/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/mach>
/usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:69:in `command': Error compiling (RuntimeError)
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:235:in `cxx_compile'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:222:in `compile'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:438:in `build'
        from /usr/home/gimbal/wk/dist_wk/ports_devo/lang/rubinius/work/rubinius-5.0/build/scripts/daedalus.rb:958:in `block (2 levels) in perform_tasks'
~~~~
@spchamp spchamp changed the title bignum.cpp: Avoid long to double conversion under shift bignum.cpp: Avoid long to double conversion under conditional test Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant