IRA: Ignore debug insns for uses in split_live_ranges_for_shrink_wrap. [PR116179]
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / deref-before-check-pr108475-haproxy-tcpcheck.c
blob7123cf5196b742672858599f0f7bb262bf3d8277
1 /* Reduced from haproxy-2.7.1: src/tcpcheck.c. */
3 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
5 typedef __SIZE_TYPE__ size_t;
7 #include "../../gcc.dg/analyzer/analyzer-decls.h"
10 extern void *calloc(size_t __nmemb, size_t __size)
11 __attribute__((__nothrow__, __leaf__)) __attribute__((__malloc__))
12 __attribute__((__alloc_size__(1, 2)));
13 extern char *strdup(const char *__s) __attribute__((__nothrow__, __leaf__))
14 __attribute__((__malloc__)) __attribute__((__nonnull__(1)));
15 extern char *strstr(const char *__haystack, const char *__needle)
16 __attribute__((__nothrow__, __leaf__)) __attribute__((__pure__))
17 __attribute__((__nonnull__(1, 2)));
18 extern size_t strlen(const char *__s) __attribute__((__nothrow__, __leaf__))
19 __attribute__((__pure__)) __attribute__((__nonnull__(1)));
20 struct list {
21 struct list *n;
22 struct list *p;
24 struct buffer {
25 size_t size;
26 char *area;
27 size_t data;
28 size_t head;
30 struct proxy;
31 struct ist {
32 char *ptr;
33 size_t len;
35 static inline int isttest(const struct ist ist) { return ist.ptr != NULL; }
37 enum http_meth_t {
38 HTTP_METH_OPTIONS,
39 /* [...snip...] */
40 } __attribute__((packed));
42 struct http_meth {
43 enum http_meth_t meth;
44 struct buffer str;
46 enum tcpcheck_send_type {
47 /* [...snip...] */
48 TCPCHK_SEND_HTTP,
50 enum tcpcheck_rule_type {
51 TCPCHK_ACT_SEND = 0,
52 /* [...snip...] */
54 struct tcpcheck_http_hdr {
55 struct ist name;
56 struct list value;
57 struct list list;
59 struct tcpcheck_send {
60 enum tcpcheck_send_type type;
61 union {
62 /* [...snip...] */
63 struct {
64 unsigned int flags;
65 struct http_meth meth;
66 union {
67 struct ist uri;
68 /* [...snip...] */
70 struct ist vsn;
71 struct list hdrs;
72 /* [...snip...] */
73 } http;
76 struct tcpcheck_rule {
77 /* [...snip...] */
78 enum tcpcheck_rule_type action;
79 /* [...snip...] */
80 union {
81 /* [...snip...] */
82 struct tcpcheck_send send;
83 /* [...snip...] */
86 enum http_meth_t find_http_meth(const char *str, const int len);
87 void free_tcpcheck(struct tcpcheck_rule *rule, int in_pool);
88 void free_tcpcheck_http_hdr(struct tcpcheck_http_hdr *hdr);
90 #define ist(str) ({ \
91 char *__x = (char *) ((void *)(str)); \
92 (struct ist){ \
93 .ptr = __x, \
94 .len = __builtin_constant_p(str) ? \
95 ((void *)str == (void *)0) ? 0 : \
96 __builtin_strlen(__x) : \
97 ({ \
98 size_t __l = 0; \
99 if (__x) for (__l--; __x[++__l]; ) ; \
100 __l; \
101 }) \
102 }; \
105 struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg,
106 struct proxy *px, char **errmsg) {
107 struct tcpcheck_rule *chk = NULL;
108 struct tcpcheck_http_hdr *hdr = NULL;
109 char *meth = NULL, *uri = NULL, *vsn = NULL;
110 char *hdrs, *body;
112 hdrs = (*args[cur_arg + 2] ? strstr(args[cur_arg + 2], "\r\n") : NULL);
113 body = (*args[cur_arg + 2] ? strstr(args[cur_arg + 2], "\r\n\r\n") : NULL);
114 if (hdrs || body) {
115 /* [...snip...] */
116 goto error;
119 chk = (struct tcpcheck_rule *) calloc(1, sizeof(*chk));
120 if (!chk) {
121 /* [...snip...] */
122 goto error;
124 chk->action = TCPCHK_ACT_SEND;
125 chk->send.type = TCPCHK_SEND_HTTP;
126 chk->send.http.flags |= 0x0004;
127 chk->send.http.meth.meth = HTTP_METH_OPTIONS;
128 ((&chk->send.http.hdrs)->n = (&chk->send.http.hdrs)->p =
129 (&chk->send.http.hdrs));
131 if (*args[cur_arg]) {
132 if (!*args[cur_arg + 1])
133 uri = args[cur_arg];
134 else
135 meth = args[cur_arg];
137 if (*args[cur_arg + 1])
138 uri = args[cur_arg + 1];
139 if (*args[cur_arg + 2])
140 vsn = args[cur_arg + 2];
142 if (meth) { /* { dg-bogus "check of 'meth' for NULL after already dereferencing it" } */
143 chk->send.http.meth.meth = find_http_meth(meth, strlen(meth));
144 chk->send.http.meth.str.area = strdup(meth);
145 chk->send.http.meth.str.data = strlen(meth);
146 if (!chk->send.http.meth.str.area) {
147 /* [...snip...] */
148 goto error;
151 if (uri) {
152 chk->send.http.uri = ist(strdup(uri));
153 if (!isttest(chk->send.http.uri)) {
154 /* [...snip...] */
155 goto error;
158 if (vsn) { /* { dg-bogus "check of 'vsn' for NULL after already dereferencing it" } */
159 chk->send.http.vsn = ist(strdup(vsn));
160 if (!isttest(chk->send.http.vsn)) {
161 /* [...snip...] */
162 goto error;
165 return chk;
167 error:
168 free_tcpcheck_http_hdr(hdr);
169 free_tcpcheck(chk, 0);
170 return NULL;