Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bb6596

Browse filesBrowse files
committed
Suppress uninitialized variable warnings for small stack allocations
Add macros to disable and re-enable compiler-specific warnings about possibly uninitialized variables (`-Wmaybe-uninitialized` for GCC, `-Wuninitialized` for Clang, and warning C4700 for MSVC). Use these macros in `_PyEvalFramePushAndInit_Ex()` to suppress false positives on stack-allocated arrays like `stack_array`. This also addresses warnings such as the one in `pycore_call.h` when using `small_stack[_PY_FASTCALL_SMALL_STACK]` that may be flagged by GCC's `-Wmaybe-uninitialized`.
1 parent d47584a commit 8bb6596
Copy full SHA for 8bb6596

File tree

Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed

‎Include/pymacro.h

Copy file name to clipboardExpand all lines: Include/pymacro.h
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,21 @@ PyAPI_FUNC(uint32_t) Py_PACK_VERSION(int x, int y);
199199
#endif // Py_LIMITED_API < 3.14
200200

201201

202+
#if defined(__clang__)
203+
#define DISABLE_UNINIT_WARNINGS _Pragma("clang diagnostic push") \
204+
_Pragma("clang diagnostic ignored \"-Wuninitialized\"")
205+
#define ENABLE_UNINIT_WARNINGS _Pragma("clang diagnostic pop")
206+
#elif defined(__GNUC__) || defined(__GNUG__)
207+
#define DISABLE_UNINIT_WARNINGS _Pragma("GCC diagnostic push") \
208+
_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
209+
#define ENABLE_UNINIT_WARNINGS _Pragma("GCC diagnostic pop")
210+
#elif defined(_MSC_VER)
211+
#define DISABLE_UNINIT_WARNINGS __pragma(warning(push)) \
212+
__pragma(warning(disable: 4700))
213+
#define ENABLE_UNINIT_WARNINGS __pragma(warning(pop))
214+
#else
215+
#define DISABLE_UNINIT_WARNINGS
216+
#define ENABLE_UNINIT_WARNINGS
217+
#endif
218+
202219
#endif /* Py_PYMACRO_H */

‎Python/ceval.c

Copy file name to clipboardExpand all lines: Python/ceval.c
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,7 @@ _PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
18141814
PyObject *kwnames = NULL;
18151815
_PyStackRef *newargs;
18161816
PyObject *const *object_array = NULL;
1817+
DISABLE_UNINIT_WARNINGS
18171818
_PyStackRef stack_array[8];
18181819
if (has_dict) {
18191820
object_array = _PyStack_UnpackDict(tstate, _PyTuple_ITEMS(callargs), nargs, kwargs, &kwnames);
@@ -1855,6 +1856,7 @@ _PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
18551856
else if (nargs > 8) {
18561857
PyMem_Free((void *)newargs);
18571858
}
1859+
ENABLE_UNINIT_WARNINGS
18581860
/* No need to decref func here because the reference has been stolen by
18591861
_PyEvalFramePushAndInit.
18601862
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.