<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - analyzer does not know that failed syscalls set errno"
href="https://bugs.llvm.org/show_bug.cgi?id=43670">43670</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>analyzer does not know that failed syscalls set errno
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dcoughlin@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>npl@chello.at
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following code will produce a report, even though the analyzer could/should
deduce that errno is set to non-zero if socket returns < 0.
Adding the __builtin_unreachable fixes the report, but this should be automatic
for reading errno after entering a branch that requires a failed syscall.
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
extern int dosomething(char *);
static int connect_socket(char **mname) {
int ret;
*mname = (char *)malloc(PATH_MAX);
int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
if (fd < 0) {
ret = errno;
// if (ret == 0)
// __builtin_unreachable();
free(*mname);
return ret;
}
{
ret = recv(fd, *mname, PATH_MAX, 0);
if (ret > 0) return 0;
}
close(fd);
return ret;
}
int do_init()
{
char *mname;
int ret = connect_socket(&mname);
if (ret)
return ret;
return dosomething(mname);
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>