Skip to content

Commit 3ecf00a

Browse files
Fix MSVC shift warnings in IR vector bounds checks
Make the conversion of IR_VECTOR_LENGTH to int64_t explicit in the REPLACE and EXTRACT folding rules. The vector length fits in 32 bits, but MSVC warns when its shifted value is implicitly widened for comparison (C4334), breaking builds with /WX. Keep the fix as a bundled-source patch so the IR import remains reproducible.
1 parent f6b6bfa commit 3ecf00a

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/ext/opcache/jit/ir/ir_fold.h b/ext/opcache/jit/ir/ir_fold.h
2+
index c5fd2f28894..fae3b4b4655 100644
3+
--- a/ext/opcache/jit/ir/ir_fold.h
4+
+++ b/ext/opcache/jit/ir/ir_fold.h
5+
@@ -1841,7 +1841,7 @@ IR_FOLD(REPLACE(LONG_CONST, _))
6+
&& IR_IS_CONST_REF(op2)
7+
&& IR_IS_TYPE_INT(op2_insn->type)
8+
&& op2_insn->val.i64 >= 0
9+
- && op2_insn->val.i64 < IR_VECTOR_LENGTH(op1_insn->type)) {
10+
+ && op2_insn->val.i64 < (int64_t)IR_VECTOR_LENGTH(op1_insn->type)) {
11+
IR_ASSERT(IR_IS_TYPE_VECTOR(op1_insn->type)
12+
&& (IR_VECTOR_BASE_TYPE(op1_insn->type) == op3_insn->type
13+
|| (IR_IS_TYPE_INT(IR_VECTOR_BASE_TYPE(op1_insn->type))
14+
@@ -1943,7 +1943,7 @@ IR_FOLD(EXTRACT(LONG_CONST, _))
15+
if (IR_IS_CONST_REF(op2)
16+
&& IR_IS_TYPE_INT(op2_insn->type)
17+
&& op2_insn->val.i64 >= 0
18+
- && op2_insn->val.i64 < IR_VECTOR_LENGTH(op1_insn->type)) {
19+
+ && op2_insn->val.i64 < (int64_t)IR_VECTOR_LENGTH(op1_insn->type)) {
20+
uint32_t idx = op2_insn->val.u32;
21+
void *ptr;
22+

‎.github/scripts/download-bundled/jit-ir.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ rm ir_mem2ssa.c
3535

3636
# add extra files
3737
git restore README
38+
39+
# patch customized files
40+
git apply -v ../../../../.github/scripts/download-bundled/jit-ir.patch

‎ext/opcache/jit/ir/ir_fold.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ IR_FOLD(REPLACE(LONG_CONST, _))
18411841
&& IR_IS_CONST_REF(op2)
18421842
&& IR_IS_TYPE_INT(op2_insn->type)
18431843
&& op2_insn->val.i64 >= 0
1844-
&& op2_insn->val.i64 < IR_VECTOR_LENGTH(op1_insn->type)) {
1844+
&& op2_insn->val.i64 < (int64_t)IR_VECTOR_LENGTH(op1_insn->type)) {
18451845
IR_ASSERT(IR_IS_TYPE_VECTOR(op1_insn->type)
18461846
&& (IR_VECTOR_BASE_TYPE(op1_insn->type) == op3_insn->type
18471847
|| (IR_IS_TYPE_INT(IR_VECTOR_BASE_TYPE(op1_insn->type))
@@ -1943,7 +1943,7 @@ IR_FOLD(EXTRACT(LONG_CONST, _))
19431943
if (IR_IS_CONST_REF(op2)
19441944
&& IR_IS_TYPE_INT(op2_insn->type)
19451945
&& op2_insn->val.i64 >= 0
1946-
&& op2_insn->val.i64 < IR_VECTOR_LENGTH(op1_insn->type)) {
1946+
&& op2_insn->val.i64 < (int64_t)IR_VECTOR_LENGTH(op1_insn->type)) {
19471947
uint32_t idx = op2_insn->val.u32;
19481948
void *ptr;
19491949

0 commit comments

Comments
 (0)