nir: Silence a warning at -Og
authorAdam Jackson <ajax@redhat.com>
Tue, 26 Jan 2021 18:18:29 +0000 (13:18 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 18 Feb 2021 20:59:43 +0000 (20:59 +0000)
This throws a curious warning:

   In file included from ../src/compiler/nir/nir.h:32,
                    from ../src/compiler/nir/nir_opt_if.c:24:
   ../src/compiler/nir/nir_opt_if.c: In function ‘opt_if_loop_last_continue’:
   ../src/compiler/glsl/list.h:415:64: warning: ‘nif’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     415 |    return !exec_list_is_empty(list) ? list->tail_sentinel.prev : NULL;
         |                                                                ^

What's going on here is not enough of the optimizer has run to be able
to prove that nif is always initialized. So just handle the "can't
happen" case as if it could.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8724>

src/compiler/nir/nir_opt_if.c

index 80116df..edda179 100644 (file)
@@ -788,7 +788,7 @@ nir_block_ends_in_continue(nir_block *block)
 static bool
 opt_if_loop_last_continue(nir_loop *loop, bool aggressive_last_continue)
 {
-   nir_if *nif;
+   nir_if *nif = NULL;
    bool then_ends_in_continue = false;
    bool else_ends_in_continue = false;
 
@@ -824,7 +824,7 @@ opt_if_loop_last_continue(nir_loop *loop, bool aggressive_last_continue)
    }
 
    /* If we didn't find an if to optimise return */
-   if (!then_ends_in_continue && !else_ends_in_continue)
+   if (!nif || (!then_ends_in_continue && !else_ends_in_continue))
       return false;
 
    /* If there is nothing after the if-statement we bail */