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
13int Array[] = {1, 2, 3};
14auto IntPtr = reinterpret_cast<int *>(0xabc);
15
16llvm::ArrayRef<int> ArrayRef(Array);
17llvm::MutableArrayRef<int> MutableArrayRef(Array);
18llvm::DenseMap<int, int> DenseMap = {{4, 5}, {6, 7}};
19llvm::StringMap<int> StringMap = {{"foo", 123}, {"bar", 456}};
20llvm::Expected<int> ExpectedValue(8);
21llvm::Expected<int> ExpectedError(llvm::createStringError(EC: {}, Fmt: ""));
22std::optional<int> OptionalValue(9);
23std::optional<int> OptionalNone(std::nullopt);
24llvm::SmallVector<int, 5> SmallVector = {10, 11, 12};
25llvm::SmallString<5> SmallString("foo");
26llvm::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).
30std::string String = "foo";
31llvm::Twine TempTwine = llvm::Twine(String) + StringRef;
32llvm::Twine Twine = TempTwine + "baz";
33llvm::PointerIntPair<int *, 1> PointerIntPair(IntPtr, 1);
34
35struct alignas(8) Z {};
36llvm::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.
40llvm::PointerUnion<Z *, float *> RawPrintingPointerUnion(nullptr);
41
42using IlistTag = llvm::ilist_tag<struct A>;
43using SimpleIlistTag = llvm::ilist_tag<struct B>;
44struct IlistNode : llvm::ilist_node<IlistNode, IlistTag>,
45 llvm::ilist_node<IlistNode, SimpleIlistTag> {
46 int Value;
47};
48auto 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}();
56auto SimpleIlist = []() {
57 llvm::simple_ilist<IlistNode, SimpleIlistTag> Result;
58 for (auto &Node : Ilist)
59 Result.push_front(Node);
60 return Result;
61}();
62
63int 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

source code of cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.cpp