1*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fblocks -fexceptions -fobjc-exceptions -disable-llvm-optzns -o - %s | FileCheck -check-prefix=NO-METADATA %s 3*f4a2713aSLionel Sambuc// 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*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc// The front-end should emit clang.arc.no_objc_arc_exceptions in -fobjc-arc-exceptions 6*f4a2713aSLionel Sambuc// mode when optimization is enabled, and not otherwise. 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambucvoid thrower(void); 9*f4a2713aSLionel Sambucvoid not(void) __attribute__((nothrow)); 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test0( 12*f4a2713aSLionel Sambuc// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions ! 13*f4a2713aSLionel Sambuc// CHECK: call void @not() [[NUW:#[0-9]+]], !clang.arc.no_objc_arc_exceptions ! 14*f4a2713aSLionel Sambuc// NO-METADATA-LABEL: define void @test0( 15*f4a2713aSLionel Sambuc// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions 16*f4a2713aSLionel Sambuc// NO-METADATA: } 17*f4a2713aSLionel Sambucvoid test0(void) { 18*f4a2713aSLionel Sambuc thrower(); 19*f4a2713aSLionel Sambuc not(); 20*f4a2713aSLionel Sambuc} 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test1( 23*f4a2713aSLionel Sambuc// CHECK: call void @thrower(), !clang.arc.no_objc_arc_exceptions ! 24*f4a2713aSLionel Sambuc// CHECK: call void @not() [[NUW]], !clang.arc.no_objc_arc_exceptions ! 25*f4a2713aSLionel Sambuc// NO-METADATA-LABEL: define void @test1( 26*f4a2713aSLionel Sambuc// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions 27*f4a2713aSLionel Sambuc// NO-METADATA: } 28*f4a2713aSLionel Sambucvoid test1(id x) { 29*f4a2713aSLionel Sambuc id y = x; 30*f4a2713aSLionel Sambuc thrower(); 31*f4a2713aSLionel Sambuc not(); 32*f4a2713aSLionel Sambuc} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambucvoid NSLog(id, ...); 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test2( 37*f4a2713aSLionel Sambuc// CHECK: invoke void (i8*, ...)* @NSLog(i8* bitcast (%struct.NSConstantString* @_unnamed_cfstring_ to i8*), i32* %{{.*}}) 38*f4a2713aSLionel Sambuc// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions ! 39*f4a2713aSLionel Sambuc// NO-METADATA-LABEL: define void @test2( 40*f4a2713aSLionel Sambuc// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions 41*f4a2713aSLionel Sambuc// NO-METADATA: } 42*f4a2713aSLionel Sambucvoid test2(void) { 43*f4a2713aSLionel Sambuc @autoreleasepool { 44*f4a2713aSLionel Sambuc __attribute__((__blocks__(byref))) int x; 45*f4a2713aSLionel Sambuc NSLog(@"Address of x outside of block: %p", &x); 46*f4a2713aSLionel Sambuc } 47*f4a2713aSLionel Sambuc} 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test3( 50*f4a2713aSLionel Sambuc// CHECK: invoke void %{{.*}}(i8* %{{.*}}) 51*f4a2713aSLionel Sambuc// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions ! 52*f4a2713aSLionel Sambuc// NO-METADATA-LABEL: define void @test3( 53*f4a2713aSLionel Sambuc// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions 54*f4a2713aSLionel Sambuc// NO-METADATA: } 55*f4a2713aSLionel Sambucvoid test3(void) { 56*f4a2713aSLionel Sambuc @autoreleasepool { 57*f4a2713aSLionel Sambuc __attribute__((__blocks__(byref))) int x; 58*f4a2713aSLionel Sambuc ^{ 59*f4a2713aSLionel Sambuc NSLog(@"Address of x in non-assigned block: %p", &x); 60*f4a2713aSLionel Sambuc }(); 61*f4a2713aSLionel Sambuc } 62*f4a2713aSLionel Sambuc} 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test4( 65*f4a2713aSLionel Sambuc// CHECK: invoke void %{{.*}}(i8* %{{.*}}) 66*f4a2713aSLionel Sambuc// CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions ! 67*f4a2713aSLionel Sambuc// NO-METADATA-LABEL: define void @test4( 68*f4a2713aSLionel Sambuc// NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions 69*f4a2713aSLionel Sambuc// NO-METADATA: } 70*f4a2713aSLionel Sambucvoid test4(void) { 71*f4a2713aSLionel Sambuc @autoreleasepool { 72*f4a2713aSLionel Sambuc __attribute__((__blocks__(byref))) int x; 73*f4a2713aSLionel Sambuc void (^b)(void) = ^{ 74*f4a2713aSLionel Sambuc NSLog(@"Address of x in assigned block: %p", &x); 75*f4a2713aSLionel Sambuc }; 76*f4a2713aSLionel Sambuc b(); 77*f4a2713aSLionel Sambuc } 78*f4a2713aSLionel Sambuc} 79*f4a2713aSLionel Sambuc 80*f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind } 81