[PATCH] D47564: [Parse] Use CapturedStmt for @finally on MSVC

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 7 13:12:17 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL334224: [Parse] Use CapturedStmt for @finally on MSVC (authored by smeenai, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47564

Files:
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/Basic/CapturedStmt.h
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/lib/Parse/ParseObjc.cpp
  cfe/trunk/test/SemaObjC/finally-msvc.m


Index: cfe/trunk/test/SemaObjC/finally-msvc.m
===================================================================
--- cfe/trunk/test/SemaObjC/finally-msvc.m
+++ cfe/trunk/test/SemaObjC/finally-msvc.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple i686--windows-msvc -fexceptions -fobjc-exceptions -ast-dump %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fexceptions -fobjc-exceptions -ast-dump %s 2>&1 | FileCheck %s
+
+void f() {
+  @try {
+  } @finally {
+  }
+}
+
+// CHECK:      ObjCAtFinallyStmt
+// CHECK-NEXT:   CapturedStmt
+// CHECK-NEXT:     CapturedDecl
+// CHECK-NEXT:       CompoundStmt
+// CHECK-NEXT:       ImplicitParamDecl
Index: cfe/trunk/lib/Parse/ParseObjc.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp
+++ cfe/trunk/lib/Parse/ParseObjc.cpp
@@ -2585,13 +2585,26 @@
       ParseScope FinallyScope(this,
                               Scope::DeclScope | Scope::CompoundStmtScope);
 
+      bool ShouldCapture =
+          getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+      if (ShouldCapture)
+        Actions.ActOnCapturedRegionStart(Tok.getLocation(), getCurScope(),
+                                         CR_ObjCAtFinally, 1);
+
       StmtResult FinallyBody(true);
       if (Tok.is(tok::l_brace))
         FinallyBody = ParseCompoundStatementBody();
       else
         Diag(Tok, diag::err_expected) << tok::l_brace;
-      if (FinallyBody.isInvalid())
+
+      if (FinallyBody.isInvalid()) {
         FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
+        if (ShouldCapture)
+          Actions.ActOnCapturedRegionError();
+      } else if (ShouldCapture) {
+        FinallyBody = Actions.ActOnCapturedRegionEnd(FinallyBody.get());
+      }
+
       FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
                                                    FinallyBody.get());
       catch_or_finally_seen = true;
Index: cfe/trunk/include/clang/AST/Stmt.h
===================================================================
--- cfe/trunk/include/clang/AST/Stmt.h
+++ cfe/trunk/include/clang/AST/Stmt.h
@@ -2133,7 +2133,7 @@
 
   /// The pointer part is the implicit the outlined function and the 
   /// int part is the captured region kind, 'CR_Default' etc.
-  llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
+  llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
 
   /// The record for captured variables, a RecordDecl or CXXRecordDecl.
   RecordDecl *TheRecordDecl = nullptr;
Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===================================================================
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -748,6 +748,8 @@
     switch (CapRegionKind) {
     case CR_Default:
       return "default captured statement";
+    case CR_ObjCAtFinally:
+      return "Objective-C @finally statement";
     case CR_OpenMP:
       return "OpenMP region";
     }
Index: cfe/trunk/include/clang/Basic/CapturedStmt.h
===================================================================
--- cfe/trunk/include/clang/Basic/CapturedStmt.h
+++ cfe/trunk/include/clang/Basic/CapturedStmt.h
@@ -16,6 +16,7 @@
 /// The different kinds of captured statement.
 enum CapturedRegionKind {
   CR_Default,
+  CR_ObjCAtFinally,
   CR_OpenMP
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47564.150397.patch
Type: text/x-patch
Size: 3401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180607/34d7d259/attachment-0001.bin>


More information about the cfe-commits mailing list