Current behavior of int4shr/int4shl/.. is an UB in cases where shift count exceeds bitness of the integer being shifted.
 
For example in this case if `arg2` >= 32 this is an UB:
 
Datum
int4shl(PG_FUNCTION_ARGS)
{
    int32        arg1 = PG_GETARG_INT32(0);
    int32        arg2 = PG_GETARG_INT32(1);
 
    PG_RETURN_INT32(arg1 << arg2);
}
 
x86 handled this by applying a mask (e.g. & 31) while ARM will produce 0 and RISC-V will crash. So besides being an UB it is inconsistent across platforms.
 
The proposed solution is to report an error to the user: "shift count out of range". This is also what other functions already do, for example:
int4pl/int4mi/int4mul/int4neg report ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE, "integer out of range" (int.c:825–856)
The corresponding patch file is attached.

Originally the issue was found by fuzzing by Ilya Khaprov.