xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/for-range-temporaries.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR %s | opt -instnamer -S | FileCheck %s
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR %s | opt -instnamer -S | FileCheck %s
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE %s | opt -instnamer -S | FileCheck %s
4*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE %s | opt -instnamer -S | FileCheck %s
5*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE -DDEPENDENT %s | opt -instnamer -S | FileCheck %s
6*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE -DDEPENDENT %s | opt -instnamer -S | FileCheck %s
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc struct A {
9*f4a2713aSLionel Sambuc   A();
10*f4a2713aSLionel Sambuc   A(const A &);
11*f4a2713aSLionel Sambuc   ~A();
12*f4a2713aSLionel Sambuc };
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc struct B {
15*f4a2713aSLionel Sambuc   B();
16*f4a2713aSLionel Sambuc   B(const B &);
17*f4a2713aSLionel Sambuc   ~B();
18*f4a2713aSLionel Sambuc };
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc struct C {
21*f4a2713aSLionel Sambuc   C(const B &);
22*f4a2713aSLionel Sambuc   C(const C &);
23*f4a2713aSLionel Sambuc   ~C();
24*f4a2713aSLionel Sambuc };
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc struct E;
27*f4a2713aSLionel Sambuc struct D {
28*f4a2713aSLionel Sambuc   D(const C &);
29*f4a2713aSLionel Sambuc   D(const D &);
30*f4a2713aSLionel Sambuc   ~D();
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc E begin(D);
33*f4a2713aSLionel Sambuc E end(D);
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc struct F;
36*f4a2713aSLionel Sambuc struct G;
37*f4a2713aSLionel Sambuc struct H;
38*f4a2713aSLionel Sambuc struct E {
39*f4a2713aSLionel Sambuc   E(const E &);
40*f4a2713aSLionel Sambuc   ~E();
41*f4a2713aSLionel Sambuc   F operator*();
42*f4a2713aSLionel Sambuc   G operator++();
43*f4a2713aSLionel Sambuc   H operator!=(const E &o);
44*f4a2713aSLionel Sambuc };
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc struct I;
47*f4a2713aSLionel Sambuc struct F {
48*f4a2713aSLionel Sambuc   F(const F &);
49*f4a2713aSLionel Sambuc   ~F();
50*f4a2713aSLionel Sambuc   operator I();
51*f4a2713aSLionel Sambuc };
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc struct G {
54*f4a2713aSLionel Sambuc   G(const G &);
55*f4a2713aSLionel Sambuc   ~G();
56*f4a2713aSLionel Sambuc   operator bool();
57*f4a2713aSLionel Sambuc };
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc struct H {
60*f4a2713aSLionel Sambuc   H(const H &);
61*f4a2713aSLionel Sambuc   ~H();
62*f4a2713aSLionel Sambuc   operator bool();
63*f4a2713aSLionel Sambuc };
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc struct I {
66*f4a2713aSLionel Sambuc   I(const I &);
67*f4a2713aSLionel Sambuc   ~I();
68*f4a2713aSLionel Sambuc };
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc void body(const I &);
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc #ifdef TEMPLATE
73*f4a2713aSLionel Sambuc #ifdef DEPENDENT
74*f4a2713aSLionel Sambuc template<typename D>
75*f4a2713aSLionel Sambuc #else
76*f4a2713aSLionel Sambuc template<typename>
77*f4a2713aSLionel Sambuc #endif
78*f4a2713aSLionel Sambuc #endif
for_temps()79*f4a2713aSLionel Sambuc void for_temps() {
80*f4a2713aSLionel Sambuc   A a;
81*f4a2713aSLionel Sambuc #ifdef DESUGAR
82*f4a2713aSLionel Sambuc   {
83*f4a2713aSLionel Sambuc     auto && __range = D(B());
84*f4a2713aSLionel Sambuc     for (auto __begin = begin(__range), __end = end(__range);
85*f4a2713aSLionel Sambuc          __begin != __end; ++__begin) {
86*f4a2713aSLionel Sambuc       I i = *__begin;
87*f4a2713aSLionel Sambuc       body(i);
88*f4a2713aSLionel Sambuc     }
89*f4a2713aSLionel Sambuc   }
90*f4a2713aSLionel Sambuc #else
91*f4a2713aSLionel Sambuc   for (I i : D(B())) {
92*f4a2713aSLionel Sambuc     body(i);
93*f4a2713aSLionel Sambuc   }
94*f4a2713aSLionel Sambuc #endif
95*f4a2713aSLionel Sambuc }
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc #ifdef TEMPLATE
98*f4a2713aSLionel Sambuc template void for_temps<D>();
99*f4a2713aSLionel Sambuc #endif
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc // CHECK: define {{.*}}for_temps
102*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AC1Ev(
103*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BC1Ev(
104*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1CC1ERK1B(
105*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1DC1ERK1C(
106*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1CD1Ev(
107*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1BD1Ev(
108*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1DC1ERKS_(
109*f4a2713aSLionel Sambuc // CHECK: call void @_Z5begin1D(
110*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1DD1Ev(
111*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1DC1ERKS_(
112*f4a2713aSLionel Sambuc // CHECK: call void @_Z3end1D(
113*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1DD1Ev(
114*f4a2713aSLionel Sambuc // CHECK: br label %[[COND:.*]]
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc // CHECK: [[COND]]:
117*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1EneERKS_(
118*f4a2713aSLionel Sambuc // CHECK: %[[CMP:.*]] = call zeroext i1 @_ZN1HcvbEv(
119*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1HD1Ev(
120*f4a2713aSLionel Sambuc // CHECK: br i1 %[[CMP]], label %[[BODY:.*]], label %[[CLEANUP:.*]]
121*f4a2713aSLionel Sambuc 
122*f4a2713aSLionel Sambuc // CHECK: [[CLEANUP]]:
123*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1ED1Ev(
124*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1ED1Ev(
125*f4a2713aSLionel Sambuc // In for-range:
126*f4a2713aSLionel Sambuc // call void @_ZN1DD1Ev(
127*f4a2713aSLionel Sambuc // CHECK: br label %[[END:.*]]
128*f4a2713aSLionel Sambuc 
129*f4a2713aSLionel Sambuc // CHECK: [[BODY]]:
130*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1EdeEv(
131*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1Fcv1IEv(
132*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1FD1Ev(
133*f4a2713aSLionel Sambuc // CHECK: call void @_Z4bodyRK1I(
134*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1ID1Ev(
135*f4a2713aSLionel Sambuc // CHECK: br label %[[INC:.*]]
136*f4a2713aSLionel Sambuc 
137*f4a2713aSLionel Sambuc // CHECK: [[INC]]:
138*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1EppEv(
139*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1GD1Ev(
140*f4a2713aSLionel Sambuc // CHECK: br label %[[COND]]
141*f4a2713aSLionel Sambuc 
142*f4a2713aSLionel Sambuc // CHECK: [[END]]:
143*f4a2713aSLionel Sambuc // In desugared version:
144*f4a2713aSLionel Sambuc // call void @_ZN1DD1Ev(
145*f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AD1Ev(
146*f4a2713aSLionel Sambuc // CHECK: ret void
147