1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fcxx-exceptions -fexceptions -emit-llvm -std=c++98 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
2 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fcxx-exceptions -fexceptions -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
3 
4 // Reduced from a crash on boost::interprocess's node_allocator_test.cpp.
5 namespace test0 {
6   struct A { A(); ~A(); };
7   struct V { V(const A &a = A()); ~V(); };
8 
9   // CHECK-LABEL: define linkonce_odr i32 @_ZN5test04testILi0EEEii
test(int x)10   template<int X> int test(int x) {
11     // CHECK:      [[RET:%.*]] = alloca i32
12     // CHECK-NEXT: [[X:%.*]] = alloca i32
13     // CHECK-NEXT: [[Y:%.*]] = alloca [[A:%.*]],
14     // CHECK-NEXT: [[Z:%.*]] = alloca [[A]]
15     // CHECK-NEXT: [[EXN:%.*]] = alloca i8*
16     // CHECK-NEXT: [[SEL:%.*]] = alloca i32
17     // CHECK-NEXT: [[V:%.*]] = alloca [[V:%.*]]*,
18     // CHECK-NEXT: [[TMP:%.*]] = alloca [[A]]
19     // CHECK-NEXT: [[CLEANUPACTIVE:%.*]] = alloca i1
20     // CHECK:      call void @_ZN5test01AC1Ev([[A]]* {{[^,]*}} [[Y]])
21     // CHECK-NEXT: invoke void @_ZN5test01AC1Ev([[A]]* {{[^,]*}} [[Z]])
22     // CHECK:      [[NEW:%.*]] = invoke noalias nonnull i8* @_Znwm(i64 1)
23     // CHECK:      store i1 true, i1* [[CLEANUPACTIVE]]
24     // CHECK:      [[NEWCAST:%.*]] = bitcast i8* [[NEW]] to [[V]]*
25     // CHECK-NEXT: invoke void @_ZN5test01AC1Ev([[A]]* {{[^,]*}} [[TMP]])
26     // CHECK:      invoke void @_ZN5test01VC1ERKNS_1AE([[V]]* {{[^,]*}} [[NEWCAST]], [[A]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[TMP]])
27     // CHECK:      store i1 false, i1* [[CLEANUPACTIVE]]
28 
29     // CHECK98-NEXT: invoke void @_ZN5test01AD1Ev([[A]]* {{[^,]*}} [[TMP]])
30     // CHECK11-NEXT: call void @_ZN5test01AD1Ev([[A]]* {{[^,]*}} [[TMP]])
31     A y;
32     try {
33       A z;
34       V *v = new V();
35 
36       if (x) return 1;
37     } catch (int ex) {
38       return 1;
39     }
40     return 0;
41   }
42 
test()43   int test() {
44     return test<0>(5);
45   }
46 }
47