-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
HW/DSPHLE: Fix struct aliasing undefined behavior in AX ucode #8525
Conversation
The buildbot build now has audio in Mario Party 8, so this seems to fix the issue. |
Could a warning or some compiler flag have caught this? |
As far as I know compilers don't have any warnings regarding strict aliasing. |
Source/Core/Common/BitUtils.h
Outdated
// Similar to BitCastPtr, but specifically for aliasing structs to arrays. | ||
template <typename ArrayType, typename T, | ||
typename Container = | ||
std::array<ArrayType, (sizeof(T) + sizeof(ArrayType) - 1) / sizeof(ArrayType)>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there really a case for supporting sizeof(T) % sizeof(ArrayType) != 0
? seems like it could cause surprising bugs in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't think there's any reasonable circumstances under which you'd use it like that. Should we just enforce alignment with ArrayType
using an assert?
@booto suggested doing it that way, but thinking about it maybe it's better to just disallow that use case.
c15b9c9
to
3fe8a36
Compare
{ | ||
u16 cmd = m_cmdlist[curr_idx++]; | ||
|
||
switch (cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole switch statement looks quite duplicated, is there a way the common parts could be abstracted into a template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. All the enum constants have an offset and there's some other subtle differences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I know this discussion was ended on IRC yesterday, leaving it here just in case)
0b03e07
to
25c6110
Compare
I have reverted this PR to the original patch and will do the refactor in a separate PR. |
LGTM. |
This fixes Old AX Wii games having no audio when compiled under VS2019. This also includes some minor code cleanup and moving a function to avoid duplication.
Fixes no audio when compiled on VS2019 issue in Old_AXWii games (Wii Sports, Mario Party 8, WarioWare: Smooth Moves, probably a few others).
There are more undefined behaviors in AXWii code, I will address those soon.Fixes https://bugs.dolphin-emu.org/issues/11781