1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // #include <memory>
11
12 // void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
13
14 #include <memory>
15 #include <cassert>
16
main()17 int main()
18 {
19 const unsigned N = 20;
20 char buf[N];
21 void* r;
22 void* p = &buf[0];
23 std::size_t s = N;
24 r = std::align(4, 10, p, s);
25 assert(p == &buf[0]);
26 assert(r == p);
27 assert(s == N);
28
29 p = &buf[1];
30 s = N;
31 r = std::align(4, 10, p, s);
32 assert(p == &buf[4]);
33 assert(r == p);
34 assert(s == N-3);
35
36 p = &buf[2];
37 s = N;
38 r = std::align(4, 10, p, s);
39 assert(p == &buf[4]);
40 assert(r == p);
41 assert(s == N-2);
42
43 p = &buf[3];
44 s = N;
45 r = std::align(4, 10, p, s);
46 assert(p == &buf[4]);
47 assert(r == p);
48 assert(s == N-1);
49
50 p = &buf[4];
51 s = N;
52 r = std::align(4, 10, p, s);
53 assert(p == &buf[4]);
54 assert(r == p);
55 assert(s == N);
56
57 p = &buf[0];
58 s = N;
59 r = std::align(4, N, p, s);
60 assert(p == &buf[0]);
61 assert(r == p);
62 assert(s == N);
63
64 p = &buf[1];
65 s = N-1;
66 r = std::align(4, N-4, p, s);
67 assert(p == &buf[4]);
68 assert(r == p);
69 assert(s == N-4);
70
71 p = &buf[1];
72 s = N-1;
73 r = std::align(4, N-3, p, s);
74 assert(p == &buf[1]);
75 assert(r == nullptr);
76 assert(s == N-1);
77
78 p = &buf[0];
79 s = N;
80 r = std::align(1, N+1, p, s);
81 assert(p == &buf[0]);
82 assert(r == nullptr);
83 assert(s == N);
84 }
85