Polly 20.0.0git
isl_test_cpp17-generic.cc
Go to the documentation of this file.
1/* A class that sets a boolean when an object of the class gets destroyed.
2 */
3struct S {
4 S(bool *freed) : freed(freed) {}
5 ~S();
6
7 bool *freed;
8};
9
10/* S destructor.
11 *
12 * Set the boolean, a pointer to which was passed to the constructor.
13 */
15{
16 *freed = true;
17}
18
19/* Construct an isl::id with an S object attached that sets *freed
20 * when it gets destroyed.
21 */
22static isl::id construct_id(isl::ctx ctx, bool *freed)
23{
24 auto s = std::make_shared<S>(freed);
25 isl::id id(ctx, "S", s);
26 return id;
27}
28
29/* Test id::try_user.
30 *
31 * In particular, check that the object attached to an identifier
32 * can be retrieved again, that trying to retrieve an object of the wrong type
33 * or trying to retrieve an object when no object was attached fails.
34 * Furthermore, check that the object attached to an identifier
35 * gets properly freed.
36 */
37static void test_try_user(isl::ctx ctx)
38{
39 isl::id id(ctx, "test", 5);
40 isl::id id2(ctx, "test2");
41
42 auto maybe_int = id.try_user<int>();
43 auto maybe_s = id.try_user<std::shared_ptr<S>>();
44 auto maybe_int2 = id2.try_user<int>();
45
46 if (!maybe_int)
47 die("integer cannot be retrieved from isl::id");
48 if (maybe_int.value() != 5)
49 die("wrong integer retrieved from isl::id");
50 if (maybe_s)
51 die("structure unexpectedly retrieved from isl::id");
52 if (maybe_int2)
53 die("integer unexpectedly retrieved from isl::id");
54
55 bool freed = false;
56 {
57 isl::id id = construct_id(ctx, &freed);
58 if (freed)
59 die("data structure freed prematurely");
60 auto maybe_s = id.try_user<std::shared_ptr<S>>();
61 if (!maybe_s)
62 die("structure cannot be retrieved from isl::id");
63 if (maybe_s.value()->freed != &freed)
64 die("invalid structure retrieved from isl::id");
65 }
66 if (!freed)
67 die("data structure not freed");
68}
const char * id
Definition: isl_test.c:7279
static isl::id construct_id(isl::ctx ctx, bool *freed)
static void test_try_user(isl::ctx ctx)
#define die(msg)
Definition: isl_test_cpp.cc:35
S(bool *freed)
bool * freed