2013-04-03 08:56:07 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -fobjc-exceptions -O2 -o - %s | FileCheck %s
|
2010-04-24 03:12:32 +08:00
|
|
|
//
|
|
|
|
// <rdar://problem/7471679> [irgen] [eh] Exception code built with clang (x86_64) crashes
|
|
|
|
|
|
|
|
// Just check that we don't emit any dead blocks.
|
|
|
|
@interface NSArray @end
|
|
|
|
void f0() {
|
|
|
|
@try {
|
|
|
|
@try {
|
|
|
|
@throw @"a";
|
|
|
|
} @catch(NSArray *e) {
|
|
|
|
}
|
|
|
|
} @catch (id e) {
|
|
|
|
}
|
|
|
|
}
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f1()
|
2010-07-06 09:34:17 +08:00
|
|
|
void f1() {
|
|
|
|
extern void foo(void);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// CHECK: call void @objc_exception_try_enter
|
|
|
|
// CHECK-NEXT: getelementptr
|
|
|
|
// CHECK-NEXT: call i32 @_setjmp(
|
|
|
|
// CHECK-NEXT: icmp
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
@try {
|
2010-08-04 13:59:32 +08:00
|
|
|
// CHECK: call void asm sideeffect "", "*m"
|
|
|
|
// CHECK-NEXT: call void @foo()
|
2010-07-06 09:34:17 +08:00
|
|
|
foo();
|
2013-04-03 08:56:07 +08:00
|
|
|
// CHECK: call void @objc_exception_try_exit
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2010-08-04 13:59:32 +08:00
|
|
|
// CHECK: call void asm sideeffect "", "=*m"
|
2010-07-06 09:34:17 +08:00
|
|
|
} @finally {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-01 07:20:56 +08:00
|
|
|
|
|
|
|
// Test that modifications to local variables are respected under
|
|
|
|
// optimization. rdar://problem/8160285
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @f2()
|
2010-08-01 07:20:56 +08:00
|
|
|
int f2() {
|
|
|
|
extern void foo(void);
|
|
|
|
|
|
|
|
// CHECK: [[X:%.*]] = alloca i32
|
2010-08-04 13:59:32 +08:00
|
|
|
// CHECK: store i32 5, i32* [[X]]
|
2010-08-01 07:20:56 +08:00
|
|
|
int x = 0;
|
2010-08-04 13:59:32 +08:00
|
|
|
x += 5;
|
2010-08-01 07:20:56 +08:00
|
|
|
|
|
|
|
// CHECK: [[SETJMP:%.*]] = call i32 @_setjmp
|
|
|
|
// CHECK-NEXT: [[CAUGHT:%.*]] = icmp eq i32 [[SETJMP]], 0
|
|
|
|
// CHECK-NEXT: br i1 [[CAUGHT]]
|
|
|
|
@try {
|
2011-11-15 08:19:16 +08:00
|
|
|
// CHECK: store i32 6, i32* [[X]]
|
2010-08-01 07:20:56 +08:00
|
|
|
x++;
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK-NEXT: call void asm sideeffect "", "*m,*m"(i32* nonnull [[X]]
|
2010-08-01 07:20:56 +08:00
|
|
|
// CHECK-NEXT: call void @foo()
|
2010-08-04 13:59:32 +08:00
|
|
|
// CHECK-NEXT: call void @objc_exception_try_exit
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T:%.*]] = load i32, i32* [[X]]
|
2010-08-01 07:20:56 +08:00
|
|
|
foo();
|
|
|
|
} @catch (id) {
|
2010-08-04 13:59:32 +08:00
|
|
|
// Landing pad. Note that we elide the re-enter.
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void asm sideeffect "", "=*m,=*m"(i32* nonnull [[X]]
|
2010-08-01 07:20:56 +08:00
|
|
|
// CHECK-NEXT: call i8* @objc_exception_extract
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[X]]
|
2011-02-17 10:02:42 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = add nsw i32 [[T1]], -1
|
2010-08-04 13:59:32 +08:00
|
|
|
|
|
|
|
// This store is dead.
|
2010-08-01 07:20:56 +08:00
|
|
|
// CHECK-NEXT: store i32 [[T2]], i32* [[X]]
|
|
|
|
x--;
|
|
|
|
}
|
2011-01-28 14:05:16 +08:00
|
|
|
|
2010-08-01 07:20:56 +08:00
|
|
|
return x;
|
|
|
|
}
|
2010-08-11 08:16:14 +08:00
|
|
|
|
|
|
|
// Test that the cleanup destination is saved when entering a finally
|
|
|
|
// block. rdar://problem/8293901
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f3()
|
2010-08-11 08:16:14 +08:00
|
|
|
void f3() {
|
|
|
|
extern void f3_helper(int, int*);
|
|
|
|
|
|
|
|
// CHECK: [[X:%.*]] = alloca i32
|
2015-04-23 05:38:15 +08:00
|
|
|
// CHECK: [[XPTR:%.*]] = bitcast i32* [[X]] to i8*
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK: call void @llvm.lifetime.start(i64 4, i8* nonnull [[XPTR]])
|
2010-08-11 08:16:14 +08:00
|
|
|
// CHECK: store i32 0, i32* [[X]]
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
// CHECK: call void @objc_exception_try_enter(
|
|
|
|
// CHECK: call i32 @_setjmp
|
|
|
|
// CHECK-NEXT: icmp eq
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
|
|
|
|
@try {
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void @f3_helper(i32 0, i32* nonnull [[X]])
|
2010-08-11 08:16:14 +08:00
|
|
|
// CHECK: call void @objc_exception_try_exit(
|
|
|
|
f3_helper(0, &x);
|
|
|
|
} @finally {
|
|
|
|
// CHECK: [[DEST1:%.*]] = phi i32 [ 0, {{%.*}} ], [ 3, {{%.*}} ]
|
|
|
|
// CHECK: call void @objc_exception_try_enter
|
|
|
|
// CHECK: call i32 @_setjmp
|
|
|
|
@try {
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void @f3_helper(i32 1, i32* nonnull [[X]])
|
2010-08-11 08:16:14 +08:00
|
|
|
// CHECK: call void @objc_exception_try_exit(
|
|
|
|
f3_helper(1, &x);
|
|
|
|
} @finally {
|
|
|
|
// CHECK: [[DEST2:%.*]] = phi i32 [ 0, {{%.*}} ], [ 5, {{%.*}} ]
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void @f3_helper(i32 2, i32* nonnull [[X]])
|
2010-08-11 08:16:14 +08:00
|
|
|
f3_helper(2, &x);
|
|
|
|
|
|
|
|
// This loop is large enough to dissuade the optimizer from just
|
|
|
|
// duplicating the finally block.
|
|
|
|
while (x) f3_helper(3, &x);
|
|
|
|
|
2010-08-11 10:06:44 +08:00
|
|
|
// This is a switch or maybe some chained branches, but relying
|
|
|
|
// on a specific result from the optimizer is really unstable.
|
|
|
|
// CHECK: [[DEST2]]
|
2010-08-11 08:16:14 +08:00
|
|
|
}
|
|
|
|
|
2010-08-11 10:06:44 +08:00
|
|
|
// This is a switch or maybe some chained branches, but relying
|
|
|
|
// on a specific result from the optimizer is really unstable.
|
|
|
|
// CHECK: [[DEST1]]
|
2010-08-11 08:16:14 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void @f3_helper(i32 4, i32* nonnull [[X]])
|
2015-09-16 02:49:51 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.lifetime.end(i64 4, i8* nonnull [[XPTR]])
|
2010-08-11 08:16:14 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
f3_helper(4, &x);
|
|
|
|
}
|
2010-10-05 07:42:51 +08:00
|
|
|
|
|
|
|
// rdar://problem/8440970
|
|
|
|
void f4() {
|
|
|
|
extern void f4_help(int);
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f4()
|
2010-10-05 07:42:51 +08:00
|
|
|
// CHECK: [[EXNDATA:%.*]] = alloca [[EXNDATA_T:%.*]], align
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call void @objc_exception_try_enter([[EXNDATA_T]]* nonnull [[EXNDATA]])
|
2010-10-05 07:42:51 +08:00
|
|
|
// CHECK: call i32 @_setjmp
|
|
|
|
@try {
|
|
|
|
// CHECK: call void @f4_help(i32 0)
|
|
|
|
f4_help(0);
|
|
|
|
|
|
|
|
// The finally cleanup has two threaded entrypoints after optimization:
|
|
|
|
|
|
|
|
// finally.no-call-exit: Predecessor is when the catch throws.
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call i8* @objc_exception_extract([[EXNDATA_T]]* nonnull [[EXNDATA]])
|
2010-10-05 07:42:51 +08:00
|
|
|
// CHECK-NEXT: call void @f4_help(i32 2)
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// -> rethrow
|
|
|
|
|
|
|
|
// finally.call-exit: Predecessors are the @try and @catch fallthroughs
|
|
|
|
// as well as the no-match case in the catch mechanism. The i1 is whether
|
|
|
|
// to rethrow and should be true only in the last case.
|
2012-09-24 09:10:25 +08:00
|
|
|
// CHECK: phi i8*
|
|
|
|
// CHECK-NEXT: phi i1
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK-NEXT: call void @objc_exception_try_exit([[EXNDATA_T]]* nonnull [[EXNDATA]])
|
2010-10-05 07:42:51 +08:00
|
|
|
// CHECK-NEXT: call void @f4_help(i32 2)
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
// -> ret, rethrow
|
|
|
|
|
|
|
|
// ret:
|
|
|
|
// CHECK: ret void
|
|
|
|
|
|
|
|
// Catch mechanism:
|
2015-06-17 04:24:06 +08:00
|
|
|
// CHECK: call i8* @objc_exception_extract([[EXNDATA_T]]* nonnull [[EXNDATA]])
|
|
|
|
// CHECK-NEXT: call void @objc_exception_try_enter([[EXNDATA_T]]* nonnull [[EXNDATA]])
|
2010-10-05 07:42:51 +08:00
|
|
|
// CHECK: call i32 @_setjmp
|
|
|
|
// -> next, finally.no-call-exit
|
|
|
|
// CHECK: call i32 @objc_exception_match
|
|
|
|
// -> finally.call-exit, match
|
|
|
|
} @catch (NSArray *a) {
|
|
|
|
// match:
|
|
|
|
// CHECK: call void @f4_help(i32 1)
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// -> finally.call-exit
|
|
|
|
f4_help(1);
|
|
|
|
} @finally {
|
|
|
|
f4_help(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// rethrow:
|
|
|
|
// CHECK: phi i8*
|
|
|
|
// CHECK-NEXT: call void @objc_exception_throw(i8*
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
}
|