Skip to content

Commit 3382f76

Browse files
author
Gernot Gebhard
committed
UPDATE: introduce SLJIT_FALLTHROUGH macro similar to the change made in PCRE2Project/pcre2#789.
1 parent e281e19 commit 3382f76

11 files changed

+68
-46
lines changed

sljit_src/sljitConfigInternal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,28 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code);
970970

971971
#endif /* !SLJIT_COMPILE_ASSERT */
972972

973+
#ifndef SLJIT_FALLTHROUGH
974+
975+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
976+
#if defined(__has_c_attribute)
977+
#if __has_c_attribute(__fallthrough__)
978+
#define SLJIT_FALLTHROUGH [[__fallthrough__]]
979+
#endif
980+
#endif
981+
#endif
982+
983+
#if defined(__has_attribute) && !defined(SLJIT_FALLTHROUGH)
984+
#if __has_attribute(__fallthrough__)
985+
#define SLJIT_FALLTHROUGH __attribute__((__fallthrough__))
986+
#endif
987+
#endif
988+
989+
#ifndef SLJIT_FALLTHROUGH
990+
#define SLJIT_FALLTHROUGH do {} while(0)
991+
#endif
992+
993+
#endif /* !SLJIT_FALLTHROUGH */
994+
973995
#ifdef __cplusplus
974996
} /* extern "C" */
975997
#endif

sljit_src/sljitLir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler
28052805
case SLJIT_MOV_P:
28062806
case SLJIT_MOV:
28072807
allowed_flags |= SLJIT_MEM_ALIGNED_32;
2808-
/* fallthrough */
2808+
SLJIT_FALLTHROUGH; /* fallthrough */
28092809
case SLJIT_MOV_U32:
28102810
case SLJIT_MOV_S32:
28112811
case SLJIT_MOV32:

sljit_src/sljitNativeARM_32.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl
18201820
src2 = TMP_REG2;
18211821
} else
18221822
compiler->shift_imm = (sljit_uw)(-(sljit_sw)compiler->shift_imm) & 0x1f;
1823-
/* fallthrough */
1823+
SLJIT_FALLTHROUGH; /* fallthrough */
18241824

18251825
case SLJIT_ROTR:
18261826
shift_type = 3;
@@ -3089,15 +3089,15 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type)
30893089
case SLJIT_CARRY:
30903090
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
30913091
return 0x20000000;
3092-
/* fallthrough */
3092+
SLJIT_FALLTHROUGH; /* fallthrough */
30933093

30943094
case SLJIT_LESS:
30953095
return 0x30000000;
30963096

30973097
case SLJIT_NOT_CARRY:
30983098
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
30993099
return 0x30000000;
3100-
/* fallthrough */
3100+
SLJIT_FALLTHROUGH; /* fallthrough */
31013101

31023102
case SLJIT_GREATER_EQUAL:
31033103
return 0x20000000;
@@ -3132,15 +3132,15 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type)
31323132
case SLJIT_OVERFLOW:
31333133
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
31343134
return 0x10000000;
3135-
/* fallthrough */
3135+
SLJIT_FALLTHROUGH; /* fallthrough */
31363136

31373137
case SLJIT_UNORDERED:
31383138
return 0x60000000;
31393139

31403140
case SLJIT_NOT_OVERFLOW:
31413141
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
31423142
return 0x00000000;
3143-
/* fallthrough */
3143+
SLJIT_FALLTHROUGH; /* fallthrough */
31443144

31453145
case SLJIT_ORDERED:
31463146
return 0x70000000;

sljit_src/sljitNativeARM_64.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
951951
FAIL_IF(push_inst(compiler, (ORN ^ inv_bits) | RD(dst) | RN(TMP_ZERO) | RM(reg)));
952952
goto set_flags;
953953
}
954-
/* fallthrough */
954+
SLJIT_FALLTHROUGH; /* fallthrough */
955955
case SLJIT_OR:
956956
inst_bits = logical_imm(imm, LOGICAL_IMM_CHECK | ((flags & INT_OP) ? 16 : 32));
957957
if (!inst_bits)
@@ -1060,7 +1060,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
10601060
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
10611061
if (dst == arg2)
10621062
return SLJIT_SUCCESS;
1063-
/* fallthrough */
1063+
SLJIT_FALLTHROUGH; /* fallthrough */
10641064
case SLJIT_MOV_U32:
10651065
SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
10661066
return push_inst(compiler, (MOV ^ W_OP) | RD(dst) | RM(arg2));
@@ -1145,7 +1145,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
11451145
case SLJIT_ROTL:
11461146
FAIL_IF(push_inst(compiler, (SUB ^ inv_bits) | RD(TMP_REG2) | RN(TMP_ZERO) | RM(arg2)));
11471147
arg2 = TMP_REG2;
1148-
/* fallthrough */
1148+
SLJIT_FALLTHROUGH; /* fallthrough */
11491149
case SLJIT_ROTR:
11501150
return push_inst(compiler, (RORV ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
11511151
case SLJIT_MULADD:
@@ -2316,15 +2316,15 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type)
23162316
case SLJIT_CARRY:
23172317
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
23182318
return 0x3;
2319-
/* fallthrough */
2319+
SLJIT_FALLTHROUGH; /* fallthrough */
23202320

23212321
case SLJIT_LESS:
23222322
return 0x2;
23232323

23242324
case SLJIT_NOT_CARRY:
23252325
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
23262326
return 0x2;
2327-
/* fallthrough */
2327+
SLJIT_FALLTHROUGH; /* fallthrough */
23282328

23292329
case SLJIT_GREATER_EQUAL:
23302330
return 0x3;
@@ -2359,15 +2359,15 @@ static sljit_ins get_cc(struct sljit_compiler *compiler, sljit_s32 type)
23592359
case SLJIT_OVERFLOW:
23602360
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
23612361
return 0x0;
2362-
/* fallthrough */
2362+
SLJIT_FALLTHROUGH; /* fallthrough */
23632363

23642364
case SLJIT_UNORDERED:
23652365
return 0x7;
23662366

23672367
case SLJIT_NOT_OVERFLOW:
23682368
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
23692369
return 0x1;
2370-
/* fallthrough */
2370+
SLJIT_FALLTHROUGH; /* fallthrough */
23712371

23722372
case SLJIT_ORDERED:
23732373
return 0x6;
@@ -2792,19 +2792,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *
27922792
break;
27932793
case SLJIT_MOV_S8:
27942794
sign = 1;
2795-
/* fallthrough */
2795+
SLJIT_FALLTHROUGH; /* fallthrough */
27962796
case SLJIT_MOV_U8:
27972797
inst = STURBI | (MEM_SIZE_SHIFT(BYTE_SIZE) << 30) | 0x400;
27982798
break;
27992799
case SLJIT_MOV_S16:
28002800
sign = 1;
2801-
/* fallthrough */
2801+
SLJIT_FALLTHROUGH; /* fallthrough */
28022802
case SLJIT_MOV_U16:
28032803
inst = STURBI | (MEM_SIZE_SHIFT(HALF_SIZE) << 30) | 0x400;
28042804
break;
28052805
case SLJIT_MOV_S32:
28062806
sign = 1;
2807-
/* fallthrough */
2807+
SLJIT_FALLTHROUGH; /* fallthrough */
28082808
case SLJIT_MOV_U32:
28092809
case SLJIT_MOV32:
28102810
inst = STURBI | (MEM_SIZE_SHIFT(INT_SIZE) << 30) | 0x400;

sljit_src/sljitNativeARM_T2_32.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
10421042
return push_inst32(compiler, ASR_WI | (flags & SET_FLAGS) | RD4(dst) | RM4(reg) | IMM5(imm));
10431043
case SLJIT_ROTL:
10441044
imm = (imm ^ 0x1f) + 1;
1045-
/* fallthrough */
1045+
SLJIT_FALLTHROUGH; /* fallthrough */
10461046
default: /* SLJIT_ROTR */
10471047
return push_inst32(compiler, ROR_WI | RD4(dst) | RM4(reg) | IMM5(imm));
10481048
}
@@ -1178,7 +1178,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
11781178
reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2;
11791179
FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f));
11801180
arg2 = (sljit_uw)reg;
1181-
/* fallthrough */
1181+
SLJIT_FALLTHROUGH; /* fallthrough */
11821182
case SLJIT_SHL:
11831183
if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2))
11841184
return push_inst16(compiler, LSLS | RD3(dst) | RN3(arg2));
@@ -1187,7 +1187,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
11871187
reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2;
11881188
FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f));
11891189
arg2 = (sljit_uw)reg;
1190-
/* fallthrough */
1190+
SLJIT_FALLTHROUGH; /* fallthrough */
11911191
case SLJIT_LSHR:
11921192
if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2))
11931193
return push_inst16(compiler, LSRS | RD3(dst) | RN3(arg2));
@@ -1196,7 +1196,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
11961196
reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2;
11971197
FAIL_IF(push_inst32(compiler, ANDI | RD4(reg) | RN4(arg2) | 0x1f));
11981198
arg2 = (sljit_uw)reg;
1199-
/* fallthrough */
1199+
SLJIT_FALLTHROUGH; /* fallthrough */
12001200
case SLJIT_ASHR:
12011201
if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2))
12021202
return push_inst16(compiler, ASRS | RD3(dst) | RN3(arg2));
@@ -1205,7 +1205,7 @@ static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, s
12051205
reg = (arg2 == TMP_REG1) ? TMP_REG1 : TMP_REG2;
12061206
FAIL_IF(push_inst32(compiler, RSB_WI | RD4(reg) | RN4(arg2) | 0));
12071207
arg2 = (sljit_uw)reg;
1208-
/* fallthrough */
1208+
SLJIT_FALLTHROUGH; /* fallthrough */
12091209
case SLJIT_ROTR:
12101210
if (dst == (sljit_s32)arg1 && IS_2_LO_REGS(dst, arg2))
12111211
return push_inst16(compiler, RORS | RD3(dst) | RN3(arg2));
@@ -2653,15 +2653,15 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type)
26532653
case SLJIT_CARRY:
26542654
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
26552655
return 0x2;
2656-
/* fallthrough */
2656+
SLJIT_FALLTHROUGH; /* fallthrough */
26572657

26582658
case SLJIT_LESS:
26592659
return 0x3;
26602660

26612661
case SLJIT_NOT_CARRY:
26622662
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_ADD)
26632663
return 0x3;
2664-
/* fallthrough */
2664+
SLJIT_FALLTHROUGH; /* fallthrough */
26652665

26662666
case SLJIT_GREATER_EQUAL:
26672667
return 0x2;
@@ -2696,15 +2696,15 @@ static sljit_uw get_cc(struct sljit_compiler *compiler, sljit_s32 type)
26962696
case SLJIT_OVERFLOW:
26972697
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
26982698
return 0x1;
2699-
/* fallthrough */
2699+
SLJIT_FALLTHROUGH; /* fallthrough */
27002700

27012701
case SLJIT_UNORDERED:
27022702
return 0x6;
27032703

27042704
case SLJIT_NOT_OVERFLOW:
27052705
if (!(compiler->status_flags_state & (SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB)))
27062706
return 0x0;
2707-
/* fallthrough */
2707+
SLJIT_FALLTHROUGH; /* fallthrough */
27082708

27092709
case SLJIT_ORDERED:
27102710
return 0x7;

sljit_src/sljitNativeLOONGARCH_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3938,7 +3938,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi
39383938

39393939
case SLJIT_MOV32:
39403940
mem_flags = INT_DATA;
3941-
/* fallthrough */
3941+
SLJIT_FALLTHROUGH; /* fallthrough */
39423942
case SLJIT_MOV_S32:
39433943
PTR_FAIL_IF(push_inst(compiler, LU12I_W | RD(dst_r) | (sljit_ins)((init_value >> 7) & 0x1ffffe0)));
39443944
PTR_FAIL_IF(push_inst(compiler, ORI | RD(dst_r) | RJ(dst_r) | IMM_I12(init_value)));

sljit_src/sljitNativeMIPS_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ static SLJIT_INLINE sljit_s32 emit_single_op(struct sljit_compiler *compiler, sl
21812181
FAIL_IF(push_inst(compiler, SELECT_OP(DSUBU, SUBU) | SA(0) | T(src2) | D(TMP_REG2), DR(TMP_REG2)));
21822182
src2 = TMP_REG2;
21832183
}
2184-
/* fallthrough */
2184+
SLJIT_FALLTHROUGH; /* fallthrough */
21852185

21862186
case SLJIT_ROTR:
21872187
EMIT_SHIFT(DROTR, DROTR32, ROTR, DROTRV, ROTRV);
@@ -2648,7 +2648,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile
26482648
if ((src1 == SLJIT_IMM && src1w == -1) || (src2 == SLJIT_IMM && src2w == -1)) {
26492649
return emit_op(compiler, op, flags | CUMULATIVE_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
26502650
}
2651-
/* fallthrough */
2651+
SLJIT_FALLTHROUGH; /* fallthrough */
26522652
case SLJIT_AND:
26532653
case SLJIT_OR:
26542654
return emit_op(compiler, op, flags | CUMULATIVE_OP | LOGICAL_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
@@ -4423,7 +4423,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi
44234423
#if (defined(SLJIT_CONFIG_MIPS_64) && SLJIT_CONFIG_MIPS_64)
44244424
case SLJIT_MOV32:
44254425
mem_flags = INT_DATA;
4426-
/* fallthrough */
4426+
SLJIT_FALLTHROUGH; /* fallthrough */
44274427
case SLJIT_MOV_S32:
44284428
PTR_FAIL_IF(push_inst(compiler, LUI | T(dst_r) | IMM(init_value >> 16), DR(dst_r)));
44294429
PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | T(dst_r) | IMM(init_value), DR(dst_r)));

sljit_src/sljitNativePPC_common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compile
17041704
#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
17051705
op |= SLJIT_32;
17061706
#endif /* SLJIT_CONFIG_PPC_64 */
1707-
/* fallthrough */
1707+
SLJIT_FALLTHROUGH; /* fallthrough */
17081708
case SLJIT_REV:
17091709
case SLJIT_REV_U16:
17101710
case SLJIT_REV_S16:
@@ -1946,7 +1946,7 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compile
19461946
if (src1 == SLJIT_IMM && src1w == -1) {
19471947
return emit_op(compiler, GET_OPCODE(op), flags | ALT_FORM4, dst, dstw, TMP_REG1, 0, src2, src2w);
19481948
}
1949-
/* fallthrough */
1949+
SLJIT_FALLTHROUGH; /* fallthrough */
19501950
case SLJIT_AND:
19511951
case SLJIT_OR:
19521952
/* Commutative unsigned operations. */
@@ -2528,7 +2528,7 @@ static sljit_ins get_bo_bi_flags(struct sljit_compiler *compiler, sljit_s32 type
25282528
case SLJIT_NOT_CARRY:
25292529
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB)
25302530
return (4 << 21) | (2 << 16);
2531-
/* fallthrough */
2531+
SLJIT_FALLTHROUGH; /* fallthrough */
25322532

25332533
case SLJIT_EQUAL:
25342534
case SLJIT_ATOMIC_STORED:
@@ -2537,7 +2537,7 @@ static sljit_ins get_bo_bi_flags(struct sljit_compiler *compiler, sljit_s32 type
25372537
case SLJIT_CARRY:
25382538
if (compiler->status_flags_state & SLJIT_CURRENT_FLAGS_SUB)
25392539
return (12 << 21) | (2 << 16);
2540-
/* fallthrough */
2540+
SLJIT_FALLTHROUGH; /* fallthrough */
25412541

25422542
case SLJIT_NOT_EQUAL:
25432543
case SLJIT_ATOMIC_NOT_STORED:
@@ -3323,7 +3323,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi
33233323
#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
33243324
case SLJIT_MOV32:
33253325
mem_flags = INT_DATA;
3326-
/* fallthrough */
3326+
SLJIT_FALLTHROUGH; /* fallthrough */
33273327
case SLJIT_MOV_S32:
33283328
PTR_FAIL_IF(push_inst(compiler, ADDIS | D(dst_r) | A(0) | IMM(init_value >> 16)));
33293329
PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | A(dst_r) | IMM(init_value)));

sljit_src/sljitNativeRISCV_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4548,7 +4548,7 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi
45484548
#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64)
45494549
case SLJIT_MOV32:
45504550
mem_flags = INT_DATA;
4551-
/* fallthrough */
4551+
SLJIT_FALLTHROUGH; /* fallthrough */
45524552
case SLJIT_MOV_S32:
45534553
if ((init_value & 0x800) != 0)
45544554
init_value ^= ~(sljit_sw)0xfff;

0 commit comments

Comments
 (0)