Skip to content

gh-135183: Suppress MSVC warning 5274 locally #135184

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

encukou
Copy link
Member

@encukou encukou commented Jun 5, 2025

@zooba
Copy link
Member

zooba commented Jun 5, 2025

Why? The suppression was restricted to our headers, which is local enough. It's only warning about changed behaviour from the old syntax, which we never used.

Are we going to replicate the same suppression code every time it gets used?

@encukou
Copy link
Member Author

encukou commented Jun 5, 2025

We want core devs to use _Py_ALIGN_AS, and when they do, they need to think about this issue (in cases where the warning shows up).

It's only warning about changed behaviour from the old syntax, which we never used.

AFAICS, it's not about syntax changes. MSVC 17.9 vs. older versions produce different ABI for _Alignas.

@encukou
Copy link
Member Author

encukou commented Jun 5, 2025

It might be clearer with the example from the MS docs:

struct Outer
{
    _Alignas(32) struct Inner { int i; } member1;
    struct Inner member2;
};

The layout of this structure is different depending on what version of MSVC you compile with. We do not want to define such a struct in our headers.

Are we going to replicate the same suppression code every time it gets used?

Yes.

@zooba
Copy link
Member

zooba commented Jun 5, 2025

We do not want to define such a struct in our headers.

Then suppressing the warning isn't the way, and we should be removing/changing _Py_ALIGN_AS? Or blocking earlier MSVC versions in the headers?

@encukou
Copy link
Member Author

encukou commented Jun 6, 2025

Then suppressing the warning isn't the way, and we should be removing/changing _Py_ALIGN_AS?

I think suppressing is the way. Once you (as a core dev) confirm that you're not defining such a struct, add the suppression.
The warning is there to make you consider this weird compiler bug; you wouldn't do that otherwise.

Hm, maybe I wasn't clear here:

Are we going to replicate the same suppression code every time it gets used?

Yes.

By “it” I mean the suppression code, not _Py_ALIGN_AS.
The suppression is only needed when defining a struct and a member at once.

... which suggests another possible workaround here: define the struct for PyASCIIObject.state outside of PyASCIIObject. Then no suppression is necessary -- but that means we don't get to add an example of what to do when you get C5274 from the CI.

Or blocking earlier MSVC versions in the headers?

Well, you're the expert on that :)
I feel that 17.8 should be supported, and it's worth it to work around its bug.

@encukou
Copy link
Member Author

encukou commented Jun 6, 2025

See also #135209, for a possible bigger change to _Py_ALIGN_AS.

@zooba
Copy link
Member

zooba commented Jun 6, 2025

I like the other change better. Including the type and the alignment as arguments to the macro should be easier to support long-term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants