2012-03-07 04:05:56 +08:00
|
|
|
// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
#include "literal-support.h"
|
|
|
|
|
|
|
|
// Check the various selector names we'll be using, in order.
|
|
|
|
|
|
|
|
// CHECK: c"numberWithInt:\00"
|
|
|
|
// CHECK: c"numberWithUnsignedInt:\00"
|
|
|
|
// CHECK: c"numberWithUnsignedLongLong:\00"
|
|
|
|
// CHECK: c"numberWithChar:\00"
|
2014-10-29 02:28:16 +08:00
|
|
|
// CHECK: c"arrayWithObjects:count:\00"
|
|
|
|
// CHECK: c"dictionaryWithObjects:forKeys:count:\00"
|
2012-03-07 04:05:56 +08:00
|
|
|
// CHECK: c"prop\00"
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test_numeric()
|
2012-03-07 04:05:56 +08:00
|
|
|
void test_numeric() {
|
|
|
|
// CHECK: {{call.*objc_msgSend.*i32 17}}
|
|
|
|
// CHECK: call i8* @objc_retainAutoreleasedReturnValue
|
|
|
|
id ilit = @17;
|
|
|
|
// CHECK: {{call.*objc_msgSend.*i32 25}}
|
|
|
|
// CHECK: call i8* @objc_retainAutoreleasedReturnValue
|
|
|
|
id ulit = @25u;
|
|
|
|
// CHECK: {{call.*objc_msgSend.*i64 42}}
|
|
|
|
// CHECK: call i8* @objc_retainAutoreleasedReturnValue
|
|
|
|
id ulllit = @42ull;
|
|
|
|
// CHECK: {{call.*objc_msgSend.*i8 signext 97}}
|
|
|
|
// CHECK: call i8* @objc_retainAutoreleasedReturnValue
|
|
|
|
id charlit = @'a';
|
|
|
|
// CHECK: call void @objc_release
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: call void @llvm.lifetime.end
|
2012-03-07 04:05:56 +08:00
|
|
|
// CHECK: call void @objc_release
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: call void @llvm.lifetime.end
|
2012-03-07 04:05:56 +08:00
|
|
|
// CHECK: call void @objc_release
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: call void @llvm.lifetime.end
|
2012-03-07 04:05:56 +08:00
|
|
|
// CHECK: call void @objc_release
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: call void @llvm.lifetime.end
|
2012-03-07 04:05:56 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test_array
|
2012-03-07 04:05:56 +08:00
|
|
|
void test_array(id a, id b) {
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK: [[A:%.*]] = alloca i8*,
|
|
|
|
// CHECK: [[B:%.*]] = alloca i8*,
|
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
// Retaining parameters
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
|
|
|
|
// Constructing the array
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[A]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[B]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
|
|
|
|
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
|
2014-10-29 02:28:16 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 2)
|
|
|
|
// CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]])
|
2015-04-17 07:25:00 +08:00
|
|
|
// CHECK: call void (...) @clang.arc.use(i8* [[V0]], i8* [[V1]])
|
2012-03-07 04:05:56 +08:00
|
|
|
id arr = @[a, b];
|
|
|
|
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test_dictionary
|
2012-03-07 04:05:56 +08:00
|
|
|
void test_dictionary(id k1, id o1, id k2, id o2) {
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK: [[K1:%.*]] = alloca i8*,
|
|
|
|
// CHECK: [[O1:%.*]] = alloca i8*,
|
|
|
|
// CHECK: [[K2:%.*]] = alloca i8*,
|
|
|
|
// CHECK: [[O2:%.*]] = alloca i8*,
|
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
// Retaining parameters
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
// CHECK: call i8* @objc_retain(i8*
|
|
|
|
|
|
|
|
// Constructing the arrays
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[K1]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V0]], i8** [[T0]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[O1]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V2:%.*]] = load i8*, i8** [[K2]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V2]], i8** [[T0]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[V3:%.*]] = load i8*, i8** [[O2]],
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: store i8* [[V3]], i8** [[T0]]
|
2012-03-07 04:05:56 +08:00
|
|
|
|
|
|
|
// Constructing the dictionary
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST
|
|
|
|
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
|
2014-10-29 02:28:16 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8**
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = bitcast [2 x i8*]* [[KEYS]] to i8**
|
|
|
|
// CHECK-NEXT: [[T4:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i8** [[T3]], i64 2)
|
|
|
|
// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
|
2015-04-17 07:25:00 +08:00
|
|
|
// CHECK-NEXT: call void (...) @clang.arc.use(i8* [[V0]], i8* [[V1]], i8* [[V2]], i8* [[V3]])
|
2013-04-04 08:20:38 +08:00
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
id dict = @{ k1 : o1, k2 : o2 };
|
|
|
|
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface A
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface B
|
|
|
|
@property (retain) A* prop;
|
|
|
|
@end
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @test_property
|
2012-03-07 04:05:56 +08:00
|
|
|
void test_property(B *b) {
|
|
|
|
// Retain parameter
|
|
|
|
// CHECK: call i8* @objc_retain
|
|
|
|
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[T0:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[OBJECTS:%.*]], i32 0, i32 0
|
2013-04-04 08:20:38 +08:00
|
|
|
|
2012-03-07 04:05:56 +08:00
|
|
|
// Invoke 'prop'
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast
|
|
|
|
// CHECK-NEXT: [[T2:%.*]] = call [[B:%.*]]* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]])
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = bitcast [[B]]* [[T2]] to i8*
|
|
|
|
// CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]])
|
|
|
|
// CHECK-NEXT: [[V0:%.*]] = bitcast i8* [[T4]] to [[B]]*
|
|
|
|
// CHECK-NEXT: [[V1:%.*]] = bitcast [[B]]* [[V0]] to i8*
|
|
|
|
|
|
|
|
// Store to array.
|
|
|
|
// CHECK-NEXT: store i8* [[V1]], i8** [[T0]]
|
2012-03-07 04:05:56 +08:00
|
|
|
|
2014-10-29 02:28:16 +08:00
|
|
|
// Invoke arrayWithObjects:count:
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T]]*, [[CLASS_T]]** @"OBJC_CLASSLIST
|
|
|
|
// CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8*
|
2014-10-29 02:28:16 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = bitcast [1 x i8*]* [[OBJECTS]] to i8**
|
|
|
|
// CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}}(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 1)
|
|
|
|
// CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]])
|
2015-04-17 07:25:00 +08:00
|
|
|
// CHECK-NEXT: call void (...) @clang.arc.use(i8* [[V1]])
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: store
|
2012-03-07 04:05:56 +08:00
|
|
|
id arr = @[ b.prop ];
|
|
|
|
|
|
|
|
// Release b.prop
|
2013-04-04 08:20:38 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[V0]] to i8*
|
|
|
|
// CHECK-NEXT: call void @objc_release(i8* [[T0]])
|
2012-03-07 04:05:56 +08:00
|
|
|
|
|
|
|
// Destroy arr
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
|
|
|
|
// Destroy b
|
|
|
|
// CHECK: call void @objc_release
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|