Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 16 +++++----------- libs/vkd3d-shader/hlsl.y | 34 ++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 3544b9d6..01d5e773 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1278,7 +1278,6 @@ void hlsl_free_instr_list(struct list *list) * the "uses" list. */ LIST_FOR_EACH_ENTRY_SAFE_REV(node, next_node, list, struct hlsl_ir_node, entry) hlsl_free_instr(node); - vkd3d_free(list); }
static void free_ir_constant(struct hlsl_ir_constant *constant) @@ -1297,12 +1296,8 @@ static void free_ir_expr(struct hlsl_ir_expr *expr)
static void free_ir_if(struct hlsl_ir_if *if_node) { - struct hlsl_ir_node *node, *next_node; - - LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->then_instrs, struct hlsl_ir_node, entry) - hlsl_free_instr(node); - LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &if_node->else_instrs, struct hlsl_ir_node, entry) - hlsl_free_instr(node); + hlsl_free_instr_list(&if_node->then_instrs); + hlsl_free_instr_list(&if_node->else_instrs); hlsl_src_remove(&if_node->condition); vkd3d_free(if_node); } @@ -1320,10 +1315,7 @@ static void free_ir_load(struct hlsl_ir_load *load)
static void free_ir_loop(struct hlsl_ir_loop *loop) { - struct hlsl_ir_node *node, *next_node; - - LIST_FOR_EACH_ENTRY_SAFE(node, next_node, &loop->body, struct hlsl_ir_node, entry) - hlsl_free_instr(node); + hlsl_free_instr_list(&loop->body); vkd3d_free(loop); }
@@ -1342,6 +1334,8 @@ static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle)
void hlsl_free_instr(struct hlsl_ir_node *node) { + assert(list_empty(&node->uses)); + switch (node->type) { case HLSL_IR_CONSTANT: diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 5f1e9167..cb4fd7c8 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -136,6 +136,12 @@ static struct list *make_empty_list(struct hlsl_ctx *ctx) return list; }
+static void destroy_instr_list(struct list *list) +{ + hlsl_free_instr_list(list); + vkd3d_free(list); +} + static void check_invalid_matrix_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, struct vkd3d_shader_location loc) { if (modifiers & HLSL_MODIFIERS_MAJORITY_MASK) @@ -385,10 +391,10 @@ oom: vkd3d_free(loop); vkd3d_free(cond_jump); vkd3d_free(list); - hlsl_free_instr_list(init); - hlsl_free_instr_list(cond); - hlsl_free_instr_list(iter); - hlsl_free_instr_list(body); + destroy_instr_list(init); + destroy_instr_list(cond); + destroy_instr_list(iter); + destroy_instr_list(body); return NULL; }
@@ -405,7 +411,7 @@ static unsigned int initializer_size(const struct parse_initializer *initializer
static void free_parse_initializer(struct parse_initializer *initializer) { - hlsl_free_instr_list(initializer->instrs); + destroy_instr_list(initializer->instrs); vkd3d_free(initializer->args); }
@@ -1789,7 +1795,7 @@ hlsl_prog: { if (!list_empty($2)) hlsl_fixme(ctx, @2, "Uniform initializer."); - hlsl_free_instr_list($2); + destroy_instr_list($2); } | hlsl_prog preproc_directive | hlsl_prog ';' @@ -2364,7 +2370,7 @@ arrays: unsigned int size = evaluate_array_dimension(node_from_list($2)); uint32_t *new_array;
- hlsl_free_instr_list($2); + destroy_instr_list($2);
$$ = $4;
@@ -2656,7 +2662,7 @@ postfix_expr: { if (!add_increment(ctx, $1, false, true, @2)) { - hlsl_free_instr_list($1); + destroy_instr_list($1); YYABORT; } $$ = $1; @@ -2665,7 +2671,7 @@ postfix_expr: { if (!add_increment(ctx, $1, true, true, @2)) { - hlsl_free_instr_list($1); + destroy_instr_list($1); YYABORT; } $$ = $1; @@ -2717,20 +2723,20 @@ postfix_expr: if (index->data_type->type != HLSL_CLASS_SCALAR) { hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Array index is not scalar."); - hlsl_free_instr_list($1); + destroy_instr_list($1); YYABORT; }
if (!(cast = hlsl_new_cast(ctx, index, ctx->builtin_types.scalar[HLSL_TYPE_UINT], &index->loc))) { - hlsl_free_instr_list($1); + destroy_instr_list($1); YYABORT; } list_add_tail($1, &cast->node.entry);
if (!add_array_load(ctx, $1, array, &cast->node, @2)) { - hlsl_free_instr_list($1); + destroy_instr_list($1); YYABORT; } $$ = $1; @@ -2821,7 +2827,7 @@ unary_expr: { if (!add_increment(ctx, $2, false, false, @1)) { - hlsl_free_instr_list($2); + destroy_instr_list($2); YYABORT; } $$ = $2; @@ -2830,7 +2836,7 @@ unary_expr: { if (!add_increment(ctx, $2, true, false, @1)) { - hlsl_free_instr_list($2); + destroy_instr_list($2); YYABORT; } $$ = $2;