[Mesa-dev] [PATCH] glsl: Avoid calling get_array_element for scalar constants
Danylo Piliaiev
danylo.piliaiev at gmail.com
Tue Aug 14 09:20:45 UTC 2018
Hi,
On 08/14/2018 10:43 AM, Tapani Pälli wrote:
>
>
> On 08/13/2018 08:54 PM, Ian Romanick wrote:
>> On 08/13/2018 08:57 AM, Danylo Piliaiev wrote:
>>> Accessing scalar constant as an array in function call or
>>> initializer list triggered assert in get_array_element.
>>> Examples:
>>> func(0[0]);
>>> vec2 t = { 0[0], 0 };
>>
>> Do we have tests like this in piglit? What happens if 0[0] syntax is
>> used other places? What do happens in these cases after this change?
>> Some sort of graceful compile-time error, I hope...
>
In other places we already fail with the same error ("cannot dereference
non-array / non-matrix / non-vector").
> I've sent a glslparsertest for this. With the change we fail
> compilation in this case like:
>
> 0:8(9): error: cannot dereference non-array / non-matrix / non-vector
> 0:8(2): error: no function with name 'func'
>
Thanks for the test.
- Danil
>
>>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107550
>>>
>>> Signed-off-by: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
>>> ---
>>> src/compiler/glsl/ir_constant_expression.cpp | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/compiler/glsl/ir_constant_expression.cpp
>>> b/src/compiler/glsl/ir_constant_expression.cpp
>>> index 4a0aff72c6..c9788c7053 100644
>>> --- a/src/compiler/glsl/ir_constant_expression.cpp
>>> +++ b/src/compiler/glsl/ir_constant_expression.cpp
>>> @@ -826,7 +826,7 @@
>>> ir_dereference_array::constant_expression_value(void *mem_ctx,
>>> const unsigned component = idx->value.u[0];
>>> return new(mem_ctx) ir_constant(array, component);
>>> - } else {
>>> + } else if (array->type->is_array()) {
>>> const unsigned index = idx->value.u[0];
>>> return array->get_array_element(index)->clone(mem_ctx,
>>> NULL);
>>> }
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
More information about the mesa-dev
mailing list