about summary refs log tree commit diff homepage
path: root/test/CXX/symex/libc++/general_catch.cpp
blob: c544f7a3a131c6857c52f80cd401e02744429614 (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
55
56
57
58
59
60
61
// REQUIRES: not-msan
// Disabling msan because it times out on CI
// REQUIRES: libcxx
// REQUIRES: eh-cxx
// RUN: %clangxx %s -emit-llvm %O0opt -c -std=c++11 -I "%libcxx_include" -g -nostdinc++ -o %t1.bc
// RUN: rm -rf %t.klee-out
// RUN: %klee --output-dir=%t.klee-out --libc=uclibc --libcxx %t1.bc 2>&1 | FileCheck %s

#include "klee/klee.h"
#include <cassert>
#include <cstdio>

struct CustomStruct {
  int a;
};

int thrower(int x) {
  if (x == 0) {
    CustomStruct p;
    throw p;
  } else if (x == 1) {
    throw 7;
  } else if (x == 2) {
    throw new CustomStruct();
  } else {
    throw &thrower;
  }
}

int catcher(int x) {
  try {
    thrower(x);
  } catch (int ex) {
    printf("Caught int\n");
    // CHECK-DAG: Caught int
    return 1;
  } catch (CustomStruct ex) {
    printf("Caught normal CustomStruct\n");
    // CHECK-DAG: Caught normal CustomStruct
    return 2;
  } catch (CustomStruct *ex) {
    printf("Caught pointer CustomStruct\n");
    // CHECK-DAG: Caught pointer CustomStruct
    return 3;
  } catch (...) {
    printf("Caught general exception\n");
    // CHECK-DAG: Caught general exception
    return 4;
  }
  // Unreachable instruction
  assert(0);
  return 0;
}

int main(int argc, char **args) {
  int x = klee_int("x");
  int res = catcher(x);
  return res;
}

// CHECK-DAG: KLEE: done: completed paths = 4