summaryrefslogtreecommitdiffstats
path: root/test/CodeGenObjC
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2012-02-16 00:57:37 +0000
committerDan Gohman <gohman@apple.com>2012-02-16 00:57:37 +0000
commitb49bd27b334a6c4e3bf9d810a7d5b022578f1194 (patch)
tree581c0e3a331d44255a09a3c38c7d4e2e707b8244 /test/CodeGenObjC
parent9f02d6d2b7d62971ea619b4d0a6e68508e50ec24 (diff)
Teach clang to add metadata tags to calls and invokes in ObjC with
-fno-objc-arc-exceptions. This will allow the optimizer to perform optimizations which are only safe under that flag. This is a part of rdar://10803830. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenObjC')
-rw-r--r--test/CodeGenObjC/arc-no-arc-exceptions.m78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/CodeGenObjC/arc-no-arc-exceptions.m b/test/CodeGenObjC/arc-no-arc-exceptions.m
new file mode 100644
index 0000000000..d03a0c9322
--- /dev/null
+++ b/test/CodeGenObjC/arc-no-arc-exceptions.m
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fblocks -fexceptions -fobjc-exceptions -O2 -disable-llvm-optzns -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fblocks -fexceptions -fobjc-exceptions -O0 -disable-llvm-optzns -o - %s | FileCheck -check-prefix=NO-METADATA %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fblocks -fexceptions -fobjc-exceptions -O2 -disable-llvm-optzns -o - %s -fobjc-arc-exceptions | FileCheck -check-prefix=NO-METADATA %s
+
+// The front-end should emit clang.arc.no_objc_arc_exceptions in -fobjc-arc-exceptions
+// mode when optimization is enabled, and not otherwise.
+
+void thrower(void);
+void not(void) __attribute__((nothrow));
+
+// CHECK: define void @test0(
+// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions !0
+// CHECK: call void @not() nounwind, !clang.arc.no_objc_arc_exceptions !0
+// NO-METADATA: define void @test0(
+// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
+// NO-METADATA: }
+void test0(void) {
+ thrower();
+ not();
+}
+
+// CHECK: define void @test1(
+// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions !0
+// CHECK: call void @not() nounwind, !clang.arc.no_objc_arc_exceptions !0
+// NO-METADATA: define void @test1(
+// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
+// NO-METADATA: }
+void test1(id x) {
+ id y = x;
+ thrower();
+ not();
+}
+
+void NSLog(id, ...);
+
+// CHECK: define void @test2(
+// CHECK: invoke void (i8*, ...)* @NSLog(i8* bitcast (%struct.NSConstantString* @_unnamed_cfstring_ to i8*), i32* %x2)
+// CHECK: to label %invoke.cont unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
+// NO-METADATA: define void @test2(
+// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
+// NO-METADATA: }
+void test2(void) {
+ @autoreleasepool {
+ __attribute__((__blocks__(byref))) int x;
+ NSLog(@"Address of x outside of block: %p", &x);
+ }
+}
+
+// CHECK: define void @test3(
+// CHECK: invoke void %9(i8* %7)
+// CHECK: to label %invoke.cont unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
+// NO-METADATA: define void @test3(
+// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
+// NO-METADATA: }
+void test3(void) {
+ @autoreleasepool {
+ __attribute__((__blocks__(byref))) int x;
+ ^{
+ NSLog(@"Address of x in non-assigned block: %p", &x);
+ }();
+ }
+}
+
+// CHECK: define void @test4(
+// CHECK: invoke void %13(i8* %11)
+// CHECK: to label %invoke.cont unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0
+// NO-METADATA: define void @test4(
+// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
+// NO-METADATA: }
+void test4(void) {
+ @autoreleasepool {
+ __attribute__((__blocks__(byref))) int x;
+ void (^b)(void) = ^{
+ NSLog(@"Address of x in assigned block: %p", &x);
+ };
+ b();
+ }
+}