Mesa (staging/18.3): glsl: do not allow implicit casts of unsized array initializers
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Nov 8 16:21:16 UTC 2018
Module: Mesa
Branch: staging/18.3
Commit: 09c5e548c4eb1b9a4f5a8b3c2bac3da857338464
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=09c5e548c4eb1b9a4f5a8b3c2bac3da857338464
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Thu Oct 25 21:33:52 2018 +0200
glsl: do not allow implicit casts of unsized array initializers
The GLSL 4.6 specification (section 4.1.14. "Implicit Conversions")
says:
"There are no implicit array or structure conversions. For
example, an array of int cannot be implicitly converted to an
array of float."
So let's add a check in place when assigning array initializers to
implicitly sized arrays, to avoid incorrectly allowing code on the
form:
int[] foo = float[](1.0, 2.0, 3.0)
This fixes the following dEQP test-cases:
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.int_to_float_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.int_to_float_fragment
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.int_to_uint_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.int_to_uint_fragment
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.uint_to_float_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es31.invalid.arrays.uint_to_float_fragment
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.int_to_float_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.int_to_float_fragment
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.int_to_uint_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.int_to_uint_fragment
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.uint_to_float_vertex
- dEQP-GLES31.functional.shaders.implicit_conversions.es32.invalid.arrays.uint_to_float_fragment
Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
(cherry picked from commit 742dace8251b764775ee049cf529715f90afecc1)
---
src/compiler/glsl/ast_to_hir.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 084b7021a9..cf52f079df 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -892,7 +892,8 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
}
if (unsized_array) {
if (is_initializer) {
- return rhs;
+ if (rhs->type->get_scalar_type() == lhs->type->get_scalar_type())
+ return rhs;
} else {
_mesa_glsl_error(&loc, state,
"implicitly sized arrays cannot be assigned");
More information about the mesa-commit
mailing list