cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Compiler warnings in main / 3.11

Open tiran opened this issue 3 years ago • 1 comments

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 avatar Aug 16 '22 06:08 tiran

Petr takes care of parts.h in https://github.com/python/cpython/pull/95992

tiran avatar Aug 16 '22 11:08 tiran

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

brettcannon avatar Oct 03 '22 17:10 brettcannon

See issue #97786 for the _Py_InIntegralTypeRange() warning.

vstinner avatar Oct 04 '22 08:10 vstinner

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

OTheDev avatar Feb 21 '23 10:02 OTheDev

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 avatar Apr 05 '23 16:04 vstinner