1// RUN: %clang_cc1 -emit-llvm -fblocks -o - -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s | FileCheck %s
2
3// CHECK: @_ZZZN26externally_visible_statics1S3fooEiEd_Ub0_E1k = linkonce_odr global i32 0
4// CHECK: @_ZZ26externally_visible_statics1S1xMUb0_E1j = linkonce_odr global i32 0
5// CHECK: @_ZZZN26externally_visible_statics10inlinefuncEvEUb0_E1i = linkonce_odr global i32 0
6
7int f();
8
9void foo() {
10  // CHECK-LABEL: define internal i32 @___Z3foov_block_invoke
11  // CHECK: call i32 @__cxa_guard_acquire(i64* @_ZGVZZ3foovEUb_E5value
12  (void)^(int x) {
13    static int value = f();
14    return x + value;
15  };
16}
17
18// CHECK-LABEL: define internal i32 @i_block_invoke
19int i = ^(int x) { return x;}(i);
20
21@interface A
22- (void)method;
23@end
24
25@implementation A
26- (void)method {
27  // CHECK: define internal signext i8 @"__11-[A method]_block_invoke"
28  (void)^(int x) {
29    // CHECK: @"_ZZZ11-[A method]EUb1_E4name"
30    static const char *name = "hello";
31    return name[x];
32  };
33}
34@end
35
36void foo(int) {
37  (void)^(int x) {
38    static const char *name = "hello";
39    return name[x];
40  };
41}
42
43namespace N {
44  // CHECK-LABEL: define internal signext i8 @___Z3fooi_block_invoke
45  void bar() {
46    (void)^(int x) {
47      // CHECK: @_ZZZN1N3barEvEUb3_E4name
48      static const char *name = "hello";
49      return name[x];
50    };
51  }
52}
53
54class C {
55  C();
56};
57C::C() {
58  (void)^(int x) {
59    // CHECK: @_ZZZN1CC1EvEUb4_E5nameb
60    static const char *nameb = "hello";
61    return nameb[x];
62  };
63}
64
65int f();
66namespace externally_visible_statics {
67  inline void inlinefunc() {
68    ^{
69      static int i = f();
70    }();
71  }
72  struct S {
73    int x = ^{
74      static int j = f();
75      return j;
76    }();
77    void foo(int y = ^{ static int k = f(); return k; }()) {}
78  };
79  void g() {
80    inlinefunc();
81    S s;
82    s.foo();
83  }
84}
85