]> granicus.if.org Git - clang/commitdiff
Driver/OptParser: Add a NoForward flag to prevent forwarding certain options to
authorDaniel Dunbar <daniel@zuster.org>
Fri, 13 Aug 2010 04:44:20 +0000 (04:44 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 13 Aug 2010 04:44:20 +0000 (04:44 +0000)
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

include/clang/Driver/OptParser.td
include/clang/Driver/OptTable.h
include/clang/Driver/Option.h
include/clang/Driver/Options.td
lib/Driver/OptTable.cpp
lib/Driver/Option.cpp
test/Driver/gcc_forward.c [new file with mode: 0644]

index a9f4289fc86e0e0088c33966276348e631bf8699..04efd00fb1d878452c14d478c2a0ae9a2e817677 100644 (file)
@@ -82,6 +82,9 @@ def Unsupported : OptionFlag;
 // 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> {
index e4a2eba578b882c2505b2faeff834ec8fe822830..65682805bc8b6e3821046b5ae7ef3f29ad73bcd7 100644 (file)
@@ -25,10 +25,11 @@ namespace options {
     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)
   };
 }
 
index 0864382cb3a63bf4a36c9fd781b7f366c6bc3019..9625465f48f4d2836724f83f2a9241d2180cced1 100644 (file)
@@ -92,6 +92,9 @@ namespace driver {
     /// 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 @@ namespace driver {
     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).
index 042c6c64d09c8b89e7f6820c4d102b9ce122317f..034a234d6b00b82bb4b806fe9aa05933b37bda5e 100644 (file)
@@ -180,7 +180,8 @@ def Xarch__ : JoinedAndSeparate<"-Xarch_">, Flags<[DriverOption]>;
 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 mhard_float : Flag<"-mhard-float">, Group<m_Group>;
 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>;
index 39530f211d808c1fb4fb7e967c768c23cd446c6c..3c363142d7fd8be45b9fe04cd746245eea523935 100644 (file)
@@ -164,6 +164,8 @@ Option *OptTable::CreateOption(unsigned id) const {
     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) {
index dd48af8018ac455e2f207d69b93b73f153de7d85..5396250dfae175c2489af2675300689da71e81d6 100644 (file)
@@ -20,7 +20,7 @@ Option::Option(OptionClass _Kind, OptSpecifier _ID, const char *_Name,
                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 (file)
index 0000000..c584a4e
--- /dev/null
@@ -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