Module: Mesa Branch: main Commit: e3b4c77ed3468a1b455d164f45f91d90247eabb2 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e3b4c77ed3468a1b455d164f45f91d90247eabb2
Author: Marcin Ślusarz <[email protected]> Date: Tue Aug 17 11:17:18 2021 +0200 glsl: refactor code to avoid static analyzer noise Clang analyzer thinks struct_base_offset can be used uninitialized because it doesn't know that glsl_type_is_struct_or_ifc returns the same value for the same type. Refactor the code to make it clear what is going on. As a side effect this should be faster because glsl_get_length and glsl_type_is_struct_or_ifc will be called only once (they are not inline functions). This is an alternative approach to https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12399. Signed-off-by: Marcin Ślusarz <[email protected]> Reviewed-by: Alejandro Piñeiro <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12403> --- src/compiler/glsl/gl_nir_link_uniform_blocks.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_uniform_blocks.c b/src/compiler/glsl/gl_nir_link_uniform_blocks.c index 9c95918287b..a2b2e9dbecc 100644 --- a/src/compiler/glsl/gl_nir_link_uniform_blocks.c +++ b/src/compiler/glsl/gl_nir_link_uniform_blocks.c @@ -374,18 +374,22 @@ iterate_type_fill_variables(const struct glsl_type *type, struct gl_shader_program *prog, struct gl_uniform_block *block) { - unsigned int struct_base_offset; + unsigned length = glsl_get_length(type); + if (length == 0) + return; - for (unsigned i = 0; i < glsl_get_length(type); i++) { + unsigned struct_base_offset; + + bool struct_or_ifc = glsl_type_is_struct_or_ifc(type); + if (struct_or_ifc) + struct_base_offset = *offset; + + for (unsigned i = 0; i < length; i++) { const struct glsl_type *field_type; - if (glsl_type_is_struct_or_ifc(type)) { + if (struct_or_ifc) { field_type = glsl_get_struct_field(type, i); - if (i == 0) { - struct_base_offset = *offset; - } - *offset = struct_base_offset + glsl_get_struct_field_offset(type, i); } else { field_type = glsl_get_array_element(type);
