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

    <tr>
        <th>Summary</th>
        <td>
            [analyzer] FP caused by invalid reasoning about atomics
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    In our project we use a lot of object with intrusive refcounting. So following (very simplified) pattern occurs a lot:

```c
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdatomic.h>
#include <assert.h>

struct SomeData {
        size_t i;
        _Atomic int ref;
};

static struct SomeData *alloc_data(void)
{
        struct SomeData *data = calloc(sizeof(*data), 1);
        assert(data);

        atomic_store(&data->ref, 2);
        return data;
}

static void put_data(struct SomeData *data)
{
        if (atomic_fetch_sub(&data->ref, 1) == 1)
                free(data);
}

void test(void)
{
        struct SomeData *data = alloc_data();

        put_data(data);
        printf("%lx\n", data->i); // <-- Warns here about UAF
        put_data(data);
}
```

CSA warns about UAF, even tho it does not happen, since refcounter will be equal to 1 after first `put_data`. 

I do understand limitations of static analysis and how it's hard to model concurrent code. My question is how to suppress such warnings? It's possible to add `suppress`  attribute to all FP occurrences, but it would trash the source, since we really see a lot of them.

Maybe it would be possible to implement a new flag like `dont-warn-on-atomic-conditions``? Or smth like that...
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2P2zYQ_TX0ZWBBovx58GFjx0AOQQssih4XFDmy2NCkwhnadX59QcmOvd3doCiwkNaa4Zv33gxJRWQPHnEj5p_EfDdRibsQNz19iwd1mDTBXDZfPIQUoY_hL9QMZ4RECApcYAgthGb8bLkD6zkmsieEiK0OybP1hwKeA7TBuXC2_gBCrk4YL0D22DvbWjRCrqFXzBg9BK1TpBFd1E-i3Iny9lyU45--_pa19dolgyDqLbEx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