Module: Mesa
Branch: main
Commit: 8e196214a0c3d90ed8c4fe53a9cf308402274d2b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8e196214a0c3d90ed8c4fe53a9cf308402274d2b

Author: Corentin Noël <corentin.n...@collabora.com>
Date:   Mon Nov  6 14:22:32 2023 +0100

mesa: Use a switch for state_iter and be more precise about its type

Even if this technically won't change anything, it prevents a false-positive of
uninitialized use of variables with clang.

Signed-off-by: Corentin Noël <corentin.n...@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-l...@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26067>

---

 src/mesa/program/prog_statevars.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/mesa/program/prog_statevars.c 
b/src/mesa/program/prog_statevars.c
index 62d8a23d20d..cd6cafe6d49 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -1617,22 +1617,28 @@ _mesa_optimize_state_parameters(struct gl_constants 
*consts,
          gl_state_index16 state = STATE_NOT_STATE_VAR;
          unsigned num_lights = 0;
 
-         for (unsigned state_iter = STATE_LIGHTPROD_ARRAY_FRONT;
+         for (gl_state_index state_iter = STATE_LIGHTPROD_ARRAY_FRONT;
               state_iter <= STATE_LIGHTPROD_ARRAY_TWOSIDE; state_iter++) {
             unsigned num_attribs, base_attrib, attrib_incr;
 
-            if (state_iter == STATE_LIGHTPROD_ARRAY_FRONT)  {
+            switch (state_iter) {
+            case STATE_LIGHTPROD_ARRAY_FRONT:
                num_attribs = 3;
                base_attrib = MAT_ATTRIB_FRONT_AMBIENT;
                attrib_incr = 2;
-            } else if (state_iter == STATE_LIGHTPROD_ARRAY_BACK) {
+               break;
+            case STATE_LIGHTPROD_ARRAY_BACK:
                num_attribs = 3;
                base_attrib = MAT_ATTRIB_BACK_AMBIENT;
                attrib_incr = 2;
-            } else if (state_iter == STATE_LIGHTPROD_ARRAY_TWOSIDE) {
+               break;
+            case STATE_LIGHTPROD_ARRAY_TWOSIDE:
                num_attribs = 6;
                base_attrib = MAT_ATTRIB_FRONT_AMBIENT;
                attrib_incr = 1;
+               break;
+            default:
+               unreachable("unexpected state-var");
             }
 
             /* Find all attributes for one light. */

Reply via email to