aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-08-13 04:44:20 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-08-13 04:44:20 +0000
commitcaeed1d3a5b366ae8fda5dda9bddc7bbb859c41f (patch)
tree931a528e8f0274919e3119ec3a5325851d16f052
parent914ed9d30e9abf829a62aa996b083b1e47c19ff6 (diff)
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
-rw-r--r--include/clang/Driver/OptParser.td3
-rw-r--r--include/clang/Driver/OptTable.h9
-rw-r--r--include/clang/Driver/Option.h10
-rw-r--r--include/clang/Driver/Options.td5
-rw-r--r--lib/Driver/OptTable.cpp2
-rw-r--r--lib/Driver/Option.cpp2
-rw-r--r--test/Driver/gcc_forward.c13
7 files changed, 36 insertions, 8 deletions
diff --git a/include/clang/Driver/OptParser.td b/include/clang/Driver/OptParser.td
index a9f4289fc8..04efd00fb1 100644
--- a/include/clang/Driver/OptParser.td
+++ b/include/clang/Driver/OptParser.td
@@ -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> {
diff --git a/include/clang/Driver/OptTable.h b/include/clang/Driver/OptTable.h
index e4a2eba578..65682805bc 100644
--- a/include/clang/Driver/OptTable.h
+++ b/include/clang/Driver/OptTable.h
@@ -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)
};
}
diff --git a/include/clang/Driver/Option.h b/include/clang/Driver/Option.h
index 0864382cb3..9625465f48 100644
--- a/include/clang/Driver/Option.h
+++ b/include/clang/Driver/Option.h
@@ -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).
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 042c6c64d0..034a234d6b 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -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>;
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp
index 39530f211d..3c363142d7 100644
--- a/lib/Driver/OptTable.cpp
+++ b/lib/Driver/OptTable.cpp
@@ -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) {
diff --git a/lib/Driver/Option.cpp b/lib/Driver/Option.cpp
index dd48af8018..5396250dfa 100644
--- a/lib/Driver/Option.cpp
+++ b/lib/Driver/Option.cpp
@@ -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
index 0000000000..c584a4e8fa
--- /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