2013-09-04 12:12:25 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-arc -o - %s | FileCheck %s
|
2013-03-09 06:25:36 +08:00
|
|
|
|
|
|
|
id makeObject1() __attribute__((ns_returns_retained));
|
|
|
|
id makeObject2() __attribute__((ns_returns_retained));
|
|
|
|
void releaseObject(__attribute__((ns_consumed)) id);
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z10sanityTestv
|
2013-03-09 06:25:36 +08:00
|
|
|
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()
|
2016-05-25 22:15:08 +08:00
|
|
|
// CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
|
2013-03-09 06:25:36 +08:00
|
|
|
releaseObject(makeObject2());
|
|
|
|
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[X]], i8* null)
|
2013-03-09 06:25:36 +08:00
|
|
|
// 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);
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z12templateTestv
|
2013-03-09 06:25:36 +08:00
|
|
|
void templateTest() {
|
|
|
|
// CHECK: [[X:%.*]] = alloca i8*, align 8
|
2016-05-25 22:15:08 +08:00
|
|
|
// CHECK-NEXT: [[OBJ1:%.*]] = call i8* @_Z12makeObjectT1IU8__strongP11objc_objectET_v()
|
2013-03-09 06:25:36 +08:00
|
|
|
// CHECK-NEXT: store i8* [[OBJ1]], i8** [[X]], align 8
|
|
|
|
id x = makeObjectT1<id>();
|
|
|
|
|
2016-05-25 22:15:08 +08:00
|
|
|
// CHECK-NEXT: [[OBJ2:%.*]] = call i8* @_Z12makeObjectT2IU8__strongP11objc_objectET_v()
|
|
|
|
// CHECK-NEXT: call void @_Z13releaseObjectP11objc_object(i8* [[OBJ2]])
|
2013-03-09 06:25:36 +08:00
|
|
|
releaseObject(makeObjectT2<id>());
|
|
|
|
|
|
|
|
// CHECK-NEXT: [[OBJ3:%.*]] = call i8* @_Z11makeObject1v()
|
2016-05-25 22:15:08 +08:00
|
|
|
// CHECK-NEXT: call void @_Z14releaseObjectTIU8__strongP11objc_objectEvT_(i8* [[OBJ3]])
|
2013-03-09 06:25:36 +08:00
|
|
|
releaseObjectT(makeObject1());
|
|
|
|
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[X]], i8* null)
|
2013-03-09 06:25:36 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
2016-11-18 09:08:24 +08:00
|
|
|
|
|
|
|
// PR27887
|
|
|
|
struct ForwardConsumed {
|
|
|
|
ForwardConsumed(__attribute__((ns_consumed)) id x);
|
|
|
|
};
|
|
|
|
|
|
|
|
ForwardConsumed::ForwardConsumed(__attribute__((ns_consumed)) id x) {}
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK: define{{.*}} void @_ZN15ForwardConsumedC2EP11objc_object(
|
2016-11-18 09:08:24 +08:00
|
|
|
// CHECK-NOT: objc_retain
|
|
|
|
// CHECK: store i8* {{.*}}, i8** [[X:%.*]],
|
|
|
|
// CHECK-NOT: [[X]]
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call void @llvm.objc.storeStrong(i8** [[X]], i8* null)
|
2016-11-18 09:08:24 +08:00
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK: define{{.*}} void @_ZN15ForwardConsumedC1EP11objc_object(
|
2016-11-18 09:08:24 +08:00
|
|
|
// CHECK-NOT: objc_retain
|
|
|
|
// CHECK: store i8* {{.*}}, i8** [[X:%.*]],
|
|
|
|
// CHECK: [[T0:%.*]] = load i8*, i8** [[X]],
|
|
|
|
// CHECK-NEXT: store i8* null, i8** [[X]],
|
|
|
|
// CHECK-NEXT: call void @_ZN15ForwardConsumedC2EP11objc_object({{.*}}, i8* [[T0]])
|
2018-12-19 04:33:00 +08:00
|
|
|
// CHECK: call void @llvm.objc.storeStrong(i8** [[X]], i8* null)
|