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

    <tr>
        <th>Summary</th>
        <td>
            unix.StdCLibraryFunctions analysis regression
        </td>
    </tr>

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

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

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

<pre>
    There seems to be a regression in the `unix.StdCLibraryFunctions` analysis check.
Found below is code for a small example.  Running `clang --analyze sendto.c` produces warnings such as the following:
```
sendto.c:20:3: warning: The 1st argument to 'sendto' is -1 but should be >= 0 [unix.StdCLibraryFunctions]
   20 | sendto(sockfd, NULL, 0, 0, NULL, 0);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

This happens for versions 19.1.2 and 19.1.3 but not 18.1.8.  All acquired via this Github project.

It seems the analysis pass believes `some_function_outside_tu` can set `sockfd` to `-1` as removing the call to it or adding `if(0 > sockfd) return 1;` between it and the call to `sendto` resolves this warning.  `some_function_outside_tu` should not be able to modify `sockfd` since the implementation is in a different translation unit and `sockfd` is `static`.

Here is the code for `sendto.c`:

```
#include <arpa/inet.h>
#include <sys/socket.h>
#include <stddef.h>

static int sockfd = -1;

void some_function_outside_tu(); // declared here, but implementation
                                 // is outside this translation unit

int main(int argc, const char* argv[]) {
  (void)argc; (void)argv;

 sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if(0 > sockfd) {
 return 1;
  }

  some_function_outside_tu(); // this causes issues
  sendto(sockfd, NULL, 0, 0, NULL, 0);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU1z4jgQ_TXi0oXLksHggw8khNnUZiepTOZMCanB2hESK8lksof97Vtt8zmV7GwNRRljS6-7X7_XkjGajUOs2fiGjecD2abGh1rurW9NHKy8fqtfGgwIEXEbI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