diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h index 03c808d394e5..3b678dcc754f 100644 --- a/clang/include/clang/AST/Stmt.h +++ b/clang/include/clang/AST/Stmt.h @@ -2133,7 +2133,7 @@ private: /// 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; diff --git a/clang/include/clang/Basic/CapturedStmt.h b/clang/include/clang/Basic/CapturedStmt.h index 6c8d6edab0b5..324e1b1d3d09 100644 --- a/clang/include/clang/Basic/CapturedStmt.h +++ b/clang/include/clang/Basic/CapturedStmt.h @@ -16,6 +16,7 @@ namespace clang { /// The different kinds of captured statement. enum CapturedRegionKind { CR_Default, + CR_ObjCAtFinally, CR_OpenMP }; diff --git a/clang/include/clang/Sema/ScopeInfo.h b/clang/include/clang/Sema/ScopeInfo.h index b0f6bac99467..fa1b1037a2f7 100644 --- a/clang/include/clang/Sema/ScopeInfo.h +++ b/clang/include/clang/Sema/ScopeInfo.h @@ -748,6 +748,8 @@ public: switch (CapRegionKind) { case CR_Default: return "default captured statement"; + case CR_ObjCAtFinally: + return "Objective-C @finally statement"; case CR_OpenMP: return "OpenMP region"; } diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 6ca0ad855f54..ff33d5fb96bc 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -2585,13 +2585,26 @@ StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { 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; diff --git a/clang/test/Coverage/ast-printing.m b/clang/test/Coverage/ast-printing.m index 81c3a6b0ba53..d9909b285915 100644 --- a/clang/test/Coverage/ast-printing.m +++ b/clang/test/Coverage/ast-printing.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-exceptions %s -// RUN: %clang_cc1 -ast-print -fobjc-exceptions %s -// RUN: %clang_cc1 -ast-dump -fobjc-exceptions %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -fobjc-exceptions %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -ast-print -fobjc-exceptions %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -ast-dump -fobjc-exceptions %s #include "objc-language-features.inc" diff --git a/clang/test/PCH/objc_stmts.m b/clang/test/PCH/objc_stmts.m index 8deb14a81545..ee7b780731a9 100644 --- a/clang/test/PCH/objc_stmts.m +++ b/clang/test/PCH/objc_stmts.m @@ -1,11 +1,11 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/objc_stmts.h -emit-llvm -fobjc-exceptions -o - %s -// RUN: %clang_cc1 -include %S/objc_stmts.h -ast-print -fobjc-exceptions -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -include %S/objc_stmts.h -emit-llvm -fobjc-exceptions -o - %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -include %S/objc_stmts.h -ast-print -fobjc-exceptions -o - %s | FileCheck %s // Test with pch. -// RUN: %clang_cc1 -x objective-c -emit-pch -fobjc-exceptions -o %t %S/objc_stmts.h -// RUN: %clang_cc1 -include-pch %t -emit-llvm -fobjc-exceptions -o - %s -// RUN: %clang_cc1 -include-pch %t -ast-print -fobjc-exceptions -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -x objective-c -emit-pch -fobjc-exceptions -o %t %S/objc_stmts.h +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -include-pch %t -emit-llvm -fobjc-exceptions -o - %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -include-pch %t -ast-print -fobjc-exceptions -o - %s | FileCheck %s // CHECK: @catch(A *a) // CHECK: @catch(B *b) diff --git a/clang/test/Parser/objc-try-catch-1.m b/clang/test/Parser/objc-try-catch-1.m index a3220ebc6477..3a60148c8be9 100644 --- a/clang/test/Parser/objc-try-catch-1.m +++ b/clang/test/Parser/objc-try-catch-1.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions %s -// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -x objective-c++ %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -verify -fobjc-exceptions %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -verify -fobjc-exceptions -x objective-c++ %s void * proc(); @interface NSConstantString diff --git a/clang/test/Rewriter/rewrite-modern-try-finally.m b/clang/test/Rewriter/rewrite-modern-try-finally.m index 500133b86142..41737e95f0cd 100644 --- a/clang/test/Rewriter/rewrite-modern-try-finally.m +++ b/clang/test/Rewriter/rewrite-modern-try-finally.m @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -x objective-c -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -fcxx-exceptions -fexceptions -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp typedef struct objc_class *Class; typedef struct objc_object { diff --git a/clang/test/SemaObjC/finally-msvc.m b/clang/test/SemaObjC/finally-msvc.m new file mode 100644 index 000000000000..5db08a7f7100 --- /dev/null +++ b/clang/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 diff --git a/clang/test/SemaObjC/scope-check.m b/clang/test/SemaObjC/scope-check.m index b52e7a06ffc2..b23edd1240f9 100644 --- a/clang/test/SemaObjC/scope-check.m +++ b/clang/test/SemaObjC/scope-check.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10 -fsyntax-only -verify -fobjc-exceptions -Wno-objc-root-class %s @class A, B, C;