1// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2
3// tdestroy is a GNU extension
4// UNSUPPORTED: target={{.*(netbsd|freebsd).*}}
5
6#include <assert.h>
7#include <search.h>
8#include <stdlib.h>
9
10int compare(const void *pa, const void *pb) {
11 int a = *(const int *)pa;
12 int b = *(const int *)pb;
13 if (a < b)
14 return -1;
15 else if (a > b)
16 return 1;
17 else
18 return 0;
19}
20
21void myfreenode(void *p) {
22 delete (int *)p;
23}
24
25int main(void) {
26 void *root = NULL;
27 for (int i = 0; i < 5; ++i) {
28 int *p = new int(i);
29 void *q = tsearch(key: p, rootp: &root, compar: compare);
30 if (q == NULL)
31 exit(status: 1);
32 if (*(int **)q != p)
33 delete p;
34 }
35
36 tdestroy(root: root, freefct: myfreenode);
37
38 return 0;
39}
40

source code of compiler-rt/test/msan/tsearch.cpp