Skip to content

C: avoid undefined behavior for bit shifts >= 32 - #54

Open
arthurfabre wants to merge 1 commit into
masterfrom
afabre/shifts
Open

C: avoid undefined behavior for bit shifts >= 32#54
arthurfabre wants to merge 1 commit into
masterfrom
afabre/shifts

Conversation

@arthurfabre

Copy link
Copy Markdown
Collaborator

The C standard says, for bit shifts:

If the value of the right operand [...] is greater than or equal to the width of the promoted left operand, the behavior is undefined.

But in our generated C code, we allow shifts for the full value of RegX.

Do the same thing the kernel does: mask it with & 31 to avoid any undefined behavior.

The C standard says, for bit shifts:

> If the value of the right operand [...] is greater than or equal to the width of the promoted left operand, the behavior is undefined.

But in our generated C code, we allow shifts for the full value of RegX.

Do the same thing the kernel does: mask it with & 31 to avoid any
undefined behavior.
@arthurfabre arthurfabre self-assigned this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant