[AMDGPU] Test codegen'ing True16 additions.
[llvm-project.git] / polly / lib / External / isl / isl_test_cpp17.cc
blob5765a1f9ae0bcf8ca8e7eb1fc243afc7a45e700c
1 #include <stdlib.h>
3 #include <exception>
4 #include <sstream>
6 #include <isl/options.h>
7 #include <isl/cpp.h>
9 /* Throw a runtime exception.
11 static void die_impl(const char *file, int line, const char *message)
13 std::ostringstream ss;
14 ss << file << ":" << line << ": " << message;
15 throw std::runtime_error(ss.str());
18 #define die(msg) die_impl(__FILE__, __LINE__, msg)
20 #include "isl_test_cpp17-generic.cc"
22 /* Check that an isl::exception_invalid gets thrown by "fn".
24 static void check_invalid(const std::function<void(void)> &fn)
26 bool caught = false;
27 try {
28 fn();
29 } catch (const isl::exception_invalid &e) {
30 caught = true;
32 if (!caught)
33 die("no invalid exception was generated");
36 /* Test id::user.
38 * In particular, check that the object attached to an identifier
39 * can be retrieved again and that retrieving an object of the wrong type
40 * or retrieving an object when no object was attached results in an exception.
42 static void test_user(isl::ctx ctx)
44 isl::id id(ctx, "test", 5);
45 isl::id id2(ctx, "test2");
46 isl::id id3(ctx, "test3", std::string("s"));
48 auto int_user = id.user<int>();
49 if (int_user != 5)
50 die("wrong integer retrieved from isl::id");
51 auto s_user = id3.user<std::string>();
52 if (s_user != "s")
53 die("wrong string retrieved from isl::id");
54 check_invalid([&id] () { id.user<std::string>(); });
55 check_invalid([&id2] () { id2.user<int>(); });
56 check_invalid([&id2] () { id2.user<std::string>(); });
57 check_invalid([&id3] () { id3.user<int>(); });
60 /* Test the C++17 specific features of the (unchecked) isl C++ interface
62 * In particular, test
63 * - id::try_user
64 * - id::user
66 int main()
68 isl_ctx *ctx = isl_ctx_alloc();
70 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
72 test_try_user(ctx);
73 test_user(ctx);
75 isl_ctx_free(ctx);
77 return EXIT_SUCCESS;