r227695 - Tweak behavior due to -fexceptions, in C++ mode, imply -fcxx-exceptions

Filipe Cabecinhas me at filcab.net
Sat Jan 31 15:05:52 PST 2015


Author: filcab
Date: Sat Jan 31 17:05:51 2015
New Revision: 227695

URL: http://llvm.org/viewvc/llvm-project?rev=227695&view=rev
Log:
Tweak behavior due to -fexceptions, in C++ mode, imply -fcxx-exceptions

Added test

Modified:
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/rtti-options.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=227695&r1=227694&r2=227695&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sat Jan 31 17:05:51 2015
@@ -3949,6 +3949,7 @@ void Clang::ConstructJob(Compilation &C,
   if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti,
                     !Triple.isPS4CPU()) ||
       KernelOrKext) {
+    bool IsCXX = types::isCXX(InputType);
     bool RTTIEnabled = false;
     Arg *NoRTTIArg = Args.getLastArg(
         options::OPT_mkernel, options::OPT_fapple_kext, options::OPT_fno_rtti);
@@ -3956,11 +3957,18 @@ void Clang::ConstructJob(Compilation &C,
     // PS4 requires rtti when exceptions are enabled. If -fno-rtti was
     // explicitly passed, error out. Otherwise enable rtti and emit a
     // warning.
-    if (Triple.isPS4CPU()) {
-      if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions)) {
+    Arg *Exceptions = Args.getLastArg(
+        options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
+        options::OPT_fexceptions, options::OPT_fno_exceptions);
+    if (Triple.isPS4CPU() && Exceptions) {
+      bool CXXExceptions =
+          (IsCXX &&
+           Exceptions->getOption().matches(options::OPT_fexceptions)) ||
+          Exceptions->getOption().matches(options::OPT_fcxx_exceptions);
+      if (CXXExceptions) {
         if (NoRTTIArg)
           D.Diag(diag::err_drv_argument_not_allowed_with)
-              << NoRTTIArg->getAsString(Args) << A->getAsString(Args);
+              << NoRTTIArg->getAsString(Args) << Exceptions->getAsString(Args);
         else {
           RTTIEnabled = true;
           D.Diag(diag::warn_drv_enabling_rtti_with_exceptions);

Modified: cfe/trunk/test/Driver/rtti-options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/rtti-options.cpp?rev=227695&r1=227694&r2=227695&view=diff
==============================================================================
--- cfe/trunk/test/Driver/rtti-options.cpp (original)
+++ cfe/trunk/test/Driver/rtti-options.cpp Sat Jan 31 17:05:51 2015
@@ -22,6 +22,11 @@
 // RUN: %clang -### -c -target x86_64-scei-ps4 -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-EXC-WARN %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown -fcxx-exceptions -fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
 // RUN: %clang -### -c -target x86_64-unknown-unknown -fcxx-exceptions %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
+// In C++, -fexceptions implies -fcxx-exceptions
+// RUN: %clang -x c++ -### -c -target x86_64-scei-ps4 -fexceptions -fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-EXC-ERROR %s
+// RUN: %clang -x c++ -### -c -target x86_64-scei-ps4 -fexceptions %s 2>&1 | FileCheck -check-prefix=CHECK-EXC-WARN %s
+// RUN: %clang -x c++ -### -c -target x86_64-unknown-unknown -fexceptions -fno-rtti %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
+// RUN: %clang -x c++ -### -c -target x86_64-unknown-unknown -fexceptions %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
 
 // -frtti + exceptions
 // RUN: %clang -### -c -target x86_64-scei-ps4 -fcxx-exceptions -frtti %s 2>&1 | FileCheck -check-prefix=CHECK-OK %s
@@ -38,6 +43,7 @@
 // CHECK-SAN-WARN: implicitly disabling vptr sanitizer because rtti wasn't enabled
 // CHECK-SAN-ERROR: invalid argument '-fsanitize=vptr' not allowed with '-fno-rtti'
 // CHECK-EXC-WARN: implicitly enabling rtti for exception handling
+// CHECK-EXC-ERROR: invalid argument '-fno-rtti' not allowed with '-fexceptions'
 // CHECK-EXC-ERROR-CXX: invalid argument '-fno-rtti' not allowed with '-fcxx-exceptions'
 // CHECK-RTTI-NOT: "-fno-rtti"
 // CHECK-NO-RTTI-NOT: "-frtti"





More information about the cfe-commits mailing list