@@ -2610,21 +2610,24 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
2610
2610
2611
2611
case INDEX_op_shl_i32 :
2612
2612
if (const_args [2 ]) {
2613
- tcg_out_shli32 (s , args [0 ], args [1 ], args [2 ]);
2613
+ /* Limit immediate shift count lest we create an illegal insn. */
2614
+ tcg_out_shli32 (s , args [0 ], args [1 ], args [2 ] & 31 );
2614
2615
} else {
2615
2616
tcg_out32 (s , SLW | SAB (args [1 ], args [0 ], args [2 ]));
2616
2617
}
2617
2618
break ;
2618
2619
case INDEX_op_shr_i32 :
2619
2620
if (const_args [2 ]) {
2620
- tcg_out_shri32 (s , args [0 ], args [1 ], args [2 ]);
2621
+ /* Limit immediate shift count lest we create an illegal insn. */
2622
+ tcg_out_shri32 (s , args [0 ], args [1 ], args [2 ] & 31 );
2621
2623
} else {
2622
2624
tcg_out32 (s , SRW | SAB (args [1 ], args [0 ], args [2 ]));
2623
2625
}
2624
2626
break ;
2625
2627
case INDEX_op_sar_i32 :
2626
2628
if (const_args [2 ]) {
2627
- tcg_out32 (s , SRAWI | RS (args [1 ]) | RA (args [0 ]) | SH (args [2 ]));
2629
+ /* Limit immediate shift count lest we create an illegal insn. */
2630
+ tcg_out32 (s , SRAWI | RS (args [1 ]) | RA (args [0 ]) | SH (args [2 ] & 31 ));
2628
2631
} else {
2629
2632
tcg_out32 (s , SRAW | SAB (args [1 ], args [0 ], args [2 ]));
2630
2633
}
@@ -2696,14 +2699,16 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
2696
2699
2697
2700
case INDEX_op_shl_i64 :
2698
2701
if (const_args [2 ]) {
2699
- tcg_out_shli64 (s , args [0 ], args [1 ], args [2 ]);
2702
+ /* Limit immediate shift count lest we create an illegal insn. */
2703
+ tcg_out_shli64 (s , args [0 ], args [1 ], args [2 ] & 63 );
2700
2704
} else {
2701
2705
tcg_out32 (s , SLD | SAB (args [1 ], args [0 ], args [2 ]));
2702
2706
}
2703
2707
break ;
2704
2708
case INDEX_op_shr_i64 :
2705
2709
if (const_args [2 ]) {
2706
- tcg_out_shri64 (s , args [0 ], args [1 ], args [2 ]);
2710
+ /* Limit immediate shift count lest we create an illegal insn. */
2711
+ tcg_out_shri64 (s , args [0 ], args [1 ], args [2 ] & 63 );
2707
2712
} else {
2708
2713
tcg_out32 (s , SRD | SAB (args [1 ], args [0 ], args [2 ]));
2709
2714
}
0 commit comments