Skip to content

Commit

Permalink
[X86] Attempt to fix ubsan failure.
Browse files Browse the repository at this point in the history
operator~ promote the single bit input to int. The ~ will cause the upper
31 bits to become 1s making it a negative value. This is undefined for
shift.

Mask it back down to a single bit.

The extra 1s were being shifted to bit 8 and above and the they aren't
used by the emitByte call so this shouldn't be a functional change.
  • Loading branch information
topperc committed Feb 10, 2023
1 parent 185dbf9 commit d37a31c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
Expand Up @@ -219,7 +219,7 @@ class X86OpcodePrefixHelper {
return;
case VEX2:
emitByte(0xC5, OS);
emitByte(~R << 7 | LastPayload, OS);
emitByte(((~R) & 1) << 7 | LastPayload, OS);
return;
case VEX3:
case XOP:
Expand Down

0 comments on commit d37a31c

Please sign in to comment.