Module: vkd3d Branch: master Commit: a838f97e3f97032cabb7214e700372b0b9d64bf5 URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/a838f97e3f97032cabb7214e700372...
Author: Francisco Casas fcasas@codeweavers.com Date: Fri Mar 15 00:48:01 2024 -0300
vkd3d-shader/hlsl: Cast to bool before applying LOGIC_NOT.
Before this commit, it is possible for one of the tests of cf-cond-types.shader_test to pass a non-bool to LOGIC_NOT, which should not be allowed.
---
libs/vkd3d-shader/hlsl.y | 10 ++++++++-- libs/vkd3d-shader/hlsl_codegen.c | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index ec8b3d22..2824e26d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -438,8 +438,9 @@ static uint32_t add_modifiers(struct hlsl_ctx *ctx, uint32_t modifiers, uint32_t
static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *cond_block) { - struct hlsl_ir_node *condition, *not, *iff, *jump; + struct hlsl_ir_node *condition, *cast, *not, *iff, *jump; struct hlsl_block then_block; + struct hlsl_type *bool_type;
/* E.g. "for (i = 0; ; ++i)". */ if (list_empty(&cond_block->instrs)) @@ -449,7 +450,12 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct hlsl_block *co
check_condition_type(ctx, condition);
- if (!(not = hlsl_new_unary_expr(ctx, HLSL_OP1_LOGIC_NOT, condition, &condition->loc))) + bool_type = hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL); + if (!(cast = hlsl_new_cast(ctx, condition, bool_type, &condition->loc))) + return false; + hlsl_block_add_instr(cond_block, cast); + + if (!(not = hlsl_new_unary_expr(ctx, HLSL_OP1_LOGIC_NOT, cast, &condition->loc))) return false; hlsl_block_add_instr(cond_block, not);
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e4084d34..fb7d1f56 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -2919,6 +2919,9 @@ static bool lower_logic_not(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, st arg = expr->operands[0].node; float_type = hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, arg->data_type->dimx);
+ /* If this is happens, it means we failed to cast the argument to boolean somewhere. */ + assert(arg->data_type->base_type == HLSL_TYPE_BOOL); + if (!(arg_cast = hlsl_new_cast(ctx, arg, float_type, &arg->loc))) return false; hlsl_block_add_instr(block, arg_cast);