Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/pr94596.c

raw
1 /* Minimized/hacked up from openvswitch lib/conntrack.c, which had this license
2 header: */
3 /*
4 * Copyright (c) 2015-2019 Nicira, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include "../../gcc.dg/analyzer/analyzer-decls.h"
20
21 /* { dg-additional-options "-Wno-analyzer-symbol-too-complex" } */
22
23 typedef __SIZE_TYPE__ size_t;
24
25 #ifndef __cplusplus
26 #define false 0
27 #endif
28
29 #define OBJECT_OFFSETOF(OBJECT, MEMBER)\
30 __builtin_offsetof(struct zone_limit, MEMBER)
31
32 #define OBJECT_CONTAINING(POINTER, OBJECT, MEMBER) \
33 ((struct zone_limit *) (void *) \
34 ((char *) (POINTER) - OBJECT_OFFSETOF(OBJECT, MEMBER)))
35
36 #define ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER) \
37 ((OBJECT) = OBJECT_CONTAINING(POINTER, OBJECT, MEMBER), (void) 0)
38
39 #define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \
40 ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER))
41
42 #define HMAP_FOR_EACH_POP(NODE, MEMBER, HMAP) \
43 for (size_t bucket__ = 0; \
44 INIT_CONTAINER(NODE, hmap_pop_helper__(HMAP, &bucket__), MEMBER), \
45 (NODE != OBJECT_CONTAINING(NULL, NODE, MEMBER)) \
46 || ((NODE = NULL), false);)
47
48 struct hmap {
49 struct hmap_node **buckets;
50 struct hmap_node *one;
51 size_t mask;
52 size_t n;
53 };
54
55 struct hmap_node {
56 size_t hash;
57 struct hmap_node *next;
58 };
59
60 static inline void hmap_remove(struct hmap *, struct hmap_node *);
61
62 struct hmap_node *
63 hmap_pop_helper__(struct hmap *hmap, size_t *bucket) {
64
65 for (; *bucket <= hmap->mask; (*bucket)++) {
66 struct hmap_node *node = hmap->buckets[*bucket];
67
68 if (node) {
69 hmap_remove(hmap, node);
70 return node;
71 }
72 }
73
74 return NULL;
75 }
76
77 static inline void
78 hmap_remove(struct hmap *hmap, struct hmap_node *node)
79 {
80 struct hmap_node **bucket = &hmap->buckets[node->hash & hmap->mask];
81 while (*bucket != node) {
82 bucket = &(*bucket)->next;
83 }
84 *bucket = node->next;
85 hmap->n--;
86 }
87
88 struct conntrack {
89 struct hmap zone_limits;
90 };
91
92 struct zone_limit {
93 struct hmap_node node;
94 };
95
96 void
97 conntrack_destroy(struct conntrack *ct)
98 {
99 struct zone_limit *zl;
100 HMAP_FOR_EACH_POP (zl, node, &ct->zone_limits) {
101 __builtin_free(zl);
102 }
103 }