Bug 1305816 - explicitly specify underlying type of js::jit::X86Encoding::RegisterID; r?jandem draft
authorNathan Froyd <froydnj@mozilla.com>
Tue, 27 Sep 2016 15:29:18 -0400
changeset 418118 578bf98b07abcf8fd210e4309265c2d3f2bef26e
parent 418117 78dfc6666c59cf05dc88bf06f2c1c96296db4bd1
child 418119 2d2e5965e97ca722aed1ce605c44de5c5a8ee8a1
push id30599
push userbmo:nfroyd@mozilla.com
push dateTue, 27 Sep 2016 19:39:57 +0000
reviewersjandem
bugs1305816
milestone52.0a1
Bug 1305816 - explicitly specify underlying type of js::jit::X86Encoding::RegisterID; r?jandem Recent clang-cl warns when building for x86-64 Windows about initializing Assembler-x86-shared.h's Operand::index_ with Registers::Invalid. This warning stems from a couple of implementation-defined behaviors in the C++ standard: - The only constraints on an (non-fixed-width) enum's type are that the type is at least as large as `int`, and that the chosen type can accomodate all the values of the enum. MSVC (and clang-cl) default to int wherever possible. - Bitfields declared with `int` (resp. `char`, `short`, `long`) may be either signed or unsigned at the implementation's discretion. It is therefore encouraged that you always declare bitfields with unsigned types. Operand::index_ is a 5-bit field, with a declared type of Register::Encoding; on x86, that boils down to the enum js::jit::X86Encoding::RegisterID. The compiler defaults the underlying type of RegisterID to `int` (so the bitfield is signed on some implementations), and Registers::Invalid is 16 on x86-64, large enough to silently change sign when stored into the bitfield. Declaring the bitfield as a fixed-width unsigned 8-bit enum is sufficient to silence the warning. MozReview-Commit-ID: 2uKIXle3mdc
js/src/jit/x86-shared/Constants-x86-shared.h
--- a/js/src/jit/x86-shared/Constants-x86-shared.h
+++ b/js/src/jit/x86-shared/Constants-x86-shared.h
@@ -6,23 +6,24 @@
 
 #ifndef jit_x86_shared_Constants_x86_shared_h
 #define jit_x86_shared_Constants_x86_shared_h
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 
 #include <stddef.h>
+#include <stdint.h>
 
 namespace js {
 namespace jit {
 
 namespace X86Encoding {
 
-enum RegisterID {
+enum RegisterID : uint8_t {
     rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi
 #ifdef JS_CODEGEN_X64
    ,r8, r9, r10, r11, r12, r13, r14, r15
 #endif
    ,invalid_reg
 };
 
 enum HRegisterID {