Driver/OptParser: Add a NoForward flag to prevent forwarding certain options to
GCC.
 - Mark -Xclang and -mlinker-version= with it for now, although I am sure there
   are more.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111005 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/OptParser.td b/include/clang/Driver/OptParser.td
index a9f4289..04efd00 100644
--- a/include/clang/Driver/OptParser.td
+++ b/include/clang/Driver/OptParser.td
@@ -82,6 +82,9 @@
 // arguments to implement hidden help groups.
 def HelpHidden : OptionFlag;
 
+// NoForward - The option should not be implicitly forwarded to other tools.
+def NoForward : OptionFlag;
+
 // Define the option group class.
 
 class OptionGroup<string name> {
diff --git a/include/clang/Driver/OptTable.h b/include/clang/Driver/OptTable.h
index e4a2eba..6568280 100644
--- a/include/clang/Driver/OptTable.h
+++ b/include/clang/Driver/OptTable.h
@@ -25,10 +25,11 @@
     HelpHidden       = (1 << 1),
     LinkerInput      = (1 << 2),
     NoArgumentUnused = (1 << 3),
-    RenderAsInput    = (1 << 4),
-    RenderJoined     = (1 << 5),
-    RenderSeparate   = (1 << 6),
-    Unsupported      = (1 << 7)
+    NoForward        = (1 << 4),
+    RenderAsInput    = (1 << 5),
+    RenderJoined     = (1 << 6),
+    RenderSeparate   = (1 << 7),
+    Unsupported      = (1 << 8)
   };
 }
 
diff --git a/include/clang/Driver/Option.h b/include/clang/Driver/Option.h
index 0864382..9625465 100644
--- a/include/clang/Driver/Option.h
+++ b/include/clang/Driver/Option.h
@@ -92,6 +92,9 @@
     /// This option should not report argument unused errors.
     bool NoArgumentUnused : 1;
 
+    /// This option should not be implicitly forwarded.
+    bool NoForward : 1;
+
   protected:
     Option(OptionClass Kind, OptSpecifier ID, const char *Name,
            const OptionGroup *Group, const Option *Alias);
@@ -124,7 +127,12 @@
     bool hasNoArgumentUnused() const { return NoArgumentUnused; }
     void setNoArgumentUnused(bool Value) { NoArgumentUnused = Value; }
 
-    bool hasForwardToGCC() const { return !DriverOption && !LinkerInput; }
+    bool hasNoForward() const { return NoForward; }
+    void setNoForward(bool Value) { NoForward = Value; }
+
+    bool hasForwardToGCC() const {
+      return !NoForward && !DriverOption && !LinkerInput;
+    }
 
     /// getUnaliasedOption - Return the final option this option
     /// aliases (itself, if the option has no alias).
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 042c6c6..034a234 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -180,7 +180,8 @@
 def Xassembler : Separate<"-Xassembler">,
   HelpText<"Pass <arg> to the assembler">, MetaVarName<"<arg>">;
 def Xclang : Separate<"-Xclang">,
-  HelpText<"Pass <arg> to the clang compiler">, MetaVarName<"<arg>">;
+  HelpText<"Pass <arg> to the clang compiler">, MetaVarName<"<arg>">,
+  Flags<[NoForward]>;
 def Xlinker : Separate<"-Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass <arg> to the linker">, MetaVarName<"<arg>">;
 def Xpreprocessor : Separate<"-Xpreprocessor">,
@@ -442,7 +443,7 @@
 def miphoneos_version_min_EQ : Joined<"-miphoneos-version-min=">, Group<m_Group>;
 def mios_version_min_EQ : Joined<"-mios-version-min=">, Alias<miphoneos_version_min_EQ>;
 def mkernel : Flag<"-mkernel">, Group<m_Group>;
-def mlinker_version_EQ : Joined<"-mlinker-version=">;
+def mlinker_version_EQ : Joined<"-mlinker-version=">, Flags<[NoForward]>;
 def mllvm : Separate<"-mllvm">;
 def mmacosx_version_min_EQ : Joined<"-mmacosx-version-min=">, Group<m_Group>;
 def mmmx : Flag<"-mmmx">, Group<m_x86_Features_Group>;
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp
index 39530f2..3c36314 100644
--- a/lib/Driver/OptTable.cpp
+++ b/lib/Driver/OptTable.cpp
@@ -164,6 +164,8 @@
     Opt->setLinkerInput(true);
   if (info.Flags & NoArgumentUnused)
     Opt->setNoArgumentUnused(true);
+  if (info.Flags & NoForward)
+    Opt->setNoForward(true);
   if (info.Flags & RenderAsInput)
     Opt->setNoOptAsInput(true);
   if (info.Flags & RenderJoined) {
diff --git a/lib/Driver/Option.cpp b/lib/Driver/Option.cpp
index dd48af8..5396250 100644
--- a/lib/Driver/Option.cpp
+++ b/lib/Driver/Option.cpp
@@ -20,7 +20,7 @@
                const OptionGroup *_Group, const Option *_Alias)
   : Kind(_Kind), ID(_ID.getID()), Name(_Name), Group(_Group), Alias(_Alias),
     Unsupported(false), LinkerInput(false), NoOptAsInput(false),
-    DriverOption(false), NoArgumentUnused(false) {
+    DriverOption(false), NoArgumentUnused(false), NoForward(false) {
 
   // Multi-level aliases are not supported, and alias options cannot
   // have groups. This just simplifies option tracking, it is not an
diff --git a/test/Driver/gcc_forward.c b/test/Driver/gcc_forward.c
new file mode 100644
index 0000000..c584a4e
--- /dev/null
+++ b/test/Driver/gcc_forward.c
@@ -0,0 +1,13 @@
+// Check that we don't try to forward -Xclang or -mlinker-version to GCC.
+//
+// RUN: %clang -ccc-host-triple powerpc-unknown-unknown \
+// RUN:   -ccc-clang-archs i386 -c %s \
+// RUN:   -Xclang foo-bar \
+// RUN:   -mlinker-version=10 -### 2> %t
+// RUN: FileCheck < %t %s
+//
+// CHECK: gcc{{.*}}"
+// CHECK-NOT: "-mlinker-version=10"
+// CHECK-NOT: "-Xclang"
+// CHECK-NOT: "foo-bar"
+// CHECK: gcc_forward