about summary refs log tree commit diff homepage
path: root/test/CXX/symex/libc++/landingpad.cpp
blob: c23b8ee2392a6d8fa9ddc8d7207ead2eb37106cb (plain) (blame)
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
// Testcase for proper handling of
// c++ type, constructors and destructors.
// Based on: https://gcc.gnu.org/wiki/Dwarf2EHNewbiesHowto
// REQUIRES: uclibc
// REQUIRES: libcxx
// REQUIRES: eh-cxx
// RUN: %clangxx %s -emit-llvm %O0opt -std=c++11 -c %libcxx_includes -g -nostdinc++ -o %t.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --exit-on-error --libcxx --libc=uclibc  %t.bc | FileCheck %s
// Expect the following output:
// CHECK: Throwing 1...
// CHECK: A() 1
// CHECK: A(const A&) 2
// CHECK: Caught.
// CHECK: ~A() 2
// CHECK: ~A() 1
// CHECK: c == 2, d == 2

#include <stdio.h>

int c, d;

struct A {
  int i;
  A() {
    i = ++c;
    printf("A() %d\n", i);
  }
  A(const A &) {
    i = ++c;
    printf("A(const A&) %d\n", i);
  }
  ~A() {
    printf("~A() %d\n", i);
    ++d;
  }
};

void f() {
  printf("Throwing 1...\n");
  throw A();
}

int main() {
  c = 0;
  d = 0;
  try {
    f();
  } catch (A) {
    printf("Caught.\n");
  }
  printf("c == %d, d == %d\n", c, d);
  return c != d;
}