Drop misleading comments about undefined behavior #17532
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is no undefined behavior here. If
BitScan*()
returns zero, the value written to the first parameter is undefined, but we return a reasonable value.This came up in #17527.
While having a closer look, I found that
zend_ulong_ntz()
andzend_ulong_nlz()
are documented to behave differently if the argument is zero. While the latter states that for zero the result is undefined, the former states that for zero, LEN would be returned:php-src/Zend/zend_bitset.h
Line 47 in ce53dab
While this is actually true on Windows, and for the fallback implementation, it is apparently not the case when
__builtin_ctzl()
or__builtin_ctzll()
are used. From https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html:So at least the comment should be fixed, and I would put in assert regarding the pre-condition, but see #17506 (comment) (I'm not sure whether all callers use the function accordingly). Also, in that case the Windows implementation would not need to check the return value.
Possible alternative: define the functions for
num == 0
.