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