Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

gh-132314: fix stack array init warning#132376

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dura0ok wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromdura0ok:gh-132314

Conversation

dura0ok
Copy link
Contributor

@dura0okdura0ok commentedApr 10, 2025
edited by bedevere-appbot
Loading

@python-cla-bot
Copy link

python-cla-botbot commentedApr 10, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

@dura0ok
Copy link
ContributorAuthor

There was no warning with the configuration without options, but I reproduced it with the --enable-optimization --with-lto options. The mistake is very simple.

@@ -1814,7 +1814,7 @@ _PyEvalFramePushAndInit_Ex(PyThreadState *tstate, _PyStackRef func,
PyObject *kwnames = NULL;
_PyStackRef *newargs;
PyObject *const *object_array = NULL;
_PyStackRef stack_array[8];
_PyStackRef stack_array[8] = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IMHO, the compiler warning is a false-positive.

If thestack_array is used

cpython/Python/ceval.c

Lines 1832 to 1834 inad3bbe8

if (nargs <=8) {
newargs=stack_array;
}

it is initialized

cpython/Python/ceval.c

Lines 1844 to 1846 inad3bbe8

for (Py_ssize_ti=0;i<nargs;i++) {
newargs[i]=PyStackRef_FromPyObjectNew(PyTuple_GET_ITEM(callargs,i));
}

Having a small array on the stack to avoid thePyMem_Malloc is a common pattern, e.g. further down

_PyStackRefstack_array[8];

or like mentioned in the issue#132314
PyObject*small_stack[_PY_FASTCALL_SMALL_STACK];

They all follow the same pattern, and if the compiler is not smart enough to detect it, it will issue a warning.

IMHO, initializing those stack variables using= {} is a waste of CPU cycles, and we should silence the warning using adiagnostic pragma.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think hiding warnings using pragma it is not good idea, because we have other compilers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, but not all of them emit the warning, so we only have to silence those that do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes and we can selectively decide which compilers need to be silenced as well so I think for a falsey positive like that it's better to silence the warning.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed. Check please new version.@chris-eibl@picnixz

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry@dura0ok, I totally missed this one - but#134207 rang a bell and so I am here again.

I had a simpler approach in mind just using a pragma for GCC directly in the affected places but I like your approach, too, since it is re-usable.

There is already infrastructure and I'd place the macro next to

#if defined(__clang__)
#define_Py_COMP_DIAG_PUSH_Pragma("clang diagnostic push")
#define_Py_COMP_DIAG_IGNORE_DEPR_DECLS \
_Pragma("clang diagnostic ignored\"-Wdeprecated-declarations\"")
#define_Py_COMP_DIAG_POP_Pragma("clang diagnostic pop")
#elif defined(__GNUC__) \

I'd also go with the naming scheme used there, e.g._Py_COMP_DIAG_IGNORE_MAYBE_UNINITIALIZED, and use it like

cpython/Modules/main.c

Lines 522 to 530 inc740fe3

staticvoid
pymain_set_inspect(PyConfig*config,intinspect)
{
config->inspect=inspect;
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Py_InspectFlag=inspect;
_Py_COMP_DIAG_POP
}

Add macros to disable and re-enable compiler-specific warnings aboutpossibly uninitialized variables (`-Wmaybe-uninitialized` for GCC,`-Wuninitialized` for Clang, and warning C4700 for MSVC). Use thesemacros in `_PyEvalFramePushAndInit_Ex()` to suppress false positiveson stack-allocated arrays like `stack_array`.This also addresses warnings such as the one in `pycore_call.h` whenusing `small_stack[_PY_FASTCALL_SMALL_STACK]` that may be flagged byGCC's `-Wmaybe-uninitialized`.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz left review comments

@chris-eiblchris-eiblchris-eibl left review comments

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@dura0ok@picnixz@chris-eibl@sobolevn

[8]ページ先頭

©2009-2025 Movatter.jp