r201310 - XCore target -fexceptions flag handling
Robert Lytton
robert at xmos.com
Thu Feb 13 02:34:44 PST 2014
Author: rlytton
Date: Thu Feb 13 04:34:44 2014
New Revision: 201310
URL: http://llvm.org/viewvc/llvm-project?rev=201310&view=rev
Log:
XCore target -fexceptions flag handling
XCore target has -fno-exception as the default option
Pass on "-fexceptions" flag to xcc (linker)
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/xcore-opts.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=201310&r1=201309&r2=201310&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Feb 13 04:34:44 2014
@@ -1524,6 +1524,43 @@ shouldUseExceptionTablesForObjCException
Triple.getArch() == llvm::Triple::arm));
}
+namespace {
+ struct ExceptionSettings {
+ bool ExceptionsEnabled;
+ bool ShouldUseExceptionTables;
+ ExceptionSettings() : ExceptionsEnabled(false),
+ ShouldUseExceptionTables(false) {}
+ };
+} // end anonymous namespace.
+
+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;
+
+ if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
+ 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 ES;
+}
+
/// addExceptionArgs - Adds exception related arguments to the driver command
/// arguments. There's a master flag, -fexceptions and also language specific
/// flags to enable/disable C++ and Objective-C exceptions.
@@ -1546,28 +1583,8 @@ static void addExceptionArgs(const ArgLi
return;
}
- // Exceptions are enabled by default.
- bool ExceptionsEnabled = true;
-
- // This keeps track of whether exceptions were explicitly turned on or off.
- bool DidHaveExplicitExceptionFlag = false;
-
- if (Arg *A = Args.getLastArg(options::OPT_fexceptions,
- options::OPT_fno_exceptions)) {
- if (A->getOption().matches(options::OPT_fexceptions))
- ExceptionsEnabled = true;
- else
- ExceptionsEnabled = false;
-
- DidHaveExplicitExceptionFlag = true;
- }
-
- bool ShouldUseExceptionTables = false;
-
- // Exception tables and cleanups can be enabled with -fexceptions even if the
- // language itself doesn't support exceptions.
- if (ExceptionsEnabled && DidHaveExplicitExceptionFlag)
- ShouldUseExceptionTables = true;
+ // Gather the exception settings from the command line arguments.
+ ExceptionSettings ES = exceptionSettings(Args, Triple);
// Obj-C exceptions are enabled by default, regardless of -fexceptions. This
// is not necessarily sensible, but follows GCC.
@@ -1577,12 +1594,12 @@ static void addExceptionArgs(const ArgLi
true)) {
CmdArgs.push_back("-fobjc-exceptions");
- ShouldUseExceptionTables |=
+ ES.ShouldUseExceptionTables |=
shouldUseExceptionTablesForObjCExceptions(objcRuntime, Triple);
}
if (types::isCXX(InputType)) {
- bool CXXExceptionsEnabled = ExceptionsEnabled;
+ bool CXXExceptionsEnabled = ES.ExceptionsEnabled;
if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions,
options::OPT_fno_cxx_exceptions,
@@ -1597,11 +1614,11 @@ static void addExceptionArgs(const ArgLi
if (CXXExceptionsEnabled) {
CmdArgs.push_back("-fcxx-exceptions");
- ShouldUseExceptionTables = true;
+ ES.ShouldUseExceptionTables = true;
}
}
- if (ShouldUseExceptionTables)
+ if (ES.ShouldUseExceptionTables)
CmdArgs.push_back("-fexceptions");
}
@@ -7296,6 +7313,10 @@ void XCore::Link::ConstructJob(Compilati
assert(Output.isNothing() && "Invalid output.");
}
+ ExceptionSettings EH = exceptionSettings(Args, getToolChain().getTriple());
+ if (EH.ShouldUseExceptionTables)
+ CmdArgs.push_back("-fexceptions");
+
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
const char *Exec =
Modified: cfe/trunk/test/Driver/xcore-opts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/xcore-opts.c?rev=201310&r1=201309&r2=201310&view=diff
==============================================================================
--- cfe/trunk/test/Driver/xcore-opts.c (original)
+++ cfe/trunk/test/Driver/xcore-opts.c Thu Feb 13 04:34:44 2014
@@ -1,13 +1,28 @@
// RUN: %clang -target xcore %s -g -Wl,L1Arg,L2Arg -Wa,A1Arg,A2Arg -fverbose-asm -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -target xcore -x c++ %s -g -Wl,L1Arg,L2Arg -Wa,A1Arg,A2Arg -fverbose-asm -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -target xcore -x c++ %s -fexceptions -### -o %t.o 2>&1 | FileCheck -check-prefix CHECK-EXCEP %s
// CHECK: "-nostdsysteminc"
// CHECK: "-momit-leaf-frame-pointer"
// CHECK-NOT: "-mdisable-fp-elim"
// CHECK: "-fno-signed-char"
// CHECK: "-fno-use-cxa-atexit"
+// CHECK-NOT: "-fcxx-exceptions"
+// CHECK-NOT: "-fexceptions"
// CHECK: "-fno-common"
// CHECH: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
// CHECK: "-c" "-g" "-fverbose-asm" "A1Arg" "A2Arg"
// CHECK: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
// CHECK: "L1Arg" "L2Arg"
+// CHECK-EXCEP: "-fno-use-cxa-atexit"
+// CHECK-EXCEP: "-fcxx-exceptions"
+// CHECK-EXCEP: "-fexceptions"
+// CHECK-EXCEP: "-fno-common"
+// CHECH-EXCEP: xcc" "-o"
+// CHECK-EXCEP-NOT: "-fexceptions"
+// CHECK-EXCEP: xcc" "-o"
+// CHECK-EXCEP: "-fexceptions"
+
More information about the cfe-commits
mailing list