summaryrefslogtreecommitdiff
path: root/test/cfi/stats.cpp
blob: ca6b3bf0df48146ef03932eb0d9f04899b66a167 (plain)
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
// RUN: %clangxx_cfi %debug_info_flags -fsanitize-stats -o %t %s
// RUN: env SANITIZER_STATS_PATH=%t.stats %run %t
// RUN: sanstats %t.stats | FileCheck %s

// FIXME: We currently emit the wrong debug info under devirtualization.
// UNSUPPORTED: devirt

// FIXME: %t.stats must be transferred from device to host for this to work on Android.
// XFAIL: android

struct ABase {};

struct A : ABase {
  virtual void vf() {}
  void nvf() {}
};

extern "C" __attribute__((noinline)) void vcall(A *a) {
  // CHECK: stats.cpp:[[@LINE+1]] {{_?}}vcall cfi-vcall 37
  a->vf();
}

extern "C" __attribute__((noinline)) void nvcall(A *a) {
  // CHECK: stats.cpp:[[@LINE+1]] {{_?}}nvcall cfi-nvcall 51
  a->nvf();
}

extern "C" __attribute__((noinline)) A *dcast(A *a) {
  // CHECK: stats.cpp:[[@LINE+1]] {{_?}}dcast cfi-derived-cast 24
  return (A *)(ABase *)a;
}

extern "C" __attribute__((noinline)) A *ucast(A *a) {
  // CHECK: stats.cpp:[[@LINE+1]] {{_?}}ucast cfi-unrelated-cast 81
  return (A *)(char *)a;
}

extern "C" __attribute__((noinline)) void unreachable(A *a) {
  // CHECK-NOT: unreachable
  a->vf();
}

int main() {
  A a;
  for (unsigned i = 0; i != 37; ++i)
    vcall(&a);
  for (unsigned i = 0; i != 51; ++i)
    nvcall(&a);
  for (unsigned i = 0; i != 24; ++i)
    dcast(&a);
  for (unsigned i = 0; i != 81; ++i)
    ucast(&a);
  for (unsigned i = 0; i != 0; ++i)
    unreachable(&a);
}