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

Lots of new compiler warnings #124064

Closed
sobolevn opened this issue Sep 13, 2024 · 7 comments · Fixed by #124065
Closed

Lots of new compiler warnings #124064

sobolevn opened this issue Sep 13, 2024 · 7 comments · Fixed by #124065
Labels
build The build process and cross-build

Comments

@sobolevn
Copy link
Member

sobolevn commented Sep 13, 2024

In file included from ./Include/internal/pycore_global_objects.h:12:
./Include/internal/pycore_gc.h:230:21: warning: implicit conversion changes signedness: 'int' to 'uintptr_t' (aka 'unsigned long') [-Wsign-conversion]
    gc->_gc_prev &= ~_PyGC_PREV_MASK_FINALIZED;
                 ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./Include/internal/pycore_code.h:13:
./Include/internal/pycore_backoff.h:78:66: warning: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Wimplicit-int-conversion]
        return make_backoff_counter((1 << (counter.backoff + 1)) - 1, counter.backoff + 1);
               ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from ./Include/internal/pycore_mimalloc.h:45:
./Include/internal/mimalloc/mimalloc/internal.h:489:84: warning: implicit conversion changes signedness: 'int' to 'mi_thread_free_t' (aka 'unsigned long') [-Wsign-conversion]
  return (mi_block_t*)(mi_atomic_load_relaxed(&((mi_page_t*)page)->xthread_free) & ~3);
                                                                                 ~ ^~
./Include/internal/mimalloc/mimalloc/internal.h:508:29: warning: implicit conversion changes signedness: 'int' to 'mi_thread_free_t' (aka 'unsigned long') [-Wsign-conversion]
  return (mi_block_t*)(tf & ~0x03);
                          ~ ^~~~~
./Include/internal/mimalloc/mimalloc/internal.h:806:10: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
  return __builtin_clzl(x);
  ~~~~~~ ^~~~~~~~~~~~~~~~~
./Include/internal/mimalloc/mimalloc/internal.h:814:10: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
  return __builtin_ctzl(x);
  ~~~~~~ ^~~~~~~~~~~~~~~~~
./Modules/getpath.c:264:48: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
                                               ^ ~
./Modules/getpath.c:269:22: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    memset(parts, 0, n * sizeof(wchar_t *));
                     ^ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:77:33: note: expanded from macro 'memset'
                __builtin___memset_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest))
                                              ^~~~~~~~~~~
./Modules/getpath.c:295:61: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    wchar_t *final = cchFinal > 0 ? (wchar_t *)PyMem_Malloc(cchFinal * sizeof(wchar_t)) : NULL;
                                                            ^~~~~~~~ ~
./Modules/getpath.c:318:57: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            } else if (_Py_add_relfile(final, parts[i], cchFinal) < 0) {
                       ~~~~~~~~~~~~~~~                  ^~~~~~~~
./Modules/getpath.c:385:63: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
    wchar_t *wbuffer = _Py_DecodeUTF8_surrogateescape(buffer, cb, &len);
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ^~
./Modules/getpath.c:663:43: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
            u = PyUnicode_FromWideChar(w, len);
                ~~~~~~~~~~~~~~~~~~~~~~    ^~~
./Modules/getpath.c:707:43: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
            u = PyUnicode_FromWideChar(w, len);
                ~~~~~~~~~~~~~~~~~~~~~~    ^~~
13 warnings generated.

Related #123020

Linked PRs

@sobolevn sobolevn added the build The build process and cross-build label Sep 13, 2024
@sobolevn
Copy link
Member Author

Oh, I get 100s of warnings:

gcc -c -fno-strict-overflow -Wsign-compare -g -Og -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -fstack-protector-strong -Wconversion -Wimplicit-fallthrough -Werror=format-security -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/opt/openssl/include  -DPy_BUILD_CORE -o Objects/bytes_methods.o Objects/bytes_methods.c
Objects/bytes_methods.c:256:21: warning: implicit conversion changes signedness: 'const unsigned char' to 'char' [-Wsign-conversion]
        result[i] = Py_TOLOWER((unsigned char) cptr[i]);
                  ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/cpython/pyctype.h:32:24: note: expanded from macro 'Py_TOLOWER'
#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytes_methods.c:272:21: warning: implicit conversion changes signedness: 'const unsigned char' to 'char' [-Wsign-conversion]
        result[i] = Py_TOUPPER((unsigned char) cptr[i]);
                  ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/cpython/pyctype.h:33:24: note: expanded from macro 'Py_TOUPPER'
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytes_methods.c:301:21: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
        *result++ = c;
                  ~ ^
Objects/bytes_methods.c:316:19: warning: implicit conversion changes signedness: 'const unsigned char' to 'char' [-Wsign-conversion]
        *result = Py_TOUPPER(*s);
                ~ ^~~~~~~~~~~~~~
./Include/cpython/pyctype.h:33:24: note: expanded from macro 'Py_TOUPPER'
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytes_methods.c:336:23: warning: implicit conversion changes signedness: 'const unsigned char' to 'char' [-Wsign-conversion]
            *result = Py_TOUPPER(c);
                    ~ ^~~~~~~~~~~~~
./Include/cpython/pyctype.h:33:24: note: expanded from macro 'Py_TOUPPER'
#define Py_TOUPPER(c) (_Py_ctype_toupper[Py_CHARMASK(c)])
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytes_methods.c:339:23: warning: implicit conversion changes signedness: 'const unsigned char' to 'char' [-Wsign-conversion]
            *result = Py_TOLOWER(c);
                    ~ ^~~~~~~~~~~~~
./Include/cpython/pyctype.h:32:24: note: expanded from macro 'Py_TOLOWER'
#define Py_TOLOWER(c) (_Py_ctype_tolower[Py_CHARMASK(c)])
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytes_methods.c:342:23: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
            *result = c;
                    ~ ^
In file included from Objects/bytes_methods.c:387:
Objects/stringlib/fastsearch.h:58:42: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        p = STRINGLIB_FAST_MEMCHR(s, ch, n);
            ~~~~~~~~~~~~~~~~~~~~~        ^
Objects/stringlib/fastsearch.h:336:42: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
                                  p->cut * STRINGLIB_SIZEOF_CHAR));
                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Objects/stringlib/fastsearch.h:348:27: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
    STRINGLIB_CHAR last = needle[len_needle - 1] & TABLE_MASK;
                          ^~~~~~~~~~~~~~~~~~~~~~ ~
Objects/stringlib/fastsearch.h:350:28: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
        STRINGLIB_CHAR x = needle[i] & TABLE_MASK;
                           ^~~~~~~~~ ~
Objects/stringlib/fastsearch.h:365:18: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
        p->table[needle[i] & TABLE_MASK] = shift;
                 ^~~~~~~~~ ~
Objects/stringlib/fastsearch.h:395:43: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                          ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:407:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
            assert((window[len_needle - 1] & TABLE_MASK) ==
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytes_methods.c:387:
Objects/stringlib/fastsearch.h:408:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                   (needle[len_needle - 1] & TABLE_MASK));
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytes_methods.c:387:
Objects/stringlib/fastsearch.h:434:47: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                    Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                              ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:460:43: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                          ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:471:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
            assert((window[len_needle - 1] & TABLE_MASK) ==
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytes_methods.c:387:
Objects/stringlib/fastsearch.h:472:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                   (needle[len_needle - 1] & TABLE_MASK));
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
Objects/bytes_methods.c:623:36: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    return memchr(str, (int) ival, len) != NULL;
           ~~~~~~                  ^~~
Objects/bytes_methods.c:666:34: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    if (memcmp(str + start, sub, slen) != 0)
        ~~~~~~                   ^~~~
21 warnings generated.
gcc -c -fno-strict-overflow -Wsign-compare -g -Og -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -fstack-protector-strong -Wconversion -Wimplicit-fallthrough -Werror=format-security -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/opt/openssl/include  -DPy_BUILD_CORE -o Objects/bytearrayobject.o Objects/bytearrayobject.c
In file included from Objects/bytearrayobject.c:7:
In file included from ./Include/internal/pycore_ceval.h:13:
In file included from ./Include/internal/pycore_interp.h:16:
In file included from ./Include/internal/pycore_code.h:11:
In file included from ./Include/internal/pycore_stackref.h:11:
In file included from ./Include/internal/pycore_object_deferred.h:8:
./Include/internal/pycore_gc.h:230:21: warning: implicit conversion changes signedness: 'int' to 'uintptr_t' (aka 'unsigned long') [-Wsign-conversion]
    gc->_gc_prev &= ~_PyGC_PREV_MASK_FINALIZED;
                 ~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from Objects/bytearrayobject.c:7:
In file included from ./Include/internal/pycore_ceval.h:13:
In file included from ./Include/internal/pycore_interp.h:16:
In file included from ./Include/internal/pycore_code.h:13:
./Include/internal/pycore_backoff.h:78:66: warning: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Wimplicit-int-conversion]
        return make_backoff_counter((1 << (counter.backoff + 1)) - 1, counter.backoff + 1);
               ~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from Objects/bytearrayobject.c:7:
In file included from ./Include/internal/pycore_ceval.h:13:
In file included from ./Include/internal/pycore_interp.h:31:
In file included from ./Include/internal/pycore_mimalloc.h:45:
./Include/internal/mimalloc/mimalloc/internal.h:489:84: warning: implicit conversion changes signedness: 'int' to 'mi_thread_free_t' (aka 'unsigned long') [-Wsign-conversion]
  return (mi_block_t*)(mi_atomic_load_relaxed(&((mi_page_t*)page)->xthread_free) & ~3);
                                                                                 ~ ^~
./Include/internal/mimalloc/mimalloc/internal.h:508:29: warning: implicit conversion changes signedness: 'int' to 'mi_thread_free_t' (aka 'unsigned long') [-Wsign-conversion]
  return (mi_block_t*)(tf & ~0x03);
                          ~ ^~~~~
./Include/internal/mimalloc/mimalloc/internal.h:806:10: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
  return __builtin_clzl(x);
  ~~~~~~ ^~~~~~~~~~~~~~~~~
./Include/internal/mimalloc/mimalloc/internal.h:814:10: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
  return __builtin_ctzl(x);
  ~~~~~~ ^~~~~~~~~~~~~~~~~
In file included from Objects/bytearrayobject.c:8:
./Include/internal/pycore_object.h:445:58: warning: implicit conversion changes signedness: 'int' to 'uintptr_t' (aka 'unsigned long') [-Wsign-conversion]
    gc->_gc_next = ((uintptr_t)generation0) | interp->gc.visited_space;
                                            ~ ~~~~~~~~~~~^~~~~~~~~~~~~
./Include/internal/pycore_object.h:763:54: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
        _PyType_HasFeature(tp, Py_TPFLAGS_PREHEADER) * 2 * sizeof(PyObject *)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ ~
./Include/internal/pycore_object.h:761:9: warning: implicit conversion changes signedness: 'int' to 'unsigned long' [-Wsign-conversion]
        _PyType_IS_GC(tp) * sizeof(PyGC_Head) +
        ^~~~~~~~~~~~~~~~~ ~
./Include/internal/pycore_object.h:754:26: note: expanded from macro '_PyType_IS_GC'
#define _PyType_IS_GC(t) _PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_object.h:824:40: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    assert(tp->tp_basicsize > 0 && tp->tp_basicsize % sizeof(PyObject *) == 0);
                                   ~~~~^~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytearrayobject.c:10:
./Include/internal/pycore_long.h:274:29: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
    op->long_value.lv_tag = TAG_FROM_SIGN_AND_SIZE(sign, (size_t)size);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/internal/pycore_long.h:266:48: note: expanded from macro 'TAG_FROM_SIGN_AND_SIZE'
#define TAG_FROM_SIGN_AND_SIZE(sign, size) ((1 - (sign)) | ((size) << NON_SIZE_BITS))
                                             ~~^~~~~~~~  ~
./Include/internal/pycore_long.h:289:30: warning: implicit conversion changes signedness: 'int' to 'uintptr_t' (aka 'unsigned long') [-Wsign-conversion]
    op->long_value.lv_tag &= NON_SIZE_MASK;
                          ~~ ^~~~~~~~~~~~~
./Include/internal/pycore_long.h:284:23: note: expanded from macro 'NON_SIZE_MASK'
#define NON_SIZE_MASK ~((1 << NON_SIZE_BITS) - 1)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytearrayobject.c:40:14: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
    *value = face_value;
           ~ ^~~~~~~~~~
Objects/bytearrayobject.c:135:38: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
        new->ob_bytes = PyMem_Malloc(alloc);
                        ~~~~~~~~~~~~ ^~~~~
Objects/bytearrayobject.c:202:31: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
            Py_SET_SIZE(self, size);
            ~~~~~~~~~~~~~~~~~~^~~~~
./Include/object.h:299:69: note: expanded from macro 'Py_SET_SIZE'
#  define Py_SET_SIZE(ob, size) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
                                ~~~~~~~~~~~                         ^~~~
Objects/bytearrayobject.c:242:23: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
    Py_SET_SIZE(self, size);
    ~~~~~~~~~~~~~~~~~~^~~~~
./Include/object.h:299:69: note: expanded from macro 'Py_SET_SIZE'
#  define Py_SET_SIZE(ob, size) Py_SET_SIZE(_PyVarObject_CAST(ob), (size))
                                ~~~~~~~~~~~                         ^~~~
Objects/bytearrayobject.c:243:21: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
    obj->ob_alloc = alloc;
                  ~ ^~~~~
Objects/bytearrayobject.c:412:24: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            for (cur = start, i = 0; i < slicelength;
                     ~ ^~~~~
Objects/bytearrayobject.c:413:25: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
                 cur += step, i++) {
                     ~~ ^~~~
Objects/bytearrayobject.c:586:38: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    PyByteArray_AS_STRING(self)[i] = ival;
                                   ~ ^~~~
Objects/bytearrayobject.c:698:24: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            for (cur = start, i = 0;
                     ~ ^~~~~
Objects/bytearrayobject.c:699:39: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
                 i < slicelen; cur += step, i++) {
                                   ~~ ^~~~
Objects/bytearrayobject.c:702:27: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
                if (cur + step >= (size_t)PyByteArray_GET_SIZE(self))
                        ~ ^~~~
Objects/bytearrayobject.c:703:60: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
                    lim = PyByteArray_GET_SIZE(self) - cur - 1;
                        ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
Objects/bytearrayobject.c:703:27: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
                    lim = PyByteArray_GET_SIZE(self) - cur - 1;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~ ~
./Include/cpython/bytearrayobject.h:34:36: note: expanded from macro 'PyByteArray_GET_SIZE'
#define PyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Objects/bytearrayobject.c:709:44: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            cur = start + (size_t)slicelen*step;
                                          ~^~~~
Objects/bytearrayobject.c:709:19: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            cur = start + (size_t)slicelen*step;
                  ^~~~~ ~
Objects/bytearrayobject.c:713:25: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
                        PyByteArray_GET_SIZE(self) - cur);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Include/cpython/bytearrayobject.h:34:36: note: expanded from macro 'PyByteArray_GET_SIZE'
#define PyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))
                                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_string.h:70:34: note: expanded from macro 'memmove'
                __builtin___memmove_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest))
                                               ^~~~~~~~~~~
Objects/bytearrayobject.c:733:24: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            for (cur = start, i = 0; i < slicelen; cur += step, i++)
                     ~ ^~~~~
Objects/bytearrayobject.c:733:59: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
            for (cur = start, i = 0; i < slicelen; cur += step, i++)
                                                       ~~ ^~~~
Objects/bytearrayobject.c:867:20: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
            s[i] = value;
                 ~ ^~~~~
Objects/bytearrayobject.c:913:56: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
        PyByteArray_AS_STRING(self)[Py_SIZE(self)-1] = value;
                                                     ~ ^~~~~
Objects/bytearrayobject.c:946:15: warning: implicit conversion changes signedness: 'unsigned long' to 'Py_ssize_t' (aka 'long') [-Wsign-conversion]
    newsize = strlen(className);
            ~ ^~~~~~~~~~~~~~~~~
Objects/bytearrayobject.c:954:27: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
    buffer = PyMem_Malloc(newsize);
             ~~~~~~~~~~~~ ^~~~~~~
Objects/bytearrayobject.c:977:12: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    *p++ = quote;
         ~ ^~~~~
Objects/bytearrayobject.c:1005:12: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    *p++ = quote;
         ~ ^~~~~
Objects/bytearrayobject.c:1067:40: warning: operand of ? changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
                     Py_MIN(self_size, other_size));
                                       ^~~~~~~~~~
./Include/pymacro.h:27:38: note: expanded from macro 'Py_MIN'
#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))
                                     ^
Objects/bytearrayobject.c:1067:29: warning: operand of ? changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
                     Py_MIN(self_size, other_size));
                            ^~~~~~~~~
./Include/pymacro.h:27:44: note: expanded from macro 'Py_MIN'
#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))
                                           ^
In file included from Objects/bytearrayobject.c:1114:
Objects/stringlib/fastsearch.h:58:42: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        p = STRINGLIB_FAST_MEMCHR(s, ch, n);
            ~~~~~~~~~~~~~~~~~~~~~        ^
Objects/stringlib/fastsearch.h:336:42: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
                                  p->cut * STRINGLIB_SIZEOF_CHAR));
                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Objects/stringlib/fastsearch.h:348:27: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
    STRINGLIB_CHAR last = needle[len_needle - 1] & TABLE_MASK;
                          ^~~~~~~~~~~~~~~~~~~~~~ ~
Objects/stringlib/fastsearch.h:350:28: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
        STRINGLIB_CHAR x = needle[i] & TABLE_MASK;
                           ^~~~~~~~~ ~
Objects/stringlib/fastsearch.h:365:18: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
        p->table[needle[i] & TABLE_MASK] = shift;
                 ^~~~~~~~~ ~
Objects/stringlib/fastsearch.h:395:43: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                          ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:407:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
            assert((window[len_needle - 1] & TABLE_MASK) ==
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytearrayobject.c:1114:
Objects/stringlib/fastsearch.h:408:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                   (needle[len_needle - 1] & TABLE_MASK));
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytearrayobject.c:1114:
Objects/stringlib/fastsearch.h:434:47: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                    Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                              ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:460:43: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
                                          ^~~~~~~~~~~~  ~
Objects/stringlib/fastsearch.h:471:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
            assert((window[len_needle - 1] & TABLE_MASK) ==
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytearrayobject.c:1114:
Objects/stringlib/fastsearch.h:472:21: warning: implicit conversion changes signedness: 'const char' to 'unsigned int' [-Wsign-conversion]
                   (needle[len_needle - 1] & TABLE_MASK));
                    ^~~~~~~~~~~~~~~~~~~~~~ ~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
In file included from Objects/bytearrayobject.c:1117:
Objects/stringlib/join.h:46:40: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        buffers = PyMem_NEW(Py_buffer, seqlen);
                  ~~~~~~~~~~~~~~~~~~~~~^~~~~~~
./Include/pymem.h:82:52: note: expanded from macro 'PyMem_NEW'
#define PyMem_NEW(type, n)        PyMem_New(type, (n))
                                  ~~~~~~~~~~~~~~~~~^~~
./Include/pymem.h:65:34: note: expanded from macro 'PyMem_New'
        ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
                                 ^  ~
In file included from Objects/bytearrayobject.c:1121:
Objects/stringlib/transmogrify.h:264:41: warning: implicit conversion changes signedness: 'long' to 'unsigned long' [-Wsign-conversion]
    while ((start = findchar(start, end - start, c)) != NULL) {
                    ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Objects/stringlib/transmogrify.h:253:46: note: expanded from macro 'findchar'
  ((char *)memchr((const void *)(target), c, target_len))
           ~~~~~~                            ^~~~~~~~~~
Objects/stringlib/transmogrify.h:378:36: warning: implicit conversion changes signedness: 'long' to 'unsigned long' [-Wsign-conversion]
        next = findchar(start, end - start, from_c);
               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Objects/stringlib/transmogrify.h:253:46: note: expanded from macro 'findchar'
  ((char *)memchr((const void *)(target), c, target_len))
           ~~~~~~                            ^~~~~~~~~~
Objects/stringlib/transmogrify.h:458:29: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
    next = findchar(self_s, self_len, from_c);
           ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
Objects/stringlib/transmogrify.h:253:46: note: expanded from macro 'findchar'
  ((char *)memchr((const void *)(target), c, target_len))
           ~~~~~~                            ^~~~~~~~~~
Objects/stringlib/transmogrify.h:480:36: warning: implicit conversion changes signedness: 'long' to 'unsigned long' [-Wsign-conversion]
        next = findchar(start, end - start, from_c);
               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Objects/stringlib/transmogrify.h:253:46: note: expanded from macro 'findchar'
  ((char *)memchr((const void *)(target), c, target_len))
           ~~~~~~                            ^~~~~~~~~~
Objects/stringlib/transmogrify.h:582:36: warning: implicit conversion changes signedness: 'long' to 'unsigned long' [-Wsign-conversion]
        next = findchar(start, end - start, from_c);
               ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Objects/stringlib/transmogrify.h:253:46: note: expanded from macro 'findchar'
  ((char *)memchr((const void *)(target), c, target_len))
           ~~~~~~                            ^~~~~~~~~~
Objects/bytearrayobject.c:1321:45: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        && memcmp(self_start, prefix_start, prefix_len) == 0)
           ~~~~~~                           ^~~~~~~~~~
Objects/bytearrayobject.c:1354:33: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
                  suffix_start, suffix_len) == 0)
                                ^~~~~~~~~~
Objects/bytearrayobject.c:1742:18: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    buf[index] = item;
               ~ ^~~~
Objects/bytearrayobject.c:1771:38: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    PyByteArray_AS_STRING(self)[n] = item;
                                   ~ ^~~~
Objects/bytearrayobject.c:1838:22: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
        buf[len++] = value;
                   ~ ^~~~~
Objects/bytearrayobject.c:1947:41: warning: implicit conversion loses integer precision: 'int' to 'char' [-Wimplicit-int-conversion]
    where = stringlib_find_char(buf, n, value);
            ~~~~~~~~~~~~~~~~~~~         ^~~~~
Objects/bytearrayobject.c:1989:78: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        while (left < mysize && memchr(bytesptr, (unsigned char)myptr[left], byteslen))
                                ~~~~~~                                       ^~~~~~~~
Objects/bytearrayobject.c:1996:81: warning: implicit conversion changes signedness: 'Py_ssize_t' (aka 'long') to 'unsigned long' [-Wsign-conversion]
        } while (right >= left && memchr(bytesptr, (unsigned char)myptr[right], byteslen));
                                  ~~~~~~                                        ^~~~~~~~
64 warnings generated.

these are just some from my output!

@ZeroIntensity
Copy link
Member

What configure arguments were used? I compiled earlier today and saw only a few warnings, not hundreds.

@sobolevn
Copy link
Member Author

--with-pydebug

@Eclips4
Copy link
Member

Eclips4 commented Sep 13, 2024

What configure arguments were used? I compiled earlier today and saw only a few warnings, not hundreds.

Perhaps that's because Nikita is using clang

@ZeroIntensity
Copy link
Member

Oh right, I forgot about the compiler. IIRC, mine was gcc.

@sobolevn
Copy link
Member Author

No, I am using gcc :)
It is visible here:

gcc -c -fno-strict-overflow -Wsign-compare -g -Og -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -fstack-protector-strong -Wconversion -Wimplicit-fallthrough -Werror=format-security -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/opt/openssl/include  -DPy_BUILD_CORE -o Objects/bytearrayobject.o Objects/bytearrayobject.c

@nohlson
Copy link
Contributor

nohlson commented Sep 13, 2024

New compiler options were added based on OpenSSF compiler hardening guidance. You can configure with the option --disable-safety to not include these compiler options in your build. We have been working to roll in the suggested compiler options: #112301

hugovk added a commit that referenced this issue Sep 16, 2024
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
vstinner added a commit to vstinner/cpython that referenced this issue Sep 17, 2024
vstinner added a commit to vstinner/cpython that referenced this issue Sep 17, 2024
Change also the fix for pycore_gc.h and pycore_stackref.h: declare
constants as uintptr_t rather than casting constants.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 17, 2024
Change also the fix for pycore_gc.h and pycore_stackref.h: declare
constants as uintptr_t rather than casting constants.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 17, 2024
vstinner added a commit that referenced this issue Sep 17, 2024
Change also the fix for pycore_gc.h and pycore_stackref.h:
declare constants as uintptr_t, rather than casting constants.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 18, 2024
Fix integer overflow check in decode_unicode_with_escapes(): use
PY_SSIZE_T_MAX instead of SIZE_MAX.
vstinner added a commit that referenced this issue Sep 18, 2024
Fix integer overflow check in decode_unicode_with_escapes(): use
PY_SSIZE_T_MAX instead of SIZE_MAX.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 18, 2024
…ythonGH-124204)

Fix integer overflow check in decode_unicode_with_escapes(): use
PY_SSIZE_T_MAX instead of SIZE_MAX.
(cherry picked from commit f9fa6ba)

Co-authored-by: Victor Stinner <[email protected]>
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
…n#124070)

Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
…ython#124177)

Change also the fix for pycore_gc.h and pycore_stackref.h:
declare constants as uintptr_t, rather than casting constants.
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this issue Sep 22, 2024
…ython#124204)

Fix integer overflow check in decode_unicode_with_escapes(): use
PY_SSIZE_T_MAX instead of SIZE_MAX.
Yhg1s pushed a commit that referenced this issue Sep 30, 2024
…GH-124204) (#124216)

gh-124064: Fix -Wconversion warnings in Parser/string_parser.c (GH-124204)

Fix integer overflow check in decode_unicode_with_escapes(): use
PY_SSIZE_T_MAX instead of SIZE_MAX.
(cherry picked from commit f9fa6ba)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
Projects
None yet
4 participants