150
|
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-runtime-has-weak -o - -std=c++11 %s | FileCheck %s
|
|
2
|
|
3 // CHECK: %[[TYPE:[a-z0-9]+]] = type opaque
|
|
4 // CHECK: @[[CFSTRING:[a-z0-9_]+]] = private global %struct.__NSConstantString_tag
|
|
5 @class NSString;
|
|
6
|
|
7 // CHECK-LABEL: define void @_Z5test1v
|
|
8 // CHECK: %[[ALLOCA:[A-Z]+]] = alloca %[[TYPE]]*
|
|
9 // CHECK: %[[V0:[0-9]+]] = call i8* @llvm.objc.retain(i8* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]]
|
|
10 // CHECK: %[[V1:[0-9]+]] = bitcast i8* %[[V0]] to %[[TYPE]]*
|
|
11 // CHECK: store %[[TYPE]]* %[[V1]], %[[TYPE]]** %[[ALLOCA]]
|
|
12 // CHECK: %[[V2:[0-9]+]] = bitcast %[[TYPE]]** %[[ALLOCA]]
|
|
13 // CHECK: call void @llvm.objc.storeStrong(i8** %[[V2]], i8* null)
|
|
14 void test1() {
|
|
15 constexpr NSString *S = @"abc";
|
|
16 }
|
|
17
|
|
18 // CHECK-LABEL: define void @_Z5test2v
|
|
19 // CHECK: %[[CONST:[a-zA-Z]+]] = alloca %[[TYPE]]*
|
|
20 // CHECK: %[[REF_CONST:[a-zA-Z]+]] = alloca %[[TYPE]]*
|
|
21 // CHECK: %[[V0:[0-9]+]] = call i8* @llvm.objc.retain(i8* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]]
|
|
22 // CHECK-NEXT: %[[V1:[0-9]+]] = bitcast i8* %[[V0]] to %[[TYPE]]*
|
|
23 // CHECK-NEXT: store %[[TYPE]]* %[[V1]], %[[TYPE]]** %[[CONST]]
|
|
24 // CHECK: %[[V2:[0-9]+]] = call i8* @llvm.objc.retain(i8* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]]
|
|
25 // CHECK-NEXT: %[[V3:[0-9]+]] = bitcast i8* %[[V2]] to %[[TYPE]]*
|
|
26 // CHECK-NEXT: store %[[TYPE]]* %[[V3]], %[[TYPE]]** %[[REF_CONST]]
|
|
27 // CHECK: %[[V4:[0-9]+]] = bitcast %[[TYPE]]** %[[REF_CONST]]
|
|
28 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** %[[V4]], i8* null)
|
|
29 // CHECK: %[[V5:[0-9]+]] = bitcast %[[TYPE]]** %[[CONST]]
|
|
30 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** %[[V5]], i8* null)
|
|
31 void test2() {
|
|
32 constexpr NSString *Const = @"abc";
|
|
33 // In IR RefConst should be initialized with Const initializer instead of
|
|
34 // reading from variable.
|
|
35 NSString* RefConst = Const;
|
|
36 }
|
|
37
|
|
38 // CHECK-LABEL: define void @_Z5test3v
|
|
39 // CHECK: %[[WEAK_CONST:[a-zA-Z]+]] = alloca %[[TYPE]]*
|
|
40 // CHECK: %[[REF_WEAK_CONST:[a-zA-Z]+]] = alloca %[[TYPE]]*
|
|
41 // CHECK: %[[V0:[0-9]+]] = bitcast %[[TYPE]]** %[[WEAK_CONST]]
|
|
42 // CHECK-NEXT: %[[V1:[0-9]+]] = call i8* @llvm.objc.initWeak(i8** %[[V0]], i8* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]]
|
|
43 // CHECK: store %[[TYPE]]* bitcast (%struct.__NSConstantString_tag* @[[CFSTRING]] to %[[TYPE]]*), %[[TYPE]]** %[[REF_WEAK_CONST]]
|
|
44 // CHECK: %[[V2:[0-9]+]] = bitcast %[[TYPE]]** %[[REF_WEAK_CONST]]
|
|
45 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** %[[V2]], i8* null)
|
|
46 // CHECK: %[[V3:[0-9]+]] = bitcast %[[TYPE]]** %[[WEAK_CONST]]
|
|
47 // CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** %[[V3]])
|
|
48 void test3() {
|
|
49 __weak constexpr NSString *WeakConst = @"abc";
|
|
50 NSString* RefWeakConst = WeakConst;
|
|
51 }
|