head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.8
	netbsd-11-0-RC3:1.1.1.8
	netbsd-11-0-RC2:1.1.1.8
	netbsd-11-0-RC1:1.1.1.8
	perseant-exfatfs-base-20250801:1.1.1.8
	netbsd-11:1.1.1.8.0.10
	netbsd-11-base:1.1.1.8
	netbsd-10-1-RELEASE:1.1.1.8
	perseant-exfatfs-base-20240630:1.1.1.8
	perseant-exfatfs:1.1.1.8.0.8
	perseant-exfatfs-base:1.1.1.8
	netbsd-8-3-RELEASE:1.1.1.6
	netbsd-9-4-RELEASE:1.1.1.7
	netbsd-10-0-RELEASE:1.1.1.8
	netbsd-10-0-RC6:1.1.1.8
	netbsd-10-0-RC5:1.1.1.8
	netbsd-10-0-RC4:1.1.1.8
	netbsd-10-0-RC3:1.1.1.8
	netbsd-10-0-RC2:1.1.1.8
	netbsd-10-0-RC1:1.1.1.8
	netbsd-10:1.1.1.8.0.6
	netbsd-10-base:1.1.1.8
	netbsd-9-3-RELEASE:1.1.1.7
	cjep_sun2x:1.1.1.8.0.4
	cjep_sun2x-base:1.1.1.8
	cjep_staticlib_x-base1:1.1.1.8
	netbsd-9-2-RELEASE:1.1.1.7
	cjep_staticlib_x:1.1.1.8.0.2
	cjep_staticlib_x-base:1.1.1.8
	netbsd-9-1-RELEASE:1.1.1.7
	phil-wifi-20200421:1.1.1.8
	phil-wifi-20200411:1.1.1.8
	phil-wifi-20200406:1.1.1.8
	netbsd-8-2-RELEASE:1.1.1.6
	netbsd-9-0-RELEASE:1.1.1.7
	netbsd-9-0-RC2:1.1.1.7
	netbsd-9-0-RC1:1.1.1.7
	netbsd-9:1.1.1.7.0.2
	netbsd-9-base:1.1.1.7
	phil-wifi-20190609:1.1.1.7
	netbsd-8-1-RELEASE:1.1.1.6
	netbsd-8-1-RC1:1.1.1.6
	pgoyette-compat-merge-20190127:1.1.1.6.12.1
	pgoyette-compat-20190127:1.1.1.7
	pgoyette-compat-20190118:1.1.1.7
	pgoyette-compat-1226:1.1.1.7
	pgoyette-compat-1126:1.1.1.7
	pgoyette-compat-1020:1.1.1.7
	pgoyette-compat-0930:1.1.1.7
	pgoyette-compat-0906:1.1.1.7
	netbsd-7-2-RELEASE:1.1.1.4
	pgoyette-compat-0728:1.1.1.7
	clang-337282:1.1.1.7
	netbsd-8-0-RELEASE:1.1.1.6
	phil-wifi:1.1.1.6.0.14
	phil-wifi-base:1.1.1.6
	pgoyette-compat-0625:1.1.1.6
	netbsd-8-0-RC2:1.1.1.6
	pgoyette-compat-0521:1.1.1.6
	pgoyette-compat-0502:1.1.1.6
	pgoyette-compat-0422:1.1.1.6
	netbsd-8-0-RC1:1.1.1.6
	pgoyette-compat-0415:1.1.1.6
	pgoyette-compat-0407:1.1.1.6
	pgoyette-compat-0330:1.1.1.6
	pgoyette-compat-0322:1.1.1.6
	pgoyette-compat-0315:1.1.1.6
	netbsd-7-1-2-RELEASE:1.1.1.4
	pgoyette-compat:1.1.1.6.0.12
	pgoyette-compat-base:1.1.1.6
	netbsd-7-1-1-RELEASE:1.1.1.4
	clang-319952:1.1.1.6
	matt-nb8-mediatek:1.1.1.6.0.10
	matt-nb8-mediatek-base:1.1.1.6
	clang-309604:1.1.1.6
	perseant-stdc-iso10646:1.1.1.6.0.8
	perseant-stdc-iso10646-base:1.1.1.6
	netbsd-8:1.1.1.6.0.6
	netbsd-8-base:1.1.1.6
	prg-localcount2-base3:1.1.1.6
	prg-localcount2-base2:1.1.1.6
	prg-localcount2-base1:1.1.1.6
	prg-localcount2:1.1.1.6.0.4
	prg-localcount2-base:1.1.1.6
	pgoyette-localcount-20170426:1.1.1.6
	bouyer-socketcan-base1:1.1.1.6
	pgoyette-localcount-20170320:1.1.1.6
	netbsd-7-1:1.1.1.4.0.10
	netbsd-7-1-RELEASE:1.1.1.4
	netbsd-7-1-RC2:1.1.1.4
	clang-294123:1.1.1.6
	netbsd-7-nhusb-base-20170116:1.1.1.4
	bouyer-socketcan:1.1.1.6.0.2
	bouyer-socketcan-base:1.1.1.6
	clang-291444:1.1.1.6
	pgoyette-localcount-20170107:1.1.1.5
	netbsd-7-1-RC1:1.1.1.4
	pgoyette-localcount-20161104:1.1.1.5
	netbsd-7-0-2-RELEASE:1.1.1.4
	localcount-20160914:1.1.1.5
	netbsd-7-nhusb:1.1.1.4.0.8
	netbsd-7-nhusb-base:1.1.1.4
	clang-280599:1.1.1.5
	pgoyette-localcount-20160806:1.1.1.5
	pgoyette-localcount-20160726:1.1.1.5
	pgoyette-localcount:1.1.1.5.0.2
	pgoyette-localcount-base:1.1.1.5
	netbsd-7-0-1-RELEASE:1.1.1.4
	clang-261930:1.1.1.5
	netbsd-7-0:1.1.1.4.0.6
	netbsd-7-0-RELEASE:1.1.1.4
	netbsd-7-0-RC3:1.1.1.4
	netbsd-7-0-RC2:1.1.1.4
	netbsd-7-0-RC1:1.1.1.4
	clang-237755:1.1.1.4
	clang-232565:1.1.1.4
	clang-227398:1.1.1.4
	tls-maxphys-base:1.1.1.4
	tls-maxphys:1.1.1.4.0.4
	netbsd-7:1.1.1.4.0.2
	netbsd-7-base:1.1.1.4
	clang-215315:1.1.1.4
	clang-209886:1.1.1.3
	yamt-pagecache:1.1.1.2.0.4
	yamt-pagecache-base9:1.1.1.2
	tls-earlyentropy:1.1.1.2.0.2
	tls-earlyentropy-base:1.1.1.3
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.2
	riastradh-drm2-base3:1.1.1.2
	clang-202566:1.1.1.2
	clang-201163:1.1.1.2
	clang-199312:1.1.1.2
	clang-198450:1.1.1.2
	clang-196603:1.1.1.1
	clang-195771:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@// @;


1.1
date	2013.11.28.14.14.58;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	ow8OybrawrB1f3fx;

1.1.1.1
date	2013.11.28.14.14.58;	author joerg;	state Exp;
branches;
next	1.1.1.2;
commitid	ow8OybrawrB1f3fx;

1.1.1.2
date	2014.01.05.15.40.05;	author joerg;	state Exp;
branches
	1.1.1.2.2.1
	1.1.1.2.4.1;
next	1.1.1.3;
commitid	wh3aCSIWykURqWjx;

1.1.1.3
date	2014.05.30.18.14.47;	author joerg;	state Exp;
branches;
next	1.1.1.4;
commitid	8q0kdlBlCn09GACx;

1.1.1.4
date	2014.08.10.17.08.40;	author joerg;	state Exp;
branches
	1.1.1.4.4.1;
next	1.1.1.5;
commitid	N85tXAN6Ex9VZPLx;

1.1.1.5
date	2016.02.27.22.10.24;	author joerg;	state Exp;
branches
	1.1.1.5.2.1;
next	1.1.1.6;
commitid	tIimz3oDlh1NpBWy;

1.1.1.6
date	2017.01.11.10.39.56;	author joerg;	state Exp;
branches
	1.1.1.6.12.1
	1.1.1.6.14.1;
next	1.1.1.7;
commitid	CNnUNfII1jgNmxBz;

1.1.1.7
date	2018.07.17.18.31.28;	author joerg;	state Exp;
branches;
next	1.1.1.8;
commitid	wDzL46ALjrCZgwKA;

1.1.1.8
date	2019.11.13.22.20.14;	author joerg;	state dead;
branches;
next	;
commitid	QD8YATxuNG34YJKB;

1.1.1.2.2.1
date	2014.08.10.07.08.14;	author tls;	state Exp;
branches;
next	;
commitid	t01A1TLTYxkpGMLx;

1.1.1.2.4.1
date	2014.01.05.15.40.05;	author yamt;	state dead;
branches;
next	1.1.1.2.4.2;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.2.4.2
date	2014.05.22.16.18.56;	author yamt;	state Exp;
branches;
next	;
commitid	WSrDtL5nYAUyiyBx;

1.1.1.4.4.1
date	2014.08.10.17.08.40;	author tls;	state dead;
branches;
next	1.1.1.4.4.2;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.4.4.2
date	2014.08.19.23.47.57;	author tls;	state Exp;
branches;
next	;
commitid	jTnpym9Qu0o4R1Nx;

1.1.1.5.2.1
date	2017.03.20.06.52.58;	author pgoyette;	state Exp;
branches;
next	;
commitid	jjw7cAwgyKq7RfKz;

1.1.1.6.12.1
date	2018.07.28.04.33.42;	author pgoyette;	state Exp;
branches;
next	;
commitid	1UP1xAIUxv1ZgRLA;

1.1.1.6.14.1
date	2019.06.10.21.45.51;	author christos;	state Exp;
branches;
next	1.1.1.6.14.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.6.14.2
date	2020.04.13.07.47.28;	author martin;	state dead;
branches;
next	;
commitid	X01YhRUPVUDaec4C;


desc
@@


1.1
log
@Initial revision
@
text
@// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s

struct test1_D {
  double d;
} d1;

void test1() {
  throw d1;
}

// CHECK-LABEL:     define void @@_Z5test1v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8*
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* [[EXN2]], i8* bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i32 8, i1 false)
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8* }* @@_ZTI7test1_D to i8*), i8* null) [[NR:#[0-9]+]]
// CHECK-NEXT:  unreachable


struct test2_D {
  test2_D(const test2_D&o);
  test2_D();
  virtual void bar() { }
  int i; int j;
} d2;

void test2() {
  throw d2;
}

// CHECK-LABEL:     define void @@_Z5test2v()
// CHECK:       [[EXNVAR:%.*]] = alloca i8*
// CHECK-NEXT:  [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 16)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] @@d2)
// CHECK-NEXT:     to label %[[CONT:.*]] unwind label %{{.*}}
//      :     [[CONT]]:   (can't check this in Release-Asserts builds)
// CHECK:       call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTI7test2_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


struct test3_D {
  test3_D() { }
  test3_D(volatile test3_D&o);
  virtual void bar();
};

void test3() {
  throw (volatile test3_D *)0;
}

// CHECK-LABEL:     define void @@_Z5test3v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[D:%[^*]+]]**
// CHECK-NEXT:  store [[D]]* null, [[D]]** [[EXN]]
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8*, i32, i8* }* @@_ZTIPV7test3_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


void test4() {
  throw;
}

// CHECK-LABEL:     define void @@_Z5test4v()
// CHECK:        call void @@__cxa_rethrow() [[NR]]
// CHECK-NEXT:   unreachable


// rdar://problem/7696549
namespace test5 {
  struct A {
    A();
    A(const A&);
    ~A();
  };

  void test() {
    try { throw A(); } catch (A &x) {}
  }
// CHECK-LABEL:      define void @@_ZN5test54testEv()
// CHECK:      [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 1)
// CHECK:      [[EXNCAST:%.*]] = bitcast i8* [[EXNOBJ]] to [[A:%[^*]*]]*
// CHECK-NEXT: invoke void @@_ZN5test51AC1Ev([[A]]* [[EXNCAST]])
// CHECK:      invoke void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @@_ZN5test51AD1Ev to i8*)) [[NR]]
// CHECK-NEXT:   to label {{%.*}} unwind label %[[HANDLER:[^ ]*]]
//      :    [[HANDLER]]:  (can't check this in Release-Asserts builds)
// CHECK:      {{%.*}} = call i32 @@llvm.eh.typeid.for(i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*))
}

namespace test6 {
  template <class T> struct allocator {
    ~allocator() throw() { }
  };

  void foo() {
    allocator<int> a;
  }
}

// PR7127
namespace test7 {
// CHECK-LABEL:      define i32 @@_ZN5test73fooEv() 
  int foo() {
// CHECK:      [[CAUGHTEXNVAR:%.*]] = alloca i8*
// CHECK-NEXT: [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT: [[INTCATCHVAR:%.*]] = alloca i32
    try {
      try {
// CHECK-NEXT: [[EXNALLOC:%.*]] = call i8* @@__cxa_allocate_exception
// CHECK-NEXT: bitcast i8* [[EXNALLOC]] to i32*
// CHECK-NEXT: store i32 1, i32*
// CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXNALLOC]], i8* bitcast (i8** @@_ZTIi to i8*), i8* null
        throw 1;
      }

// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: br label
// CHECK:      [[SELECTOR:%.*]] = load i32* [[SELECTORVAR]]
// CHECK-NEXT: [[T0:%.*]] = call i32 @@llvm.eh.typeid.for(i8* bitcast (i8** @@_ZTIi to i8*))
// CHECK-NEXT: icmp eq i32 [[SELECTOR]], [[T0]]
// CHECK-NEXT: br i1
// CHECK:      [[T0:%.*]] = load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[T1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[T0]])
// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i32*
// CHECK-NEXT: [[T3:%.*]] = load i32* [[T2]]
// CHECK-NEXT: store i32 [[T3]], i32* {{%.*}}, align 4
// CHECK-NEXT: invoke void @@__cxa_rethrow
      catch (int) {
        throw;
      }
    }
// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: call void @@__cxa_end_catch()
// CHECK-NEXT: br label
// CHECK:      load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: call i8* @@__cxa_begin_catch
// CHECK-NEXT: call void @@__cxa_end_catch
    catch (...) {
    }
// CHECK:      ret i32 0
    return 0;
  }
}

// Ordering of destructors in a catch handler.
namespace test8 {
  struct A { A(const A&); ~A(); };
  void bar();

  // CHECK-LABEL: define void @@_ZN5test83fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN5test83barEv()
      bar();
    } catch (A a) {
      // CHECK:      call i8* @@__cxa_get_exception_ptr
      // CHECK-NEXT: bitcast
      // CHECK-NEXT: invoke void @@_ZN5test81AC1ERKS0_(
      // CHECK:      call i8* @@__cxa_begin_catch
      // CHECK-NEXT: call void @@_ZN5test81AD1Ev(
      // CHECK:      call void @@__cxa_end_catch()
      // CHECK:      ret void
    }
  }
}

// Constructor function-try-block must rethrow on fallthrough.
// rdar://problem/7696603
namespace test9 {
  void opaque();

  struct A { A(); };

  // CHECK-LABEL:      define void @@_ZN5test91AC1Ev(%"struct.test9::A"* %this) unnamed_addr
  // CHECK:      call void @@_ZN5test91AC2Ev
  // CHECK-NEXT: ret void

  // CHECK-LABEL: define void @@_ZN5test91AC2Ev(%"struct.test9::A"* %this) unnamed_addr
  A::A() try {
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
    opaque();
  } catch (int x) {
  // CHECK:      landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
  // CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)

  // CHECK:      call i8* @@__cxa_begin_catch
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
  // CHECK:      invoke void @@__cxa_rethrow()
    opaque();
  }
}

// __cxa_end_catch can throw for some kinds of caught exceptions.
namespace test10 {
  void opaque();

  struct A { ~A(); };
  struct B { int x; };

  // CHECK-LABEL: define void @@_ZN6test103fooEv()
  void foo() {
    A a; // force a cleanup context

    try {
    // CHECK:      invoke void @@_ZN6test106opaqueEv()
      opaque();
    } catch (int i) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: load i32*
    // CHECK-NEXT: store i32
    // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW:#[0-9]+]]
    } catch (B a) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: call void @@llvm.memcpy
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    } catch (...) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    }

    // CHECK: call void @@_ZN6test101AD1Ev(
  }
}

// __cxa_begin_catch returns pointers by value, even when catching by reference
// <rdar://problem/8212123>
namespace test11 {
  void opaque();

  // CHECK-LABEL: define void @@_ZN6test113fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (int**&p) {
      // CHECK:      [[EXN:%.*]] = load i8**
      // CHECK-NEXT: call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ1:%.*]] = getelementptr i8* [[EXN]], i32 32
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to i32***
      // CHECK-NEXT: store i32*** [[ADJ2]], i32**** [[P:%.*]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }

  struct A {};

  // CHECK-LABEL: define void @@_ZN6test113barEv()
  void bar() {
    try {
      // CHECK:      [[EXNSLOT:%.*]] = alloca i8*
      // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
      // CHECK-NEXT: [[P:%.*]] = alloca [[A:%.*]]**,
      // CHECK-NEXT: [[TMP:%.*]] = alloca [[A]]*
      // CHECK-NEXT: invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (A*&p) {
      // CHECK:      [[EXN:%.*]] = load i8** [[EXNSLOT]]
      // CHECK-NEXT: [[ADJ1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to [[A]]*
      // CHECK-NEXT: store [[A]]* [[ADJ2]], [[A]]** [[TMP]]
      // CHECK-NEXT: store [[A]]** [[TMP]], [[A]]*** [[P]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }
}

// PR7686
namespace test12 {
  struct A { ~A() noexcept(false); };
  bool opaque(const A&);

  // CHECK-LABEL: define void @@_ZN6test124testEv()
  void test() {
    // CHECK: [[X:%.*]] = alloca [[A:%.*]],
    // CHECK: [[EHCLEANUPDEST:%.*]] = alloca i32
    // CHECK: [[Y:%.*]] = alloca [[A]]
    // CHECK: [[Z:%.*]] = alloca [[A]]
    // CHECK: [[CLEANUPDEST:%.*]] = alloca i32

    A x;
    // CHECK: invoke zeroext i1 @@_ZN6test126opaqueERKNS_1AE(
    if (opaque(x)) {
      A y;
      A z;

      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Z]])
      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Y]])
      // CHECK-NOT: switch
      goto success;
    }

  success:
    bool _ = true;

    // CHECK: call void @@_ZN6test121AD1Ev([[A]]* [[X]])
    // CHECK-NEXT: ret void
  }
}

// Reduced from some TableGen code that was causing a self-host crash.
namespace test13 {
  struct A { ~A(); };

  void test0(int x) {
    try {
      switch (x) {
      case 0:
        break;
      case 1:{
        A a;
        break;
      }
      default:
        return;
      }
      return;
    } catch (int x) {
    }
    return;
  }

  void test1(int x) {
    A y;
    try {
      switch (x) {
      default: break;
      }
    } catch (int x) {}
  }
}

// rdar://problem/8231514
namespace test14 {
  struct A { ~A(); };
  struct B { ~B(); };

  B b();
  void opaque();

  void foo() {
    A a;
    try {
      B str = b();
      opaque();
    } catch (int x) {
    }
  }
}

// rdar://problem/8231514
// JumpDests shouldn't get confused by scopes that aren't normal cleanups.
namespace test15 {
  struct A { ~A(); };

  bool opaque(int);

  // CHECK-LABEL: define void @@_ZN6test153fooEv()
  void foo() {
    A a;

    try {
      // CHECK:      [[X:%.*]] = alloca i32
      // CHECK:      store i32 10, i32* [[X]]
      // CHECK-NEXT: br label
      //   -> while.cond
      int x = 10;

      while (true) {
        // CHECK:      load i32* [[X]]
        // CHECK-NEXT: [[COND:%.*]] = invoke zeroext i1 @@_ZN6test156opaqueEi
        // CHECK:      br i1 [[COND]]
        if (opaque(x))
        // CHECK:      br label
          break;

        // CHECK:      br label
      }
      // CHECK:      br label
    } catch (int x) { }

    // CHECK: call void @@_ZN6test151AD1Ev
  }
}

namespace test16 {
  struct A { A(); ~A() noexcept(false); };
  struct B { int x; B(const A &); ~B() noexcept(false); };
  void foo();
  bool cond();

  // CHECK-LABEL: define void @@_ZN6test163barEv()
  void bar() {
    // CHECK:      [[EXN_SAVE:%.*]] = alloca i8*
    // CHECK-NEXT: [[EXN_ACTIVE:%.*]] = alloca i1
    // CHECK-NEXT: [[TEMP:%.*]] = alloca [[A:%.*]],
    // CHECK-NEXT: [[EXNSLOT:%.*]] = alloca i8*
    // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
    // CHECK-NEXT: [[TEMP_ACTIVE:%.*]] = alloca i1

    cond() ? throw B(A()) : foo();

    // CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @@_ZN6test164condEv()
    // CHECK-NEXT: store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: store i1 false, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: br i1 [[COND]],

    // CHECK:      [[EXN:%.*]] = call i8* @@__cxa_allocate_exception(i64 4)
    // CHECK-NEXT: store i8* [[EXN]], i8** [[EXN_SAVE]]
    // CHECK-NEXT: store i1 true, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[EXN]] to [[B:%.*]]*
    // CHECK-NEXT: invoke void @@_ZN6test161AC1Ev([[A]]* [[TEMP]])
    // CHECK:      store i1 true, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* [[TEMP]])
    // CHECK:      store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXN]],

    // CHECK:      invoke void @@_ZN6test163fooEv()
    // CHECK:      br label

    // CHECK:      invoke void @@_ZN6test161AD1Ev([[A]]* [[TEMP]])
    // CHECK:      ret void

    // CHECK:      [[T0:%.*]] = load i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: br i1 [[T0]]
    // CHECK:      [[T1:%.*]] = load i8** [[EXN_SAVE]]
    // CHECK-NEXT: call void @@__cxa_free_exception(i8* [[T1]])
    // CHECK-NEXT: br label
  }
}

// CHECK: attributes [[NUW]] = { nounwind }
// CHECK: attributes [[NR]] = { noreturn }
@


1.1.1.1
log
@Import Clang 3.4rc1 r195771.
@
text
@@


1.1.1.2
log
@Import clang 3.5svn r198450.
@
text
@d187 3
a201 4

  // CHECK-LABEL:      define void @@_ZN5test91AC1Ev(%"struct.test9::A"* %this) unnamed_addr
  // CHECK:      call void @@_ZN5test91AC2Ev
  // CHECK-NEXT: ret void
@


1.1.1.2.2.1
log
@Rebase.
@
text
@d37 1
a37 1
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] nonnull @@d2)
d431 1
a431 1
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* nonnull [[TEMP]])
@


1.1.1.3
log
@Import Clang 3.5svn r209886.
@
text
@d37 1
a37 1
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] nonnull @@d2)
d431 1
a431 1
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* nonnull [[TEMP]])
@


1.1.1.4
log
@Import clang 3.6svn r215315.
@
text
@d37 1
a37 1
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] dereferenceable({{[0-9]+}}) @@d2)
d431 1
a431 1
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* dereferenceable({{[0-9]+}}) [[TEMP]])
@


1.1.1.5
log
@Import Clang 3.8.0rc3 r261930.
@
text
@a104 1
// CHECK-SAME:  personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
d118 1
a118 1
// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 }
d126 1
a126 1
// CHECK:      [[SELECTOR:%.*]] = load i32, i32* [[SELECTORVAR]]
d130 1
a130 1
// CHECK:      [[T0:%.*]] = load i8*, i8** [[CAUGHTEXNVAR]]
d133 1
a133 1
// CHECK-NEXT: [[T3:%.*]] = load i32, i32* [[T2]]
d140 1
a140 1
// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 }
d148 1
a148 1
// CHECK:      load i8*, i8** [[CAUGHTEXNVAR]]
a188 1
  // CHECK-SAME:  personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
d193 1
a193 1
  // CHECK:      landingpad { i8*, i32 }
d224 1
a224 1
    // CHECK-NEXT: load i32, i32*
d254 1
a254 1
      // CHECK:      [[EXN:%.*]] = load i8*, i8**
d256 1
a256 1
      // CHECK-NEXT: [[ADJ1:%.*]] = getelementptr i8, i8* [[EXN]], i32 32
d275 1
a275 1
      // CHECK:      [[EXN:%.*]] = load i8*, i8** [[EXNSLOT]]
d387 1
a387 1
        // CHECK:      load i32, i32* [[X]]
d441 1
a441 1
    // CHECK:      [[T0:%.*]] = load i1, i1* [[EXN_ACTIVE]]
d443 1
a443 1
    // CHECK:      [[T1:%.*]] = load i8*, i8** [[EXN_SAVE]]
@


1.1.1.5.2.1
log
@Sync with HEAD
@
text
@a450 22
namespace test17 {
class BaseException {
private:
  int a[4];
public:
  BaseException() {};
};

class DerivedException: public BaseException {
};

int foo() {
  throw DerivedException();
  // The alignment passed to memset is 8, not 16, on Darwin.

  // CHECK: [[T0:%.*]] = call i8* @@__cxa_allocate_exception(i64 16)
  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to %"class.test17::DerivedException"*
  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* [[T1]] to i8*
  // CHECK-NEXT: call void @@llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, i32 8, i1 false)
}
}

@


1.1.1.6
log
@Import Clang pre-4.0.0 r291444.
@
text
@a450 22
namespace test17 {
class BaseException {
private:
  int a[4];
public:
  BaseException() {};
};

class DerivedException: public BaseException {
};

int foo() {
  throw DerivedException();
  // The alignment passed to memset is 8, not 16, on Darwin.

  // CHECK: [[T0:%.*]] = call i8* @@__cxa_allocate_exception(i64 16)
  // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to %"class.test17::DerivedException"*
  // CHECK-NEXT: [[T2:%.*]] = bitcast %"class.test17::DerivedException"* [[T1]] to i8*
  // CHECK-NEXT: call void @@llvm.memset.p0i8.i64(i8* [[T2]], i8 0, i64 16, i32 8, i1 false)
}
}

@


1.1.1.6.14.1
log
@Sync with HEAD
@
text
@d1 2
a2 2
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - \
// RUN:   | FileCheck %s
d16 1
a16 1
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i1 false)
d464 1
a464 1
  // The alignment passed to memset is 16 on Darwin.
d469 1
a469 1
  // CHECK-NEXT: call void @@llvm.memset.p0i8.i64(i8* align 16 [[T2]], i8 0, i64 16, i1 false)
@


1.1.1.6.14.2
log
@Mostly merge changes from HEAD upto 20200411
@
text
@@


1.1.1.6.12.1
log
@Sync with HEAD
@
text
@d1 2
a2 2
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - \
// RUN:   | FileCheck %s
d16 1
a16 1
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i1 false)
d464 1
a464 1
  // The alignment passed to memset is 16 on Darwin.
d469 1
a469 1
  // CHECK-NEXT: call void @@llvm.memset.p0i8.i64(i8* align 16 [[T2]], i8 0, i64 16, i1 false)
@


1.1.1.7
log
@Import clang r337282 from trunk
@
text
@d1 2
a2 2
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - \
// RUN:   | FileCheck %s
d16 1
a16 1
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[EXN2]], i8* align 8 bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i1 false)
d464 1
a464 1
  // The alignment passed to memset is 16 on Darwin.
d469 1
a469 1
  // CHECK-NEXT: call void @@llvm.memset.p0i8.i64(i8* align 16 [[T2]], i8 0, i64 16, i1 false)
@


1.1.1.8
log
@Mark old LLVM instance as dead.
@
text
@@


1.1.1.4.4.1
log
@file eh.cpp was added on branch tls-maxphys on 2014-08-19 23:47:57 +0000
@
text
@d1 450
@


1.1.1.4.4.2
log
@Rebase to HEAD as of a few days ago.
@
text
@a0 450
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s

struct test1_D {
  double d;
} d1;

void test1() {
  throw d1;
}

// CHECK-LABEL:     define void @@_Z5test1v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8*
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* [[EXN2]], i8* bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i32 8, i1 false)
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8* }* @@_ZTI7test1_D to i8*), i8* null) [[NR:#[0-9]+]]
// CHECK-NEXT:  unreachable


struct test2_D {
  test2_D(const test2_D&o);
  test2_D();
  virtual void bar() { }
  int i; int j;
} d2;

void test2() {
  throw d2;
}

// CHECK-LABEL:     define void @@_Z5test2v()
// CHECK:       [[EXNVAR:%.*]] = alloca i8*
// CHECK-NEXT:  [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 16)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] dereferenceable({{[0-9]+}}) @@d2)
// CHECK-NEXT:     to label %[[CONT:.*]] unwind label %{{.*}}
//      :     [[CONT]]:   (can't check this in Release-Asserts builds)
// CHECK:       call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTI7test2_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


struct test3_D {
  test3_D() { }
  test3_D(volatile test3_D&o);
  virtual void bar();
};

void test3() {
  throw (volatile test3_D *)0;
}

// CHECK-LABEL:     define void @@_Z5test3v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[D:%[^*]+]]**
// CHECK-NEXT:  store [[D]]* null, [[D]]** [[EXN]]
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8*, i32, i8* }* @@_ZTIPV7test3_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


void test4() {
  throw;
}

// CHECK-LABEL:     define void @@_Z5test4v()
// CHECK:        call void @@__cxa_rethrow() [[NR]]
// CHECK-NEXT:   unreachable


// rdar://problem/7696549
namespace test5 {
  struct A {
    A();
    A(const A&);
    ~A();
  };

  void test() {
    try { throw A(); } catch (A &x) {}
  }
// CHECK-LABEL:      define void @@_ZN5test54testEv()
// CHECK:      [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 1)
// CHECK:      [[EXNCAST:%.*]] = bitcast i8* [[EXNOBJ]] to [[A:%[^*]*]]*
// CHECK-NEXT: invoke void @@_ZN5test51AC1Ev([[A]]* [[EXNCAST]])
// CHECK:      invoke void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @@_ZN5test51AD1Ev to i8*)) [[NR]]
// CHECK-NEXT:   to label {{%.*}} unwind label %[[HANDLER:[^ ]*]]
//      :    [[HANDLER]]:  (can't check this in Release-Asserts builds)
// CHECK:      {{%.*}} = call i32 @@llvm.eh.typeid.for(i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*))
}

namespace test6 {
  template <class T> struct allocator {
    ~allocator() throw() { }
  };

  void foo() {
    allocator<int> a;
  }
}

// PR7127
namespace test7 {
// CHECK-LABEL:      define i32 @@_ZN5test73fooEv() 
  int foo() {
// CHECK:      [[CAUGHTEXNVAR:%.*]] = alloca i8*
// CHECK-NEXT: [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT: [[INTCATCHVAR:%.*]] = alloca i32
    try {
      try {
// CHECK-NEXT: [[EXNALLOC:%.*]] = call i8* @@__cxa_allocate_exception
// CHECK-NEXT: bitcast i8* [[EXNALLOC]] to i32*
// CHECK-NEXT: store i32 1, i32*
// CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXNALLOC]], i8* bitcast (i8** @@_ZTIi to i8*), i8* null
        throw 1;
      }

// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: br label
// CHECK:      [[SELECTOR:%.*]] = load i32* [[SELECTORVAR]]
// CHECK-NEXT: [[T0:%.*]] = call i32 @@llvm.eh.typeid.for(i8* bitcast (i8** @@_ZTIi to i8*))
// CHECK-NEXT: icmp eq i32 [[SELECTOR]], [[T0]]
// CHECK-NEXT: br i1
// CHECK:      [[T0:%.*]] = load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[T1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[T0]])
// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i32*
// CHECK-NEXT: [[T3:%.*]] = load i32* [[T2]]
// CHECK-NEXT: store i32 [[T3]], i32* {{%.*}}, align 4
// CHECK-NEXT: invoke void @@__cxa_rethrow
      catch (int) {
        throw;
      }
    }
// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: call void @@__cxa_end_catch()
// CHECK-NEXT: br label
// CHECK:      load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: call i8* @@__cxa_begin_catch
// CHECK-NEXT: call void @@__cxa_end_catch
    catch (...) {
    }
// CHECK:      ret i32 0
    return 0;
  }
}

// Ordering of destructors in a catch handler.
namespace test8 {
  struct A { A(const A&); ~A(); };
  void bar();

  // CHECK-LABEL: define void @@_ZN5test83fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN5test83barEv()
      bar();
    } catch (A a) {
      // CHECK:      call i8* @@__cxa_get_exception_ptr
      // CHECK-NEXT: bitcast
      // CHECK-NEXT: invoke void @@_ZN5test81AC1ERKS0_(
      // CHECK:      call i8* @@__cxa_begin_catch
      // CHECK-NEXT: call void @@_ZN5test81AD1Ev(
      // CHECK:      call void @@__cxa_end_catch()
      // CHECK:      ret void
    }
  }
}

// Constructor function-try-block must rethrow on fallthrough.
// rdar://problem/7696603
namespace test9 {
  void opaque();

  struct A { A(); };


  // CHECK-LABEL: define void @@_ZN5test91AC2Ev(%"struct.test9::A"* %this) unnamed_addr
  A::A() try {
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
    opaque();
  } catch (int x) {
  // CHECK:      landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
  // CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)

  // CHECK:      call i8* @@__cxa_begin_catch
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
  // CHECK:      invoke void @@__cxa_rethrow()

  // CHECK-LABEL:      define void @@_ZN5test91AC1Ev(%"struct.test9::A"* %this) unnamed_addr
  // CHECK:      call void @@_ZN5test91AC2Ev
  // CHECK-NEXT: ret void
    opaque();
  }
}

// __cxa_end_catch can throw for some kinds of caught exceptions.
namespace test10 {
  void opaque();

  struct A { ~A(); };
  struct B { int x; };

  // CHECK-LABEL: define void @@_ZN6test103fooEv()
  void foo() {
    A a; // force a cleanup context

    try {
    // CHECK:      invoke void @@_ZN6test106opaqueEv()
      opaque();
    } catch (int i) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: load i32*
    // CHECK-NEXT: store i32
    // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW:#[0-9]+]]
    } catch (B a) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: call void @@llvm.memcpy
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    } catch (...) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    }

    // CHECK: call void @@_ZN6test101AD1Ev(
  }
}

// __cxa_begin_catch returns pointers by value, even when catching by reference
// <rdar://problem/8212123>
namespace test11 {
  void opaque();

  // CHECK-LABEL: define void @@_ZN6test113fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (int**&p) {
      // CHECK:      [[EXN:%.*]] = load i8**
      // CHECK-NEXT: call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ1:%.*]] = getelementptr i8* [[EXN]], i32 32
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to i32***
      // CHECK-NEXT: store i32*** [[ADJ2]], i32**** [[P:%.*]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }

  struct A {};

  // CHECK-LABEL: define void @@_ZN6test113barEv()
  void bar() {
    try {
      // CHECK:      [[EXNSLOT:%.*]] = alloca i8*
      // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
      // CHECK-NEXT: [[P:%.*]] = alloca [[A:%.*]]**,
      // CHECK-NEXT: [[TMP:%.*]] = alloca [[A]]*
      // CHECK-NEXT: invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (A*&p) {
      // CHECK:      [[EXN:%.*]] = load i8** [[EXNSLOT]]
      // CHECK-NEXT: [[ADJ1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to [[A]]*
      // CHECK-NEXT: store [[A]]* [[ADJ2]], [[A]]** [[TMP]]
      // CHECK-NEXT: store [[A]]** [[TMP]], [[A]]*** [[P]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }
}

// PR7686
namespace test12 {
  struct A { ~A() noexcept(false); };
  bool opaque(const A&);

  // CHECK-LABEL: define void @@_ZN6test124testEv()
  void test() {
    // CHECK: [[X:%.*]] = alloca [[A:%.*]],
    // CHECK: [[EHCLEANUPDEST:%.*]] = alloca i32
    // CHECK: [[Y:%.*]] = alloca [[A]]
    // CHECK: [[Z:%.*]] = alloca [[A]]
    // CHECK: [[CLEANUPDEST:%.*]] = alloca i32

    A x;
    // CHECK: invoke zeroext i1 @@_ZN6test126opaqueERKNS_1AE(
    if (opaque(x)) {
      A y;
      A z;

      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Z]])
      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Y]])
      // CHECK-NOT: switch
      goto success;
    }

  success:
    bool _ = true;

    // CHECK: call void @@_ZN6test121AD1Ev([[A]]* [[X]])
    // CHECK-NEXT: ret void
  }
}

// Reduced from some TableGen code that was causing a self-host crash.
namespace test13 {
  struct A { ~A(); };

  void test0(int x) {
    try {
      switch (x) {
      case 0:
        break;
      case 1:{
        A a;
        break;
      }
      default:
        return;
      }
      return;
    } catch (int x) {
    }
    return;
  }

  void test1(int x) {
    A y;
    try {
      switch (x) {
      default: break;
      }
    } catch (int x) {}
  }
}

// rdar://problem/8231514
namespace test14 {
  struct A { ~A(); };
  struct B { ~B(); };

  B b();
  void opaque();

  void foo() {
    A a;
    try {
      B str = b();
      opaque();
    } catch (int x) {
    }
  }
}

// rdar://problem/8231514
// JumpDests shouldn't get confused by scopes that aren't normal cleanups.
namespace test15 {
  struct A { ~A(); };

  bool opaque(int);

  // CHECK-LABEL: define void @@_ZN6test153fooEv()
  void foo() {
    A a;

    try {
      // CHECK:      [[X:%.*]] = alloca i32
      // CHECK:      store i32 10, i32* [[X]]
      // CHECK-NEXT: br label
      //   -> while.cond
      int x = 10;

      while (true) {
        // CHECK:      load i32* [[X]]
        // CHECK-NEXT: [[COND:%.*]] = invoke zeroext i1 @@_ZN6test156opaqueEi
        // CHECK:      br i1 [[COND]]
        if (opaque(x))
        // CHECK:      br label
          break;

        // CHECK:      br label
      }
      // CHECK:      br label
    } catch (int x) { }

    // CHECK: call void @@_ZN6test151AD1Ev
  }
}

namespace test16 {
  struct A { A(); ~A() noexcept(false); };
  struct B { int x; B(const A &); ~B() noexcept(false); };
  void foo();
  bool cond();

  // CHECK-LABEL: define void @@_ZN6test163barEv()
  void bar() {
    // CHECK:      [[EXN_SAVE:%.*]] = alloca i8*
    // CHECK-NEXT: [[EXN_ACTIVE:%.*]] = alloca i1
    // CHECK-NEXT: [[TEMP:%.*]] = alloca [[A:%.*]],
    // CHECK-NEXT: [[EXNSLOT:%.*]] = alloca i8*
    // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
    // CHECK-NEXT: [[TEMP_ACTIVE:%.*]] = alloca i1

    cond() ? throw B(A()) : foo();

    // CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @@_ZN6test164condEv()
    // CHECK-NEXT: store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: store i1 false, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: br i1 [[COND]],

    // CHECK:      [[EXN:%.*]] = call i8* @@__cxa_allocate_exception(i64 4)
    // CHECK-NEXT: store i8* [[EXN]], i8** [[EXN_SAVE]]
    // CHECK-NEXT: store i1 true, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[EXN]] to [[B:%.*]]*
    // CHECK-NEXT: invoke void @@_ZN6test161AC1Ev([[A]]* [[TEMP]])
    // CHECK:      store i1 true, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* dereferenceable({{[0-9]+}}) [[TEMP]])
    // CHECK:      store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXN]],

    // CHECK:      invoke void @@_ZN6test163fooEv()
    // CHECK:      br label

    // CHECK:      invoke void @@_ZN6test161AD1Ev([[A]]* [[TEMP]])
    // CHECK:      ret void

    // CHECK:      [[T0:%.*]] = load i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: br i1 [[T0]]
    // CHECK:      [[T1:%.*]] = load i8** [[EXN_SAVE]]
    // CHECK-NEXT: call void @@__cxa_free_exception(i8* [[T1]])
    // CHECK-NEXT: br label
  }
}

// CHECK: attributes [[NUW]] = { nounwind }
// CHECK: attributes [[NR]] = { noreturn }
@


1.1.1.2.4.1
log
@file eh.cpp was added on branch yamt-pagecache on 2014-05-22 16:18:56 +0000
@
text
@d1 450
@


1.1.1.2.4.2
log
@sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs.  ("Protocol error: too many arguments")
@
text
@a0 450
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s

struct test1_D {
  double d;
} d1;

void test1() {
  throw d1;
}

// CHECK-LABEL:     define void @@_Z5test1v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  [[EXN2:%.*]] = bitcast [[DSTAR]] [[EXN]] to i8*
// CHECK-NEXT:  call void @@llvm.memcpy.p0i8.p0i8.i64(i8* [[EXN2]], i8* bitcast ([[DSTAR]] @@d1 to i8*), i64 8, i32 8, i1 false)
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8* }* @@_ZTI7test1_D to i8*), i8* null) [[NR:#[0-9]+]]
// CHECK-NEXT:  unreachable


struct test2_D {
  test2_D(const test2_D&o);
  test2_D();
  virtual void bar() { }
  int i; int j;
} d2;

void test2() {
  throw d2;
}

// CHECK-LABEL:     define void @@_Z5test2v()
// CHECK:       [[EXNVAR:%.*]] = alloca i8*
// CHECK-NEXT:  [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT:  [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 16)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[DSTAR:%[^*]*\*]]
// CHECK-NEXT:  invoke void @@_ZN7test2_DC1ERKS_([[DSTAR]] [[EXN]], [[DSTAR]] @@d2)
// CHECK-NEXT:     to label %[[CONT:.*]] unwind label %{{.*}}
//      :     [[CONT]]:   (can't check this in Release-Asserts builds)
// CHECK:       call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTI7test2_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


struct test3_D {
  test3_D() { }
  test3_D(volatile test3_D&o);
  virtual void bar();
};

void test3() {
  throw (volatile test3_D *)0;
}

// CHECK-LABEL:     define void @@_Z5test3v()
// CHECK:       [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 8)
// CHECK-NEXT:  [[EXN:%.*]] = bitcast i8* [[EXNOBJ]] to [[D:%[^*]+]]**
// CHECK-NEXT:  store [[D]]* null, [[D]]** [[EXN]]
// CHECK-NEXT:  call void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({ i8*, i8*, i32, i8* }* @@_ZTIPV7test3_D to i8*), i8* null) [[NR]]
// CHECK-NEXT:  unreachable


void test4() {
  throw;
}

// CHECK-LABEL:     define void @@_Z5test4v()
// CHECK:        call void @@__cxa_rethrow() [[NR]]
// CHECK-NEXT:   unreachable


// rdar://problem/7696549
namespace test5 {
  struct A {
    A();
    A(const A&);
    ~A();
  };

  void test() {
    try { throw A(); } catch (A &x) {}
  }
// CHECK-LABEL:      define void @@_ZN5test54testEv()
// CHECK:      [[EXNOBJ:%.*]] = call i8* @@__cxa_allocate_exception(i64 1)
// CHECK:      [[EXNCAST:%.*]] = bitcast i8* [[EXNOBJ]] to [[A:%[^*]*]]*
// CHECK-NEXT: invoke void @@_ZN5test51AC1Ev([[A]]* [[EXNCAST]])
// CHECK:      invoke void @@__cxa_throw(i8* [[EXNOBJ]], i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*), i8* bitcast (void ([[A]]*)* @@_ZN5test51AD1Ev to i8*)) [[NR]]
// CHECK-NEXT:   to label {{%.*}} unwind label %[[HANDLER:[^ ]*]]
//      :    [[HANDLER]]:  (can't check this in Release-Asserts builds)
// CHECK:      {{%.*}} = call i32 @@llvm.eh.typeid.for(i8* bitcast ({{.*}}* @@_ZTIN5test51AE to i8*))
}

namespace test6 {
  template <class T> struct allocator {
    ~allocator() throw() { }
  };

  void foo() {
    allocator<int> a;
  }
}

// PR7127
namespace test7 {
// CHECK-LABEL:      define i32 @@_ZN5test73fooEv() 
  int foo() {
// CHECK:      [[CAUGHTEXNVAR:%.*]] = alloca i8*
// CHECK-NEXT: [[SELECTORVAR:%.*]] = alloca i32
// CHECK-NEXT: [[INTCATCHVAR:%.*]] = alloca i32
    try {
      try {
// CHECK-NEXT: [[EXNALLOC:%.*]] = call i8* @@__cxa_allocate_exception
// CHECK-NEXT: bitcast i8* [[EXNALLOC]] to i32*
// CHECK-NEXT: store i32 1, i32*
// CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXNALLOC]], i8* bitcast (i8** @@_ZTIi to i8*), i8* null
        throw 1;
      }

// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: br label
// CHECK:      [[SELECTOR:%.*]] = load i32* [[SELECTORVAR]]
// CHECK-NEXT: [[T0:%.*]] = call i32 @@llvm.eh.typeid.for(i8* bitcast (i8** @@_ZTIi to i8*))
// CHECK-NEXT: icmp eq i32 [[SELECTOR]], [[T0]]
// CHECK-NEXT: br i1
// CHECK:      [[T0:%.*]] = load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[T1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[T0]])
// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i32*
// CHECK-NEXT: [[T3:%.*]] = load i32* [[T2]]
// CHECK-NEXT: store i32 [[T3]], i32* {{%.*}}, align 4
// CHECK-NEXT: invoke void @@__cxa_rethrow
      catch (int) {
        throw;
      }
    }
// CHECK:      [[CAUGHTVAL:%.*]] = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
// CHECK-NEXT:   catch i8* null
// CHECK-NEXT: [[CAUGHTEXN:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 0
// CHECK-NEXT: store i8* [[CAUGHTEXN]], i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: [[SELECTOR:%.*]] = extractvalue { i8*, i32 } [[CAUGHTVAL]], 1
// CHECK-NEXT: store i32 [[SELECTOR]], i32* [[SELECTORVAR]]
// CHECK-NEXT: call void @@__cxa_end_catch()
// CHECK-NEXT: br label
// CHECK:      load i8** [[CAUGHTEXNVAR]]
// CHECK-NEXT: call i8* @@__cxa_begin_catch
// CHECK-NEXT: call void @@__cxa_end_catch
    catch (...) {
    }
// CHECK:      ret i32 0
    return 0;
  }
}

// Ordering of destructors in a catch handler.
namespace test8 {
  struct A { A(const A&); ~A(); };
  void bar();

  // CHECK-LABEL: define void @@_ZN5test83fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN5test83barEv()
      bar();
    } catch (A a) {
      // CHECK:      call i8* @@__cxa_get_exception_ptr
      // CHECK-NEXT: bitcast
      // CHECK-NEXT: invoke void @@_ZN5test81AC1ERKS0_(
      // CHECK:      call i8* @@__cxa_begin_catch
      // CHECK-NEXT: call void @@_ZN5test81AD1Ev(
      // CHECK:      call void @@__cxa_end_catch()
      // CHECK:      ret void
    }
  }
}

// Constructor function-try-block must rethrow on fallthrough.
// rdar://problem/7696603
namespace test9 {
  void opaque();

  struct A { A(); };


  // CHECK-LABEL: define void @@_ZN5test91AC2Ev(%"struct.test9::A"* %this) unnamed_addr
  A::A() try {
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
    opaque();
  } catch (int x) {
  // CHECK:      landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @@__gxx_personality_v0 to i8*)
  // CHECK-NEXT:   catch i8* bitcast (i8** @@_ZTIi to i8*)

  // CHECK:      call i8* @@__cxa_begin_catch
  // CHECK:      invoke void @@_ZN5test96opaqueEv()
  // CHECK:      invoke void @@__cxa_rethrow()

  // CHECK-LABEL:      define void @@_ZN5test91AC1Ev(%"struct.test9::A"* %this) unnamed_addr
  // CHECK:      call void @@_ZN5test91AC2Ev
  // CHECK-NEXT: ret void
    opaque();
  }
}

// __cxa_end_catch can throw for some kinds of caught exceptions.
namespace test10 {
  void opaque();

  struct A { ~A(); };
  struct B { int x; };

  // CHECK-LABEL: define void @@_ZN6test103fooEv()
  void foo() {
    A a; // force a cleanup context

    try {
    // CHECK:      invoke void @@_ZN6test106opaqueEv()
      opaque();
    } catch (int i) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: load i32*
    // CHECK-NEXT: store i32
    // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW:#[0-9]+]]
    } catch (B a) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: bitcast
    // CHECK-NEXT: call void @@llvm.memcpy
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    } catch (...) {
    // CHECK:      call i8* @@__cxa_begin_catch
    // CHECK-NEXT: invoke void @@__cxa_end_catch()
    }

    // CHECK: call void @@_ZN6test101AD1Ev(
  }
}

// __cxa_begin_catch returns pointers by value, even when catching by reference
// <rdar://problem/8212123>
namespace test11 {
  void opaque();

  // CHECK-LABEL: define void @@_ZN6test113fooEv()
  void foo() {
    try {
      // CHECK:      invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (int**&p) {
      // CHECK:      [[EXN:%.*]] = load i8**
      // CHECK-NEXT: call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ1:%.*]] = getelementptr i8* [[EXN]], i32 32
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to i32***
      // CHECK-NEXT: store i32*** [[ADJ2]], i32**** [[P:%.*]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }

  struct A {};

  // CHECK-LABEL: define void @@_ZN6test113barEv()
  void bar() {
    try {
      // CHECK:      [[EXNSLOT:%.*]] = alloca i8*
      // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
      // CHECK-NEXT: [[P:%.*]] = alloca [[A:%.*]]**,
      // CHECK-NEXT: [[TMP:%.*]] = alloca [[A]]*
      // CHECK-NEXT: invoke void @@_ZN6test116opaqueEv()
      opaque();
    } catch (A*&p) {
      // CHECK:      [[EXN:%.*]] = load i8** [[EXNSLOT]]
      // CHECK-NEXT: [[ADJ1:%.*]] = call i8* @@__cxa_begin_catch(i8* [[EXN]]) [[NUW]]
      // CHECK-NEXT: [[ADJ2:%.*]] = bitcast i8* [[ADJ1]] to [[A]]*
      // CHECK-NEXT: store [[A]]* [[ADJ2]], [[A]]** [[TMP]]
      // CHECK-NEXT: store [[A]]** [[TMP]], [[A]]*** [[P]]
      // CHECK-NEXT: call void @@__cxa_end_catch() [[NUW]]
    }
  }
}

// PR7686
namespace test12 {
  struct A { ~A() noexcept(false); };
  bool opaque(const A&);

  // CHECK-LABEL: define void @@_ZN6test124testEv()
  void test() {
    // CHECK: [[X:%.*]] = alloca [[A:%.*]],
    // CHECK: [[EHCLEANUPDEST:%.*]] = alloca i32
    // CHECK: [[Y:%.*]] = alloca [[A]]
    // CHECK: [[Z:%.*]] = alloca [[A]]
    // CHECK: [[CLEANUPDEST:%.*]] = alloca i32

    A x;
    // CHECK: invoke zeroext i1 @@_ZN6test126opaqueERKNS_1AE(
    if (opaque(x)) {
      A y;
      A z;

      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Z]])
      // CHECK: invoke void @@_ZN6test121AD1Ev([[A]]* [[Y]])
      // CHECK-NOT: switch
      goto success;
    }

  success:
    bool _ = true;

    // CHECK: call void @@_ZN6test121AD1Ev([[A]]* [[X]])
    // CHECK-NEXT: ret void
  }
}

// Reduced from some TableGen code that was causing a self-host crash.
namespace test13 {
  struct A { ~A(); };

  void test0(int x) {
    try {
      switch (x) {
      case 0:
        break;
      case 1:{
        A a;
        break;
      }
      default:
        return;
      }
      return;
    } catch (int x) {
    }
    return;
  }

  void test1(int x) {
    A y;
    try {
      switch (x) {
      default: break;
      }
    } catch (int x) {}
  }
}

// rdar://problem/8231514
namespace test14 {
  struct A { ~A(); };
  struct B { ~B(); };

  B b();
  void opaque();

  void foo() {
    A a;
    try {
      B str = b();
      opaque();
    } catch (int x) {
    }
  }
}

// rdar://problem/8231514
// JumpDests shouldn't get confused by scopes that aren't normal cleanups.
namespace test15 {
  struct A { ~A(); };

  bool opaque(int);

  // CHECK-LABEL: define void @@_ZN6test153fooEv()
  void foo() {
    A a;

    try {
      // CHECK:      [[X:%.*]] = alloca i32
      // CHECK:      store i32 10, i32* [[X]]
      // CHECK-NEXT: br label
      //   -> while.cond
      int x = 10;

      while (true) {
        // CHECK:      load i32* [[X]]
        // CHECK-NEXT: [[COND:%.*]] = invoke zeroext i1 @@_ZN6test156opaqueEi
        // CHECK:      br i1 [[COND]]
        if (opaque(x))
        // CHECK:      br label
          break;

        // CHECK:      br label
      }
      // CHECK:      br label
    } catch (int x) { }

    // CHECK: call void @@_ZN6test151AD1Ev
  }
}

namespace test16 {
  struct A { A(); ~A() noexcept(false); };
  struct B { int x; B(const A &); ~B() noexcept(false); };
  void foo();
  bool cond();

  // CHECK-LABEL: define void @@_ZN6test163barEv()
  void bar() {
    // CHECK:      [[EXN_SAVE:%.*]] = alloca i8*
    // CHECK-NEXT: [[EXN_ACTIVE:%.*]] = alloca i1
    // CHECK-NEXT: [[TEMP:%.*]] = alloca [[A:%.*]],
    // CHECK-NEXT: [[EXNSLOT:%.*]] = alloca i8*
    // CHECK-NEXT: [[SELECTORSLOT:%.*]] = alloca i32
    // CHECK-NEXT: [[TEMP_ACTIVE:%.*]] = alloca i1

    cond() ? throw B(A()) : foo();

    // CHECK-NEXT: [[COND:%.*]] = call zeroext i1 @@_ZN6test164condEv()
    // CHECK-NEXT: store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: store i1 false, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: br i1 [[COND]],

    // CHECK:      [[EXN:%.*]] = call i8* @@__cxa_allocate_exception(i64 4)
    // CHECK-NEXT: store i8* [[EXN]], i8** [[EXN_SAVE]]
    // CHECK-NEXT: store i1 true, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[EXN]] to [[B:%.*]]*
    // CHECK-NEXT: invoke void @@_ZN6test161AC1Ev([[A]]* [[TEMP]])
    // CHECK:      store i1 true, i1* [[TEMP_ACTIVE]]
    // CHECK-NEXT: invoke void @@_ZN6test161BC1ERKNS_1AE([[B]]* [[T0]], [[A]]* [[TEMP]])
    // CHECK:      store i1 false, i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: invoke void @@__cxa_throw(i8* [[EXN]],

    // CHECK:      invoke void @@_ZN6test163fooEv()
    // CHECK:      br label

    // CHECK:      invoke void @@_ZN6test161AD1Ev([[A]]* [[TEMP]])
    // CHECK:      ret void

    // CHECK:      [[T0:%.*]] = load i1* [[EXN_ACTIVE]]
    // CHECK-NEXT: br i1 [[T0]]
    // CHECK:      [[T1:%.*]] = load i8** [[EXN_SAVE]]
    // CHECK-NEXT: call void @@__cxa_free_exception(i8* [[T1]])
    // CHECK-NEXT: br label
  }
}

// CHECK: attributes [[NUW]] = { nounwind }
// CHECK: attributes [[NR]] = { noreturn }
@


