Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/hlsl_constant_ops.c:
}
+static bool fold_lshift(struct hlsl_ctx *ctx, struct hlsl_constant_value *dst, const struct hlsl_type *dst_type,
const struct hlsl_ir_constant *src1, const struct hlsl_ir_constant *src2)
+{
- unsigned int k;
- assert(dst_type->base_type == src1->node.data_type->base_type);
- assert(src2->node.data_type->base_type == HLSL_TYPE_INT);
- for (k = 0; k < dst_type->dimx; ++k)
- {
switch (src1->node.data_type->base_type)
{
case HLSL_TYPE_INT:
dst->u[k].i = src1->value.u[k].i << src2->value.u[k].i;
In C shifts are undefined behavior when the RHS is negative or larger or equal then the LHS' type bit width. We don't want the HLSL compiler to hit UB, so please work out what the native compiler actually does here (truncate to 5 bits? Return zero?) and do the same without UB. Please add tests too.
The same happens below in this commit and in the next commit.