From 611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 17 Jul 2011 15:40:56 +0000 Subject: Vendor import of clang trunk r135360: http://llvm.org/svn/llvm-project/cfe/trunk@135360 --- test/CodeGenObjC/arc-arm.m | 20 + test/CodeGenObjC/arc-block-ivar-layout.m | 60 ++ test/CodeGenObjC/arc-bridged-cast.m | 90 ++ test/CodeGenObjC/arc-compound-stmt.m | 29 + test/CodeGenObjC/arc-foreach.m | 72 ++ test/CodeGenObjC/arc-ivar-layout.m | 44 + test/CodeGenObjC/arc-no-runtime.m | 9 + test/CodeGenObjC/arc-related-result-type.m | 30 + test/CodeGenObjC/arc-unbridged-cast.m | 37 + test/CodeGenObjC/arc-unopt.m | 69 ++ test/CodeGenObjC/arc-weak-property.m | 55 + test/CodeGenObjC/arc.m | 1554 ++++++++++++++++++++++++++++ test/CodeGenObjC/autorelease.m | 30 + test/CodeGenObjC/block-6.m | 14 +- test/CodeGenObjC/blocks.m | 10 +- test/CodeGenObjC/debug-info-foreach.m | 20 - test/CodeGenObjC/encode-test.m | 4 + test/CodeGenObjC/exceptions-nonfragile.m | 16 +- test/CodeGenObjC/gc.m | 14 + test/CodeGenObjC/mrr-autorelease.m | 24 + test/CodeGenObjC/nonlazy-msgSend.m | 6 + test/CodeGenObjC/property-list-in-class.m | 4 +- test/CodeGenObjC/related-result-type.m | 54 + test/CodeGenObjC/terminate.m | 29 + test/CodeGenObjC/variadic-sends.m | 8 +- 25 files changed, 2266 insertions(+), 36 deletions(-) create mode 100644 test/CodeGenObjC/arc-arm.m create mode 100644 test/CodeGenObjC/arc-block-ivar-layout.m create mode 100644 test/CodeGenObjC/arc-bridged-cast.m create mode 100644 test/CodeGenObjC/arc-compound-stmt.m create mode 100644 test/CodeGenObjC/arc-foreach.m create mode 100644 test/CodeGenObjC/arc-ivar-layout.m create mode 100644 test/CodeGenObjC/arc-no-runtime.m create mode 100644 test/CodeGenObjC/arc-related-result-type.m create mode 100644 test/CodeGenObjC/arc-unbridged-cast.m create mode 100644 test/CodeGenObjC/arc-unopt.m create mode 100644 test/CodeGenObjC/arc-weak-property.m create mode 100644 test/CodeGenObjC/arc.m create mode 100644 test/CodeGenObjC/autorelease.m delete mode 100644 test/CodeGenObjC/debug-info-foreach.m create mode 100644 test/CodeGenObjC/gc.m create mode 100644 test/CodeGenObjC/mrr-autorelease.m create mode 100644 test/CodeGenObjC/nonlazy-msgSend.m create mode 100644 test/CodeGenObjC/related-result-type.m create mode 100644 test/CodeGenObjC/terminate.m (limited to 'test/CodeGenObjC') diff --git a/test/CodeGenObjC/arc-arm.m b/test/CodeGenObjC/arc-arm.m new file mode 100644 index 0000000..a3d55c2 --- /dev/null +++ b/test/CodeGenObjC/arc-arm.m @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple armv7-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -o - %s | FileCheck %s + +id test0(void) { + extern id test0_helper(void); + // CHECK: [[T0:%.*]] = call arm_aapcscc i8* @test0_helper() + // CHECK-NEXT: ret i8* [[T0]] + return test0_helper(); +} + +void test1(void) { + extern id test1_helper(void); + // CHECK: [[T0:%.*]] = call arm_aapcscc i8* @test1_helper() + // CHECK-NEXT: call void asm sideeffect "mov\09r7, r7 + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], + // CHECK-NEXT: load + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: ret void + id x = test1_helper(); +} diff --git a/test/CodeGenObjC/arc-block-ivar-layout.m b/test/CodeGenObjC/arc-block-ivar-layout.m new file mode 100644 index 0000000..50c35ba --- /dev/null +++ b/test/CodeGenObjC/arc-block-ivar-layout.m @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://8991729 + +__weak id wid; +void x(id y) {} +void y(int a) {} + +extern id opaque_id(); + +void f() { + __block int byref_int = 0; + char ch = 'a'; + char ch1 = 'b'; + char ch2 = 'c'; + short sh = 2; + const id bar = (id) opaque_id(); + id baz = 0; + __strong id strong_void_sta; + __block id byref_bab = (id)0; + __block id bl_var1; + int i; double dob; + +// The patterns here are a sequence of bytes, each saying first how +// many sizeof(void*) chunks to skip (high nibble) and then how many +// to scan (low nibble). A zero byte says that we've reached the end +// of the pattern. +// +// All of these patterns start with 01 3x because the block header on +// LP64 consists of an isa pointer (which we're supposed to scan for +// some reason) followed by three words (2 ints, a function pointer, +// and a descriptor pointer). + +// Test 1 +// byref int, short, char, char, char, id, id, strong id, byref id +// 01 35 10 00 +// CHECK-LP64: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [4 x i8] c"\015\10\00" + void (^b)() = ^{ + byref_int = sh + ch+ch1+ch2 ; + x(bar); + x(baz); + x((id)strong_void_sta); + x(byref_bab); + }; + b(); + +// Test 2 +// byref int, short, char, char, char, id, id, strong id, byref void*, byref id +// 01 36 10 00 +// CHECK-LP64: @"\01L_OBJC_CLASS_NAME_{{.*}}" = internal global [4 x i8] c"\016\10\00" + void (^c)() = ^{ + byref_int = sh + ch+ch1+ch2 ; + x(bar); + x(baz); + x((id)strong_void_sta); + x(wid); + bl_var1 = 0; + x(byref_bab); + }; +} diff --git a/test/CodeGenObjC/arc-bridged-cast.m b/test/CodeGenObjC/arc-bridged-cast.m new file mode 100644 index 0000000..3354bda --- /dev/null +++ b/test/CodeGenObjC/arc-bridged-cast.m @@ -0,0 +1,90 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -O2 -disable-llvm-optzns -o - %s | FileCheck %s + +typedef const void *CFTypeRef; +typedef const struct __CFString *CFStringRef; + +@interface NSString +@end + +CFTypeRef CFCreateSomething(void); +CFStringRef CFCreateString(void); +CFTypeRef CFGetSomething(void); +CFStringRef CFGetString(void); + +id CreateSomething(void); +NSString *CreateNSString(void); + +// CHECK: define void @bridge_transfer_from_cf +void bridge_transfer_from_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CFCreateSomething() + id obj1 = (__bridge_transfer id)CFCreateSomething(); + // CHECK-NOT: retain + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CFCreateSomething() + // CHECK-NOT: retain + // CHECK: store i32 13 + (void)(__bridge_transfer id)CFCreateSomething(), *i = 13; + // CHECK: call void @objc_release + // CHECK: store i32 17 + *i = 17; + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_from_cf +void bridge_from_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CFCreateSomething() + id obj1 = (__bridge id)CFCreateSomething(); + // CHECK: objc_retainAutoreleasedReturnValue + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CFCreateSomething() + // CHECK-NOT: release + // CHECK: store i32 13 + (void)(__bridge id)CFCreateSomething(), *i = 13; + // CHECK: store i32 17 + *i = 17; + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_retained_of_cf +void bridge_retained_of_cf(int *i) { + *i = 7; + // CHECK: call i8* @CreateSomething() + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CreateSomething() + (__bridge_retained CFTypeRef)CreateSomething(), *i = 13; + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue + // CHECK: store i32 13 + // CHECK: store i32 17 + *i = 17; + // CHECK-NEXT: ret void +} + +// CHECK: define void @bridge_of_cf +void bridge_of_cf(int *i) { + // CHECK: store i32 7 + *i = 7; + // CHECK: call i8* @CreateSomething() + CFTypeRef cf1 = (__bridge CFTypeRef)CreateSomething(); + // CHECK-NOT: retain + // CHECK: store i32 11 + *i = 11; + // CHECK: call i8* @CreateSomething + (__bridge CFTypeRef)CreateSomething(), *i = 13; + // CHECK: store i32 13 + // CHECK-NOT: release + // CHECK: store i32 17 + *i = 17; + // CHECK-NEXT: ret void +} + diff --git a/test/CodeGenObjC/arc-compound-stmt.m b/test/CodeGenObjC/arc-compound-stmt.m new file mode 100644 index 0000000..946d72f --- /dev/null +++ b/test/CodeGenObjC/arc-compound-stmt.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-arc -o - %s +// rdar://9694706 + +typedef unsigned long NSUInteger; + +@interface NSString +- (NSString *)stringByAppendingString:(NSString *)aString; +- (NSString *)substringFromIndex:(NSUInteger)from; +@end + +@interface MyClass +- (void)inst; +@end + +@implementation MyClass + +- (void)inst; +{ + NSString *propName; + + NSString *capitalPropName = ({ + NSString *cap; + if (propName) + cap = [cap stringByAppendingString:[propName substringFromIndex:1]]; + cap; + }); +} + +@end diff --git a/test/CodeGenObjC/arc-foreach.m b/test/CodeGenObjC/arc-foreach.m new file mode 100644 index 0000000..f9d7782 --- /dev/null +++ b/test/CodeGenObjC/arc-foreach.m @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -emit-llvm %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://9503326 +// rdar://9606600 + +extern void use(id); +extern void use_block(void (^)(void)); +@class NSArray; + +void test0(NSArray *array) { + // 'x' should be initialized without a retain. + // We should actually do a non-constant capture, and that + // capture should require a retain. + for (id x in array) { + use_block(^{ use(x); }); + } +} + +// CHECK-LP64: define void @test0( +// CHECK-LP64: alloca [[ARRAY_T:%.*]]*, +// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, +// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], +// CHECK-LP64-NEXT: alloca [16 x i8*], align 8 +// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 +// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] +// CHECK-LP64-NEXT: store i8* [[T3]], i8** [[X]] + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[X]] +// CHECK-LP64-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]] +// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] +// CHECK-LP64: call void @use_block( +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8** [[T0]] +// CHECK-LP64-NEXT: call void @objc_release(i8* [[T1]]) + +// CHECK-LP64: define internal void @__test0_block_invoke +// CHECK-LP64: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* +// CHECK-LP64-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T2:%.*]] = load i8** [[T0]], align 8 +// CHECK-LP64-NEXT: call void @use(i8* [[T2]]) + +void test1(NSArray *array) { + for (__weak id x in array) { + use_block(^{ use(x); }); + } +} + +// CHECK-LP64: define void @test1( +// CHECK-LP64: alloca [[ARRAY_T:%.*]]*, +// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, +// CHECK-LP64-NEXT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], +// CHECK-LP64-NEXT: alloca [16 x i8*], align 8 +// CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]]* [[STATE]], i32 0, i32 1 +// CHECK-LP64-NEXT: [[T1:%.*]] = load i8*** [[T0]] +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr i8** [[T1]], i64 +// CHECK-LP64-NEXT: [[T3:%.*]] = load i8** [[T2]] +// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T3]]) + +// CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-LP64-NEXT: [[T1:%.*]] = call i8* @objc_loadWeak(i8** [[X]]) +// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[T0]], i8* [[T1]]) +// CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to +// CHECK-LP64: call void @use_block +// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[T0]]) +// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[X]]) diff --git a/test/CodeGenObjC/arc-ivar-layout.m b/test/CodeGenObjC/arc-ivar-layout.m new file mode 100644 index 0000000..cb930fe --- /dev/null +++ b/test/CodeGenObjC/arc-ivar-layout.m @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-weak -triple x86_64-apple-darwin -O0 -S %s -o %t-64.s +// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s +// rdar://8991729 + +@interface NSObject { + id isa; +} +@end + +@interface AllPointers : NSObject { + id foo; + id __strong bar; + NSObject *bletch; +} +@end + +@implementation AllPointers +@end +// CHECK-LP64: L_OBJC_CLASS_NAME_1: +// CHECK-LP64-NEXT: .asciz "\003" + +@class NSString, NSNumber; +@interface A : NSObject { + NSString *foo; + NSNumber *bar; + unsigned int bletch; + __weak id delegate; +} +@end + +@interface B : A { + unsigned int x; + NSString *y; + NSString *z; +} +@end + +@implementation A @end + +@implementation B @end + +// CHECK-LP64: L_OBJC_CLASS_NAME_15: +// CHECK-LP64-NEXT: .asciz "\022" + diff --git a/test/CodeGenObjC/arc-no-runtime.m b/test/CodeGenObjC/arc-no-runtime.m new file mode 100644 index 0000000..39f7da3 --- /dev/null +++ b/test/CodeGenObjC/arc-no-runtime.m @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fobjc-nonfragile-abi -emit-llvm %s -o - | FileCheck %s + +// rdar://problem/9224855 +void test0() { + id x = 0; + // CHECK: call void @objc_release( +} + +// CHECK: declare extern_weak void @objc_release( diff --git a/test/CodeGenObjC/arc-related-result-type.m b/test/CodeGenObjC/arc-related-result-type.m new file mode 100644 index 0000000..c51757d --- /dev/null +++ b/test/CodeGenObjC/arc-related-result-type.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -o - %s | FileCheck %s + +@interface Test0 +- (id) self; +@end +void test0(Test0 *val) { + Test0 *x = [val self]; + +// CHECK: define void @test0( +// CHECK: [[VAL:%.*]] = alloca [[TEST0:%.*]]* +// CHECK-NEXT: [[X:%.*]] = alloca [[TEST0]]* +// CHECK-NEXT: bitcast +// CHECK-NEXT: call i8* @objc_retain( +// CHECK-NEXT: bitcast +// CHECK-NEXT: store +// CHECK-NEXT: load [[TEST0]]** [[VAL]], +// CHECK-NEXT: load +// CHECK-NEXT: bitcast +// CHECK-NEXT: [[T0:%.*]] = call i8* bitcast ( +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST0]]* +// CHECK-NEXT: store [[TEST0]]* [[T2]], [[TEST0]]** [[X]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST0]]** [[X]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST0]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: [[T0:%.*]] = load [[TEST0]]** [[VAL]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST0]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: ret void +} diff --git a/test/CodeGenObjC/arc-unbridged-cast.m b/test/CodeGenObjC/arc-unbridged-cast.m new file mode 100644 index 0000000..0f3db09 --- /dev/null +++ b/test/CodeGenObjC/arc-unbridged-cast.m @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-nonfragile-abi -fobjc-arc -o - %s | FileCheck %s +// rdar://9744349 + +typedef const struct __CFString * CFStringRef; + +@interface I +@property CFStringRef P; +- (CFStringRef) CFMeth __attribute__((cf_returns_retained)); +- (CFStringRef) newSomething; +- (CFStringRef) P __attribute__((cf_returns_retained)); +@end + +@implementation I +@synthesize P; +- (id) Meth { + I* p1 = (id)[p1 P]; + id p2 = (id)[p1 CFMeth]; + id p3 = (id)[p1 newSomething]; + return (id) p1.P; +} +- (CFStringRef) CFMeth { return 0; } +- (CFStringRef) newSomething { return 0; } +- (CFStringRef) P { return 0; } +- (void) setP : (CFStringRef)arg {} +@end + +// rdar://9544832 +CFStringRef SomeOtherFunc() __attribute__((cf_returns_retained)); +id MMM() +{ + id obj = (id)((CFStringRef) __builtin___CFStringMakeConstantString ("" "Some CF String" "")); + if (obj) + return (id) SomeOtherFunc(); + return 0; +} + +// CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue diff --git a/test/CodeGenObjC/arc-unopt.m b/test/CodeGenObjC/arc-unopt.m new file mode 100644 index 0000000..ed46052 --- /dev/null +++ b/test/CodeGenObjC/arc-unopt.m @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s + +// A test to ensure that we generate fused calls at -O0. + +@class Test0; +Test0 *test0(void) { + extern Test0 *test0_helper; + return test0_helper; + + // CHECK: [[LD:%.*]] = load [[TEST0:%.*]]** @test0_helper + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST0]]* [[LD]] to i8* + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleaseReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST0]]* + // CHECK-NEXT: ret [[TEST0]]* [[T2]] +} + +id test1(void) { + extern id test1_helper; + return test1_helper; + + // CHECK: [[LD:%.*]] = load i8** @test1_helper + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleaseReturnValue(i8* [[LD]]) + // CHECK-NEXT: ret i8* [[T0]] +} + +void test2(void) { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void + __weak id x; +} + +id test3(void) { + extern id test3_helper(void); + // CHECK: [[T0:%.*]] = call i8* @test3_helper() + // CHECK-NEXT: ret i8* [[T0]] + return test3_helper(); +} + +@interface Test4 { id x; } @end +@interface Test4_sub : Test4 { id y; } @end +Test4 *test4(void) { + extern Test4_sub *test4_helper(void); + // CHECK: [[T0:%.*]] = call [[TEST4S:%.*]]* @test4_helper() + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST4S]]* [[T0]] to [[TEST4:%.*]]* + // CHECK-NEXT: ret [[TEST4]]* [[T1]] + return test4_helper(); +} + +// rdar://problem/9418404 +@class Test5; +void test5(void) { + Test5 *x, *y; + if ((x = y)) + y = 0; + +// CHECK: define void @test5() +// CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, +// CHECK-NEXT: [[Y:%.*]] = alloca [[TEST5:%.*]]*, +// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[X]], +// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[Y]], +// CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[Y]], +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]** [[X]] to i8** +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_storeStrong(i8** [[T1]], i8* [[T2]]) +// CHECK-NEXT: [[T3:%.*]] = icmp ne [[TEST5]]* [[T0]], null +// CHECK-NEXT: br i1 [[T3]], +} diff --git a/test/CodeGenObjC/arc-weak-property.m b/test/CodeGenObjC/arc-weak-property.m new file mode 100644 index 0000000..c079604 --- /dev/null +++ b/test/CodeGenObjC/arc-weak-property.m @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s +// rdar://8899430 + +@interface WeakPropertyTest { + __weak id PROP; +} +@property () __weak id PROP; +@end + +@implementation WeakPropertyTest +@synthesize PROP; +@end + +// CHECK: define internal i8* @"\01-[WeakPropertyTest PROP]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]]) +// CHECK-NEXT: [[T6:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T5]]) +// CHECK-NEXT: ret i8* [[T6]] + +// CHECK: define internal void @"\01-[WeakPropertyTest setPROP:]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: [[PROP:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[PROP]] +// CHECK-NEXT: [[V:%.*]] = load i8** [[PROP]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: call i8* @objc_storeWeak(i8** [[T4]], i8* [[V]]) +// CHECK-NEXT: ret void + +// CHECK: define internal void @"\01-[WeakPropertyTest .cxx_destruct]" +// CHECK: [[SELF:%.*]] = alloca [[WPT:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: store [[WPT]]* {{%.*}}, [[WPT]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[WPT]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_WeakPropertyTest.PROP" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[WPT]]* [[T0]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T4]]) +// CHECK-NEXT: ret void diff --git a/test/CodeGenObjC/arc.m b/test/CodeGenObjC/arc.m new file mode 100644 index 0000000..407b3eb --- /dev/null +++ b/test/CodeGenObjC/arc.m @@ -0,0 +1,1554 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s + +// CHECK: define void @test0 +void test0(id x) { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}}) + // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) + // CHECK-NEXT: ret void +} + +// CHECK: define i8* @test1(i8* +id test1(id x) { + // CHECK: [[RET:%.*]] = alloca i8* + // CHECK-NEXT: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[Y:%.*]] = alloca i8* + // CHECK-NEXT: alloca i32 + // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) + // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[RET]] + // CHECK-NEXT: store i32 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T0]]) + // CHECK-NEXT: ret i8* [[T1]] + id y; + return y; +} + +@interface Test2 ++ (void) class_method; +- (void) inst_method; +@end +@implementation Test2 + +// The self pointer of a class method is not retained. +// CHECK: define internal void @"\01+[Test2 class_method]" +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret void ++ (void) class_method {} + +// The self pointer of an instance method is not retained. +// CHECK: define internal void @"\01-[Test2 inst_method]" +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret void +- (void) inst_method {} +@end + +@interface Test3 ++ (id) alloc; +- (id) initWith: (int) x; +- (id) copy; +@end + +// CHECK: define void @test3_unelided() +void test3_unelided() { + extern void test3_helper(void); + + // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]* + // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align + Test3 *x; + + // Call to +alloc. + // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: bitcast + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @objc_release(i8* + [Test3 alloc]; + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* + // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]], + // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) nounwind + [x copy]; + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NEXT: ret void +} + +// CHECK: define void @test3() +void test3() { + // CHECK: [[X:%.*]] = alloca i8* + + id x = [[Test3 alloc] initWith: 5]; + + // Call to +alloc. + // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: bitcast + + // Call to -initWith: with elided retain of consumed argument. + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = bitcast + // Assignment for initialization, retention elided. + // CHECK-NEXT: store i8* [[INIT]], i8** [[X]] + + // Call to -copy. + // CHECK-NEXT: [[V:%.*]] = load i8** [[X]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]], + + // Assignment to x. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[COPY]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + + x = [x copy]; + + // Cleanup for x. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + + // CHECK-NEXT: ret void +} + +// CHECK: define i8* @test4() +id test4() { + // Call to +alloc. + // CHECK: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_ + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[ALLOC:%.*]] = bitcast + + // Call to -initWith: with elided retain of consumed argument. + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: [[ALLOC:%.*]] = bitcast + // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]], + + // Initialization of return value, occuring within full-expression. + // Retain/release elided. + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[INIT:%.*]] = bitcast + // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[INIT]]) + + // CHECK-NEXT: ret i8* [[RET]] + + return [[Test3 alloc] initWith: 6]; +} + +@interface Test5 { +@public + id var; +} +@end + +// CHECK: define void @test5 +void test5(Test5 *x, id y) { + // Prologue. + // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, + // CHECK-NEXT: [[Y:%.*]] = alloca i8* + // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8* + // CHECK-NEXT: call i8* @objc_retain + // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]* + // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]] + // CHECK-NEXT: call i8* @objc_retain + // CHECK-NEXT: store + + // CHECK-NEXT: load [[TEST5]]** [[X]] + // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[VAR:%.*]] = bitcast + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* null, i8** [[VAR]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + x->var = 0; + + // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]] + // CHECK-NEXT: load [[TEST5]]** [[X]] + // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[VAR:%.*]] = bitcast + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) nounwind + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + x->var = y; + + // Epilogue. + // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind + // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NEXT: ret void +} + +id test6_helper(void) __attribute__((ns_returns_retained)); +// CHECK: define void @test6() +void test6() { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper() + // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x = test6_helper(); +} + +void test7_helper(id __attribute__((ns_consumed))); +// CHECK: define void @test7() +void test7() { + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind + // CHECK-NEXT: call void @test7_helper(i8* [[T1]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x; + test7_helper(x); +} + +id test8_helper(void) __attribute__((ns_returns_retained)); +void test8() { + __unsafe_unretained id x = test8_helper(); + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper() + // CHECK-NEXT: store i8* [[T0]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NOT: imprecise_release + // CHECK-NEXT: ret void +} + +id test9_helper(void) __attribute__((ns_returns_retained)); +void test9() { + id x __attribute__((objc_precise_lifetime)) = test9_helper(); + x = 0; + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test9_helper() + // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] + + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind + // CHECK-NOT: clang.imprecise_release + + // CHECK-NEXT: ret void +} + +@interface Test10 +@property (retain) Test10 *me; +@end +void test10() { + Test10 *x; + id y = x.me.me; + + // CHECK: define void @test10() + // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align + // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align + // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]] + // CHECK-NEXT: load [[TEST10]]** [[X]], align + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}" + // CHECK-NEXT: bitcast + // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* + // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8* + // CHECK-NEXT: store i8* [[T4]], i8** [[Y]] + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: ret void +} + +void test11(id (*f)(void) __attribute__((ns_returns_retained))) { + // CHECK: define void @test11( + // CHECK: [[F:%.*]] = alloca i8* ()*, align + // CHECK-NEXT: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align + // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align + // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]() + // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align + // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T3]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: ret void + id x = f(); +} + +void test12(void) { + extern id test12_helper(void); + + // CHECK: define void @test12() + // CHECK: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align + + __weak id x = test12_helper(); + // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + x = test12_helper(); + // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + id y = x; + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]]) + // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align + + // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]] + // CHECK-NEXT: call void @objc_release(i8* [[T4]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void +} + +// Indirect consuming calls. +void test13(void) { + // CHECK: define void @test13() + // CHECK: [[X:%.*]] = alloca i8*, align + // CHECK-NEXT: store i8* null, i8** [[X]], align + id x; + + typedef void fnty(id __attribute__((ns_consumed))); + extern fnty *test13_func; + // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align + // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align + // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind + // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]]) + test13_func(x); + + extern fnty ^test13_block; + // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align + // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]* + // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3 + // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8* + // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align + // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind + // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]] + // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)* + // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]]) + test13_block(x); + + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void +} + +@interface Test16_super @end +@interface Test16 : Test16_super { + id z; +} +@property (assign) int x; +@property (retain) id y; +- (void) dealloc; +@end +@implementation Test16 +@synthesize x; +@synthesize y; +- (void) dealloc { + // CHECK: define internal void @"\01-[Test16 dealloc]"( + // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align + // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align + // CHECK-NEXT: alloca + // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align + // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] + + // Call super. + // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T0:%.*]] = getelementptr + // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]] + // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: store + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void ( + // CHECK-NEXT: ret void +} + +// .cxx_destruct + // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"( + // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align + // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align + // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align + // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] + + // Destroy y. + // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y" + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]] + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** + // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind + + // Destroy z. + // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z" + // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]] + // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** + // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind + + // CHECK-NEXT: ret void + +@end + +// This shouldn't crash. +@interface Test17A +@property (assign) int x; +@end +@interface Test17B : Test17A +@end +@implementation Test17B +- (int) x { return super.x + 1; } +@end + +// This shouldn't crash. +void test18(id (^maker)(void)) { + maker(); +} + +void test19() { + // CHECK: define void @test19() + // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16 + // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8* + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false) + id x[5]; + + extern id test19_helper(void); + x[2] = test19_helper(); + + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) nounwind + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] + // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5 + // CHECK-NEXT: br label + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: ret void +} + +void test20(unsigned n) { + // CHECK: define void @test20 + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* + // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 + + id x[n]; + + // Capture the VLA size. + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 + + // Save the stack pointer. + // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() + // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] + + // Allocate the VLA. + // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16 + + // Zero-initialize. + // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8* + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8 + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T1]], i32 8, i1 false) + + // Destroy. + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]] + // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]] + // CHECK-NEXT: br i1 [[EMPTY]] + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] + // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) + // CHECK-NEXT: ret void +} + +void test21(unsigned n) { + // CHECK: define void @test21 + // CHECK: [[N:%.*]] = alloca i32, align 4 + // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* + // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 + + id x[2][n][3]; + + // Capture the VLA size. + // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 + // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 + + // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() + // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] + + + // Allocate the VLA. + // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16 + + // Zero-initialize. + // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8* + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24 + // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T2]], i32 8, i1 false) + + // Destroy. + // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] + // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0 + // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3 + // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]] + // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]] + // CHECK-NEXT: br i1 [[EMPTY]] + + // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] + // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] + // CHECK-NEXT: br i1 [[EQ]], + + // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] + // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) + // CHECK-NEXT: ret void +} + +void test22(_Bool cond) { + id test22_helper(void) __attribute__((ns_returns_retained)); + + // CHECK: define void @test22( + // CHECK: [[COND:%.*]] = alloca i8, + // CHECK-NEXT: [[X:%.*]] = alloca i8*, + // CHECK-NEXT: [[RELCOND:%.*]] = alloca i1 + // CHECK-NEXT: [[RELVAL:%.*]] = alloca i8* + // CHECK-NEXT: store i1 false, i1* [[RELCOND]] + // CHECK-NEXT: zext + // CHECK-NEXT: store + // CHECK-NEXT: [[T0:%.*]] = load i8* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = trunc i8 [[T0]] to i1 + // CHECK-NEXT: br i1 [[T1]], + // CHECK: br label + // CHECK: [[CALL:%.*]] = call i8* @test22_helper() + // CHECK-NEXT: store i1 true, i1* [[RELCOND]] + // CHECK-NEXT: store i8* [[CALL]], i8** [[RELVAL]] + // CHECK-NEXT: br label + // CHECK: [[T0:%.*]] = phi i8* [ null, {{%.*}} ], [ [[CALL]], {{%.*}} ] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind + // CHECK-NEXT: store i8* [[T1]], i8** [[X]], + // CHECK-NEXT: [[REL:%.*]] = load i1* [[RELCOND]] + // CHECK-NEXT: br i1 [[REL]], + // CHECK: [[T0:%.*]] = load i8** [[RELVAL]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: br label + // CHECK: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void + id x = (cond ? 0 : test22_helper()); +} + +// rdar://problem/8922540 +// Note that we no longer emit .release_ivars flags. +// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 134, +@interface Test23 { id x; } @end +@implementation Test23 @end + +// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130, +@interface Test24 {} @end +@implementation Test24 @end + +int (^test25(int x))(void) { + // CHECK: define i32 ()* @test25( + // CHECK: [[X:%.*]] = alloca i32, + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK-NEXT: store i32 {{%.*}}, i32* [[X]] + // CHECK: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to i32 ()* + // CHECK-NEXT: [[T1:%.*]] = bitcast i32 ()* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainBlock(i8* [[T1]]) nounwind + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i32 ()* + // CHECK-NEXT: [[T4:%.*]] = bitcast i32 ()* [[T3]] to i8* + // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T4]]) nounwind + // CHECK-NEXT: [[T6:%.*]] = bitcast i8* [[T5]] to i32 ()* + // CHECK-NEXT: ret i32 ()* [[T6]] + return ^{ return x; }; +} + +// rdar://problem/8941012 +@interface Test26 { id x[4]; } @end +@implementation Test26 @end +// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"( +// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]** +// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x" +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8* +// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] +// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]* +// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0 +// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4 +// CHECK-NEXT: br label +// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] +// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 +// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null) +// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] +// CHECK-NEXT: br i1 [[ISDONE]], +// CHECK: ret void + +// Check that 'init' retains self. +@interface Test27 +- (id) init; +@end +@implementation Test27 +- (id) init { return self; } +// CHECK: define internal i8* @"\01-[Test27 init]" +// CHECK: [[RET:%.*]] = alloca i8*, +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST27:%.*]]*, +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, +// CHECK-NEXT: [[DEST:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]] +// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + +@end + +// rdar://problem/8087194 +@interface Test28 +@property (copy) id prop; +@end +@implementation Test28 +@synthesize prop; +@end +// CHECK: define internal void @"\01-[Test28 .cxx_destruct]" +// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]** +// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop" +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8* +// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** +// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) +// CHECK-NEXT: ret void + +@interface Test29_super +- (id) initWithAllocator: (id) allocator; +@end +@interface Test29 : Test29_super +- (id) init; +- (id) initWithAllocator: (id) allocator; +@end +@implementation Test29 +static id _test29_allocator = 0; +- (id) init { +// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%.*]]* {{%.*}}, +// CHECK: [[RET:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] + +// Evaluate arguments. Note that the send argument is evaluated +// before the zeroing of self. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8 +// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8 + +// Implicit null of 'self', i.e. direct transfer of ownership. +// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] + +// Actual message send. +// CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ +// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]]) + +// Implicit write of result back into 'self'. This is not supposed to +// be detectable because we're supposed to ban accesses to the old +// self value past the delegate init call. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] + +// Return statement. +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]] +// CHECK-NEXT: [[CALL:%.*]] = bitcast +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[CALL]]) nounwind +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] +// CHECK-NEXT: [[T1:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T1]], i8** [[RET]] +// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + return [self initWithAllocator: _test29_allocator]; +} +- (id) initWithAllocator: (id) allocator { +// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"( +// CHECK: [[RET:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 +// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8 +// CHECK-NEXT: alloca +// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 +// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] +// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] +// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}}) +// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]] + +// Evaluate arguments. Note that the send argument is evaluated +// before the zeroing of self. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8 + +// Implicit null of 'self', i.e. direct transfer of ownership. +// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] + +// Actual message send. +// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2 + +// Implicit write of result back into 'self'. This is not supposed to +// be detectable because we're supposed to ban accesses to the old +// self value past the delegate init call. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] + +// Assignment. +// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]* +// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align +// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align +// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T5]]) + +// Return statement. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release + +// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + self = [super initWithAllocator: allocator]; + return self; +} +@end + +typedef struct Test30_helper Test30_helper; +@interface Test30 +- (id) init; +- (Test30_helper*) initHelper; +@end +@implementation Test30 { +char *helper; +} +- (id) init { +// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%.*]]* {{%.*}}, +// CHECK: [[RET:%.*]] = alloca i8* +// CHECK-NEXT: [[SELF:%.*]] = alloca [[TEST30]]* +// CHECK-NEXT: alloca i8* +// CHECK-NEXT: alloca i32 +// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]] +// CHECK-NEXT: store + +// Call. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]]) + +// Assignment. +// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8* +// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper" +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]] +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** +// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]] +// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT#: call void @objc_release(i8* [[T5]]) +// CHECK-NEXT: store i8* [[T0]], i8** [[T4]] + +// Return. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) +// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] +// CHECK-NEXT: [[T2:%.*]] = bitcast +// CHECK-NEXT: store i8* [[T2]], i8** [[RET]] +// CHECK-NEXT: store i32 1 + +// Cleanup. +// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] +// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T1]]) + +// Epilogue. +// CHECK-NEXT: [[T0:%.*]] = load i8** [[RET]] +// CHECK-NEXT: ret i8* [[T0]] + self->helper = [self initHelper]; + return self; +} +- (Test30_helper*) initHelper { +// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"( +// CHECK: alloca +// CHECK-NEXT: alloca +// CHECK-NEXT: store +// CHECK-NEXT: store +// CHECK-NEXT: ret [[TEST30_HELPER]]* null + return 0; +} + +@end + +void test31(id x) { +// CHECK: define void @test31( +// CHECK: [[X:%.*]] = alloca i8*, +// CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) +// CHECK-NEXT: store i8* [[PARM]], i8** [[X]] +// CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]], +// CHECK-NEXT: bitcast +// CHECK-NEXT: call void @test31_helper( +// CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release +// CHECK-NEXT: ret void + extern void test31_helper(id (^)(void)); + test31_helper(^{ return x; }); +} + +__attribute__((ns_returns_retained)) id test32(void) { +// CHECK: define i8* @test32() +// CHECK: [[CALL:%.*]] = call i8* @test32_helper() +// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) +// CHECK-NEXT: ret i8* [[T0]] + extern id test32_helper(void); + return test32_helper(); +} + +@class Test33_a; +@interface Test33 +- (void) give: (Test33_a **) x; +- (void) take: (Test33_a **) x; +- (void) giveStrong: (out __strong Test33_a **) x; +- (void) takeStrong: (inout __strong Test33_a **) x; +- (void) giveOut: (out Test33_a **) x; +@end +void test33(Test33 *ptr) { + Test33_a *a; + [ptr give: &a]; + [ptr take: &a]; + [ptr giveStrong: &a]; + [ptr takeStrong: &a]; + [ptr giveOut: &a]; + + // CHECK: define void @test33([[TEST33:%.*]]* + // CHECK: [[PTR:%.*]] = alloca [[TEST33]]* + // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]* + // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]* + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_retain + // CHECK-NEXT: bitcast + // CHECK-NEXT: store + // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]] + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP0]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP1]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) + + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) + + // 'out' + // CHECK-NEXT: load [[TEST33]]** [[PTR]] + // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]] + // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_ + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]]) + // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* + // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] + // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] + // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T5]]) + + // CHECK-NEXT: load + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_release + // CHECK-NEXT: load + // CHECK-NEXT: bitcast + // CHECK-NEXT: objc_release + // CHECK-NEXT: ret void +} + +void test34(int cond) { + __strong id strong; + __weak id weak; + extern void test34_sink(id *); + test34_sink(cond ? &strong : 0); + test34_sink(cond ? &weak : 0); + + // CHECK: define void @test34( + // CHECK: [[COND:%.*]] = alloca i32 + // CHECK-NEXT: [[STRONG:%.*]] = alloca i8* + // CHECK-NEXT: [[WEAK:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP1:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP2:%.*]] = alloca i8* + // CHECK-NEXT: store i32 + // CHECK-NEXT: store i8* null, i8** [[STRONG]] + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAK]], i8* null) + + // CHECK-NEXT: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP1]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]] + // CHECK-NEXT: br label + // CHECK: call void @test34_sink(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8** [[ARG]] + // CHECK-NEXT: store i8* [[T1]], i8** [[ARG]] + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + // CHECK-NEXT: br label + + // CHECK: [[T0:%.*]] = load i32* [[COND]] + // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 + // CHECK: [[ARG:%.*]] = phi i8** + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP2]] + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[ARG]]) + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP2]] + // CHECK-NEXT: br label + // CHECK: call void @test34_sink(i8** [[T1]]) + // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null + // CHECK-NEXT: br i1 [[T0]], + // CHECK: [[T0:%.*]] = load i8** [[TEMP2]] + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[ARG]], i8* [[T0]]) + // CHECK-NEXT: br label + + // CHECK: call void @objc_destroyWeak(i8** [[WEAK]]) + // CHECK: ret void +} + +void test35(void (^sink)(id*)) { + __strong id strong; + sink(&strong); + + // CHECK: define void @test35( + // CHECK: [[SINK:%.*]] = alloca void (i8**)* + // CHECK-NEXT: [[STRONG:%.*]] = alloca i8* + // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* + // CHECK-NEXT: bitcast void (i8**)* {{%.*}} to i8* + // CHECK-NEXT: call i8* @objc_retain( + // CHECK-NEXT: bitcast i8* + // CHECK-NEXT: store void (i8**)* {{%.*}}, void (i8**)** [[SINK]] + // CHECK-NEXT: store i8* null, i8** [[STRONG]] + + // CHECK-NEXT: load void (i8**)** [[SINK]] + // CHECK-NEXT: bitcast + // CHECK-NEXT: getelementptr + // CHECK-NEXT: [[BLOCK:%.*]] = bitcast + // CHECK-NEXT: [[T0:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]] + // CHECK-NEXT: [[F0:%.*]] = load i8** + // CHECK-NEXT: [[F1:%.*]] = bitcast i8* [[F0]] to void (i8*, i8**)* + // CHECK-NEXT: call void [[F1]](i8* [[BLOCK]], i8** [[TEMP1]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP1]] + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: store i8* [[T1]], i8** [[STRONG]] + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + + // CHECK-NEXT: [[T0:%.*]] = load i8** [[STRONG]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + + // CHECK-NEXT: load void (i8**)** [[SINK]] + // CHECK-NEXT: bitcast + // CHECK-NEXT: call void @objc_release + // CHECK-NEXT: ret void + +} + +// CHECK: define void @test36 +void test36(id x) { + // CHECK: [[X:%.*]] = alloca i8* + + // CHECK: call i8* @objc_retain + // CHECK: call i8* @objc_retain + // CHECK: call i8* @objc_retain + id array[3] = { @"A", x, @"y" }; + + // CHECK: [[T0:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + x = 0; + + // CHECK: br label + // CHECK: call void @objc_release + // CHECK: br i1 + + // CHECK: call void @objc_release + // CHECK-NEXT: ret void +} + +@class Test37; +void test37(void) { + extern void test37_helper(id *); + Test37 *var; + test37_helper(&var); + + // CHECK: define void @test37() + // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*, + // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* + // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]] + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* + // CHECK-NEXT: store i8* [[T1]], i8** [[TEMP]] + // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]]) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]] + // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]* + // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8* + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) + // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]* + // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T6]]) + + // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] + // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: ret void +} + +void test38(void) { + id test38_source(void); + void test38_helper(void (^)(void)); + __block id var = test38_source(); + test38_helper(^{ var = 0; }); + + // CHECK: define void @test38() + // CHECK: [[VAR:%.*]] = alloca [[BYREF_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 2 + // 0x02000000 - has copy/dispose helpers + // CHECK-NEXT: store i32 33554432, i32* [[T0]] + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = call i8* @test38_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: store i8* [[T0]], i8** + // CHECK: call void @test38_helper( + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__Block_byref_object_copy_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: load i8** + // CHECK-NEXT: bitcast i8* {{%.*}} to [[BYREF_T]]* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T2:%.*]] = load i8** [[T1]] + // CHECK-NEXT: store i8* [[T2]], i8** [[T0]] + // CHECK-NEXT: store i8* null, i8** [[T1]] + + // CHECK: define internal void @__Block_byref_object_dispose_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + + // CHECK: define internal void @__test38_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]], align 8 + // CHECK-NEXT: store i8* null, i8** [[SLOT]], + // CHECK-NEXT: call void @objc_release(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // CHECK: call void @_Block_object_assign(i8* {{%.*}}, i8* {{%.*}}, i32 8) + + // CHECK: define internal void @__destroy_helper_block_ + // CHECK: call void @_Block_object_dispose(i8* {{%.*}}, i32 8) +} + +void test39(void) { + extern id test39_source(void); + void test39_helper(void (^)(void)); + __unsafe_unretained id var = test39_source(); + test39_helper(^{ (void) var; }); + + // CHECK: define void @test39() + // CHECK: [[VAR:%.*]] = alloca i8* + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = call i8* @test39_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T1]], i8** [[VAR]], + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // 0x40000000 - has signature but no copy/dispose + // CHECK: store i32 1073741824, i32* + // CHECK: [[CAPTURE:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = load i8** [[VAR]] + // CHECK-NEXT: store i8* [[T0]], i8** [[CAPTURE]] + // CHECK-NEXT: [[T0:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]] to + // CHECK: call void @test39_helper + // CHECK-NEXT: ret void +} + +void test40(void) { + id test40_source(void); + void test40_helper(void (^)(void)); + __block __weak id var = test40_source(); + test40_helper(^{ var = 0; }); + + // CHECK: define void @test40() + // CHECK: [[VAR:%.*]] = alloca [[BYREF_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 2 + // 0x02000000 - has copy/dispose helpers + // CHECK-NEXT: store i32 33554432, i32* [[T0]] + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // CHECK-NEXT: [[T0:%.*]] = call i8* @test40_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[SLOT]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [[BYREF_T]]* [[VAR]], i32 0, i32 6 + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: store i8* [[T0]], i8** + // CHECK: call void @test40_helper( + // CHECK: [[T0:%.*]] = bitcast [[BYREF_T]]* [[VAR]] to i8* + // CHECK-NEXT: call void @_Block_object_dispose(i8* [[T0]], i32 8) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[SLOT]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__Block_byref_object_copy_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: load i8** + // CHECK-NEXT: bitcast i8* {{%.*}} to [[BYREF_T]]* + // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: call void @objc_moveWeak(i8** [[T0]], i8** [[T1]]) + + // CHECK: define internal void @__Block_byref_object_dispose_ + // CHECK: [[T0:%.*]] = getelementptr inbounds [[BYREF_T]]* {{%.*}}, i32 0, i32 6 + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) + + // CHECK: define internal void @__test40_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 6 + // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[SLOT]], i8* null) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // 0x8 - FIELD_IS_BYREF (no FIELD_IS_WEAK because clang in control) + // CHECK: call void @_Block_object_assign(i8* {{%.*}}, i8* {{%.*}}, i32 8) + + // CHECK: define internal void @__destroy_helper_block_ + // 0x8 - FIELD_IS_BYREF (no FIELD_IS_WEAK because clang in control) + // CHECK: call void @_Block_object_dispose(i8* {{%.*}}, i32 8) +} + +void test41(void) { + id test41_source(void); + void test41_helper(void (^)(void)); + void test41_consume(id); + __weak id var = test41_source(); + test41_helper(^{ test41_consume(var); }); + + // CHECK: define void @test41() + // CHECK: [[VAR:%.*]] = alloca i8*, + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], + // CHECK: [[T0:%.*]] = call i8* @test41_source() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[VAR]], i8* [[T1]]) + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // 0x42000000 - has signature, copy/dispose helpers + // CHECK: store i32 1107296256, + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[VAR]]) + // CHECK-NEXT: call i8* @objc_initWeak(i8** [[SLOT]], i8* [[T0]]) + // CHECK: call void @test41_helper( + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[SLOT]]) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[VAR]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__test41_block_invoke_ + // CHECK: [[SLOT:%.*]] = getelementptr inbounds [[BLOCK_T]]* {{%.*}}, i32 0, i32 5 + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[SLOT]]) + // CHECK-NEXT: call void @test41_consume(i8* [[T0]]) + // CHECK-NEXT: ret void + + // CHECK: define internal void @__copy_helper_block_ + // CHECK: getelementptr + // CHECK-NEXT: getelementptr + // CHECK-NEXT: call void @objc_copyWeak( + + // CHECK: define internal void @__destroy_helper_block_ + // CHECK: getelementptr + // CHECK-NEXT: call void @objc_destroyWeak( +} + +@interface Test42 @end +@implementation Test42 +- (void) test { +// CHECK: define internal void @"\01-[Test42 test]" +// CHECK: [[SELF:%.*]] = alloca [[TEST42:%.*]]*, +// CHECK-NEXT: alloca i8* +// CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], +// CHECK: store +// CHECK-NEXT: store +// CHECK: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 +// CHECK-NEXT: [[T1:%.*]] = load [[TEST42]]** [[SELF]], +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST42]]* [[T1]] to i8* +// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) +// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST42]]* +// CHECK-NEXT: store [[TEST42]]* [[T4]], [[TEST42]]** [[T0]] +// CHECK-NEXT: bitcast [[BLOCK_T]]* [[BLOCK]] to +// CHECK: call void @test42_helper( +// CHECK-NEXT: [[T1:%.*]] = load [[TEST42]]** [[T0]] +// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST42]]* [[T1]] to i8* +// CHECK-NEXT: call void @objc_release(i8* [[T2]]) +// CHECK-NEXT: ret void + + extern void test42_helper(void (^)(void)); + test42_helper(^{ (void) self; }); +} +@end + +@interface Test43 @end +@implementation Test43 +- (id) test __attribute__((ns_returns_retained)) { + extern id test43_produce(void); + return test43_produce(); + // CHECK: call i8* @test43_produce() + // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue( + // CHECK-NEXT: ret +} +@end + +id test44(void) { + typedef id __attribute__((ns_returns_retained)) blocktype(void); + extern test44_consume_block(blocktype^); + return ^blocktype { + extern id test44_produce(void); + return test44_produce(); + }(); + +// CHECK: define i8* @test44( +// CHECK: load i8** getelementptr +// CHECK-NEXT: bitcast i8* +// CHECK-NEXT: call i8* +// CHECK-NEXT: call i8* @objc_autoreleaseReturnValue +// CHECK-NEXT: ret i8* + +// CHECK: call i8* @test44_produce() +// CHECK-NEXT: call i8* @objc_retain +// CHECK-NEXT: ret i8* +} + +@interface Test45 +@property (retain) id x; +@end +@implementation Test45 +@synthesize x; +@end +// CHECK: define internal i8* @"\01-[Test45 x]"( +// CHECK: [[CALL:%.*]] = call i8* @objc_getProperty( +// CHECK-NEXT: ret i8* [[CALL]] + +// rdar://problem/9315552 +void test46(__weak id *wp, __weak volatile id *wvp) { + extern id test46_helper(void); + + // TODO: this is sub-optimal, we should retain at the actual call site. + + // CHECK: [[T0:%.*]] = call i8* @test46_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id x = *wp = test46_helper(); + + // CHECK: [[T0:%.*]] = call i8* @test46_helper() + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) + // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) + // CHECK-NEXT: store i8* [[T4]], i8** + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + id y = *wvp = test46_helper(); +} + +// rdar://problem/9378887 +void test47(void) { + extern id test47_helper(void); + id x = x = test47_helper(); + + // CHECK: define void @test47() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper() + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) + // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[T0]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T1]]) + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]]) + // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] + // CHECK-NEXT: store i8* [[T2]], i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T3]]) + // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]] + // CHECK-NEXT: call void @objc_release(i8* [[T4]]) + // CHECK-NEXT: ret void +} + +void test48(void) { + extern id test48_helper(void); + __weak id x = x = test48_helper(); + // CHECK: define void @test48() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null) + // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper() + // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]]) + // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]]) + // CHECK-NEXT: call void @objc_release(i8* [[T2]]) + // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) + // CHECK-NEXT: ret void +} + +void test49(void) { + extern id test49_helper(void); + __autoreleasing id x = x = test49_helper(); + // CHECK: define void @test49() + // CHECK: [[X:%.*]] = alloca i8* + // CHECK-NEXT: store i8* null, i8** [[X]] + // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper() + // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) + // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]]) + // CHECK-NEXT: store i8* [[T2]], i8** [[X]] + // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) + // CHECK-NEXT: store i8* [[T3]], i8** [[X]] + // CHECK-NEXT: ret void +} + +// rdar://9380136 +id x(); +void test50(id y) { + ({x();}); +// CHECK: [[T0:%.*]] = call i8* @objc_retain +// CHECK: call void @objc_release +} + + +// rdar://9400762 +struct CGPoint { + float x; + float y; +}; +typedef struct CGPoint CGPoint; + +@interface Foo +@property (assign) CGPoint point; +@end + +@implementation Foo +@synthesize point; +@end + +// rdar://problem/9400398 +id test52(void) { + id test52_helper(int) __attribute__((ns_returns_retained)); + return ({ int x = 5; test52_helper(x); }); + +// CHECK: define i8* @test52() +// CHECK: [[X:%.*]] = alloca i32 +// CHECK-NEXT: store i32 5, i32* [[X]], +// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T1]]) +// CHECK-NEXT: ret i8* [[T2]] +} + +// rdar://problem/9400644 +void test53(void) { + id test53_helper(void); + id x = ({ id y = test53_helper(); y; }); + (void) x; +// CHECK: define void @test53() +// CHECK: [[X:%.*]] = alloca i8*, +// CHECK-NEXT: [[Y:%.*]] = alloca i8*, +// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper() +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[Y]], +// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]], +// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) +// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]] +// CHECK-NEXT: call void @objc_release(i8* [[T2]]) +// CHECK-NEXT: store i8* [[T1]], i8** [[X]], +// CHECK-NEXT: load i8** [[X]], +// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] +// CHECK-NEXT: call void @objc_release(i8* [[T0]]) +// CHECK-NEXT: ret void +} + +// +// CHECK: define void @test54(i32 %first, ...) +void test54(int first, ...) { + __builtin_va_list arglist; + // CHECK: call void @llvm.va_start + __builtin_va_start(arglist, first); + // CHECK: call i8* @objc_retain + id obj = __builtin_va_arg(arglist, id); + // CHECK: call void @llvm.va_end + __builtin_va_end(arglist); + // CHECK: call void @objc_release + // CHECK: ret void +} + +// PR10228 +@interface Test55Base @end +@interface Test55 : Test55Base @end +@implementation Test55 (Category) +- (void) dealloc {} +@end +// CHECK: define internal void @"\01-[Test55(Category) dealloc]"( +// CHECK-NOT: ret +// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)( diff --git a/test/CodeGenObjC/autorelease.m b/test/CodeGenObjC/autorelease.m new file mode 100644 index 0000000..7bf40f1 --- /dev/null +++ b/test/CodeGenObjC/autorelease.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-nonfragile-abi -fobjc-runtime-has-arc -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -emit-llvm -fobjc-nonfragile-abi -fobjc-runtime-has-arc -o - %s | FileCheck %s +// rdar://8881826 +// rdar://9412038 + +@interface I +{ + id ivar; +} +- (id) Meth; ++ (id) MyAlloc;; +@end + +@implementation I +- (id) Meth { + @autoreleasepool { + id p = [I MyAlloc]; + if (!p) + return ivar; + } + return 0; +} ++ (id) MyAlloc { + return 0; +} +@end + +// CHECK: call i8* @objc_autoreleasePoolPush +// CHECK: [[T:%.*]] = load i8** [[A:%.*]] +// CHECK: call void @objc_autoreleasePoolPop diff --git a/test/CodeGenObjC/block-6.m b/test/CodeGenObjC/block-6.m index 3720a87..44c7a78 100644 --- a/test/CodeGenObjC/block-6.m +++ b/test/CodeGenObjC/block-6.m @@ -2,10 +2,16 @@ // rdar://8893785 void MYFUNC() { -// CHECK: [[T1:%.*]] = bitcast i8* ()* -// CHECK-NEXT: [[FORWARDING:%.*]] = getelementptr inbounds [[N_T:%.*]]* [[N:%.*]], i32 0, i32 1 -// CHECK-NEXT: [[T0:%.*]] = load [[N_T]]** [[FORWARDING]] -// CHECK-NEXT: [[OBSERVER:%.*]] = getelementptr inbounds [[N_T]]* [[T0]], i32 0, i32 6 +// CHECK: define void @MYFUNC() +// CHECK: [[OBSERVER_SLOT:%.*]] = alloca [[OBSERVER_T:%.*]], align 8 + +// CHECK: [[T0:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[OBSERVER_SLOT]], i32 0, i32 1 +// CHECK: store [[OBSERVER_T]]* [[OBSERVER_SLOT]], [[OBSERVER_T]]** [[T0]] + +// CHECK: [[T1:%.*]] = bitcast i8* ()* +// CHECK: [[FORWARDING:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[OBSERVER_SLOT]], i32 0, i32 1 +// CHECK-NEXT: [[T0:%.*]] = load [[OBSERVER_T]]** [[FORWARDING]] +// CHECK-NEXT: [[OBSERVER:%.*]] = getelementptr inbounds [[OBSERVER_T]]* [[T0]], i32 0, i32 6 // CHECK-NEXT: store i8* [[T1]], i8** [[OBSERVER]] __block id observer = ^{ return observer; }; } diff --git a/test/CodeGenObjC/blocks.m b/test/CodeGenObjC/blocks.m index 151c162..47d47cc 100644 --- a/test/CodeGenObjC/blocks.m +++ b/test/CodeGenObjC/blocks.m @@ -46,7 +46,7 @@ void test2(Test2 *x) { // CHECK: define void @test2( // CHECK: [[X:%.*]] = alloca [[TEST2:%.*]]*, // CHECK-NEXT: [[WEAKX:%.*]] = alloca [[WEAK_T:%.*]], - // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:%.*]], + // CHECK-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], // CHECK-NEXT: store [[TEST2]]* // isa=1 for weak byrefs. @@ -95,8 +95,8 @@ void test2(Test2 *x) { // CHECK: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]* // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5 // CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]] -// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]* -// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T2]], i32 0, i32 1 -// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]** [[T3]] -// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T4]], i32 0, i32 6 +// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]{{.*}}* +// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]{{.*}}* [[T2]], i32 0, i32 1 +// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]{{.*}}** [[T3]] +// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]{{.*}}* [[T4]], i32 0, i32 6 // CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[WEAKX]], align 4 diff --git a/test/CodeGenObjC/debug-info-foreach.m b/test/CodeGenObjC/debug-info-foreach.m deleted file mode 100644 index 89b409c..0000000 --- a/test/CodeGenObjC/debug-info-foreach.m +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fobjc-default-synthesize-properties -emit-llvm -g %s -o %t -// RUN: grep DW_TAG_lexical_block %t | count 5 -// rdar://8757124 - -@class NSArray; - -int i; -void f(NSArray *a) { - id keys; - for (id thisKey in keys) { - int j = i; - ++j; - i = j; - } - for (id thisKey in keys) { - int k = i; - ++k; - i = k; - } -} diff --git a/test/CodeGenObjC/encode-test.m b/test/CodeGenObjC/encode-test.m index ade0c61..f30fb26 100644 --- a/test/CodeGenObjC/encode-test.m +++ b/test/CodeGenObjC/encode-test.m @@ -161,3 +161,7 @@ struct f // CHECK: @g10 = constant [14 x i8] c"{f=i[0{?=}]i}\00" const char g10[] = @encode(struct f); + +// rdar://9622422 +// CHECK: @g11 = constant [2 x i8] c"v\00" +const char g11[] = @encode(void); diff --git a/test/CodeGenObjC/exceptions-nonfragile.m b/test/CodeGenObjC/exceptions-nonfragile.m index 280b5d4..2557aab 100644 --- a/test/CodeGenObjC/exceptions-nonfragile.m +++ b/test/CodeGenObjC/exceptions-nonfragile.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -O2 -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -fexceptions -fobjc-exceptions -o - %s | FileCheck %s // rdar://problem/8535238 // CHECK: declare void @objc_exception_rethrow() @@ -15,3 +15,17 @@ void protos() { void throwing() { @throw(@"error!"); } + +// rdar://problem/9431547 +void die(void) __attribute__((nothrow, noreturn)); +void test2(void) { + @try { + die(); + } @finally { + extern void test2_helper(void); + test2_helper(); + } + + // CHECK: define void @test2() + // CHECK-NOT: call void @test2_helper() +} diff --git a/test/CodeGenObjC/gc.m b/test/CodeGenObjC/gc.m new file mode 100644 index 0000000..93554e6 --- /dev/null +++ b/test/CodeGenObjC/gc.m @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s + +void test0(void) { + extern id test0_helper(void); + __attribute__((objc_precise_lifetime)) id x = test0_helper(); + test0_helper(); + // CHECK: define void @test0() + // CHECK: [[T0:%.*]] = call i8* @test0_helper() + // CHECK-NEXT: store i8* [[T0]], i8** [[X:%.*]], align 8 + // CHECK-NEXT: call i8* @test0_helper() + // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]], align 8 + // CHECK-NEXT: call void asm sideeffect "", "r"(i8* [[T0]]) nounwind + // CHECK-NEXT: ret void +} diff --git a/test/CodeGenObjC/mrr-autorelease.m b/test/CodeGenObjC/mrr-autorelease.m new file mode 100644 index 0000000..10f549f --- /dev/null +++ b/test/CodeGenObjC/mrr-autorelease.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +// rdar://8881826 +// rdar://9423507 + +@interface I +{ + id ivar; +} +- (id) Meth; +@end + +@implementation I +- (id) Meth { + @autoreleasepool { + } + return 0; +} +@end + +// CHECK-NOT: call i8* @objc_getClass +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend diff --git a/test/CodeGenObjC/nonlazy-msgSend.m b/test/CodeGenObjC/nonlazy-msgSend.m new file mode 100644 index 0000000..3d7ba10 --- /dev/null +++ b/test/CodeGenObjC/nonlazy-msgSend.m @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -emit-llvm -o %t %s +// RUN: grep -F 'declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind' %t + +void f0(id x) { + [x foo]; +} diff --git a/test/CodeGenObjC/property-list-in-class.m b/test/CodeGenObjC/property-list-in-class.m index a5d0dc8..0521058 100644 --- a/test/CodeGenObjC/property-list-in-class.m +++ b/test/CodeGenObjC/property-list-in-class.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm -o %t %s -// RUN: grep -F 'l_OBJC_$_PROP_LIST_C2" = internal global %8 { i32 16, i32 3' %t +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -emit-llvm %s -o - | FileCheck %s +// CHECK: l_OBJC_$_PROP_LIST_C2" = internal global { i32, i32, [3 x %struct._prop_t] } { i32 16, i32 3 @protocol P @property int i; diff --git a/test/CodeGenObjC/related-result-type.m b/test/CodeGenObjC/related-result-type.m new file mode 100644 index 0000000..ef38661 --- /dev/null +++ b/test/CodeGenObjC/related-result-type.m @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +@interface NSObject ++ (id)alloc; +- (id)init; +- (id)retain; +@end + +@interface NSString : NSObject +@end + +// CHECK: define void @test1() +void test1() { + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: bitcast i8* + NSString *str1 = [[[NSString alloc] init] retain]; +} + +// CHECK: define void @test2() +void test2() { + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: {{call.*@objc_msgSend}} + // CHECK: bitcast i8* + NSString *str1 = NSString.alloc.init.retain; +} + +@interface Test2 : NSString +- (id)init; +@end + +@implementation Test2 +// CHECK: define internal i8* @"\01-[Test2 init]" +- (id)init { + // CHECK: {{call.*@objc_msgSendSuper}} + // CHECK-NEXT: bitcast i8* + return [super init]; +} +@end + +@interface Test3 : NSString +- (id)init; +@end + +@implementation Test3 +// CHECK: define internal i8* @"\01-[Test3 init]" +- (id)init { + // CHECK: {{call.*@objc_msgSendSuper}} + // CHECK-NEXT: bitcast i8* + return [super init]; +} +@end diff --git a/test/CodeGenObjC/terminate.m b/test/CodeGenObjC/terminate.m new file mode 100644 index 0000000..f04eb6a --- /dev/null +++ b/test/CodeGenObjC/terminate.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -fobjc-exceptions -fobjc-runtime-has-terminate -o - %s | FileCheck %s -check-prefix=CHECK-WITH +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fexceptions -fobjc-exceptions -o - %s | FileCheck %s -check-prefix=CHECK-WITHOUT + +void destroy(void**); + +// rdar://problem/9519113 +void test0(void) { + void test0_helper(void); + void *ptr __attribute__((cleanup(destroy))); + test0_helper(); + + // CHECK-WITH: define void @test0() + // CHECK-WITH: [[PTR:%.*]] = alloca i8*, + // CHECK-WITH: call void @destroy(i8** [[PTR]]) + // CHECK-WITH-NEXT: ret void + // CHECK-WITH: invoke void @destroy(i8** [[PTR]]) + // CHECK-WITH: call i8* @llvm.eh.exception() + // CHECK-WITH-NEXT: @llvm.eh.selector + // CHECK-WITH-NEXT: call void @objc_terminate() + + // CHECK-WITHOUT: define void @test0() + // CHECK-WITHOUT: [[PTR:%.*]] = alloca i8*, + // CHECK-WITHOUT: call void @destroy(i8** [[PTR]]) + // CHECK-WITHOUT-NEXT: ret void + // CHECK-WITHOUT: invoke void @destroy(i8** [[PTR]]) + // CHECK-WITHOUT: call i8* @llvm.eh.exception() + // CHECK-WITHOUT-NEXT: @llvm.eh.selector + // CHECK-WITHOUT-NEXT: call void @abort() +} diff --git a/test/CodeGenObjC/variadic-sends.m b/test/CodeGenObjC/variadic-sends.m index ea13823..6b04b50 100644 --- a/test/CodeGenObjC/variadic-sends.m +++ b/test/CodeGenObjC/variadic-sends.m @@ -28,13 +28,13 @@ void f2(A *a) { @interface B : A @end @implementation B : A -(void) foo { - // CHECK-X86-32: call void bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32)*) - // CHECK-X86-64: call void bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32)*) + // CHECK-X86-32: call void bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32)*) + // CHECK-X86-64: call void bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32)*) [super im1: 1]; } -(void) bar { - // CHECK-X86-32: call void (%struct._objc_method_description*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32, i32, ...)*) - // CHECK-X86-64: call void (%struct._objc_method_description*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_method_description*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_method_description*, i8*, i32, i32, ...)*) + // CHECK-X86-32: call void (%struct._objc_super*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32, i32, ...)*) + // CHECK-X86-64: call void (%struct._objc_super*, i8*, i32, i32, ...)* bitcast (i8* (%struct._objc_super*, i8*, ...)* @objc_msgSendSuper to void (%struct._objc_super*, i8*, i32, i32, ...)*) [super im2: 1, 2]; } -- cgit v1.1