1 | #include "llvm/ADT/ArrayRef.h" |
2 | #include "llvm/ADT/DenseMap.h" |
3 | #include "llvm/ADT/PointerIntPair.h" |
4 | #include "llvm/ADT/PointerUnion.h" |
5 | #include "llvm/ADT/SmallString.h" |
6 | #include "llvm/ADT/SmallVector.h" |
7 | #include "llvm/ADT/StringMap.h" |
8 | #include "llvm/ADT/Twine.h" |
9 | #include "llvm/ADT/ilist.h" |
10 | #include "llvm/Support/Error.h" |
11 | #include <optional> |
12 | |
13 | int Array[] = {1, 2, 3}; |
14 | auto IntPtr = reinterpret_cast<int *>(0xabc); |
15 | |
16 | llvm::ArrayRef<int> ArrayRef(Array); |
17 | llvm::MutableArrayRef<int> MutableArrayRef(Array); |
18 | llvm::DenseMap<int, int> DenseMap = {{4, 5}, {6, 7}}; |
19 | llvm::StringMap<int> StringMap = {{"foo" , 123}, {"bar" , 456}}; |
20 | llvm::Expected<int> ExpectedValue(8); |
21 | llvm::Expected<int> ExpectedError(llvm::createStringError(EC: {}, Fmt: "" )); |
22 | std::optional<int> OptionalValue(9); |
23 | std::optional<int> OptionalNone(std::nullopt); |
24 | llvm::SmallVector<int, 5> SmallVector = {10, 11, 12}; |
25 | llvm::SmallString<5> SmallString("foo" ); |
26 | llvm::StringRef StringRef = "bar" ; |
27 | // Should test std::string in Twine too, but it's currently broken because I |
28 | // don't know how to add 'str' and 'gdb.LazyString' (can't figure out any way to |
29 | // string-ify LazyString). |
30 | std::string String = "foo" ; |
31 | llvm::Twine TempTwine = llvm::Twine(String) + StringRef; |
32 | llvm::Twine Twine = TempTwine + "baz" ; |
33 | llvm::PointerIntPair<int *, 1> PointerIntPair(IntPtr, 1); |
34 | |
35 | struct alignas(8) Z {}; |
36 | llvm::PointerUnion<Z *, int *> PointerUnion(IntPtr); |
37 | |
38 | // No members which instantiate PointerUnionUIntTraits<Z *> (e.g. get<T *>()) |
39 | // are called, and this instance will therefore be raw-printed. |
40 | llvm::PointerUnion<Z *, float *> RawPrintingPointerUnion(nullptr); |
41 | |
42 | using IlistTag = llvm::ilist_tag<struct A>; |
43 | using SimpleIlistTag = llvm::ilist_tag<struct B>; |
44 | struct IlistNode : llvm::ilist_node<IlistNode, IlistTag>, |
45 | llvm::ilist_node<IlistNode, SimpleIlistTag> { |
46 | int Value; |
47 | }; |
48 | auto Ilist = [] { |
49 | llvm::ilist<IlistNode, IlistTag> Result; |
50 | for (int I : {13, 14, 15}) { |
51 | Result.push_back(val: new IlistNode); |
52 | Result.back().Value = I; |
53 | } |
54 | return Result; |
55 | }(); |
56 | auto SimpleIlist = []() { |
57 | llvm::simple_ilist<IlistNode, SimpleIlistTag> Result; |
58 | for (auto &Node : Ilist) |
59 | Result.push_front(Node); |
60 | return Result; |
61 | }(); |
62 | |
63 | int main() { |
64 | std::uintptr_t result = 0; |
65 | auto dont_strip = [&](const auto &val) { |
66 | result += reinterpret_cast<std::uintptr_t>(&val); |
67 | }; |
68 | dont_strip(ArrayRef); |
69 | dont_strip(MutableArrayRef); |
70 | dont_strip(ExpectedValue); |
71 | dont_strip(ExpectedError); |
72 | dont_strip(OptionalValue); |
73 | dont_strip(OptionalNone); |
74 | return result; // Non-zero return value is OK. |
75 | } |
76 | |