File: arc-attrs.mm

package info (click to toggle)
llvm-toolchain-3.4 1%3A3.4.2-13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 253,236 kB
  • ctags: 276,203
  • sloc: cpp: 1,665,580; ansic: 298,647; asm: 206,157; objc: 84,350; python: 73,119; sh: 23,466; perl: 5,679; makefile: 5,542; ml: 5,250; pascal: 2,467; lisp: 1,420; xml: 679; cs: 236; csh: 117
file content (48 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (8)
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
46
47
48
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-arc -o - %s | FileCheck %s

id makeObject1() __attribute__((ns_returns_retained));
id makeObject2() __attribute__((ns_returns_retained));
void releaseObject(__attribute__((ns_consumed)) id);

// CHECK-LABEL: define void @_Z10sanityTestv
void sanityTest() {
  // CHECK: [[X:%.*]] = alloca i8*, align 8
  // CHECK-NEXT: [[OBJ1:%.*]] = call i8* @_Z11makeObject1v()
  // CHECK-NEXT: store i8* [[OBJ1]], i8** [[X]], align 8
  id x = makeObject1();

  // CHECK-NEXT: [[OBJ2:%.*]] = call i8* @_Z11makeObject2v()
  // CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
  releaseObject(makeObject2());

  // CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
  // CHECK-NEXT: ret void
}


template <typename T>
T makeObjectT1() __attribute__((ns_returns_retained));
template <typename T>
T makeObjectT2() __attribute__((ns_returns_retained));

template <typename T>
void releaseObjectT(__attribute__((ns_consumed)) T);  

// CHECK-LABEL: define void @_Z12templateTestv
void templateTest() {
  // CHECK: [[X:%.*]] = alloca i8*, align 8
  // CHECK-NEXT: [[OBJ1:%.*]] = call i8* @_Z12makeObjectT1IU8__strongP11objc_objectET_v()
  // CHECK-NEXT: store i8* [[OBJ1]], i8** [[X]], align 8
  id x = makeObjectT1<id>();

  // CHECK-NEXT: [[OBJ2:%.*]] = call i8* @_Z12makeObjectT2IU8__strongP11objc_objectET_v()
  // CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
  releaseObject(makeObjectT2<id>());

  // CHECK-NEXT: [[OBJ3:%.*]] = call i8* @_Z11makeObject1v()
  // CHECK-NEXT: call void @_Z14releaseObjectTIU8__strongP11objc_objectEvT_(i8* [[OBJ3]])
  releaseObjectT(makeObject1());

  // CHECK-NEXT: call void @objc_storeStrong(i8** [[X]], i8* null)
  // CHECK-NEXT: ret void
}