1 #include "llvm/ADT/ArrayRef.h" 2 #include "llvm/ADT/DenseMap.h" 3 #include "llvm/ADT/Optional.h" 4 #include "llvm/ADT/PointerIntPair.h" 5 #include "llvm/ADT/PointerUnion.h" 6 #include "llvm/ADT/SmallString.h" 7 #include "llvm/ADT/SmallVector.h" 8 #include "llvm/ADT/StringMap.h" 9 #include "llvm/ADT/Twine.h" 10 #include "llvm/ADT/ilist.h" 11 #include "llvm/Support/Error.h" 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({}, "")); 22 llvm::Optional<int> OptionalValue(9); 23 llvm::Optional<int> OptionalNone(llvm::None); 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(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 // Reference symbols that might otherwise be stripped. 65 ArrayRef[0]; 66 MutableArrayRef[0]; 67 (void)!ExpectedValue; 68 (void)!ExpectedError; 69 *OptionalValue; 70 *OptionalNone; 71 return 0; 72 } 73