gh-121040: Use __attribute__((fallthrough)) (#121044)

Fix warnings when using -Wimplicit-fallthrough compiler flag.

Annotate explicitly "fall through" switch cases with a new
_Py_FALLTHROUGH macro which uses __attribute__((fallthrough)) if
available. Replace "fall through" comments with _Py_FALLTHROUGH.

Add _Py__has_attribute() macro. No longer define __has_attribute()
macro if it's not defined. Move also _Py__has_builtin() at the top
of pyport.h.

Co-Authored-By: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Victor Stinner 2024-06-27 11:58:44 +02:00 committed by GitHub
parent 4999e0bda0
commit 12af8ec864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 131 additions and 104 deletions

View file

@ -248,14 +248,14 @@ _Py_ext_module_loader_result_set_error(
{
#ifndef NDEBUG
switch (kind) {
case _Py_ext_module_loader_result_EXCEPTION: /* fall through */
case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC:
assert(PyErr_Occurred());
break;
case _Py_ext_module_loader_result_ERR_MISSING: /* fall through */
case _Py_ext_module_loader_result_ERR_UNINITIALIZED: /* fall through */
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: /* fall through */
case _Py_ext_module_loader_result_ERR_NOT_MODULE: /* fall through */
case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_UNINITIALIZED: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_MISSING_DEF:
assert(!PyErr_Occurred());
break;
@ -279,11 +279,11 @@ _Py_ext_module_loader_result_set_error(
res->kind = _Py_ext_module_kind_INVALID;
break;
/* None of the rest affect the result kind. */
case _Py_ext_module_loader_result_EXCEPTION: /* fall through */
case _Py_ext_module_loader_result_ERR_MISSING: /* fall through */
case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC: /* fall through */
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: /* fall through */
case _Py_ext_module_loader_result_ERR_NOT_MODULE: /* fall through */
case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_MISSING_DEF:
break;
default:
@ -307,14 +307,14 @@ _Py_ext_module_loader_result_apply_error(
#ifndef NDEBUG
switch (err.kind) {
case _Py_ext_module_loader_result_EXCEPTION: /* fall through */
case _Py_ext_module_loader_result_EXCEPTION: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_UNREPORTED_EXC:
assert(err.exc != NULL);
break;
case _Py_ext_module_loader_result_ERR_MISSING: /* fall through */
case _Py_ext_module_loader_result_ERR_UNINITIALIZED: /* fall through */
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: /* fall through */
case _Py_ext_module_loader_result_ERR_NOT_MODULE: /* fall through */
case _Py_ext_module_loader_result_ERR_MISSING: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_UNINITIALIZED: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_NOT_MODULE: _Py_FALLTHROUGH;
case _Py_ext_module_loader_result_ERR_MISSING_DEF:
assert(err.exc == NULL);
break;