OSDN Git Service

glsl: Avoid propagating incompatible type of initializer
authorDanylo Piliaiev <danylo.piliaiev@gmail.com>
Wed, 15 Aug 2018 12:46:22 +0000 (15:46 +0300)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 19 Sep 2018 22:30:11 +0000 (08:30 +1000)
commit6f3c7374b11299c21d829db794fad3b756af60fb
tree5426535d63f42f086abc03152d218291a329a81d
parent194bf0a2e01769f4b29df06febf27ce340c1cd68
glsl: Avoid propagating incompatible type of initializer

do_assignment validated assigment but when rhs type was not compatible
it proceeded without issues and returned error_emitted = false.
On the other hand process_initializer expected do_assignment to always
return compatible type and never fail.

As a result when variable was initialized with incompatible type
the type of variable changed to the incompatible one.
This manifested in unnecessary error messages and in one case in crash.

Example GLSL:
 vec4 tmp = vec2(0.0);
 tmp.z -= 1.0;

Past error messages:
 initializer of type vec2 cannot be assigned to variable of type vec4
 invalid swizzle / mask `z'
 type mismatch
 operands to arithmetic operators must be numeric

After this patch:
 initializer of type vec2 cannot be assigned to variable of type vec4

In the other case when we initialize variable with incompatible struct,
accessing variable's field leaded to a crash. Example:
 uniform struct {float field;} data;
 ...
 vec4 tmp = data;
 tmp.x -= 1.0;

After the patch there is only error line without a crash:
 initializer of type #anon_struct cannot be assigned to variable of
  type vec4

Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107547
src/compiler/glsl/ast_to_hir.cpp