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

Compiler warning for _Py_InIntegralTypeRange #97786

Open
brettcannon opened this issue Oct 3, 2022 · 7 comments
Open

Compiler warning for _Py_InIntegralTypeRange #97786

brettcannon opened this issue Oct 3, 2022 · 7 comments
Assignees
Labels
3.10 3.11 3.12 expert-C-API interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

brettcannon commented Oct 3, 2022

Bug report

Python/pytime.c:297:10: warning: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]
    if (!_Py_InIntegralTypeRange(time_t, intpart)) {
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:72:45: note: expanded from macro '_Py_InIntegralTypeRange'
    (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
                                         ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:61:88: note: expanded from macro '_Py_IntegralTypeMax'
    (_Py_IS_TYPE_SIGNED(type) ? (((((type)1 << (sizeof(type)*CHAR_BIT - 2)) - 1) << 1) + 1) : ~(type)0)
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Python/pytime.c:352:14: warning: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]
        if (!_Py_InIntegralTypeRange(time_t, intpart)) {
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:72:45: note: expanded from macro '_Py_InIntegralTypeRange'
    (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
                                         ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:61:88: note: expanded from macro '_Py_IntegralTypeMax'
    (_Py_IS_TYPE_SIGNED(type) ? (((((type)1 << (sizeof(type)*CHAR_BIT - 2)) - 1) << 1) + 1) : ~(type)0)
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Python/pytime.c:518:10: warning: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion]
    if (!_Py_InIntegralTypeRange(_PyTime_t, d)) {
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:72:45: note: expanded from macro '_Py_InIntegralTypeRange'
    (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))
                                         ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_pymath.h:61:88: note: expanded from macro '_Py_IntegralTypeMax'
    (_Py_IS_TYPE_SIGNED(type) ? (((((type)1 << (sizeof(type)*CHAR_BIT - 2)) - 1) << 1) + 1) : ~(type)0)
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
3 warnings generated.

Your environment

  • CPython main (3.11.0rc2 time frame)
  • clang 10

Linked PRs

@brettcannon brettcannon added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) expert-C-API labels Oct 3, 2022
@brettcannon
Copy link
Member Author

Reported for WebAssembly builds at #97786 .

benjaminp added a commit to benjaminp/cpython that referenced this issue Oct 3, 2022
This avoids compiler warnings and is probably safer from undefined behavior than the previous code.

Fixes pythongh-97786.
benjaminp added a commit to benjaminp/cpython that referenced this issue Oct 3, 2022
This avoids compiler warnings and is probably safer from undefined behavior than the previous code.

Fixes pythongh-97786.
@vstinner
Copy link
Member

vstinner commented Oct 4, 2022

See also #83458.

This bug was one of my motivations to add math.nextafter() and math.ulp(), to help me understanding this issue :-D

@vstinner
Copy link
Member

vstinner commented Oct 4, 2022

See also #78604.

@vstinner
Copy link
Member

vstinner commented Oct 4, 2022

My abandonned attempt to fix this warning using nextafter(): PR #17933. I abandonned my PR because I didn't have time to work on it.

@gpshead
Copy link
Member

gpshead commented Feb 5, 2023

cc: @mdickinson as a numeric details expert

@mdickinson
Copy link
Member

I had half a solution to this at one point (the nextafter-based solution looks attractive in principle, but doesn't end up doing the right thing, unfortunately); I can try to pick this up if that's helpful. I'm out of cycles for this weekend, though, so it won't be before next weekend.

@gpshead
Copy link
Member

gpshead commented Feb 5, 2023

this warning has been around a while, no rush. I just figured you're the best to understand it.

clang on any platform will reproduce it.

@mdickinson mdickinson self-assigned this Feb 5, 2023
gpshead pushed a commit that referenced this issue Feb 20, 2023
Fixes compiler warnings in pytime.c.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2023
Fixes compiler warnings in pytime.c.
(cherry picked from commit b1b375e2670a58fc37cb4c2629ed73b045159918)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 3.11 3.12 expert-C-API interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants
@brettcannon @gpshead @vstinner @mdickinson and others