[PATCH] XCore target -fexceptions flag handling

robert lytton robert at xmos.com
Tue Jan 21 04:16:16 PST 2014


  The code has been refactored as suggested.

Hi echristo, rafael.espindola,

http://llvm-reviews.chandlerc.com/D2570

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2570?vs=6539&id=6556#toc

Files:
  lib/Driver/Tools.cpp
  test/Driver/xcore-opts.c

Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1511,6 +1511,43 @@
            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.
@@ -1533,28 +1570,8 @@
     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.
@@ -1564,12 +1581,12 @@
                    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,
@@ -1584,11 +1601,11 @@
     if (CXXExceptionsEnabled) {
       CmdArgs.push_back("-fcxx-exceptions");
 
-      ShouldUseExceptionTables = true;
+      ES.ShouldUseExceptionTables = true;
     }
   }
 
-  if (ShouldUseExceptionTables)
+  if (ES.ShouldUseExceptionTables)
     CmdArgs.push_back("-fexceptions");
 }
 
@@ -7105,6 +7122,10 @@
     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 =
Index: test/Driver/xcore-opts.c
===================================================================
--- test/Driver/xcore-opts.c
+++ 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"
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2570.3.patch
Type: text/x-patch
Size: 5174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140121/2a7d91fb/attachment.bin>


More information about the cfe-commits mailing list