blob: 79043544fd4a70b09025ecf5fbc1987ccb2aa149 [file] [log] [blame]
Dan Gohmanb49bd272012-02-16 00:57:37 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fblocks -fexceptions -fobjc-exceptions -O2 -disable-llvm-optzns -o - %s | FileCheck %s
2// 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
3// 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
4
5// The front-end should emit clang.arc.no_objc_arc_exceptions in -fobjc-arc-exceptions
6// mode when optimization is enabled, and not otherwise.
7
8void thrower(void);
9void not(void) __attribute__((nothrow));
10
Stephen Lin93ab6bf2013-08-15 06:47:53 +000011// CHECK-LABEL: define void @test0(
Bill Wendling5bb033b2013-02-22 21:12:51 +000012// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions !
Bill Wendling4e1125f2013-02-22 09:10:20 +000013// CHECK: call void @not() [[NUW:#[0-9]+]], !clang.arc.no_objc_arc_exceptions !
Stephen Lin93ab6bf2013-08-15 06:47:53 +000014// NO-METADATA-LABEL: define void @test0(
Dan Gohmanb49bd272012-02-16 00:57:37 +000015// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
16// NO-METADATA: }
17void test0(void) {
18 thrower();
19 not();
20}
21
Stephen Lin93ab6bf2013-08-15 06:47:53 +000022// CHECK-LABEL: define void @test1(
Bill Wendling5bb033b2013-02-22 21:12:51 +000023// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions !
Bill Wendling4e1125f2013-02-22 09:10:20 +000024// CHECK: call void @not() [[NUW]], !clang.arc.no_objc_arc_exceptions !
Stephen Lin93ab6bf2013-08-15 06:47:53 +000025// NO-METADATA-LABEL: define void @test1(
Dan Gohmanb49bd272012-02-16 00:57:37 +000026// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
27// NO-METADATA: }
28void test1(id x) {
29 id y = x;
30 thrower();
31 not();
32}
33
34void NSLog(id, ...);
35
Stephen Lin93ab6bf2013-08-15 06:47:53 +000036// CHECK-LABEL: define void @test2(
Dan Gohmanc7b55fc2012-02-16 18:51:05 +000037// CHECK: invoke void (i8*, ...)* @NSLog(i8* bitcast (%struct.NSConstantString* @_unnamed_cfstring_ to i8*), i32* %{{.*}})
38// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions !
Stephen Lin93ab6bf2013-08-15 06:47:53 +000039// NO-METADATA-LABEL: define void @test2(
Dan Gohmanb49bd272012-02-16 00:57:37 +000040// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
41// NO-METADATA: }
42void test2(void) {
43 @autoreleasepool {
44 __attribute__((__blocks__(byref))) int x;
45 NSLog(@"Address of x outside of block: %p", &x);
46 }
47}
48
Stephen Lin93ab6bf2013-08-15 06:47:53 +000049// CHECK-LABEL: define void @test3(
Dan Gohmanc7b55fc2012-02-16 18:51:05 +000050// CHECK: invoke void %{{.*}}(i8* %{{.*}})
51// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions !
Stephen Lin93ab6bf2013-08-15 06:47:53 +000052// NO-METADATA-LABEL: define void @test3(
Dan Gohmanb49bd272012-02-16 00:57:37 +000053// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
54// NO-METADATA: }
55void test3(void) {
56 @autoreleasepool {
57 __attribute__((__blocks__(byref))) int x;
58 ^{
59 NSLog(@"Address of x in non-assigned block: %p", &x);
60 }();
61 }
62}
63
Stephen Lin93ab6bf2013-08-15 06:47:53 +000064// CHECK-LABEL: define void @test4(
Dan Gohmanc7b55fc2012-02-16 18:51:05 +000065// CHECK: invoke void %{{.*}}(i8* %{{.*}})
66// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions !
Stephen Lin93ab6bf2013-08-15 06:47:53 +000067// NO-METADATA-LABEL: define void @test4(
Dan Gohmanb49bd272012-02-16 00:57:37 +000068// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions
69// NO-METADATA: }
70void test4(void) {
71 @autoreleasepool {
72 __attribute__((__blocks__(byref))) int x;
73 void (^b)(void) = ^{
74 NSLog(@"Address of x in assigned block: %p", &x);
75 };
76 b();
77 }
78}
Bill Wendling4e1125f2013-02-22 09:10:20 +000079
Bill Wendling5bb033b2013-02-22 21:12:51 +000080// CHECK: attributes [[NUW]] = { nounwind }