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
--- 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 {