r268527 - [ObjC] Enter a new evaluation context before calling

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 11:07:20 PDT 2016


Author: ahatanak
Date: Wed May  4 13:07:20 2016
New Revision: 268527

URL: http://llvm.org/viewvc/llvm-project?rev=268527&view=rev
Log:
[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

Added:
    cfe/trunk/test/SemaObjCXX/block-cleanup.mm
Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=268527&r1=268526&r2=268527&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed May  4 13:07:20 2016
@@ -6229,9 +6229,12 @@ ExprResult Sema::BuildCXXMemberCallExpr(
       // follows the normal lifetime rules for block literals instead of being
       // autoreleased.
       DiagnosticErrorTrap Trap(Diags);
+      PushExpressionEvaluationContext(PotentiallyEvaluated);
       ExprResult Exp = BuildBlockForLambdaConversion(E->getExprLoc(),
                                                      E->getExprLoc(),
                                                      Method, E);
+      PopExpressionEvaluationContext();
+
       if (Exp.isInvalid())
         Diag(E->getExprLoc(), diag::note_lambda_to_block_conv);
       return Exp;

Added: cfe/trunk/test/SemaObjCXX/block-cleanup.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/block-cleanup.mm?rev=268527&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/block-cleanup.mm (added)
+++ cfe/trunk/test/SemaObjCXX/block-cleanup.mm Wed May  4 13:07:20 2016
@@ -0,0 +1,16 @@
+// 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
+
+// CHECK:      -FunctionDecl {{.*}} test 'id (void)'
+// CHECK-NEXT:   -CompoundStmt
+// CHECK-NEXT:     -ReturnStmt
+// CHECK-NEXT:       -ExprWithCleanups
+// CHECK-NEXT:         -cleanup Block
+// CHECK-NEXT:         -cleanup Block
+
+ at interface NSDictionary
++ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
+ at end
+
+id test() {
+  return @{@"a": [](){}, @"b": [](){}};
+}




More information about the cfe-commits mailing list