Skip to content

Commit c482acd

Browse files
committedMay 4, 2016
[ObjC] Enter a new evaluation context before calling
BuildBlockForLambdaConversion. Previously, clang would build an incorrect AST for the following code: id test() { return @{@"a": [](){}, @"b": [](){}}; } ReturnStmt 0x10d080448 `-ExprWithCleanups 0x10d080428 |-cleanup Block 0x10d0801f0 // points to the second BlockDecl ... -BlockDecl 0x10d07f150 // First block ... -BlockDecl 0x10d0801f0 // Second block ... `-ExprWithCleanups 0x10d0801d0 |-cleanup Block 0x10d07f150 // points to the first BlockDecl To fix the bug, this commit enters a new evaluation context to reset ExprNeedsCleanups before each block is parsed. rdar://problem/16879958 Differential Revision: http://reviews.llvm.org/D18815 llvm-svn: 268527
1 parent 1a14f0d commit c482acd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6229,9 +6229,12 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
62296229
// follows the normal lifetime rules for block literals instead of being
62306230
// autoreleased.
62316231
DiagnosticErrorTrap Trap(Diags);
6232+
PushExpressionEvaluationContext(PotentiallyEvaluated);
62326233
ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(),
62336234
E->getExprLoc(),
62346235
Method, E);
6236+
PopExpressionEvaluationContext();
6237+
62356238
if (Exp.isInvalid())
62366239
Diag(E->getExprLoc(), diag::note_lambda_to_block_conv);
62376240
return Exp;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.11.0 -std=gnu++11 -o /dev/null -x objective-c++ -fblocks -ast-dump %s 2>&1 | FileCheck %s
2+
3+
// CHECK: -FunctionDecl {{.*}} test 'id (void)'
4+
// CHECK-NEXT: -CompoundStmt
5+
// CHECK-NEXT: -ReturnStmt
6+
// CHECK-NEXT: -ExprWithCleanups
7+
// CHECK-NEXT: -cleanup Block
8+
// CHECK-NEXT: -cleanup Block
9+
10+
@interface NSDictionary
11+
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
12+
@end
13+
14+
id test() {
15+
return @{@"a": [](){}, @"b": [](){}};
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.