[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Analysis / std-c-library-functions-POSIX.c
bloba837cc9b0b34930a454e07d97ba3b26b1de6e1a2
1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
4 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:ModelPOSIX=true \
5 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
6 // RUN: -analyzer-checker=debug.ExprInspection \
7 // RUN: -analyzer-config eagerly-assume=false \
8 // RUN: -triple i686-unknown-linux 2>&1 | FileCheck %s
10 // CHECK: Loaded summary for: long a64l(const char *str64)
11 // CHECK: Loaded summary for: char *l64a(long value)
12 // CHECK: Loaded summary for: int access(const char *pathname, int amode)
13 // CHECK: Loaded summary for: int faccessat(int dirfd, const char *pathname, int mode, int flags)
14 // CHECK: Loaded summary for: int dup(int fildes)
15 // CHECK: Loaded summary for: int dup2(int fildes1, int filedes2)
16 // CHECK: Loaded summary for: int fdatasync(int fildes)
17 // CHECK: Loaded summary for: int fnmatch(const char *pattern, const char *string, int flags)
18 // CHECK: Loaded summary for: int fsync(int fildes)
19 // CHECK: Loaded summary for: int truncate(const char *path, off_t length)
20 // CHECK: Loaded summary for: int symlink(const char *oldpath, const char *newpath)
21 // CHECK: Loaded summary for: int symlinkat(const char *oldpath, int newdirfd, const char *newpath)
22 // CHECK: Loaded summary for: int lockf(int fd, int cmd, off_t len)
23 // CHECK: Loaded summary for: int creat(const char *pathname, mode_t mode)
24 // CHECK: Loaded summary for: unsigned int sleep(unsigned int seconds)
25 // CHECK: Loaded summary for: int dirfd(DIR *dirp)
26 // CHECK: Loaded summary for: unsigned int alarm(unsigned int seconds)
27 // CHECK: Loaded summary for: int closedir(DIR *dir)
28 // CHECK: Loaded summary for: char *strdup(const char *s)
29 // CHECK: Loaded summary for: char *strndup(const char *s, size_t n)
30 // CHECK: Loaded summary for: int mkstemp(char *template)
31 // CHECK: Loaded summary for: char *mkdtemp(char *template)
32 // CHECK: Loaded summary for: char *getcwd(char *buf, size_t size)
33 // CHECK: Loaded summary for: int mkdir(const char *pathname, mode_t mode)
34 // CHECK: Loaded summary for: int mkdirat(int dirfd, const char *pathname, mode_t mode)
35 // CHECK: Loaded summary for: int mknod(const char *pathname, mode_t mode, dev_t dev)
36 // CHECK: Loaded summary for: int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev)
37 // CHECK: Loaded summary for: int chmod(const char *path, mode_t mode)
38 // CHECK: Loaded summary for: int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags)
39 // CHECK: Loaded summary for: int fchmod(int fildes, mode_t mode)
40 // CHECK: Loaded summary for: int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags)
41 // CHECK: Loaded summary for: int chown(const char *path, uid_t owner, gid_t group)
42 // CHECK: Loaded summary for: int lchown(const char *path, uid_t owner, gid_t group)
43 // CHECK: Loaded summary for: int fchown(int fildes, uid_t owner, gid_t group)
44 // CHECK: Loaded summary for: int rmdir(const char *pathname)
45 // CHECK: Loaded summary for: int chdir(const char *path)
46 // CHECK: Loaded summary for: int link(const char *oldpath, const char *newpath)
47 // CHECK: Loaded summary for: int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag)
48 // CHECK: Loaded summary for: int unlink(const char *pathname)
49 // CHECK: Loaded summary for: int unlinkat(int fd, const char *path, int flag)
50 // CHECK: Loaded summary for: int fstat(int fd, struct stat *statbuf)
51 // CHECK: Loaded summary for: int stat(const char *restrict path, struct stat *restrict buf)
52 // CHECK: Loaded summary for: int lstat(const char *restrict path, struct stat *restrict buf)
53 // CHECK: Loaded summary for: int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag)
54 // CHECK: Loaded summary for: DIR *opendir(const char *name)
55 // CHECK: Loaded summary for: DIR *fdopendir(int fd)
56 // CHECK: Loaded summary for: int isatty(int fildes)
57 // CHECK: Loaded summary for: FILE *popen(const char *command, const char *type)
58 // CHECK: Loaded summary for: int pclose(FILE *stream)
59 // CHECK: Loaded summary for: int close(int fildes)
60 // CHECK: Loaded summary for: long fpathconf(int fildes, int name)
61 // CHECK: Loaded summary for: long pathconf(const char *path, int name)
62 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
63 // CHECK: Loaded summary for: void rewinddir(DIR *dir)
64 // CHECK: Loaded summary for: void seekdir(DIR *dirp, long loc)
65 // CHECK: Loaded summary for: int rand_r(unsigned int *seedp)
66 // CHECK: Loaded summary for: int fileno(FILE *stream)
67 // CHECK: Loaded summary for: int fseeko(FILE *stream, off_t offset, int whence)
68 // CHECK: Loaded summary for: off_t ftello(FILE *stream)
69 // CHECK: Loaded summary for: void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
70 // CHECK: Loaded summary for: void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset)
71 // CHECK: Loaded summary for: int pipe(int fildes[2])
72 // CHECK: Loaded summary for: off_t lseek(int fildes, off_t offset, int whence)
73 // CHECK: Loaded summary for: ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize)
74 // CHECK: Loaded summary for: ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize)
75 // CHECK: Loaded summary for: int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath)
76 // CHECK: Loaded summary for: char *realpath(const char *restrict file_name, char *restrict resolved_name)
77 // CHECK: Loaded summary for: int execv(const char *path, char *const argv[])
78 // CHECK: Loaded summary for: int execvp(const char *file, char *const argv[])
79 // CHECK: Loaded summary for: int getopt(int argc, char *const argv[], const char *optstring)
80 // CHECK: Loaded summary for: int accept(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len)
81 // CHECK: Loaded summary for: int bind(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len)
82 // CHECK: Loaded summary for: int getpeername(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len)
83 // CHECK: Loaded summary for: int getsockname(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len)
84 // CHECK: Loaded summary for: int connect(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len)
85 // CHECK: Loaded summary for: ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags, __SOCKADDR_ARG address, socklen_t *restrict address_len)
86 // CHECK: Loaded summary for: ssize_t sendto(int socket, const void *message, size_t length, int flags, __CONST_SOCKADDR_ARG dest_addr, socklen_t dest_len)
87 // CHECK: Loaded summary for: int listen(int sockfd, int backlog)
88 // CHECK: Loaded summary for: ssize_t recv(int sockfd, void *buf, size_t len, int flags)
89 // CHECK: Loaded summary for: ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags)
90 // CHECK: Loaded summary for: ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
91 // CHECK: Loaded summary for: int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len)
92 // CHECK: Loaded summary for: int getsockopt(int socket, int level, int option_name, void *restrict option_value, socklen_t *restrict option_len)
93 // CHECK: Loaded summary for: ssize_t send(int sockfd, const void *buf, size_t len, int flags)
94 // CHECK: Loaded summary for: int socketpair(int domain, int type, int protocol, int sv[2])
95 // CHECK: Loaded summary for: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags)
96 // CHECK: Loaded summary for: int utime(const char *filename, struct utimbuf *buf)
97 // CHECK: Loaded summary for: int futimens(int fd, const struct timespec times[2])
98 // CHECK: Loaded summary for: int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags)
99 // CHECK: Loaded summary for: int utimes(const char *filename, const struct timeval times[2])
100 // CHECK: Loaded summary for: int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
101 // CHECK: Loaded summary for: struct tm *localtime(const time_t *tp)
102 // CHECK: Loaded summary for: struct tm *localtime_r(const time_t *restrict timer, struct tm *restrict result)
103 // CHECK: Loaded summary for: char *asctime_r(const struct tm *restrict tm, char *restrict buf)
104 // CHECK: Loaded summary for: char *ctime_r(const time_t *timep, char *buf)
105 // CHECK: Loaded summary for: struct tm *gmtime_r(const time_t *restrict timer, struct tm *restrict result)
106 // CHECK: Loaded summary for: struct tm *gmtime(const time_t *tp)
107 // CHECK: Loaded summary for: int clock_gettime(clockid_t clock_id, struct timespec *tp)
108 // CHECK: Loaded summary for: int getitimer(int which, struct itimerval *curr_value)
109 // CHECK: Loaded summary for: int pthread_cond_signal(pthread_cond_t *cond)
110 // CHECK: Loaded summary for: int pthread_cond_broadcast(pthread_cond_t *cond)
111 // CHECK: Loaded summary for: int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg)
112 // CHECK: Loaded summary for: int pthread_attr_destroy(pthread_attr_t *attr)
113 // CHECK: Loaded summary for: int pthread_attr_init(pthread_attr_t *attr)
114 // CHECK: Loaded summary for: int pthread_attr_getstacksize(const pthread_attr_t *restrict attr, size_t *restrict stacksize)
115 // CHECK: Loaded summary for: int pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize)
116 // CHECK: Loaded summary for: int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
117 // CHECK: Loaded summary for: int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
118 // CHECK: Loaded summary for: int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr)
119 // CHECK: Loaded summary for: int pthread_mutex_destroy(pthread_mutex_t *mutex)
120 // CHECK: Loaded summary for: int pthread_mutex_lock(pthread_mutex_t *mutex)
121 // CHECK: Loaded summary for: int pthread_mutex_trylock(pthread_mutex_t *mutex)
122 // CHECK: Loaded summary for: int pthread_mutex_unlock(pthread_mutex_t *mutex)
124 long a64l(const char *str64);
125 char *l64a(long value);
126 int access(const char *pathname, int amode);
127 int faccessat(int dirfd, const char *pathname, int mode, int flags);
128 int dup(int fildes);
129 int dup2(int fildes1, int filedes2);
130 int fdatasync(int fildes);
131 int fnmatch(const char *pattern, const char *string, int flags);
132 int fsync(int fildes);
133 typedef unsigned long off_t;
134 int truncate(const char *path, off_t length);
135 int symlink(const char *oldpath, const char *newpath);
136 int symlinkat(const char *oldpath, int newdirfd, const char *newpath);
137 int lockf(int fd, int cmd, off_t len);
138 typedef unsigned mode_t;
139 int creat(const char *pathname, mode_t mode);
140 unsigned int sleep(unsigned int seconds);
141 typedef struct {
142 int a;
143 } DIR;
144 int dirfd(DIR *dirp);
145 unsigned int alarm(unsigned int seconds);
146 int closedir(DIR *dir);
147 char *strdup(const char *s);
148 typedef typeof(sizeof(int)) size_t;
149 char *strndup(const char *s, size_t n);
150 /*FIXME How to define wchar_t in the test?*/
151 /*typedef __wchar_t wchar_t;*/
152 /*wchar_t *wcsdup(const wchar_t *s);*/
153 int mkstemp(char *template);
154 char *mkdtemp(char *template);
155 char *getcwd(char *buf, size_t size);
156 int mkdir(const char *pathname, mode_t mode);
157 int mkdirat(int dirfd, const char *pathname, mode_t mode);
158 typedef int dev_t;
159 int mknod(const char *pathname, mode_t mode, dev_t dev);
160 int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
161 int chmod(const char *path, mode_t mode);
162 int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
163 int fchmod(int fildes, mode_t mode);
164 typedef int uid_t;
165 typedef int gid_t;
166 int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
167 int chown(const char *path, uid_t owner, gid_t group);
168 int lchown(const char *path, uid_t owner, gid_t group);
169 int fchown(int fildes, uid_t owner, gid_t group);
170 int rmdir(const char *pathname);
171 int chdir(const char *path);
172 int link(const char *oldpath, const char *newpath);
173 int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag);
174 int unlink(const char *pathname);
175 int unlinkat(int fd, const char *path, int flag);
176 struct stat;
177 int fstat(int fd, struct stat *statbuf);
178 int stat(const char *restrict path, struct stat *restrict buf);
179 int lstat(const char *restrict path, struct stat *restrict buf);
180 int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag);
181 DIR *opendir(const char *name);
182 DIR *fdopendir(int fd);
183 int isatty(int fildes);
184 typedef struct {
185 int x;
186 } FILE;
187 FILE *popen(const char *command, const char *type);
188 int pclose(FILE *stream);
189 int close(int fildes);
190 long fpathconf(int fildes, int name);
191 long pathconf(const char *path, int name);
192 FILE *fdopen(int fd, const char *mode);
193 void rewinddir(DIR *dir);
194 void seekdir(DIR *dirp, long loc);
195 int rand_r(unsigned int *seedp);
196 int fileno(FILE *stream);
197 int fseeko(FILE *stream, off_t offset, int whence);
198 off_t ftello(FILE *stream);
199 void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
200 typedef off_t off64_t;
201 void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset);
202 int pipe(int fildes[2]);
203 off_t lseek(int fildes, off_t offset, int whence);
204 typedef size_t ssize_t;
205 ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
206 ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
207 int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
208 char *realpath(const char *restrict file_name, char *restrict resolved_name);
209 int execv(const char *path, char *const argv[]);
210 int execvp(const char *file, char *const argv[]);
211 int getopt(int argc, char *const argv[], const char *optstring);
213 // In some libc implementations, sockaddr parameter is a transparent
214 // union of the underlying sockaddr_ pointers instead of being a
215 // pointer to struct sockaddr.
216 // We match that with the joker Irrelevant type.
217 struct sockaddr;
218 struct sockaddr_at;
219 #define __SOCKADDR_ALLTYPES \
220 __SOCKADDR_ONETYPE(sockaddr) \
221 __SOCKADDR_ONETYPE(sockaddr_at)
222 #define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__;
223 typedef union {
224 __SOCKADDR_ALLTYPES
225 } __SOCKADDR_ARG __attribute__((__transparent_union__));
226 #undef __SOCKADDR_ONETYPE
227 #define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__;
228 typedef union {
229 __SOCKADDR_ALLTYPES
230 } __CONST_SOCKADDR_ARG __attribute__((__transparent_union__));
231 #undef __SOCKADDR_ONETYPE
232 typedef unsigned socklen_t;
234 int accept(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len);
235 int bind(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len);
236 int getpeername(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len);
237 int getsockname(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len);
238 int connect(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len);
239 ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags, __SOCKADDR_ARG address, socklen_t *restrict address_len);
240 ssize_t sendto(int socket, const void *message, size_t length, int flags, __CONST_SOCKADDR_ARG dest_addr, socklen_t dest_len);
242 int listen(int sockfd, int backlog);
243 ssize_t recv(int sockfd, void *buf, size_t len, int flags);
244 struct msghdr;
245 ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
246 ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
247 int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len);
248 int getsockopt(int socket, int level, int option_name, void *restrict option_value, socklen_t *restrict option_len);
249 ssize_t send(int sockfd, const void *buf, size_t len, int flags);
250 int socketpair(int domain, int type, int protocol, int sv[2]);
251 int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags);
252 struct utimbuf;
253 struct timespec { int x; };
254 struct timeval { int x; };
255 int utime(const char *filename, struct utimbuf *buf);
256 int futimens(int fd, const struct timespec times[2]);
257 int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);
258 int utimes(const char *filename, const struct timeval times[2]);
259 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
260 typedef unsigned long time_t;
261 struct tm *localtime(const time_t *tp);
262 struct tm *localtime_r(const time_t *restrict timer, struct tm *restrict result);
263 char *asctime_r(const struct tm *restrict tm, char *restrict buf);
264 char *ctime_r(const time_t *timep, char *buf);
265 struct tm *gmtime_r(const time_t *restrict timer, struct tm *restrict result);
266 struct tm *gmtime(const time_t *tp);
267 typedef unsigned long clockid_t;
268 int clock_gettime(clockid_t clock_id, struct timespec *tp);
269 struct itimerval;
270 int getitimer(int which, struct itimerval *curr_value);
272 typedef union {
273 int x;
274 } pthread_cond_t;
275 int pthread_cond_signal(pthread_cond_t *cond);
276 int pthread_cond_broadcast(pthread_cond_t *cond);
277 typedef union {
278 int x;
279 } pthread_attr_t;
280 typedef unsigned long int pthread_t;
281 int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg);
282 int pthread_attr_destroy(pthread_attr_t *attr);
283 int pthread_attr_init(pthread_attr_t *attr);
284 int pthread_attr_getstacksize(const pthread_attr_t *restrict attr, size_t *restrict stacksize);
285 int pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize);
286 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
287 int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
288 typedef union {
289 int x;
290 } pthread_mutex_t;
291 typedef union {
292 int x;
293 } pthread_mutexattr_t;
294 int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
295 int pthread_mutex_destroy(pthread_mutex_t *mutex);
296 int pthread_mutex_lock(pthread_mutex_t *mutex);
297 int pthread_mutex_trylock(pthread_mutex_t *mutex);
298 int pthread_mutex_unlock(pthread_mutex_t *mutex);
300 // Must have at least one call expression to initialize the summary map.
301 int bar(void);
302 void foo(void) {
303 bar();