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 CapDeclAndKind; + llvm::PointerIntPair CapDeclAndKind; /// The record for captured variables, a RecordDecl or CXXRecordDecl. RecordDecl *TheRecordDecl = nullptr; 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 }; 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/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/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