[clang] 9833b57 - [clang][driver] Add -foperator-names

Markus Böck via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 10 08:02:00 PDT 2021


Author: Markus Böck
Date: 2021-06-10T17:01:35+02:00
New Revision: 9833b57981c4e9402a326b5acd805e074cd2c802

URL: https://github.com/llvm/llvm-project/commit/9833b57981c4e9402a326b5acd805e074cd2c802
DIFF: https://github.com/llvm/llvm-project/commit/9833b57981c4e9402a326b5acd805e074cd2c802.diff

LOG: [clang][driver] Add -foperator-names

This patch adds the command line option -foperator-names which acts as the opposite of -fno-operator-names. With this command line option it is possible to reenable C++ operator keywords on the command line if -fno-operator-names had previously been passed.

Differential Revision: https://reviews.llvm.org/D103749

Added: 
    clang/test/Driver/cxx-operator-names.cpp

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7dcee76b4ed8..862cb32730a2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2221,9 +2221,10 @@ def fno_ms_compatibility : Flag<["-"], "fno-ms-compatibility">, Group<f_Group>,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, Group<f_Group>;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group<f_Group>, Flags<[CC1Option]>;
 def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, Group<f_Group>;
-def fno_operator_names : Flag<["-"], "fno-operator-names">, Group<f_Group>,
-  HelpText<"Do not treat C++ operator name keywords as synonyms for operators">,
-  Flags<[CC1Option]>, MarshallingInfoNegativeFlag<LangOpts<"CXXOperatorNames">, cplusplus.KeyPath>;
+defm operator_names : BoolFOption<"operator-names",
+  LangOpts<"CXXOperatorNames">, Default<cplusplus.KeyPath>,
+  NegFlag<SetFalse, [CC1Option], "Do not treat C++ operator name keywords as synonyms for operators">,
+  PosFlag<SetTrue>>;
 def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group<f_Group>,
   Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">,
   MarshallingInfoFlag<DiagnosticOpts<"AbsolutePath">>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 6eaa8938a8d2..3163c26e4472 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5654,11 +5654,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
 
+  if (Args.hasFlag(options::OPT_fno_operator_names,
+                   options::OPT_foperator_names, false))
+    CmdArgs.push_back("-fno-operator-names");
+
   // Forward -f (flag) options which we can pass directly.
   Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
   Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
   Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
-  Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
                   options::OPT_fno_emulated_tls);
 

diff  --git a/clang/test/Driver/cxx-operator-names.cpp b/clang/test/Driver/cxx-operator-names.cpp
new file mode 100644
index 000000000000..d8a7a01449bb
--- /dev/null
+++ b/clang/test/Driver/cxx-operator-names.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang -### -S -foperator-names -fno-operator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-1 %s
+// CHECK-1: "-fno-operator-names"
+
+// RUN: %clang -### -S -fno-operator-names -foperator-names %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=CHECK-2 %s
+// CHECK-2-NOT: "-fno-operator-names"


        


More information about the cfe-commits mailing list