From: David Majnemer Date: Fri, 5 Dec 2014 08:11:58 +0000 (+0000) Subject: Driver: Cleanup -fexceptions behavior X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8de6864146c36392caebe05ce099c439c0fc7320;p=platform%2Fupstream%2Fllvm.git Driver: Cleanup -fexceptions behavior No functionality change is intended, just a cleanup of the logic clang uses to determine what -fexceptions/-fno-exceptions ends up doing. llvm-svn: 223453 --- diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 067c389..151d87b 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -1911,43 +1911,15 @@ shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, Triple.getArch() == llvm::Triple::arm)); } -namespace { - struct ExceptionSettings { - bool ExceptionsEnabled; - bool ShouldUseExceptionTables; - ExceptionSettings() : ExceptionsEnabled(false), - ShouldUseExceptionTables(false) {} - }; -} // end anonymous namespace. - // exceptionSettings() exists to share the logic between -cc1 and linker // invocations. -static ExceptionSettings exceptionSettings(const ArgList &Args, - const llvm::Triple &Triple) { - ExceptionSettings ES; - - // Are exceptions enabled by default? - ES.ExceptionsEnabled = (Triple.getArch() != llvm::Triple::xcore); - - // This keeps track of whether exceptions were explicitly turned on or off. - bool DidHaveExplicitExceptionFlag = false; - +static bool exceptionSettings(const ArgList &Args, const llvm::Triple &Triple) { if (Arg *A = Args.getLastArg(options::OPT_fexceptions, - options::OPT_fno_exceptions)) { + options::OPT_fno_exceptions)) if (A->getOption().matches(options::OPT_fexceptions)) - ES.ExceptionsEnabled = true; - else - ES.ExceptionsEnabled = false; - - DidHaveExplicitExceptionFlag = true; - } - - // Exception tables and cleanups can be enabled with -fexceptions even if the - // language itself doesn't support exceptions. - if (ES.ExceptionsEnabled && DidHaveExplicitExceptionFlag) - ES.ShouldUseExceptionTables = true; + return true; - return ES; + return false; } /// addExceptionArgs - Adds exception related arguments to the driver command @@ -1972,8 +1944,8 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, return; } - // Gather the exception settings from the command line arguments. - ExceptionSettings ES = exceptionSettings(Args, Triple); + // Gather the exception settings from the command line arguments. + bool EH = exceptionSettings(Args, Triple); // Obj-C exceptions are enabled by default, regardless of -fexceptions. This // is not necessarily sensible, but follows GCC. @@ -1983,31 +1955,27 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, true)) { CmdArgs.push_back("-fobjc-exceptions"); - ES.ShouldUseExceptionTables |= - shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); + EH |= shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple); } if (types::isCXX(InputType)) { - bool CXXExceptionsEnabled = ES.ExceptionsEnabled; - + bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore; if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, - options::OPT_fno_exceptions)) { - if (A->getOption().matches(options::OPT_fcxx_exceptions)) - CXXExceptionsEnabled = true; - else if (A->getOption().matches(options::OPT_fno_cxx_exceptions)) - CXXExceptionsEnabled = false; - } + options::OPT_fno_exceptions)) + CXXExceptionsEnabled = + A->getOption().matches(options::OPT_fcxx_exceptions) || + A->getOption().matches(options::OPT_fexceptions); if (CXXExceptionsEnabled) { CmdArgs.push_back("-fcxx-exceptions"); - ES.ShouldUseExceptionTables = true; + EH = true; } } - if (ES.ShouldUseExceptionTables) + if (EH) CmdArgs.push_back("-fexceptions"); } @@ -8153,8 +8121,7 @@ void XCore::Link::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_v)) CmdArgs.push_back("-v"); - ExceptionSettings EH = exceptionSettings(Args, getToolChain().getTriple()); - if (EH.ShouldUseExceptionTables) + if (exceptionSettings(Args, getToolChain().getTriple())) CmdArgs.push_back("-fexceptions"); AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);