[cfe-commits] r85600 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/analyze.c
Daniel Dunbar
daniel at zuster.org
Fri Oct 30 11:12:20 PDT 2009
Author: ddunbar
Date: Fri Oct 30 13:12:20 2009
New Revision: 85600
URL: http://llvm.org/viewvc/llvm-project?rev=85600&view=rev
Log:
Change the driver to do the Darwin triple mangling itself instead of forwarding
-mmacosx-version-min and -miphoneos-version-min to clang-cc.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/analyze.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=85600&r1=85599&r2=85600&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct 30 13:12:20 2009
@@ -501,6 +501,57 @@
}
}
+/// getEffectiveClangTriple - Get the "effective" target triple, which is the
+/// triple for the target but with the OS version potentially modified for
+/// Darwin's -mmacosx-version-min.
+static std::string getEffectiveClangTriple(const Driver &D,
+ const ToolChain &TC,
+ const ArgList &Args) {
+ llvm::Triple Triple(getLLVMTriple(TC, Args));
+
+ if (Triple.getOS() != llvm::Triple::Darwin) {
+ // Diagnose use of -mmacosx-version-min and -miphoneos-version-min on
+ // non-Darwin.
+ if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ,
+ options::OPT_miphoneos_version_min_EQ))
+ D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
+ return Triple.getTriple();
+ }
+
+ // If -mmacosx-version-min=10.3.9 is specified, change the effective triple
+ // from being something like powerpc-apple-darwin9 to powerpc-apple-darwin7.
+ if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
+ unsigned Major, Minor, Micro;
+ bool HadExtra;
+ if (!Driver::GetReleaseVersion(A->getValue(Args), Major, Minor, Micro,
+ HadExtra) || HadExtra ||
+ Major != 10)
+ D.Diag(clang::diag::err_drv_invalid_version_number)
+ << A->getAsString(Args);
+
+ // Mangle the MacOS version min number into the Darwin number: e.g. 10.3.9
+ // is darwin7.9.
+ llvm::SmallString<16> Str;
+ llvm::raw_svector_ostream(Str) << "darwin" << Minor + 4 << "." << Micro;
+ Triple.setOSName(Str.str());
+ } else if (Arg *A = Args.getLastArg(options::OPT_miphoneos_version_min_EQ)) {
+ unsigned Major, Minor, Micro;
+ bool HadExtra;
+ if (!Driver::GetReleaseVersion(A->getValue(Args), Major, Minor, Micro,
+ HadExtra) || HadExtra)
+ D.Diag(clang::diag::err_drv_invalid_version_number)
+ << A->getAsString(Args);
+
+ // Mangle the iPhoneOS version number into the Darwin number: e.g. 2.0 is 2
+ // -> 9.2.0.
+ llvm::SmallString<16> Str;
+ llvm::raw_svector_ostream(Str) << "darwin9." << Major << "." << Minor;
+ Triple.setOSName(Str.str());
+ }
+
+ return Triple.getTriple();
+}
+
void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Job &Dest,
const InputInfo &Output,
@@ -512,12 +563,12 @@
assert(Inputs.size() == 1 && "Unable to handle multiple inputs.");
+ // Add the "effective" target triple.
CmdArgs.push_back("-triple");
+ std::string TripleStr = getEffectiveClangTriple(D, getToolChain(), Args);
+ CmdArgs.push_back(Args.MakeArgString(TripleStr));
- const char *TripleStr =
- Args.MakeArgString(getLLVMTriple(getToolChain(), Args));
- CmdArgs.push_back(TripleStr);
-
+ // Select the appropriate action.
if (isa<AnalyzeJobAction>(JA)) {
assert(JA.getType() == types::TY_Plist && "Invalid output type.");
CmdArgs.push_back("-analyze");
@@ -712,8 +763,6 @@
Args.AddAllArgs(CmdArgs, options::OPT_v);
Args.AddLastArg(CmdArgs, options::OPT_P);
- Args.AddLastArg(CmdArgs, options::OPT_mmacosx_version_min_EQ);
- Args.AddLastArg(CmdArgs, options::OPT_miphoneos_version_min_EQ);
Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
// Special case debug options to only pass -g to clang. This is
Modified: cfe/trunk/test/Driver/analyze.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/analyze.c?rev=85600&r1=85599&r2=85600&view=diff
==============================================================================
--- cfe/trunk/test/Driver/analyze.c (original)
+++ cfe/trunk/test/Driver/analyze.c Fri Oct 30 13:12:20 2009
@@ -2,8 +2,8 @@
// (at least for a few key ones).
// RUN: env MACOSX_DEPLOYMENT_TARGET=10.5 clang -ccc-host-triple i386-apple-darwin9 -### --analyze -o /dev/null %s -msse 2> %t.log &&
-// RUN: grep '"-analyze"' %t.log &&
-// RUN: grep '"--fmath-errno=0"' %t.log &&
-// RUN: grep '"-target-feature" "+sse"' %t.log &&
-// RUN: grep '"-mmacosx-version-min=10.5"' %t.log
+// RUN: FileCheck --input-file=%t.log %s
+// CHECK: "-analyze"
+// CHECK: "-target-feature" "+sse"
+// CHECK: "--fmath-errno=0"
More information about the cfe-commits
mailing list