Files
clang-p2996/clang/test/CodeGenObjC/arc-blocks-exceptions.m
Erik Pilkington a9a6e62ddf [CodeGen] Make sure the EH cleanup for block captures is conditional when the block literal is in a conditional context
Previously, clang was crashing on the attached test because the EH cleanup for
the block capture was incorrectly emitted under the assumption that the
expression wasn't conditionally evaluated. This was because before 9a52de00260,
pushLifetimeExtendedDestroy was mainly used with C++ automatic lifetime
extension, where a conditionally evaluated expression wasn't possible. Now that
we're using this path for block captures, we need to handle this case.

rdar://66250047

Differential revision: https://reviews.llvm.org/D86854
2020-08-31 10:12:17 -04:00

36 lines
1.3 KiB
Objective-C

// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -fexceptions -disable-llvm-passes -o - %s | FileCheck %s
void test1(_Bool c) {
void test1_fn(void (^blk)());
__weak id weakId = 0;
test1_fn(c ? ^{ (void)weakId; } : 0);
// CHECK: [[CLEANUP_COND:%.*]] = alloca i1
// CHECK-NEXT: [[CLEANUP_SAVE:%.*]] = alloca i8**
// CHECK: store i1 true, i1* [[CLEANUP_COND]]
// CHECK-NEXT: store i8** {{.*}}, i8*** [[CLEANUP_SAVE]]
// CHECK: invoke void @test1_fn(
// CHECK-NEXT: to label %[[INVOKE_CONT:.*]] unwind label %[[LANDING_PAD_LAB:.*]]
// CHECK: [[INVOKE_CONT]]:
// CHECK-NEXT: [[LOAD:%.*]] = load i1, i1* [[CLEANUP_COND]]
// CHECK-NEXT: br i1 [[LOAD]], label %[[END_OF_SCOPE_LAB:.*]], label
// CHECK: [[END_OF_SCOPE_LAB]]:
// CHECK-NEXT: [[LOAD:%.*]] = load i8**, i8*** [[CLEANUP_SAVE]]
// CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** [[LOAD]])
// CHECK-NEXT: br label
// CHECK: [[LANDING_PAD_LAB]]:
// /* some EH stuff */
// CHECK: [[LOAD:%.*]] = load i1, i1* [[CLEANUP_COND]]
// CHECK-NEXT: br i1 [[LOAD]], label %[[EH_CLEANUP_LAB:.*]], label
// CHECK: [[EH_CLEANUP_LAB]]:
// CHECK-NEXT: [[LOAD:%.*]] = load i8**, i8*** [[CLEANUP_SAVE]]
// CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** [[LOAD]])
// CHECK-NEXT: br label
}