File: arc-blocks.mm

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (45 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -emit-pch %s -o %t
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks -std=c++1y -include-pch %t -fobjc-avoid-heapify-local-blocks -emit-llvm -o - %s | FileCheck %s

#ifndef HEADER_INCLUDED
#define HEADER_INCLUDED

namespace test_block_retain {
  typedef void (^BlockTy)();
  void foo1(id);

  inline void initialization(id a) {
    // Call to @llvm.objc.retainBlock isn't needed.
    BlockTy b0 = ^{ foo1(a); };
    b0();
  }

  inline void assignmentConditional(id a, bool c) {
    BlockTy b0;
    if (c)
      // @llvm.objc.retainBlock is called since 'b0' is declared in the outer scope.
      b0 = ^{ foo1(a); };
    b0();
  }
}

#else

namespace test_block_retain {
// CHECK-LABEL: define linkonce_odr void @_ZN17test_block_retain14initializationEP11objc_object(
// CHECK-NOT: call i8* @llvm.objc.retainBlock(

  void test_initialization(id a) {
    initialization(a);
  }

// CHECK-LABEL: define{{.*}} void @_ZN17test_block_retain26test_assignmentConditionalEP11objc_objectb(
// CHECK: %[[BLOCK:.*]] = alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 8
// CHECK: call ptr @llvm.objc.retainBlock(ptr %[[BLOCK]])

  void test_assignmentConditional(id a, bool c) {
    assignmentConditional(a, c);
  }
}

#endif