Closed
Description
After #122418, GCC 11+ now emits a (spurious) warning in optimized builds, but not debug builds. Clang does not issue a warning
Objects/longobject.c: In function ‘_PyLong_FromMedium’:
./Include/internal/pycore_object.h:310:19: warning: array subscript ‘PyHeapTypeObject {aka struct _heaptypeobject}[0]’ is partly outside array bounds of ‘PyTypeObject[1]’ {aka ‘struct _typeobject[1]’} [-Warray-bounds]
310 | if ((size_t)ht->unique_id < (size_t)tstate->types.size) {
| ~~^~~~~~~~~~~
Ojects/longobject.c:6596:14: note: while referencing ‘PyLong_Type’
6596 | PyTypeObject PyLong_Type = {
| ^~~~~~~~~~~
GCC is clever enough to inline the _Py_INCREF_TYPE
call on PyLong_Type
, but not clever enough to understand the _PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)
guard.
cpython/Include/internal/pycore_object.h
Lines 296 to 322 in db6f5e1
I don't see a great way to rewrite _Py_INCREF_TYPE
to avoid the warning, so maybe we should just use a #pragma
to suppress the Warray-bounds
warnings in that function.