• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - | FileCheck %s
2 
3 template <class T> void takeItByValue(T);
4 void takeABlock(void (^)());
5 
6 // rdar://problem/11022704
7 namespace test_int {
test()8   void test() {
9     const int x = 100;
10     takeABlock(^{ takeItByValue(x); });
11     // CHECK: call void @_Z13takeItByValueIiEvT_(i32 100)
12   }
13 }
14 
15 namespace test_int_ref {
test()16   void test() {
17     const int y = 200;
18     const int &x = y;
19     takeABlock(^{ takeItByValue(x); });
20 
21     // TODO: there's no good reason that this isn't foldable.
22     // CHECK: call void @_Z13takeItByValueIiEvT_(i32 {{%.*}})
23   }
24 }
25 
26 namespace test_float {
test()27   void test() {
28     const float x = 1;
29     takeABlock(^{ takeItByValue(x); });
30     // CHECK: call void @_Z13takeItByValueIfEvT_(float 1.0
31   }
32 }
33 
34 namespace test_float_ref {
test()35   void test() {
36     const float y = 100;
37     const float &x = y;
38     takeABlock(^{ takeItByValue(x); });
39 
40     // TODO: there's no good reason that this isn't foldable.
41     // CHECK: call void @_Z13takeItByValueIfEvT_(float {{%.*}})
42   }
43 }
44 
45 namespace test_complex_int {
test()46   void test() {
47     constexpr _Complex int x = 500;
48     takeABlock(^{ takeItByValue(x); });
49     // CHECK:      store i32 500,
50 
51     // CHECK:      store i32 500,
52     // CHECK-NEXT: store i32 0,
53     // CHECK-NEXT: [[COERCE:%.*]] = bitcast
54     // CHECK-NEXT: [[CVAL:%.*]] = load i64* [[COERCE]]
55     // CHECK-NEXT: call void @_Z13takeItByValueICiEvT_(i64 [[CVAL]])
56   }
57 }
58 
59 namespace test_complex_int_ref {
test()60   void test() {
61     const _Complex int y = 100;
62     const _Complex int &x = y;
63     takeABlock(^{ takeItByValue(x); });
64     // CHECK: call void @_Z13takeItByValueICiEvT_(i64
65   }
66 }
67 
68 namespace test_complex_int_ref_mutable {
69   _Complex int y = 100;
test()70   void test() {
71     const _Complex int &x = y;
72     takeABlock(^{ takeItByValue(x); });
73     // CHECK:      [[R:%.*]] = load i32* getelementptr inbounds ({ i32, i32 }* @_ZN28test_complex_int_ref_mutable1yE, i32 0, i32 0)
74     // CHECK-NEXT: [[I:%.*]] = load i32* getelementptr inbounds ({ i32, i32 }* @_ZN28test_complex_int_ref_mutable1yE, i32 0, i32 1)
75     // CHECK-NEXT: [[RSLOT:%.*]] = getelementptr inbounds { i32, i32 }* [[CSLOT:%.*]], i32 0, i32 0
76     // CHECK-NEXT: [[ISLOT:%.*]] = getelementptr inbounds { i32, i32 }* [[CSLOT]], i32 0, i32 1
77     // CHECK-NEXT: store i32 [[R]], i32* [[RSLOT]]
78     // CHECK-NEXT: store i32 [[I]], i32* [[ISLOT]]
79     // CHECK-NEXT: [[COERCE:%.*]] = bitcast { i32, i32 }* [[CSLOT]] to i64*
80     // CHECK-NEXT: [[CVAL:%.*]] = load i64* [[COERCE]],
81     // CHECK-NEXT: call void @_Z13takeItByValueICiEvT_(i64 [[CVAL]])
82   }
83 }
84 
85