diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m | 80 | ||||
-rw-r--r-- | clang/test/Driver/objc-convert-messages-to-runtime-calls.m | 7 |
2 files changed, 87 insertions, 0 deletions
diff --git a/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m new file mode 100644 index 00000000000..0a018204f3d --- /dev/null +++ b/clang/test/CodeGenObjC/convert-messages-to-runtime-calls.m @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls | FileCheck %s --check-prefix=MSGS +// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS +// RUN: %clang_cc1 -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS +// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS +// RUN: %clang_cc1 -fobjc-runtime=ios-8.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS +// RUN: %clang_cc1 -fobjc-runtime=ios-7.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS +// Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime. +// RUN: %clang_cc1 -fobjc-runtime=ios-9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS +// RUN: %clang_cc1 -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS + +#define nil (id)0 + +@interface NSObject ++ (id)alloc; ++ (id)allocWithZone:(void*)zone; ++ (id)alloc2; +@end + +// CHECK-LABEL: define {{.*}}void @test1 +void test1(id x) { + // MSGS: {{call.*@objc_msgSend}} + // MSGS: {{call.*@objc_msgSend}} + // CALLS: {{call.*@objc_alloc}} + // CALLS: {{call.*@objc_allocWithZone}} + [NSObject alloc]; + [NSObject allocWithZone:nil]; +} + +// CHECK-LABEL: define {{.*}}void @test2 +void test2(void* x) { + // MSGS: {{call.*@objc_msgSend}} + // MSGS: {{call.*@objc_msgSend}} + // MSGS: {{call.*@objc_msgSend}} + // CALLS: {{call.*@objc_msgSend}} + // CALLS: {{call.*@objc_msgSend}} + // CALLS: {{call.*@objc_msgSend}} + [NSObject alloc2]; + [NSObject allocWithZone:(void*)-1]; + [NSObject allocWithZone:x]; +} + +@class A; +@interface B ++ (A*) alloc; ++ (A*)allocWithZone:(void*)zone; +@end + +// Make sure we get a bitcast on the return type as the +// call will return i8* which we have to cast to A* +// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr +A* test_alloc_class_ptr() { + // CALLS: {{call.*@objc_alloc}} + // CALLS-NEXT: bitcast i8* + // CALLS-NEXT: ret + return [B alloc]; +} + +// Make sure we get a bitcast on the return type as the +// call will return i8* which we have to cast to A* +// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr +A* test_allocWithZone_class_ptr() { + // CALLS: {{call.*@objc_allocWithZone}} + // CALLS-NEXT: bitcast i8* + // CALLS-NEXT: ret + return [B allocWithZone:nil]; +} + + +@interface C ++ (id)allocWithZone:(int)intArg; +@end + +// Make sure we only accept pointer types +// CHECK-LABEL: define {{.*}}void @test_allocWithZone_int +C* test_allocWithZone_int() { + // MSGS: {{call.*@objc_msgSend}} + // CALLS: {{call.*@objc_msgSend}} + return [C allocWithZone:3]; +} + diff --git a/clang/test/Driver/objc-convert-messages-to-runtime-calls.m b/clang/test/Driver/objc-convert-messages-to-runtime-calls.m new file mode 100644 index 00000000000..ed7be571eb5 --- /dev/null +++ b/clang/test/Driver/objc-convert-messages-to-runtime-calls.m @@ -0,0 +1,7 @@ +// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fobjc-convert-messages-to-runtime-calls -fno-objc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck %s --check-prefix=DISABLE +// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fno-objc-convert-messages-to-runtime-calls -fobjc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck %s --check-prefix=ENABLE + +// Check that we pass fobjc-convert-messages-to-runtime-calls only when supported, and not explicitly disabled. + +// DISABLE: "-fno-objc-convert-messages-to-runtime-calls" +// ENABLE-NOT: "-fno-objc-convert-messages-to-runtime-calls" |