prim/BitFlag: assert bit index in makeMask - #280
Conversation
|
This assert should generate the following pseudo code. Currently just based on the missing cBitNum this implementation is incorrect if (0xf < param_3) {
sead::system::HaltWithDetailNoFormat("...include/prim/seadBitFlag.h", ...LineNumber... ,"static_cast<u32>(bit) < cBitNum");
}
*(ushort *)(this + 0x70) = *(ushort *)(this + 0x70) | (ushort)(1 << (ulong)(param_3 & 0x1f)); |
Per decompiled-binary evidence shared in the PR discussion, the original assert condition is 'static_cast<u32>(bit) < cBitNum'. Expose cBitNum as a public constant of BitFlag<T> and use it in makeMask.
|
Thanks for the pseudo code — that settles it. Updated: Re-verified after the change: release codegen is still byte-identical to the pre-patch baseline (clang 15.0.7, If the |
Fixes #85.
Change
sead::BitFlag<T>::makeMaskgains the missing bit-index assertion:Rationale
static_cast<u32>(bit) < sizeof(T)*8assertions in theBitFlagbit-index functions (setBit,resetBit,changeBit,toggleBit,isOnBit,isOffBit,testAndClearBit).engine/library/include/prim/seadBitFlag.h) ships this assertion insidemakeMask(currently commented out there), covering all of the above in one place — they are all
makeMaskcallers.BitFlagUtil::countRightOnBitin the same module already carries the identicalassertion pattern; this restores consistency for the template.
Verification
BitFlag32/BitFlag64andexercising all bit-index functions compiles to a byte-identical
.owith and withoutthis patch (clang 15.0.7,
-O3,-fno-exceptions, noSEAD_DEBUG), becauseSEAD_ASSERTcollapses toif (false)in release builds.-DSEAD_DEBUG=1the same TU compiles with the asserts active (assert call sitespresent; TU size grows 1520 -> 2792 bytes).
clang-format12.0.1 (the CI-pinned version) passes on the modified header.Caveat
The issue text ends with "and more" — without the original game's debug symbols for these
functions, further missing assertions cannot be enumerated with confidence. This PR is the
minimal, lineage-backed restoration; more can follow with evidence.
This change is