From 7523606638128e19d6993c356851fd3e88078201 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 7 Jun 2013 00:48:14 +0000 Subject: [PATCH] blocks: fixes an ast bug when block pointer variable is evaluated in a condition expression and then dereferenced to envoke the block. This is pr15663 and I applied a slight variation of the patch with a test case. (patch is from Arthur O'Dwyer). Also // rdar://14085217 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183471 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 5 ++++- test/CodeGen/blocks.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2a3482238d..7bbbe72ac3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5149,7 +5149,10 @@ static QualType checkConditionalPointerCompatibility(Sema &S, ExprResult &LHS, // The pointer types are compatible. QualType ResultTy = CompositeTy.withCVRQualifiers(MergedCVRQual); - ResultTy = S.Context.getPointerType(ResultTy); + if (isa(LHSTy)) + ResultTy = S.Context.getBlockPointerType(ResultTy); + else + ResultTy = S.Context.getPointerType(ResultTy); LHS = S.ImpCastExprToType(LHS.take(), ResultTy, CK_BitCast); RHS = S.ImpCastExprToType(RHS.take(), ResultTy, CK_BitCast); diff --git a/test/CodeGen/blocks.c b/test/CodeGen/blocks.c index 71f7171c71..47708e7481 100644 --- a/test/CodeGen/blocks.c +++ b/test/CodeGen/blocks.c @@ -66,3 +66,15 @@ void f5(void) { // CHECK: alloca <{ i8*, i32, i32, i8*, {{%.*}}*, [12 x i8], [[F5:%.*]] }>, align 16 f5_helper(^(struct F5 *slot) { *slot = value; }); } + +// rdar://14085217 +void (^b)() = ^{}; +int main() { + (b?: ^{})(); +} +// CHECK: [[ZERO:%.*]] = load void (...)** @b +// CHECK-NEXT: [[TB:%.*]] = icmp ne void (...)* [[ZERO]], null +// CHECK-NEXT: br i1 [[TB]], label [[CT:%.*]], label [[CF:%.*]] +// CHECK: [[ONE:%.*]] = bitcast void (...)* [[ZERO]] to void ()* +// CHECK-NEXT: br label [[CE:%.*]] + -- 2.40.0