Skip to content

Commit aabb0b1

Browse files
committed
Driver: Handle -Xarch_, including warning for nasty -Xarch_ use cases
we aren't going to support. For example: clang -Xarch_i386 -S -Xarch_i386 -o -Xarch_i386 myi386asm.s ... llvm-svn: 67680
1 parent 0e378b1 commit aabb0b1

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def err_drv_invalid_darwin_version : Error<
3333
"invalid Darwin version number: %0">;
3434
def err_drv_missing_argument : Error<
3535
"argument to '%0' is missing (expected %1 %plural{1:value|:values}1)">;
36+
def err_drv_invalid_Xarch_argument : Error<
37+
"invalid Xarch argument: '%0'">;
3638

3739
def warn_drv_input_file_unused : Warning<
3840
"%0: '%1' input file unused when '%2' is present">;

clang/lib/Driver/ToolChains.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "clang/Driver/Arg.h"
1313
#include "clang/Driver/ArgList.h"
1414
#include "clang/Driver/Driver.h"
15+
#include "clang/Driver/DriverDiagnostic.h"
1516
#include "clang/Driver/HostInfo.h"
17+
#include "clang/Driver/Option.h"
1618

1719
#include "llvm/ADT/StringExtras.h"
1820
#include "llvm/System/Path.h"
@@ -125,8 +127,45 @@ Tool &Darwin_X86::SelectTool(const Compilation &C,
125127
}
126128

127129
DerivedArgList *Darwin_X86::TranslateArgs(InputArgList &Args) const {
128-
// FIXME: Implement!
129-
return new DerivedArgList(Args, true);
130+
DerivedArgList *DAL = new DerivedArgList(Args, false);
131+
132+
for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
133+
Arg *A = *it;
134+
135+
if (A->getOption().matches(options::OPT_Xarch__)) {
136+
// FIXME: Canonicalize name.
137+
if (getArchName() != A->getValue(Args, 0))
138+
continue;
139+
140+
// FIXME: The arg is leaked here, and we should have a nicer
141+
// interface for this.
142+
const Driver &D = getHost().getDriver();
143+
unsigned Prev, Index = Prev = A->getIndex() + 1;
144+
Arg *XarchArg = D.getOpts().ParseOneArg(Args, Index);
145+
146+
// If the argument parsing failed or more than one argument was
147+
// consumed, the -Xarch_ argument's parameter tried to consume
148+
// extra arguments. Emit an error and ignore.
149+
//
150+
// We also want to disallow any options which would alter the
151+
// driver behavior; that isn't going to work in our model. We
152+
// use isDriverOption() as an approximation, although things
153+
// like -O4 are going to slip through.
154+
if (!XarchArg || Index > Prev + 1 ||
155+
XarchArg->getOption().isDriverOption()) {
156+
D.Diag(clang::diag::err_drv_invalid_Xarch_argument)
157+
<< A->getAsString(Args);
158+
continue;
159+
}
160+
161+
A = XarchArg;
162+
}
163+
164+
// FIXME: Translate.
165+
DAL->append(A);
166+
}
167+
168+
return DAL;
130169
}
131170

132171
bool Darwin_X86::IsMathErrnoDefault() const {

clang/test/Driver/Xarch.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: clang -ccc-host-triple i386-apple-darwin9 -m32 -Xarch_i386 -O2 %s -S -### 2> %t.log &&
2+
// RUN: grep ' "-O2" ' %t.log | count 1 &&
3+
// RUN: clang -ccc-host-triple i386-apple-darwin9 -m64 -Xarch_i386 -O2 %s -S -### 2> %t.log &&
4+
// RUN: grep ' "-O2" ' %t.log | count 0 &&
5+
// RUN: grep "argument unused during compilation: '-Xarch_i386 -O2'" %t.log &&
6+
// RUN: not clang -ccc-host-triple i386-apple-darwin9 -m32 -Xarch_i386 -o -Xarch_i386 -S %s -S -Xarch_i386 -o 2> %t.log &&
7+
// RUN: grep "error: invalid Xarch argument: '-Xarch_i386 -o'" %t.log | count 2 &&
8+
// RUN: grep "error: invalid Xarch argument: '-Xarch_i386 -S'" %t.log &&
9+
// RUN: true
10+

0 commit comments

Comments
 (0)