[llvm] d37a31c - [X86] Attempt to fix ubsan failure.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 10 10:03:01 PST 2023


Author: Craig Topper
Date: 2023-02-10T10:02:51-08:00
New Revision: d37a31cf237cb4f8a18b12c91a9204feca5900ef

URL: https://github.com/llvm/llvm-project/commit/d37a31cf237cb4f8a18b12c91a9204feca5900ef
DIFF: https://github.com/llvm/llvm-project/commit/d37a31cf237cb4f8a18b12c91a9204feca5900ef.diff

LOG: [X86] Attempt to fix ubsan failure.

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.

Added: 
    

Modified: 
    llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
index 84b11af0a3565..cbdcba12f86d7 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -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:


        


More information about the llvm-commits mailing list