diff options
author | Reid Kleckner <reid@kleckner.net> | 2015-02-05 18:56:03 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2015-02-05 18:56:03 +0000 |
commit | deeddeced312a21b8454336cfab9fe2b58863cf8 (patch) | |
tree | 87170d3e4cedf4bc76f9916cbdd5d74f33e676e1 /clang/lib/Sema/SemaStmt.cpp | |
parent | c9dd02066cc0528da28bd887e8dbdb3bd9c68165 (diff) | |
download | bcm5719-llvm-deeddeced312a21b8454336cfab9fe2b58863cf8.tar.gz bcm5719-llvm-deeddeced312a21b8454336cfab9fe2b58863cf8.zip |
Re-land r228258 and make clang-cl's /EHs- disable -fexceptions again
After r228258, Clang started emitting C++ EH IR that LLVM wasn't ready
to deal with, even when exceptions were disabled with /EHs-. This time,
make /EHs- turn off -fexceptions while still emitting exceptional
constructs in functions using __try. Since Sema rejects C++ exception
handling constructs before CodeGen, landingpads should only appear in
such functions as the result of a __try.
llvm-svn: 228329
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); } |