vkd3d-shader/hlsl: Avoid assuming that expressions have at least one argument.

This commit is contained in:
Zebediah Figura 2021-09-10 16:35:54 -05:00 committed by Alexandre Julliard
parent 22a1a478ea
commit 30550c0831
Notes: Alexandre Julliard 2023-01-13 22:23:38 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/47
2 changed files with 11 additions and 7 deletions

View File

@ -467,12 +467,12 @@ static bool lower_broadcasts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, v
if (instr->type != HLSL_IR_EXPR)
return false;
cast = hlsl_ir_expr(instr);
if (cast->op != HLSL_OP1_CAST)
return false;
src_type = cast->operands[0].node->data_type;
dst_type = cast->node.data_type;
if (cast->op == HLSL_OP1_CAST
&& src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
&& src_type->dimx == 1)
if (src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR && src_type->dimx == 1)
{
struct hlsl_ir_node *replacement;
struct hlsl_ir_swizzle *swizzle;
@ -1050,12 +1050,14 @@ static bool fold_redundant_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
if (instr->type == HLSL_IR_EXPR)
{
struct hlsl_ir_expr *expr = hlsl_ir_expr(instr);
const struct hlsl_type *src_type = expr->operands[0].node->data_type;
const struct hlsl_type *dst_type = expr->node.data_type;
const struct hlsl_type *src_type;
if (expr->op != HLSL_OP1_CAST)
return false;
src_type = expr->operands[0].node->data_type;
if (hlsl_types_are_equal(src_type, dst_type)
|| (src_type->base_type == dst_type->base_type && is_vec1(src_type) && is_vec1(dst_type)))
{
@ -1213,12 +1215,12 @@ static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins
if (instr->type != HLSL_IR_EXPR)
return false;
cast = hlsl_ir_expr(instr);
if (cast->op != HLSL_OP1_CAST)
return false;
src_type = cast->operands[0].node->data_type;
dst_type = cast->node.data_type;
if (cast->op == HLSL_OP1_CAST
&& src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
&& dst_type->dimx < src_type->dimx)
if (src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR && dst_type->dimx < src_type->dimx)
{
struct hlsl_ir_swizzle *swizzle;
struct hlsl_ir_expr *new_cast;

View File

@ -509,6 +509,8 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (instr->type != HLSL_IR_EXPR)
return false;
expr = hlsl_ir_expr(instr);
if (!expr->operands[0].node)
return false;
if (instr->data_type->type > HLSL_CLASS_VECTOR)
return false;