forked from OSchip/llvm-project
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
This commit is contained in:
parent
7a1d22a2af
commit
8de6864146
|
@ -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;
|
||||
return true;
|
||||
|
||||
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 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);
|
||||
|
|
Loading…
Reference in New Issue