Skip to content

Commit

Permalink
Fix crash on x86 when building with MSVC
Browse files Browse the repository at this point in the history
There is a compiler bug in latest MSVC, which at the time of writing is
19.36.32535: given `switch (x)`, where `x` is 64 bits wide, the compiler
generates code that computes an incorrect jump table index. E.g. if
`x` is zero, it ends up reading the table entry at index -1.
  • Loading branch information
oleavr committed Jan 18, 2024
1 parent 0cfb65c commit 1115d91
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 87 deletions.
16 changes: 8 additions & 8 deletions arch/AArch64/AArch64GenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13853,7 +13853,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 0 encoded into 7 bits for 68 unique commands.
// printf("Fragment 0: %"PRIu64"\n", ((Bits >> 14) & 127));
switch ((Bits >> 14) & 127) {
switch ((uint32_t)((Bits >> 14) & 127)) {
default: // unreachable
case 0:
// DBG_VALUE, DBG_VALUE_LIST, DBG_INSTR_REF, DBG_PHI, DBG_LABEL, BUNDLE, ...
Expand Down Expand Up @@ -14400,7 +14400,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 1 encoded into 7 bits for 69 unique commands.
// printf("Fragment 1: %"PRIu64"\n", ((Bits >> 21) & 127));
switch ((Bits >> 21) & 127) {
switch ((uint32_t)((Bits >> 21) & 127)) {
default: // unreachable
case 0:
// TLSDESCCALL, AUTDZA, AUTDZB, AUTIZA, AUTIZB, BLR, BLRAAZ, BLRABZ, BR, ...
Expand Down Expand Up @@ -14761,7 +14761,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 2 encoded into 7 bits for 69 unique commands.
// printf("Fragment 2: %"PRIu64"\n", ((Bits >> 28) & 127));
switch ((Bits >> 28) & 127) {
switch ((uint32_t)((Bits >> 28) & 127)) {
default: // unreachable
case 0:
// ABS_ZPmZ_B, ABS_ZPmZ_D, ABS_ZPmZ_S, BRKA_PPmP, BRKB_PPmP, CLS_ZPmZ_B, ...
Expand Down Expand Up @@ -15135,7 +15135,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 3 encoded into 7 bits for 111 unique commands.
// printf("Fragment 3: %"PRIu64"\n", ((Bits >> 35) & 127));
switch ((Bits >> 35) & 127) {
switch ((uint32_t)((Bits >> 35) & 127)) {
default: // unreachable
case 0:
// ABS_ZPmZ_B, BRKA_PPmP, BRKB_PPmP, CDOT_ZZZI_S, CDOT_ZZZ_S, CLS_ZPmZ_B,...
Expand Down Expand Up @@ -15816,7 +15816,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 4 encoded into 7 bits for 94 unique commands.
// printf("Fragment 4: %"PRIu64"\n", ((Bits >> 42) & 127));
switch ((Bits >> 42) & 127) {
switch ((uint32_t)((Bits >> 42) & 127)) {
default: // unreachable
case 0:
// ABS_ZPmZ_B, ADD_ZZZ_H, BDEP_ZZZ_H, BEXT_ZZZ_H, BGRP_ZZZ_H, BRKA_PPmP, ...
Expand Down Expand Up @@ -16392,7 +16392,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 5 encoded into 6 bits for 41 unique commands.
// printf("Fragment 5: %"PRIu64"\n", ((Bits >> 49) & 63));
switch ((Bits >> 49) & 63) {
switch ((uint32_t)((Bits >> 49) & 63)) {
default: // unreachable
case 0:
// ADCLB_ZZZ_D, ADCLB_ZZZ_S, ADCLT_ZZZ_D, ADCLT_ZZZ_S, ADCSWr, ADCSXr, AD...
Expand Down Expand Up @@ -16625,7 +16625,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 6 encoded into 6 bits for 37 unique commands.
// printf("Fragment 6: %"PRIu64"\n", ((Bits >> 55) & 63));
switch ((Bits >> 55) & 63) {
switch ((uint32_t)((Bits >> 55) & 63)) {
default: // unreachable
case 0:
// ADDG, ASRD_ZPmI_B, ASRD_ZPmI_D, ASRD_ZPmI_S, ASR_ZPmI_B, ASR_ZPmI_D, A...
Expand Down Expand Up @@ -16832,7 +16832,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 7 encoded into 3 bits for 7 unique commands.
// printf("Fragment 7: %"PRIu64"\n", ((Bits >> 61) & 7));
switch ((Bits >> 61) & 7) {
switch ((uint32_t)((Bits >> 61) & 7)) {
default: // unreachable
case 0:
// ADDP_ZPmZ_D, ADDP_ZPmZ_S, ADD_ZPmZ_D, ADD_ZPmZ_S, AND_ZPmZ_D, AND_ZPmZ...
Expand Down
18 changes: 9 additions & 9 deletions arch/ARM/ARMGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6976,7 +6976,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 0 encoded into 5 bits for 32 unique commands.
// printf("Fragment 0: %"PRIu64"\n", ((Bits >> 12) & 31));
switch ((Bits >> 12) & 31) {
switch ((uint32_t)((Bits >> 12) & 31)) {
default: // unreachable
case 0:
// DBG_VALUE, DBG_LABEL, BUNDLE, LIFETIME_START, LIFETIME_END, FENTRY_CAL...
Expand Down Expand Up @@ -7163,7 +7163,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 1 encoded into 7 bits for 75 unique commands.
// printf("Fragment 1: %"PRIu64"\n", ((Bits >> 17) & 127));
switch ((Bits >> 17) & 127) {
switch ((uint32_t)((Bits >> 17) & 127)) {
default: // unreachable
case 0:
// ASRi, ASRr, ITasm, LDRBT_POST, LDRConstPool, LDRT_POST, LSLi, LSLr, LS...
Expand Down Expand Up @@ -7714,7 +7714,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 2 encoded into 6 bits for 60 unique commands.
// printf("Fragment 2: %"PRIu64"\n", ((Bits >> 24) & 63));
switch ((Bits >> 24) & 63) {
switch ((uint32_t)((Bits >> 24) & 63)) {
default: // unreachable
case 0:
// ASRi, ASRr, LDRBT_POST, LDRConstPool, LDRT_POST, LSLi, LSLr, LSRi, LSR...
Expand Down Expand Up @@ -8095,7 +8095,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 3 encoded into 5 bits for 30 unique commands.
// printf("Fragment 3: %"PRIu64"\n", ((Bits >> 30) & 31));
switch ((Bits >> 30) & 31) {
switch ((uint32_t)((Bits >> 30) & 31)) {
default: // unreachable
case 0:
// ASRi, ASRr, LDRBT_POST, LDRConstPool, LDRT_POST, LSLi, LSLr, LSRi, LSR...
Expand Down Expand Up @@ -8261,7 +8261,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 4 encoded into 7 bits for 65 unique commands.
// printf("Fragment 4: %"PRIu64"\n", ((Bits >> 35) & 127));
switch ((Bits >> 35) & 127) {
switch ((uint32_t)((Bits >> 35) & 127)) {
default: // unreachable
case 0:
// ASRi, ASRr, LDRConstPool, LSLi, LSLr, LSRi, LSRr, RORi, RORr, RRXi, t2...
Expand Down Expand Up @@ -8666,7 +8666,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 5 encoded into 5 bits for 23 unique commands.
// printf("Fragment 5: %"PRIu64"\n", ((Bits >> 42) & 31));
switch ((Bits >> 42) & 31) {
switch ((uint32_t)((Bits >> 42) & 31)) {
default: // unreachable
case 0:
// ASRi, ASRr, LSLi, LSLr, LSRi, LSRr, RORi, RORr, VLD1LNdWB_register_Asm...
Expand Down Expand Up @@ -8814,7 +8814,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 6 encoded into 6 bits for 38 unique commands.
// printf("Fragment 6: %"PRIu64"\n", ((Bits >> 47) & 63));
switch ((Bits >> 47) & 63) {
switch ((uint32_t)((Bits >> 47) & 63)) {
default: // unreachable
case 0:
// ASRi, ASRr, LSLi, LSLr, LSRi, LSRr, RORi, RORr, ADCrr, ADDrr, ANDrr, B...
Expand Down Expand Up @@ -9035,7 +9035,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 7 encoded into 4 bits for 13 unique commands.
// printf("Fragment 7: %"PRIu64"\n", ((Bits >> 53) & 15));
switch ((Bits >> 53) & 15) {
switch ((uint32_t)((Bits >> 53) & 15)) {
default: // unreachable
case 0:
// ASRi, ASRr, LSLi, LSLr, LSRi, LSRr, RORi, RORr, VLD1LNdWB_register_Asm...
Expand Down Expand Up @@ -9110,7 +9110,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 8 encoded into 4 bits for 12 unique commands.
// printf("Fragment 8: %"PRIu64"\n", ((Bits >> 57) & 15));
switch ((Bits >> 57) & 15) {
switch ((uint32_t)((Bits >> 57) & 15)) {
default: // unreachable
case 0:
// LDRD_POST, STRD_POST
Expand Down
12 changes: 6 additions & 6 deletions arch/Mips/MipsGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4703,7 +4703,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 0 encoded into 4 bits for 11 unique commands.
//printf("Frag-0: %"PRIu64"\n", (Bits >> 14) & 15);
switch ((Bits >> 14) & 15) {
switch ((uint32_t)((Bits >> 14) & 15)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// DBG_VALUE, BUNDLE, LIFETIME_START, LIFETIME_END, Break16, CONSTPOOL_EN...
Expand Down Expand Up @@ -4765,7 +4765,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 1 encoded into 5 bits for 17 unique commands.
//printf("Frag-1: %"PRIu64"\n", (Bits >> 18) & 31);
switch ((Bits >> 18) & 31) {
switch ((uint32_t)((Bits >> 18) & 31)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// ABSQ_S_PH, ABSQ_S_QB, ABSQ_S_W, ADD, ADDIUPC, ADDIUPC_MM, ADDIUR1SP_MM...
Expand Down Expand Up @@ -4865,7 +4865,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 2 encoded into 4 bits for 12 unique commands.
//printf("Frag-2: %"PRIu64"\n", (Bits >> 23) & 15);
switch ((Bits >> 23) & 15) {
switch ((uint32_t)((Bits >> 23) & 15)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// ABSQ_S_PH, ABSQ_S_QB, ABSQ_S_W, ADD, ADDIUPC, ADDIUPC_MM, ADDIUR1SP_MM...
Expand Down Expand Up @@ -4938,7 +4938,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 3 encoded into 4 bits for 15 unique commands.
//printf("Frag-3: %"PRIu64"\n", (Bits >> 27) & 15);
switch ((Bits >> 27) & 15) {
switch ((uint32_t)((Bits >> 27) & 15)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// ABSQ_S_PH, ABSQ_S_QB, ABSQ_S_W, ADDIUPC, ADDIUPC_MM, ADDIUR1SP_MM, ALU...
Expand Down Expand Up @@ -5033,7 +5033,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 4 encoded into 3 bits for 5 unique commands.
//printf("Frag-4: %"PRIu64"\n", (Bits >> 31) & 7);
switch ((Bits >> 31) & 7) {
switch ((uint32_t)((Bits >> 31) & 7)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// ADD, ADDIUR2_MM, ADDQH_PH, ADDQH_R_PH, ADDQH_R_W, ADDQH_W, ADDQ_PH, AD...
Expand All @@ -5060,7 +5060,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 5 encoded into 2 bits for 3 unique commands.
//printf("Frag-5: %"PRIu64"\n", (Bits >> 34) & 3);
switch ((Bits >> 34) & 3) {
switch ((uint32_t)((Bits >> 34) & 3)) {
default: // llvm_unreachable("Invalid command number.");
case 0:
// ADD, ADDIUR2_MM, ADDQH_PH, ADDQH_R_PH, ADDQH_R_W, ADDQH_W, ADDQ_PH, AD...
Expand Down
12 changes: 6 additions & 6 deletions arch/PowerPC/PPCGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6142,7 +6142,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 0 encoded into 5 bits for 19 unique commands.
// printf("Fragment 0: %"PRIu64"\n", ((Bits >> 14) & 31));
switch ((Bits >> 14) & 31) {
switch ((uint32_t)((Bits >> 14) & 31)) {
default: // unreachable
case 0:
// DBG_VALUE, DBG_LABEL, BUNDLE, LIFETIME_START, LIFETIME_END, FENTRY_CAL...
Expand Down Expand Up @@ -6257,7 +6257,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 1 encoded into 5 bits for 20 unique commands.
// printf("Fragment 1: %"PRIu64"\n", ((Bits >> 19) & 31));
switch ((Bits >> 19) & 31) {
switch ((uint32_t)((Bits >> 19) & 31)) {
default: // unreachable
case 0:
// CLRLSLDI, CLRLSLDIo, CLRLSLWI, CLRLSLWIo, CLRRDI, CLRRDIo, CLRRWI, CLR...
Expand Down Expand Up @@ -6397,7 +6397,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 2 encoded into 5 bits for 23 unique commands.
// printf("Fragment 2: %"PRIu64"\n", ((Bits >> 24) & 31));
switch ((Bits >> 24) & 31) {
switch ((uint32_t)((Bits >> 24) & 31)) {
default: // unreachable
case 0:
// CLRLSLDI, CLRLSLDIo, CLRLSLWI, CLRLSLWIo, CLRRDI, CLRRDIo, CLRRWI, CLR...
Expand Down Expand Up @@ -6530,7 +6530,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 3 encoded into 4 bits for 14 unique commands.
// printf("Fragment 3: %"PRIu64"\n", ((Bits >> 29) & 15));
switch ((Bits >> 29) & 15) {
switch ((uint32_t)((Bits >> 29) & 15)) {
default: // unreachable
case 0:
// CLRLSLDI, CLRLSLDIo, CLRLSLWI, CLRLSLWIo, CLRRDI, CLRRDIo, CLRRWI, CLR...
Expand Down Expand Up @@ -6617,7 +6617,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 4 encoded into 4 bits for 13 unique commands.
// printf("Fragment 4: %"PRIu64"\n", ((Bits >> 33) & 15));
switch ((Bits >> 33) & 15) {
switch ((uint32_t)((Bits >> 33) & 15)) {
default: // unreachable
case 0:
// CLRLSLDI, CLRLSLDIo, CLRRDI, CLRRDIo, EXTLDI, EXTLDIo, EXTRDI, EXTRDIo...
Expand Down Expand Up @@ -6697,7 +6697,7 @@ static void printInstruction(MCInst *MI, SStream *O)

// Fragment 6 encoded into 3 bits for 8 unique commands.
// printf("Fragment 6: %"PRIu64"\n", ((Bits >> 38) & 7));
switch ((Bits >> 38) & 7) {
switch ((uint32_t)((Bits >> 38) & 7)) {
default: // unreachable
case 0:
// CLRLSLDI, CLRLSLDIo, EXTLDI, EXTLDIo, EXTRDI, EXTRDIo, INSRDI, INSRDIo...
Expand Down
8 changes: 4 additions & 4 deletions arch/RISCV/RISCVGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 0 encoded into 2 bits for 4 unique commands.
switch ((Bits >> 12) & 3) {
switch ((uint32_t)((Bits >> 12) & 3)) {
default: CS_ASSERT(0 && "Invalid command number.");
case 0:
// DBG_VALUE, DBG_LABEL, BUNDLE, LIFETIME_START, LIFETIME_END, FENTRY_CAL...
Expand Down Expand Up @@ -1225,7 +1225,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 1 encoded into 2 bits for 3 unique commands.
switch ((Bits >> 14) & 3) {
switch ((uint32_t)((Bits >> 14) & 3)) {
default: CS_ASSERT(0 && "Invalid command number.");
case 0:
// PseudoCALL, PseudoTAIL, C_J, C_JAL, C_JALR, C_JR
Expand All @@ -1246,7 +1246,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 2 encoded into 2 bits for 3 unique commands.
switch ((Bits >> 16) & 3) {
switch ((uint32_t)((Bits >> 16) & 3)) {
default: CS_ASSERT(0 && "Invalid command number.");
case 0:
// PseudoLA, PseudoLI, PseudoLLA, ADD, ADDI, ADDIW, ADDW, AND, ANDI, AUIP...
Expand All @@ -1267,7 +1267,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)


// Fragment 3 encoded into 2 bits for 4 unique commands.
switch ((Bits >> 18) & 3) {
switch ((uint32_t)((Bits >> 18) & 3)) {
default: CS_ASSERT(0 && "Invalid command number.");
case 0:
// PseudoLA, PseudoLI, PseudoLLA, AUIPC, C_BEQZ, C_BNEZ, C_LI, C_LUI, C_M...
Expand Down
10 changes: 5 additions & 5 deletions arch/Sparc/SparcGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 0 encoded into 4 bits for 12 unique commands.
// printf("Frag-0: %u\n", (Bits >> 12) & 15);
switch ((Bits >> 12) & 15) {
switch ((uint32_t)((Bits >> 12) & 15)) {
default: // unreachable.
case 0:
// DBG_VALUE, BUNDLE, LIFETIME_START, LIFETIME_END, FLUSHW, NOP, SELECT_C...
Expand Down Expand Up @@ -907,7 +907,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 1 encoded into 4 bits for 16 unique commands.
// printf("Frag-1: %u\n", (Bits >> 16) & 15);
switch ((Bits >> 16) & 15) {
switch ((uint32_t)((Bits >> 16) & 15)) {
default: // unreachable.
case 0:
// ADDCCri, ADDCCrr, ADDCri, ADDCrr, ADDEri, ADDErr, ADDXC, ADDXCCC, ADDX...
Expand Down Expand Up @@ -1020,7 +1020,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 2 encoded into 2 bits for 3 unique commands.
// printf("Frag-2: %u\n", (Bits >> 20) & 3);
switch ((Bits >> 20) & 3) {
switch ((uint32_t)((Bits >> 20) & 3)) {
default: // unreachable.
case 0:
// ADDCCri, ADDCCrr, ADDCri, ADDCrr, ADDEri, ADDErr, ADDXC, ADDXCCC, ADDX...
Expand All @@ -1041,7 +1041,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 3 encoded into 2 bits for 4 unique commands.
// printf("Frag-3: %u\n", (Bits >> 22) & 3);
switch ((Bits >> 22) & 3) {
switch ((uint32_t)((Bits >> 22) & 3)) {
default: // unreachable.
case 0:
// ADDCCri, ADDCCrr, ADDCri, ADDCrr, ADDEri, ADDErr, ADDXC, ADDXCCC, ADDX...
Expand All @@ -1068,7 +1068,7 @@ static void printInstruction(MCInst *MI, SStream *O, const MCRegisterInfo *MRI)

// Fragment 4 encoded into 2 bits for 3 unique commands.
// printf("Frag-4: %u\n", (Bits >> 24) & 3);
switch ((Bits >> 24) & 3) {
switch ((uint32_t)((Bits >> 24) & 3)) {
default: // unreachable.
case 0:
// FLCMPD, FLCMPS, V9FCMPD, V9FCMPED, V9FCMPEQ, V9FCMPES, V9FCMPQ, V9FCMP...
Expand Down
Loading

0 comments on commit 1115d91

Please sign in to comment.