File: utils.h

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-6~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,418,812 kB
  • sloc: cpp: 5,290,827; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,900; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,892; xml: 953; cs: 573; fortran: 539
file content (67 lines) | stat: -rw-r--r-- 1,845 bytes parent folder | download | duplicates (49)
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
#ifndef UTILS_H
#define UTILS_H

inline void break_optimization(void *arg) {
  __asm__ __volatile__("" : : "r" (arg) : "memory");
}

// Tests will instantiate this class to pad out bit sets to test out the
// various ways we can represent the bit set (32-bit inline, 64-bit inline,
// memory). Instantiating this class will trigger the instantiation of I
// templates with I virtual tables for classes deriving from T, I-2 of which
// will be of size sizeof(void*) * 5, 1 of which will be of size sizeof(void*)
// * 3, and 1 of which will be of size sizeof(void*) * 9. (Under the MS ABI
// each virtual table will be sizeof(void*) bytes smaller). Each category
// of virtual tables is aligned to a different power of 2, precluding the
// all-ones optimization. As a result, the bit vector for the base class will
// need to contain at least I*2 entries to accommodate all the derived virtual
// tables.
template <typename T, unsigned I>
struct Deriver : T {
  Deriver() {
    break_optimization(new Deriver<T, I-1>);
  }
  virtual void f() {}
  virtual void g() {}
  virtual void h() {}
};

template <typename T>
struct Deriver<T, 0> : T {
  virtual void f() {}
  void g() {}
};

template <typename T>
struct Deriver<T, 1> : T {
  Deriver() {
    break_optimization(new Deriver<T, 0>);
  }
  virtual void f() {}
  virtual void g() {}
  virtual void h() {}
  virtual void i() {}
  virtual void j() {}
  virtual void k() {}
  virtual void l() {}
};

// Instantiate enough classes to force CFI checks for type T to use bit
// vectors of size 32 (if B32 defined), 64 (if B64 defined) or >64 (if BM
// defined).
template <typename T>
void create_derivers() {
#ifdef B32
  break_optimization(new Deriver<T, 10>);
#endif

#ifdef B64
  break_optimization(new Deriver<T, 25>);
#endif

#ifdef BM
  break_optimization(new Deriver<T, 40>);
#endif
}

#endif