From 80eb669f000e12cbf24e76ed251e81877bb8c84e Mon Sep 17 00:00:00 2001 From: Robert Lytton Date: Thu, 13 Feb 2014 10:34:44 +0000 Subject: [PATCH] XCore target -fexceptions flag handling XCore target has -fno-exception as the default option Pass on "-fexceptions" flag to xcc (linker) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201310 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 73 ++++++++++++++++++++++++++-------------- test/Driver/xcore-opts.c | 15 +++++++++ 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 77a830b12b..60992929b2 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1524,6 +1524,43 @@ shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, 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 ArgList &Args, types::ID InputType, 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 ArgList &Args, types::ID InputType, 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 ArgList &Args, types::ID InputType, 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(Compilation &C, const JobAction &JA, 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 = diff --git a/test/Driver/xcore-opts.c b/test/Driver/xcore-opts.c index adfb024e3f..49d9119616 100644 --- a/test/Driver/xcore-opts.c +++ b/test/Driver/xcore-opts.c @@ -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" + -- 2.40.0