reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -Wno-unreachable-code -Werror -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s

int val = 42;
int& test1() {
  return throw val, val;
}

int test2() {
  return val ? throw val : val;
}

// rdar://problem/8608801
void test3() {
  throw false;
}

// PR10582
int test4() {
  return 1 ? throw val : val;
}

// PR15923
int test5(bool x, bool y, int z) {
  return (x ? throw 1 : y) ? z : throw 2;
}
// CHECK-LABEL: define i32 @_Z5test5bbi(
// CHECK: br i1
//
// x.true:
// CHECK: call void @__cxa_throw(
// CHECK-NEXT: unreachable
//
// x.false:
// CHECK: br i1
//
// y.true:
// CHECK: load i32, i32*
// CHECK: br label
//
// y.false:
// CHECK: call void @__cxa_throw(
// CHECK-NEXT: unreachable
//
// end:
// CHECK: ret i32

int test6(bool x, bool y, int z) {
  return (x ? throw 1 : y) ? z : (throw 2);
}
// CHECK-LABEL: define i32 @_Z5test6bbi(
// CHECK: br i1
//
// x.true:
// CHECK: call void @__cxa_throw(
// CHECK-NEXT: unreachable
//
// x.false:
// CHECK: br i1
//
// y.true:
// CHECK: load i32, i32*
// CHECK: br label
//
// y.false:
// CHECK: call void @__cxa_throw(
// CHECK-NEXT: unreachable
//
// end:
// CHECK: ret i32

namespace DR1560 {
  struct A {
    ~A();
  };
  extern bool b;
  A get();
  // CHECK-LABEL: @_ZN6DR15601bE
  const A &r = b ? get() : throw 0;
  // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
  // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} @_ZGRN6DR15601rE
  // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
}

// CHECK-LABEL: define void @_Z5test7b(
void test7(bool cond) {
  // CHECK: br i1
  //
  // x.true:
  // CHECK: call void @__cxa_throw(
  // CHECK-NEXT: unreachable
  //
  // x.false:
  // CHECK: br label
  //
  // end:
  // CHECK: ret void
  cond ? throw test7 : val;
}

// CHECK-LABEL: define dereferenceable(4) i32* @_Z5test8b(
int &test8(bool cond) {
  // CHECK: br i1
  //
  // x.true:
  // CHECK: br label
  //
  // x.false:
  // CHECK: call void @__cxa_throw(
  // CHECK-NEXT: unreachable
  //
  // end:
  // CHECK: ret i32* @val
  return cond ? val : ((throw "foo"));
}