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
9 
10 // We test here that functions from socket.h are added when sockaddr is not a
11 // transparent union of other sockaddr_ pointers. This is the case in C++.
12 
13 // CHECK: Loaded summary for: int accept(int socket, struct sockaddr *address, socklen_t *address_len)
14 // CHECK: Loaded summary for: int bind(int socket, const struct sockaddr *address, socklen_t address_len)
15 // CHECK: Loaded summary for: int getpeername(int socket, struct sockaddr *address, socklen_t *address_len)
16 // CHECK: Loaded summary for: int getsockname(int socket, struct sockaddr *address, socklen_t *address_len)
17 // CHECK: Loaded summary for: int connect(int socket, const struct sockaddr *address, socklen_t address_len)
18 // CHECK: Loaded summary for: ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len)
19 // CHECK: Loaded summary for: ssize_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len)
20 
21 struct sockaddr;
22 using socklen_t = unsigned;
23 int accept(int socket, struct sockaddr *address, socklen_t *address_len);
24 int bind(int socket, const struct sockaddr *address, socklen_t address_len);
25 int getpeername(int socket, struct sockaddr *address, socklen_t *address_len);
26 int getsockname(int socket, struct sockaddr *address, socklen_t *address_len);
27 int connect(int socket, const struct sockaddr *address, socklen_t address_len);
28 typedef decltype(sizeof(int)) size_t;
29 typedef size_t ssize_t;
30 ssize_t recvfrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *address_len);
31 ssize_t sendto(int socket, const void *message, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
32 
33 // Must have at least one call expression to initialize the summary map.
34 int bar(void);
foo()35 void foo() {
36   bar();
37 }
38