1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
4 #include <netinet/in.h>
8 #include <sys/socket.h>
12 struct sockaddr_in addr4
;
13 struct sockaddr_in6 addr6
;
14 struct sockaddr
*addr
;
18 void *ClientThread(void *x
) {
19 int c
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
21 if (connect(c
, addr
, addrlen
)) {
30 addr4
.sin_family
= AF_INET
;
31 addr4
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
32 addr4
.sin_port
= INADDR_ANY
;
33 addr
= (struct sockaddr
*)&addr4
;
34 addrlen
= sizeof(addr4
);
36 int s
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
38 // Try to fall-back to IPv6
39 addr6
.sin6_family
= AF_INET6
;
40 addr6
.sin6_addr
= in6addr_loopback
;
41 addr6
.sin6_port
= INADDR_ANY
;
42 addr
= (struct sockaddr
*)&addr6
;
43 addrlen
= sizeof(addr6
);
44 s
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
48 bind(s
, addr
, addrlen
);
49 getsockname(s
, addr
, &addrlen
);
52 pthread_create(&t
, 0, ClientThread
, 0);
53 int c
= accept(s
, 0, 0);
58 fprintf(stderr
, "OK\n");
61 // CHECK-NOT: WARNING: ThreadSanitizer: data race