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 int i = 0;
20 const unsigned N = 20;
21 char buf[N];
22 void* r;
23 void* p = &buf[0];
24 std::size_t s = N;
25 r = std::align(4, 10, p, s);
26 assert(p == &buf[0]);
27 assert(r == p);
28 assert(s == N);
29
30 p = &buf[1];
31 s = N;
32 r = std::align(4, 10, p, s);
33 assert(p == &buf[4]);
34 assert(r == p);
35 assert(s == N-3);
36
37 p = &buf[2];
38 s = N;
39 r = std::align(4, 10, p, s);
40 assert(p == &buf[4]);
41 assert(r == p);
42 assert(s == N-2);
43
44 p = &buf[3];
45 s = N;
46 r = std::align(4, 10, p, s);
47 assert(p == &buf[4]);
48 assert(r == p);
49 assert(s == N-1);
50
51 p = &buf[4];
52 s = N;
53 r = std::align(4, 10, p, s);
54 assert(p == &buf[4]);
55 assert(r == p);
56 assert(s == N);
57
58 p = &buf[0];
59 s = N;
60 r = std::align(4, N, p, s);
61 assert(p == &buf[0]);
62 assert(r == p);
63 assert(s == N);
64
65 p = &buf[1];
66 s = N-1;
67 r = std::align(4, N-4, p, s);
68 assert(p == &buf[4]);
69 assert(r == p);
70 assert(s == N-4);
71
72 p = &buf[1];
73 s = N-1;
74 r = std::align(4, N-3, p, s);
75 assert(p == &buf[1]);
76 assert(r == nullptr);
77 assert(s == N-1);
78
79 p = &buf[0];
80 s = N;
81 r = std::align(1, N+1, p, s);
82 assert(p == &buf[0]);
83 assert(r == nullptr);
84 assert(s == N);
85 }
86