File: llvm-support.cpp

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (75 lines) | stat: -rw-r--r-- 2,539 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/ilist.h"
#include "llvm/Support/Error.h"
#include <optional>

int Array[] = {1, 2, 3};
auto IntPtr = reinterpret_cast<int *>(0xabc);

llvm::ArrayRef<int> ArrayRef(Array);
llvm::MutableArrayRef<int> MutableArrayRef(Array);
llvm::DenseMap<int, int> DenseMap = {{4, 5}, {6, 7}};
llvm::StringMap<int> StringMap = {{"foo", 123}, {"bar", 456}};
llvm::Expected<int> ExpectedValue(8);
llvm::Expected<int> ExpectedError(llvm::createStringError({}, ""));
std::optional<int> OptionalValue(9);
std::optional<int> OptionalNone(std::nullopt);
llvm::SmallVector<int, 5> SmallVector = {10, 11, 12};
llvm::SmallString<5> SmallString("foo");
llvm::StringRef StringRef = "bar";
// Should test std::string in Twine too, but it's currently broken because I
// don't know how to add 'str' and 'gdb.LazyString' (can't figure out any way to
// string-ify LazyString).
std::string String = "foo";
llvm::Twine TempTwine = llvm::Twine(String) + StringRef;
llvm::Twine Twine = TempTwine + "baz";
llvm::PointerIntPair<int *, 1> PointerIntPair(IntPtr, 1);

struct alignas(8) Z {};
llvm::PointerUnion<Z *, int *> PointerUnion(IntPtr);

// No members which instantiate PointerUnionUIntTraits<Z *> (e.g. get<T *>())
// are called, and this instance will therefore be raw-printed.
llvm::PointerUnion<Z *, float *> RawPrintingPointerUnion(nullptr);

using IlistTag = llvm::ilist_tag<struct A>;
using SimpleIlistTag = llvm::ilist_tag<struct B>;
struct IlistNode : llvm::ilist_node<IlistNode, IlistTag>,
                   llvm::ilist_node<IlistNode, SimpleIlistTag> {
  int Value;
};
auto Ilist = [] {
  llvm::ilist<IlistNode, IlistTag> Result;
  for (int I : {13, 14, 15}) {
    Result.push_back(new IlistNode);
    Result.back().Value = I;
  }
  return Result;
}();
auto SimpleIlist = []() {
  llvm::simple_ilist<IlistNode, SimpleIlistTag> Result;
  for (auto &Node : Ilist)
    Result.push_front(Node);
  return Result;
}();

int main() {
  std::uintptr_t result = 0;
  auto dont_strip = [&](const auto &val) {
    result += reinterpret_cast<std::uintptr_t>(&val);
  };
  dont_strip(ArrayRef);
  dont_strip(MutableArrayRef);
  dont_strip(ExpectedValue);
  dont_strip(ExpectedError);
  dont_strip(OptionalValue);
  dont_strip(OptionalNone);
  return result; // Non-zero return value is OK.
}