r188331 - clang-cl: Support /link option and set target to win32
Hans Wennborg
hans at hanshq.net
Tue Aug 13 16:38:58 PDT 2013
Author: hans
Date: Tue Aug 13 18:38:57 2013
New Revision: 188331
URL: http://llvm.org/viewvc/llvm-project?rev=188331&view=rev
Log:
clang-cl: Support /link option and set target to win32
This adds support for the /link option, which forwards
subsequent arguments to the linker.
The test for this will only work when targetting win32.
Since that's the only target where clang-cl makes sense,
use that target by default.
Differential Revision: http://llvm-reviews.chandlerc.com/D1388
Added:
cfe/trunk/test/Driver/cl-link.c
Modified:
cfe/trunk/include/clang/Driver/CLCompatOptions.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=188331&r1=188330&r2=188331&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)
+++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Tue Aug 13 18:38:57 2013
@@ -32,6 +32,9 @@ class CLIgnoredJoined<string name> : Opt
class CLJoinedOrSeparate<string name> : Option<["/", "-"], name,
KIND_JOINED_OR_SEPARATE>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
+class CLRemainingArgs<string name> : Option<["/", "-"], name,
+ KIND_REMAINING_ARGS>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
+
// Aliases:
def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias<c>;
@@ -96,6 +99,8 @@ def _SLASH_Fe : CLJoined<"Fe">,
def _SLASH_Fo : CLJoined<"Fo">,
HelpText<"Set output object file, or directory (ends in / or \\)">,
MetaVarName<"<file or directory>">;
+def _SLASH_link : CLRemainingArgs<"link">,
+ HelpText<"Forward options to the linker">, MetaVarName<"<options>">;
def _SLASH_MD : CLFlag<"MD">,
HelpText<"Use DLL run-time">;
def _SLASH_MDd : CLFlag<"MDd">,
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=188331&r1=188330&r2=188331&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Aug 13 18:38:57 2013
@@ -351,6 +351,12 @@ Compilation *Driver::BuildCompilation(Ar
options::OPT_ccc_pch_is_pth);
// FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld
// and getToolChain is const.
+ if (IsCLMode()) {
+ // clang-cl targets Win32.
+ llvm::Triple T(DefaultTargetTriple);
+ T.setOSName(llvm::Triple::getOSTypeName(llvm::Triple::Win32));
+ DefaultTargetTriple = T.str();
+ }
if (const Arg *A = Args->getLastArg(options::OPT_target))
DefaultTargetTriple = A->getValue();
if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=188331&r1=188330&r2=188331&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Aug 13 18:38:57 2013
@@ -6590,12 +6590,14 @@ void visualstudio::Link::ConstructJob(Co
CmdArgs.push_back("-nologo");
Args.AddAllArgValues(CmdArgs, options::OPT_l);
+ Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
// Add filenames immediately.
for (InputInfoList::const_iterator
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
if (it->isFilename())
CmdArgs.push_back(it->getFilename());
+ // FIXME: Forward -Wl, etc.
}
const char *Exec =
Added: cfe/trunk/test/Driver/cl-link.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-link.c?rev=188331&view=auto
==============================================================================
--- cfe/trunk/test/Driver/cl-link.c (added)
+++ cfe/trunk/test/Driver/cl-link.c Tue Aug 13 18:38:57 2013
@@ -0,0 +1,12 @@
+// Don't attempt slash switches on msys bash.
+// REQUIRES: shell-preserves-root
+
+// Note: %s must be preceded by -- or bound to another option, otherwise it may
+// be interpreted as a command-line option, e.g. on Mac where %s is commonly
+// under /Users.
+
+// RUN: %clang_cl /Tc%s -### /link foo bar baz 2>&1 | FileCheck %s
+// CHECK: link.exe
+// CHECK: "foo"
+// CHECK: "bar"
+// CHECK: "baz"
More information about the cfe-commits
mailing list