anv: Get rid of "may be used initialized" warning in anv_QueueSubmit2KHR
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 3 Nov 2021 03:38:33 +0000 (20:38 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 3 Nov 2021 17:14:36 +0000 (17:14 +0000)
The code is correct, but compiler can't see it.  Initialize the value
to NULL and assert on it if the function succeeds.  It both helps the
compiler and make the code slightly more robust.

```
../src/intel/vulkan/anv_queue.c: In function ‘anv_QueueSubmit2KHR’:
../src/intel/vulkan/anv_queue.c:932:16: warning: ‘impl’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  932 |       result = anv_queue_submit_add_timeline_wait(queue, submit,
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933 |                                                   &impl->timeline,
      |                                                   ~~~~~~~~~~~~~~~~
  934 |                                                   value);
      |                                                   ~~~~~~
../src/intel/vulkan/anv_queue.c:899:31: note: ‘impl’ was declared here
  899 |    struct anv_semaphore_impl *impl;
      |                               ^~~~
```

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13638>

src/intel/vulkan/anv_queue.c

index d485aee..714267a 100644 (file)
@@ -896,13 +896,15 @@ anv_queue_submit_add_in_semaphore(struct anv_queue *queue,
                                   const uint64_t value)
 {
    ANV_FROM_HANDLE(anv_semaphore, semaphore, _semaphore);
-   struct anv_semaphore_impl *impl;
+   struct anv_semaphore_impl *impl = NULL;
    VkResult result;
 
    result = maybe_transfer_temporary_semaphore(queue, submit, semaphore, &impl);
    if (result != VK_SUCCESS)
       return result;
 
+   assert(impl);
+
    switch (impl->type) {
    case ANV_SEMAPHORE_TYPE_WSI_BO:
       /* When using a window-system buffer as a semaphore, always enable