<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/110580>110580</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [analyzer] [fuchsia.HandleChecker] Leak node is generated at wrong place
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:static analyzer
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          pskrgag
      </td>
    </tr>
</table>

<pre>
    Consider following code:

```c
#include <stdint.h>
#include <stdio.h>

typedef int zx_status_t;
typedef __typeof__(sizeof(int)) zx_handle_t;

#define ZX_HANDLE_ACQUIRE __attribute__((acquire_handle("Fuchsia")))
#define ZX_HANDLE_RELEASE __attribute__((release_handle("Fuchsia")))

zx_status_t create_handle(zx_handle_t *out0 ZX_HANDLE_ACQUIRE);
zx_status_t handle_close(zx_handle_t handle ZX_HANDLE_RELEASE);

void foo(void)
{
        zx_handle_t handle;
        zx_status_t res = create_handle(&handle);

        if (res == 0) {
                printf("error\n"); // leak reported here
                printf("error1\n");
                printf("error1\n");
        }
}
```

Error node reported on some very unrelated node. I'd expect error to be report at the end of the function, since there actual leak happens.

This happens, since `handle` symbol indeed becomes dead. Note, that leak node is generated at the right place if condition is changed to `res == 1`  (which indicates allocation failure in terms of this checker). 


Godbolt https://godbolt.org/z/33xPszdd6

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVV1v5CYb_TXMzaO1MM7Y4wtfTObj3ZWi1dttK1W9sTA8tmkYcAHnY359hT2TOElTVZUshgHO4ZzDY8O9V51BrMj6lqz3Kz6G3rpq8Peu492qsfK52lnjlUQHrdXaPirTgbASSbYldE_otc3p_IjLf5YpI_QoEUi280EqE5KeZIfPpu1ydmrD84ASW1AmwPmp9oGH0deBZLdv5-s69mxb14RtvDqjbQnbKBMIKwkrI7bnRmpcYF9USGyVQfj9t_rr9vv-7lBvdz_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