Skip to content

Conversation

@chrstphrchvz
Copy link
Contributor

@chrstphrchvz chrstphrchvz commented Dec 6, 2023

This is an ongoing branch intended for code without designated owners, but these changes are independent and can be split off to different PRs if desirable.

./Modules/_localemodule.c:897:5: warning: cast from 'void (*)(PyObject *)' (aka 'void (*)(struct _object *)') to 'freefunc' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-strict]
  897 |     (freefunc)locale_free,
      |     ^~~~~~~~~~~~~~~~~~~~~

Objects/moduleobject.c:735:9: runtime error: call to function locale_free through pointer to incorrect function type 'void (*)(void *)'
_localemodule.c:884: note: locale_free defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/moduleobject.c:735:9 in
Objects/listobject.c:3167:5: warning: cast from 'PyObject *(*)(PyListObject *)' (aka 'struct _object *(*)(PyListObject *)') to 'reprfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3167 |     (reprfunc)list_repr,                        /* tp_repr */
      |     ^~~~~~~~~~~~~~~~~~~

Example UBSan -fsanitize=function error:

Objects/object.c:674:11: runtime error: call to function list_repr through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
listobject.c:382: note: list_repr defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:674:11 in
Objects/listobject.c:3162:5: warning: cast from 'void (*)(PyListObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3162 |     (destructor)list_dealloc,                   /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:2857:5: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
listobject.c:347: note: list_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:2857:5 in
Objects/listobject.c:3181:5: warning: cast from 'int (*)(PyListObject *, visitproc, void *)' (aka 'int (*)(PyListObject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 3181 |     (traverseproc)list_traverse,                /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Modules/gcmodule.c:493:16: runtime error: call to function list_traverse through pointer to incorrect function type 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)'
listobject.c:2760: note: list_traverse defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/gcmodule.c:493:16 in
Objects/listobject.c:3182:5: warning: cast from 'int (*)(PyListObject *)' to 'inquiry' (aka 'int (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3182 |     (inquiry)list_clear_slot,                   /* tp_clear */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Modules/gcmodule.c:1033:24: runtime error: call to function list_clear_slot through pointer to incorrect function type 'int (*)(struct _object *)'
listobject.c:620: note: list_clear_slot defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/gcmodule.c:1033:24 in
Objects/longobject.c:6288:5: warning: cast from 'Py_hash_t (*)(PyLongObject *)' (aka 'long (*)(struct _longobject *)') to 'hashfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6288 |     (hashfunc)long_hash,                        /* tp_hash */
      |     ^~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:999:16: runtime error: call to function long_hash through pointer to incorrect function type 'long (*)(struct _object *)'
longobject.c:3296: note: long_hash defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:999:16 in
Objects/longobject.c:6246:5: warning: cast from 'PyObject *(*)(PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *)') to 'unaryfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6246 |     (unaryfunc)long_abs,        /*tp_absolute*/
      |     ^~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:1442:25: runtime error: call to function long_abs through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
longobject.c:4882: note: long_abs defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1442:25 in
Objects/longobject.c:6244:5: warning: cast from 'PyObject *(*)(PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *)') to 'unaryfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6244 |     (unaryfunc)long_neg,        /*nb_negative*/
      |     ^~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:1391:25: runtime error: call to function long_neg through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
longobject.c:4870: note: long_neg defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1391:25 in
Objects/longobject.c:6248:5: warning: cast from 'PyObject *(*)(PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *)') to 'unaryfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6248 |     (unaryfunc)long_invert,     /*nb_invert*/
      |     ^~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:1425:25: runtime error: call to function long_invert through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
longobject.c:4854: note: long_invert defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1425:25 in
Objects/longobject.c:6247:5: warning: cast from 'int (*)(PyLongObject *)' (aka 'int (*)(struct _longobject *)') to 'inquiry' (aka 'int (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6247 |     (inquiry)long_bool,         /*tp_bool*/
      |     ^~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:1817:15: runtime error: call to function long_bool through pointer to incorrect function type 'int (*)(struct _object *)'
longobject.c:4891: note: long_bool defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1817:15 in
Objects/longobject.c:6238:5: warning: cast from 'PyObject *(*)(PyLongObject *, PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *, struct _longobject *)') to 'binaryfunc' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6238 |     (binaryfunc)long_add,       /*nb_add*/
      |     ^~~~~~~~~~~~~~~~~~~~
Objects/longobject.c:6239:5: warning: cast from 'PyObject *(*)(PyLongObject *, PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *, struct _longobject *)') to 'binaryfunc' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6239 |     (binaryfunc)long_sub,       /*nb_subtract*/
      |     ^~~~~~~~~~~~~~~~~~~~
Objects/longobject.c:6240:5: warning: cast from 'PyObject *(*)(PyLongObject *, PyLongObject *)' (aka 'struct _object *(*)(struct _longobject *, struct _longobject *)') to 'binaryfunc' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 6240 |     (binaryfunc)long_mul,       /*nb_multiply*/
      |     ^~~~~~~~~~~~~~~~~~~~

Example UBSan errors:

Objects/abstract.c:949:13: runtime error: call to function long_add through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
longobject.c:3474: note: long_add defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:949:13 in
Objects/abstract.c:949:13: runtime error: call to function long_sub through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
longobject.c:3510: note: long_sub defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:949:13 in
Objects/abstract.c:957:23: runtime error: call to function long_mul through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
longobject.c:3953: note: long_mul defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:957:23 in
Objects/tupleobject.c:851:5: warning: cast from 'void (*)(PyTupleObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  851 |     (destructor)tupledealloc,                   /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Python/generated_cases.c.h:430:17: runtime error: call to function tupledealloc through pointer to incorrect function type 'void (*)(struct _object *)'
tupleobject.c:187: note: tupledealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:430:17 in
Objects/tupleobject.c:1078:5: warning: cast from 'void (*)(_PyTupleIterObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 1078 |     (destructor)tupleiter_dealloc,              /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Python/generated_cases.c.h:2594:21: runtime error: call to function tupleiter_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
tupleobject.c:984: note: tupleiter_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:2594:21 in
Objects/tupleobject.c:1095:5: warning: cast from 'int (*)(_PyTupleIterObject *, visitproc, void *)' (aka 'int (*)(_PyTupleIterObject *, int (*)(struct _object *, void *), void *)') to 'traverseproc' (aka 'int (*)(struct _object *, int (*)(struct _object *, void *), void *)') converts to incompatible function type [-Wcast-function-type-strict]
 1095 |     (traverseproc)tupleiter_traverse,           /* tp_traverse */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

No example UBSan error
Objects/tupleobject.c:1100:5: warning: cast from 'PyObject *(*)(_PyTupleIterObject *)' (aka 'struct _object *(*)(_PyTupleIterObject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 1100 |     (iternextfunc)tupleiter_next,               /* tp_iternext */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:2972:14: runtime error: call to function tupleiter_next through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
tupleobject.c:999: note: tupleiter_next defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2972:14 in
Objects/listobject.c:2928:5: warning: cast from 'int (*)(PyListObject *, Py_ssize_t, PyObject *)' (aka 'int (*)(PyListObject *, long, struct _object *)') to 'ssizeobjargproc' (aka 'int (*)(struct _object *, long, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2928 |     (ssizeobjargproc)list_ass_item,             /* sq_ass_item */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:2032:19: runtime error: call to function list_ass_item through pointer to incorrect function type 'int (*)(struct _object *, long, struct _object *)'
listobject.c:780: note: list_ass_item defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:2032:19 in
Objects/bytesobject.c:2952:5: warning: cast from 'PyObject *(*)(PyBytesObject *, PyBytesObject *, int)' (aka 'struct _object *(*)(PyBytesObject *, PyBytesObject *, int)') to 'richcmpfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, int)') converts to incompatible function type [-Wcast-function-type-strict]
 2952 |     (richcmpfunc)bytes_richcompare,             /* tp_richcompare */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:904:15: runtime error: call to function bytes_richcompare through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, int)'
bytesobject.c:1524: note: bytes_richcompare defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:904:15 in
Objects/listobject.c:3251:5: warning: cast from 'PyObject *(*)(_PyListIterObject *)' (aka 'struct _object *(*)(_PyListIterObject *)') to 'iternextfunc' (aka 'struct _object *(*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3251 |     (iternextfunc)listiter_next,                /* tp_iternext */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/typeobject.c:8150:11: runtime error: call to function listiter_next through pointer to incorrect function type 'struct _object *(*)(struct _object *)'
listobject.c:3292: note: listiter_next defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:8150:11 in
Objects/descrobject.c:1913:5: warning: cast from 'void (*)(mappingproxyobject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 1913 |     (destructor)mappingproxy_dealloc,           /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Python/generated_cases.c.h:3315:13: runtime error: call to function mappingproxy_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:1160: note: mappingproxy_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:3315:13 in
Objects/classobject.c:326:19: warning: cast from 'void (*)(PyMethodObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  326 |     .tp_dealloc = (destructor)method_dealloc,
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Python/generated_cases.c.h:89:13: runtime error: call to function method_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
classobject.c:236: note: method_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Python/generated_cases.c.h:89:13 in
Objects/descrobject.c:808:5: warning: cast from 'PyObject *(*)(PyMemberDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyMemberDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  808 |     (descrgetfunc)member_get,                   /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
Objects/descrobject.c:809:5: warning: cast from 'int (*)(PyMemberDescrObject *, PyObject *, PyObject *)' (aka 'int (*)(PyMemberDescrObject *, struct _object *, struct _object *)') to 'descrsetfunc' (aka 'int (*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  809 |     (descrsetfunc)member_set,                   /* tp_descr_set */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:1682:19: runtime error: call to function member_set through pointer to incorrect function type 'int (*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:227: note: member_set defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1682:19 in
Objects/object.c:1564:19: runtime error: call to function member_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:160: note: member_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1564:19 in
Objects/tupleobject.c:860:5: warning: cast from 'Py_hash_t (*)(PyTupleObject *)' (aka 'long (*)(PyTupleObject *)') to 'hashfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  860 |     (hashfunc)tuplehash,                        /* tp_hash */
      |     ^~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:999:16: runtime error: call to function tuplehash through pointer to incorrect function type 'long (*)(struct _object *)'
tupleobject.c:323: note: tuplehash defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:999:16 in
Example compiler warning:

Objects/descrobject.c:703:5: warning: cast from 'void (*)(PyDescrObject *)' to 'destructor' (aka 'void (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  703 |     (destructor)descr_dealloc,                  /* tp_dealloc */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:2857:5: runtime error: call to function descr_dealloc through pointer to incorrect function type 'void (*)(struct _object *)'
descrobject.c:23: note: descr_dealloc defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:2857:5 in
Objects/descrobject.c:771:5: warning: cast from 'PyObject *(*)(PyMethodDescrObject *, PyObject *, PyObject *)' (aka 'struct _object *(*)(PyMethodDescrObject *, struct _object *, struct _object *)') to 'descrgetfunc' (aka 'struct _object *(*)(struct _object *, struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  771 |     (descrgetfunc)classmethod_get,              /* tp_descr_get */
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/typeobject.c:10293:24: runtime error: call to function classmethod_get through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *, struct _object *)'
descrobject.c:94: note: classmethod_get defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/typeobject.c:10293:24 in
Objects/bytesobject.c:1686:5: warning: cast from 'int (*)(PyBytesObject *, Py_buffer *, int)' to 'getbufferproc' (aka 'int (*)(struct _object *, Py_buffer *, int)') converts to incompatible function type [-Wcast-function-type-strict]
 1686 |     (getbufferproc)bytes_buffer_getbuffer,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:436:15: runtime error: call to function bytes_buffer_getbuffer through pointer to incorrect function type 'int (*)(struct _object *, Py_buffer *, int)'
bytesobject.c:1665: note: bytes_buffer_getbuffer defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:436:15 in
Objects/bytesobject.c:2940:5: warning: cast from 'Py_hash_t (*)(PyBytesObject *)' (aka 'long (*)(PyBytesObject *)') to 'hashfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2940 |     (hashfunc)bytes_hash,                       /* tp_hash */
      |     ^~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:999:16: runtime error: call to function bytes_hash through pointer to incorrect function type 'long (*)(struct _object *)'
bytesobject.c:1587: note: bytes_hash defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:999:16 in
Objects/tupleobject.c:755:5: warning: cast from 'PyObject *(*)(PyTupleObject *, PyObject *)' (aka 'struct _object *(*)(PyTupleObject *, struct _object *)') to 'binaryfunc' (aka 'struct _object *(*)(struct _object *, struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
  755 |     (binaryfunc)tupleconcat,                    /* sq_concat */
      |     ^~~~~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/abstract.c:1137:18: runtime error: call to function tupleconcat through pointer to incorrect function type 'struct _object *(*)(struct _object *, struct _object *)'
tupleobject.c:443: note: tupleconcat defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/abstract.c:1137:18 in
Objects/listobject.c:2923:5: warning: cast from 'Py_ssize_t (*)(PyListObject *)' (aka 'long (*)(PyListObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 2923 |     (lenfunc)list_length,                       /* sq_length */
      |     ^~~~~~~~~~~~~~~~~~~~
Objects/listobject.c:3152:5: warning: cast from 'Py_ssize_t (*)(PyListObject *)' (aka 'long (*)(PyListObject *)') to 'lenfunc' (aka 'long (*)(struct _object *)') converts to incompatible function type [-Wcast-function-type-strict]
 3152 |     (lenfunc)list_length,
      |     ^~~~~~~~~~~~~~~~~~~~

Example UBSan error:

Objects/object.c:1820:15: runtime error: call to function list_length through pointer to incorrect function type 'long (*)(struct _object *)'
listobject.c:438: note: list_length defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:1820:15 in
@vstinner
Copy link
Member

vstinner commented Apr 3, 2025

Sadly, this PR got lost in the high number of PRs attached to #111178. I believe that issues addressed in this PR are already fixed in the main branch. I close your PR. Anyway, thanks for your contribution!

@vstinner vstinner closed this Apr 3, 2025
@chrstphrchvz chrstphrchvz deleted the patch-111178 branch November 12, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants