diff options
author | Reid Kleckner <reid@kleckner.net> | 2015-02-03 22:52:35 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2015-02-03 22:52:35 +0000 |
commit | 11ca834bef952ee84d61b0e4bd3045077095f280 (patch) | |
tree | f514413543a35b9c0571bd67e2c0060ba81949ab /clang/lib/Sema/SemaStmt.cpp | |
parent | 765fcc0d5b8f7eafae0898ccde4075eea6295d70 (diff) | |
download | bcm5719-llvm-11ca834bef952ee84d61b0e4bd3045077095f280.tar.gz bcm5719-llvm-11ca834bef952ee84d61b0e4bd3045077095f280.zip |
SEH: Track users of __try so we can pick a per-func EH personality
There are four major kinds of declarations that cause code generation:
- FunctionDecl (includes CXXMethodDecl etc)
- ObjCMethodDecl
- BlockDecl
- CapturedDecl
This patch tracks __try usage on FunctionDecls and diagnoses __try usage
in other decls. If someone wants to use __try from ObjC, they can use it
from a free function, since the ObjC code will need an ObjC-style EH
personality.
Eventually we will want to look through CapturedDecls and track SEH
usage on the parent FunctionDecl, if present.
llvm-svn: 228058
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index d17cf227011..4761c32f78d 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3303,11 +3303,12 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope()) Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) << "try"; + sema::FunctionScopeInfo *FSI = getCurFunction(); + // C++ try is incompatible with SEH __try. - if (!getLangOpts().Borland && getCurFunction()->FirstSEHTryLoc.isValid()) { + if (!getLangOpts().Borland && FSI->FirstSEHTryLoc.isValid()) { Diag(TryLoc, diag::err_mixing_cxx_try_seh_try); - Diag(getCurFunction()->FirstSEHTryLoc, diag::note_conflicting_try_here) - << "'__try'"; + Diag(FSI->FirstSEHTryLoc, diag::note_conflicting_try_here) << "'__try'"; } const unsigned NumHandlers = Handlers.size(); @@ -3352,7 +3353,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, } } - getCurFunction()->setHasCXXTry(TryLoc); + FSI->setHasCXXTry(TryLoc); // FIXME: We should detect handlers that cannot catch anything because an // earlier handler catches a superclass. Need to find a method that is not @@ -3367,15 +3368,29 @@ StmtResult Sema::ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler) { assert(TryBlock && Handler); + sema::FunctionScopeInfo *FSI = getCurFunction(); + // SEH __try is incompatible with C++ try. Borland appears to support this, // however. - if (!getLangOpts().Borland && getCurFunction()->FirstCXXTryLoc.isValid()) { - Diag(TryLoc, diag::err_mixing_cxx_try_seh_try); - Diag(getCurFunction()->FirstCXXTryLoc, diag::note_conflicting_try_here) - << "'try'"; + if (!getLangOpts().Borland) { + if (FSI->FirstCXXTryLoc.isValid()) { + Diag(TryLoc, diag::err_mixing_cxx_try_seh_try); + Diag(FSI->FirstCXXTryLoc, diag::note_conflicting_try_here) << "'try'"; + } } - getCurFunction()->setHasSEHTry(TryLoc); + FSI->setHasSEHTry(TryLoc); + + // Reject __try in Obj-C methods, blocks, and captured decls, since we don't + // track if they use SEH. + DeclContext *DC = CurContext; + while (DC && !DC->isFunctionOrMethod()) + DC = DC->getParent(); + FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(DC); + if (FD) + FD->setUsesSEHTry(true); + else + Diag(TryLoc, diag::err_seh_try_outside_functions); return SEHTryStmt::Create(Context, IsCXXTry, TryLoc, TryBlock, Handler); } |