Skip to content

tests/bit_operations_tests: bit-shifts with negative RHSes are undefined behavior #114

@nwf

Description

@nwf

The bit_operations_tests probe at the behavior of 1U << -1 within the loop at

for (i = -1; i < 32; i++)
{
ax32 = most_significant_one32(1U << i);
This is, formally, undefined behavior in C. Specifically, C23 §6.5.8 ¶3 says "If the value of the right operand is negative or [...], the behavior is undefined." I think that the loop variable should start at 0 and, if the behavior of most_significant_one32 on 0 is to be tested, specific code should be added. Does that seem reasonable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions