mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-01-28 13:05:02 -08:00
vkd3d-shader/hlsl: Translate invalid implicit-size arrays to an error type.
Instead of returning nonsense (such as, currently, a type with zero size). In practice this improves error reporting for shaders such as the following: void func(float x[]) { float y[] = {x}; } Currently this outputs a nonsense test.hlsl:1:19: E5002: Implicit size arrays not allowed in function parameters. test.hlsl:3:7: E5002: Implicit size arrays need to be initialized. With this patch the second warning is removed.
This commit is contained in:
parent
e060b47330
commit
8bc9e15618
Notes:
Henri Verbeet
2024-12-03 14:56:02 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1233
@ -475,7 +475,11 @@ static bool add_explicit_conversion(struct hlsl_ctx *ctx, struct hlsl_block *blo
|
||||
for (i = 0; i < arrays->count; ++i)
|
||||
{
|
||||
if (arrays->sizes[i] == HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT)
|
||||
{
|
||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Implicit size arrays not allowed in casts.");
|
||||
dst_type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
dst_type = hlsl_new_array_type(ctx, dst_type, arrays->sizes[i]);
|
||||
}
|
||||
|
||||
@ -1190,6 +1194,8 @@ static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields,
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Implicit size arrays not allowed in struct fields.");
|
||||
field->type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
|
||||
field->type = hlsl_new_array_type(ctx, field->type, v->arrays.sizes[k]);
|
||||
@ -1280,6 +1286,12 @@ static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type,
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Implicit size arrays not allowed in typedefs.");
|
||||
if (!(type = hlsl_type_clone(ctx, ctx->builtin_types.error, 0, 0)))
|
||||
{
|
||||
free_parse_variable_def(v);
|
||||
ret = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(type = hlsl_new_array_type(ctx, type, v->arrays.sizes[i])))
|
||||
@ -2668,26 +2680,30 @@ static void declare_var(struct hlsl_ctx *ctx, struct parse_variable_def *v)
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Only innermost array size can be implicit.");
|
||||
v->initializer.args_count = 0;
|
||||
type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
else if (elem_components == 0)
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Cannot declare an implicit size array of a size 0 type.");
|
||||
v->initializer.args_count = 0;
|
||||
type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
else if (size == 0)
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Implicit size arrays need to be initialized.");
|
||||
v->initializer.args_count = 0;
|
||||
type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
else if (size % elem_components != 0)
|
||||
{
|
||||
hlsl_error(ctx, &v->loc, VKD3D_SHADER_ERROR_HLSL_WRONG_PARAMETER_COUNT,
|
||||
"Cannot initialize implicit size array with %u components, expected a multiple of %u.",
|
||||
size, elem_components);
|
||||
v->initializer.args_count = 0;
|
||||
type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2906,7 +2922,8 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
|
||||
v->initializer.args[0] = node_from_block(v->initializer.instrs);
|
||||
}
|
||||
|
||||
initialize_var(ctx, var, &v->initializer, is_default_values_initializer);
|
||||
if (var->data_type->class != HLSL_CLASS_ERROR)
|
||||
initialize_var(ctx, var, &v->initializer, is_default_values_initializer);
|
||||
|
||||
if (is_default_values_initializer)
|
||||
{
|
||||
@ -7699,7 +7716,10 @@ parameter_decl:
|
||||
{
|
||||
hlsl_error(ctx, &@3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
|
||||
"Implicit size arrays not allowed in function parameters.");
|
||||
type = ctx->builtin_types.error;
|
||||
break;
|
||||
}
|
||||
|
||||
type = hlsl_new_array_type(ctx, type, $4.sizes[i]);
|
||||
}
|
||||
vkd3d_free($4.sizes);
|
||||
|
Loading…
x
Reference in New Issue
Block a user