[clang] 46cd312 - [Driver] Revert D139717 and add -Xparser/-Xcompiler instead

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 22 12:51:25 PST 2022


Author: Fangrui Song
Date: 2022-12-22T12:51:20-08:00
New Revision: 46cd3127fe54ab51f813492017c5acdbeb1baf26

URL: https://github.com/llvm/llvm-project/commit/46cd3127fe54ab51f813492017c5acdbeb1baf26
DIFF: https://github.com/llvm/llvm-project/commit/46cd3127fe54ab51f813492017c5acdbeb1baf26.diff

LOG: [Driver] Revert D139717 and add -Xparser/-Xcompiler instead

Some macOS projects use -Xparser even if it leads to a
-Wunused-command-line-argument warning. It doesn't justify adding a broad Joined
`-X` (IgnoredGCCCompat) as GCC doesn't really support these arbitrary `-X`
options.

Note: `-Xcompiler foo` is a GNU libtool option, not a driver option.
It is misused by some ChromeOS packages (but not by Gentoo).
Keep it for a while.

It seems that GCC < 4.6 reports g++: unrecognized option '-Xfoo' but exit with 0.
GCC >= 4.6 reports g++: error: unrecognized option '-Xfoo' and exits with 1.
It never supports -Xcompiler or -Xparser, so `IgnoredGCCCompat` is not justified.

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

Added: 
    clang/test/Driver/warn-Xparser.c

Modified: 
    clang/include/clang/Driver/Options.td

Removed: 
    clang/test/Misc/warn-not-error-Xfoo.c


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e7765dbe2c30b..86ef91c0b7fed 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -846,7 +846,10 @@ def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">, Group<Preprocessor_Group>,
   HelpText<"Pass <arg> to the preprocessor">, MetaVarName<"<arg>">;
 def X_Flag : Flag<["-"], "X">, Group<Link_Group>;
-def X_Joined : Joined<["-"], "X">, IgnoredGCCCompat;
+// Used by some macOS projects. IgnoredGCCCompat is a misnomer since GCC doesn't allow it.
+def : Flag<["-"], "Xparser">, IgnoredGCCCompat;
+// FIXME -Xcompiler is misused by some ChromeOS packages. Remove it after a while.
+def : Flag<["-"], "Xcompiler">, IgnoredGCCCompat;
 def Z_Flag : Flag<["-"], "Z">, Group<Link_Group>;
 def all__load : Flag<["-"], "all_load">;
 def allowable__client : Separate<["-"], "allowable_client">;

diff  --git a/clang/test/Driver/warn-Xparser.c b/clang/test/Driver/warn-Xparser.c
new file mode 100644
index 0000000000000..191826a6f4af9
--- /dev/null
+++ b/clang/test/Driver/warn-Xparser.c
@@ -0,0 +1,6 @@
+/// Some macOS projects use -Xparser.
+// RUN: %clang -c -Xparser %s 2>&1 | FileCheck %s
+
+// CHECK: warning: argument unused during compilation: '-Xparser' [-Wunused-command-line-argument]
+
+void f(void) {}

diff  --git a/clang/test/Misc/warn-not-error-Xfoo.c b/clang/test/Misc/warn-not-error-Xfoo.c
deleted file mode 100644
index 54d97c618cddf..0000000000000
--- a/clang/test/Misc/warn-not-error-Xfoo.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// RUN: %clang -c %s -o /dev/null -Xfoo < %s 2>&1 | FileCheck --check-prefix=CHECK_STANDALONE_FOO %s
-// RUN: %clang -c %s -o /dev/null -Xfoo=bar 2>&1 | FileCheck --check-prefix=CHECK_JOINED_FOO %s
-
-// This test ensures that we only warn on -X<unknown> and -X<unknown=value>
-// in case it is used downstream. If we error, we can't ignore it and some
-// use of these (ignored) flags are in legacy use.
-// TODO: Deprecate with timebox warning so consumers can respond.
-
-// CHECK_STANDALONE_FOO: warning: argument unused during compilation: '-Xfoo' [-Wunused-command-line-argument]
-// CHECK_JOINED_FOO: warning: argument unused during compilation: '-Xfoo=bar' [-Wunused-command-line-argument]
-
-// CHECK-NOT: clang{.*}: error: unknown argument:
-
-void f(void) {}


        


More information about the cfe-commits mailing list