From bb7418065916f211fd84b1b79b10789630b13487 Mon Sep 17 00:00:00 2001 From: Elizabeth Figura Date: Thu, 29 Aug 2024 12:48:23 -0500 Subject: [PATCH] vkd3d-shader/hlsl: Return an error expression when an invalid subscript is used. --- libs/vkd3d-shader/hlsl.c | 4 ++-- libs/vkd3d-shader/hlsl.y | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index cafff2fa..d0cfc285 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -4445,8 +4445,6 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx) rb_destroy(&ctx->functions, free_function_rb, NULL); - hlsl_block_cleanup(&ctx->static_initializers); - /* State blocks must be free before the variables, because they contain instructions that may * refer to them. */ LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &ctx->scopes, struct hlsl_scope, entry) @@ -4462,6 +4460,8 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx) } } + hlsl_block_cleanup(&ctx->static_initializers); + LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &ctx->scopes, struct hlsl_scope, entry) { LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8cc34ad2..ab89e5a4 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1243,7 +1243,8 @@ static bool add_record_access_recurse(struct hlsl_ctx *ctx, struct hlsl_block *b } hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Field \"%s\" is not defined.", name); - return false; + block->value = ctx->error_instr; + return true; } static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type, struct list *list) @@ -8960,27 +8961,27 @@ postfix_expr: vkd3d_free($3); YYABORT; } - vkd3d_free($3); } else if (hlsl_is_numeric_type(node->data_type)) { struct hlsl_ir_node *swizzle; - if (!(swizzle = get_swizzle(ctx, node, $3, &@3))) + if ((swizzle = get_swizzle(ctx, node, $3, &@3))) + { + hlsl_block_add_instr($1, swizzle); + } + else { hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Invalid swizzle \"%s\".", $3); - vkd3d_free($3); - YYABORT; + $1->value = ctx->error_instr; } - hlsl_block_add_instr($1, swizzle); - vkd3d_free($3); } else if (node->data_type->class != HLSL_CLASS_ERROR) { hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Invalid subscript \"%s\".", $3); - vkd3d_free($3); - YYABORT; + $1->value = ctx->error_instr; } + vkd3d_free($3); $$ = $1; } | postfix_expr '[' expr ']'