On 9/27/21 5:20 AM, Giovanni Mascellani wrote:
Hi,
Il 25/09/21 14:09, Matteo Bruni ha scritto:
- | NEW_IDENTIFIER
{
if (ctx->in_state_block)
{
struct hlsl_ir_load *load;
struct hlsl_ir_var *var;
if (!(var = hlsl_new_var(ctx, $1, ctx->builtin_types.scalar[HLSL_TYPE_INT], @1, NULL, 0, NULL)))
YYABORT;
if (!(load = hlsl_new_var_load(ctx, var, @1)))
YYABORT;
if (!($$ = make_list(ctx, &load->node)))
{
hlsl_free_instr(&load->node);
YYABORT;
}
}
This leaks var on error.
Also, the node is doubly freed in the error path (because make_list already frees the node when it fails). Maybe the outer hlsl_free_instr was meant to free the variable instead (though the variable must also be freed when hlsl_new_var_load fails).
That said, I didn't know about this strange HLSL feature, so I don't know what the intended behavior would be. Does anybody have a link? Searching for "hlsl state block" didn't help much.
The terminology might be invented by me, but the construct is demonstrated at [1]. It's meant for effects, but the documentation on that page doesn't make that clear, to the effect that I've seen it used in regular shaders as well. In that case it's basically just ignored, including all instructions with side effects (as the tests show).
[1] https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl...