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 warnings in main / 3.11 #96017

Closed
tiran opened this issue Aug 16, 2022 · 5 comments
Closed

Compiler warnings in main / 3.11 #96017

tiran opened this issue Aug 16, 2022 · 5 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes OS-wasi type-bug An unexpected behavior, bug, or error

Comments

@tiran
Copy link
Member

tiran commented Aug 16, 2022

Bug report

I'm getting several compiler warnings when compiling on Linux X86_64, wasm32-emscripten, and wasm32-wasi.

Your environment

  • x86_64-pc-linux-gnu with gcc
  • wasm32-emscripten with clang
  • wasm32-wasi with clang

warnings

Objects/typeobject.c:6805:34: warning: comparison of integers of different signs: 'Py_ssize_t' (aka 'long') and 'unsigned long' [-Wsign-compare]
    else if (type->tp_dictoffset < sizeof(PyObject)) {

Fix: cast sizeof to Py_ssize_t

Objects/typeobject.c:74:1: warning: unused function 'static_builtin_index_is_set' [-Wunused-function]
static_builtin_index_is_set(PyTypeObject *self)
^

Fix: don't define the function if NDEBUG is set.

Modules/_testcapi/heaptype.c:280:23: warning: unused variable 'class_ht' [-Wunused-variable]
    PyHeapTypeObject *class_ht = (PyHeapTypeObject *)class;
Modules/_testcapi/heaptype.c:279:19: warning: unused variable 'class_tp' [-Wunused-variable]
    PyTypeObject *class_tp = (PyTypeObject *)class;

Fix: unset NDEBUG before including assert.h.

Python/ceval_gil.h:136:13: warning: unused function 'recreate_gil' [-Wunused-function]
static void recreate_gil(struct _gil_runtime_state *gil)

Fix: only define function ifdef HAVE_FORK

Python/pytime.c:297:10: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-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)

The warning is coming from clang from WASI-SDK.

Modules/expat/xmlparse.c:3107:9: warning: code will never be executed [-Wunreachable-code]
        parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf,
        ^~~~~~
Modules/expat/xmlparse.c:3106:16: note: silence by adding parentheses to mark code as explicitly dead
      else if (0 && parser->m_characterDataHandler)
               ^
               /* DISABLES CODE */ ( )
Modules/expat/xmlparse.c:4050:9: warning: code will never be executed [-Wunreachable-code]
        parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf,
        ^~~~~~
Modules/expat/xmlparse.c:4049:16: note: silence by adding parentheses to mark code as explicitly dead
      else if (0 && parser->m_characterDataHandler)
               ^
               /* DISABLES CODE */ ( )
Modules/expat/xmlparse.c:7681:11: warning: format specifies type 'int' but the argument has type 'ptrdiff_t' (aka 'long') [-Wformat]
          bytesMore, (account == XML_ACCOUNT_DIRECT) ? "DIR" : "EXP",
          ^~~~~~~~~
3 warnings generated.

The warnings are coming from clang from WASI-SDK. These look like issues in upstream expat code.

@tiran tiran added the type-bug An unexpected behavior, bug, or error label Aug 16, 2022
tiran added a commit to tiran/cpython that referenced this issue Aug 16, 2022
- "comparison of integers of different signs" in typeobject.c
- only define static_builtin_index_is_set in DEBUG builds
- unset NDEBUG before including assert.h
- only define recreate_gil with ifdef HAVE_FORK
@tiran tiran added 3.11 only security fixes 3.12 bugs and security fixes labels Aug 16, 2022
@tiran
Copy link
Member Author

tiran commented Aug 16, 2022

Petr takes care of parts.h in #95992

tiran added a commit to tiran/cpython that referenced this issue Aug 19, 2022
tiran added a commit that referenced this issue Aug 19, 2022
- "comparison of integers of different signs" in typeobject.c
- only define static_builtin_index_is_set in DEBUG builds
- only define recreate_gil with ifdef HAVE_FORK
tiran added a commit to tiran/cpython that referenced this issue Aug 19, 2022
- "comparison of integers of different signs" in typeobject.c
- only define static_builtin_index_is_set in DEBUG builds
- only define recreate_gil with ifdef HAVE_FORK.
(cherry picked from commit d9c1b74)

Co-authored-by: Christian Heimes <christian@python.org>
@brettcannon
Copy link
Member

I'm going to break out the _Py_InIntegralTypeRange warning as it isn't special to WASM.

@vstinner
Copy link
Member

vstinner commented Oct 4, 2022

See issue #97786 for the _Py_InIntegralTypeRange() warning.

ambv pushed a commit that referenced this issue Oct 5, 2022
- only define recreate_gil with ifdef HAVE_FORK.
(cherry picked from commit d9c1b74)

Co-authored-by: Christian Heimes <christian@python.org>
@OTheDev
Copy link
Contributor

OTheDev commented Feb 21, 2023

FYI, the last warning still appears on main but has been addressed upstream :).

@vstinner
Copy link
Member

vstinner commented Apr 5, 2023

It's hard to keep track of an issue reported multiple unrelated compiler warnings. Most of them seem to be fixed, so I close the issue. You may open new issues if some warnings are still emitted on latest versions.

@vstinner vstinner closed this as completed Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes OS-wasi type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

6 participants