blob: b8de5ad4918293d03d8a84ebf9c48f78d2c8e608 [file] [log] [blame]
Chandler Carruth1fc603e2011-12-17 23:10:01 +00001//===--- ToolChains.cpp - ToolChain Implementations -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "ToolChains.h"
David Majnemere11d3732015-06-08 00:22:46 +000011#include "Tools.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000012#include "clang/Basic/CharInfo.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000013#include "clang/Basic/Version.h"
Chandler Carruth1fc603e2011-12-17 23:10:01 +000014#include "clang/Driver/Compilation.h"
15#include "clang/Driver/Driver.h"
Rafael Espindola79764462013-03-24 15:06:53 +000016#include "clang/Driver/DriverDiagnostic.h"
Chandler Carruth1fc603e2011-12-17 23:10:01 +000017#include "clang/Driver/Options.h"
Zachary Turner0eaf8fc2014-10-22 20:40:28 +000018#include "llvm/ADT/StringExtras.h"
Alp Tokerf1ffc842014-06-22 04:31:15 +000019#include "llvm/Config/llvm-config.h"
Reid Kleckner898229a2013-06-14 17:17:23 +000020#include "llvm/Option/Arg.h"
21#include "llvm/Option/ArgList.h"
Adrian McCarthye4b26fc2016-05-13 23:20:11 +000022#include "llvm/Support/ConvertUTF.h"
Chandler Carruth1fc603e2011-12-17 23:10:01 +000023#include "llvm/Support/ErrorHandling.h"
Zachary Turner0eaf8fc2014-10-22 20:40:28 +000024#include "llvm/Support/FileSystem.h"
25#include "llvm/Support/Process.h"
Reid Kleckner6b7156b2015-01-23 19:16:25 +000026#include <cstdio>
27
Chandler Carruth1fc603e2011-12-17 23:10:01 +000028// Include the necessary headers to interface with the Windows registry and
29// environment.
Alp Tokerf1ffc842014-06-22 04:31:15 +000030#if defined(LLVM_ON_WIN32)
Alp Tokerfcce1832014-06-22 03:27:45 +000031#define USE_WIN32
32#endif
33
34#ifdef USE_WIN32
Chandler Carruth1fc603e2011-12-17 23:10:01 +000035 #define WIN32_LEAN_AND_MEAN
36 #define NOGDI
Yaron Keren7fc6f1e2014-12-04 21:46:50 +000037 #ifndef NOMINMAX
38 #define NOMINMAX
39 #endif
Logan Chien733e3c62014-06-24 16:18:10 +000040 #include <windows.h>
Chandler Carruth1fc603e2011-12-17 23:10:01 +000041#endif
42
43using namespace clang::driver;
44using namespace clang::driver::toolchains;
45using namespace clang;
Reid Kleckner898229a2013-06-14 17:17:23 +000046using namespace llvm::opt;
Chandler Carruth1fc603e2011-12-17 23:10:01 +000047
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000048MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple& Triple,
49 const ArgList &Args)
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000050 : ToolChain(D, Triple, Args) {
Zachary Turner719f58c2014-12-01 23:06:47 +000051 getProgramPaths().push_back(getDriver().getInstalledDir());
52 if (getDriver().getInstalledDir() != getDriver().Dir)
53 getProgramPaths().push_back(getDriver().Dir);
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000054}
55
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000056Tool *MSVCToolChain::buildLinker() const {
Douglas Katzman95354292015-06-23 20:42:09 +000057 return new tools::visualstudio::Linker(*this);
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000058}
59
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000060Tool *MSVCToolChain::buildAssembler() const {
Saleem Abdulrasool377066a2014-03-27 22:50:18 +000061 if (getTriple().isOSBinFormatMachO())
Douglas Katzman95354292015-06-23 20:42:09 +000062 return new tools::darwin::Assembler(*this);
Alp Tokerc8d4f0f2013-11-22 08:27:46 +000063 getDriver().Diag(clang::diag::err_no_external_assembler);
Craig Topper92fc2df2014-05-17 16:56:41 +000064 return nullptr;
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000065}
66
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000067bool MSVCToolChain::IsIntegratedAssemblerDefault() const {
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000068 return true;
69}
70
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000071bool MSVCToolChain::IsUnwindTablesDefault() const {
Reid Kleckner6b3a9402014-09-04 18:13:12 +000072 // Emit unwind tables by default on Win64. All non-x86_32 Windows platforms
73 // such as ARM and PPC actually require unwind tables, but LLVM doesn't know
74 // how to generate them yet.
Akira Hatanakae4218132016-05-05 01:41:07 +000075
76 // Don't emit unwind tables by default for MachO targets.
77 if (getTriple().isOSBinFormatMachO())
78 return false;
79
Reid Kleckner6b3a9402014-09-04 18:13:12 +000080 return getArch() == llvm::Triple::x86_64;
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000081}
82
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000083bool MSVCToolChain::isPICDefault() const {
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000084 return getArch() == llvm::Triple::x86_64;
85}
86
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000087bool MSVCToolChain::isPIEDefault() const {
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000088 return false;
89}
90
Saleem Abdulrasool819f3912014-10-22 02:37:29 +000091bool MSVCToolChain::isPICDefaultForced() const {
Hans Wennborg1cc6cce2013-08-30 09:42:06 +000092 return getArch() == llvm::Triple::x86_64;
93}
94
Zachary Turner0eaf8fc2014-10-22 20:40:28 +000095#ifdef USE_WIN32
96static bool readFullStringValue(HKEY hkey, const char *valueName,
97 std::string &value) {
Aaron Ballmanb06a3592016-06-23 14:33:53 +000098 std::wstring WideValueName;
99 if (!llvm::ConvertUTF8toWide(valueName, WideValueName))
100 return false;
101
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000102 DWORD result = 0;
103 DWORD valueSize = 0;
104 DWORD type = 0;
105 // First just query for the required size.
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000106 result = RegQueryValueExW(hkey, WideValueName.c_str(), NULL, &type, NULL,
107 &valueSize);
108 if (result != ERROR_SUCCESS || type != REG_SZ || !valueSize)
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000109 return false;
110 std::vector<BYTE> buffer(valueSize);
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000111 result = RegQueryValueExW(hkey, WideValueName.c_str(), NULL, NULL, &buffer[0],
112 &valueSize);
113 if (result == ERROR_SUCCESS) {
114 std::wstring WideValue(reinterpret_cast<const wchar_t *>(buffer.data()),
115 valueSize / sizeof(wchar_t));
116 // The destination buffer must be empty as an invariant of the conversion
117 // function; but this function is sometimes called in a loop that passes in
118 // the same buffer, however. Simply clear it out so we can overwrite it.
119 value.clear();
120 return llvm::convertWideToUTF8(WideValue, value);
121 }
122 return false;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000123}
124#endif
125
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000126/// \brief Read registry string.
127/// This also supports a means to look for high-versioned keys by use
128/// of a $VERSION placeholder in the key path.
129/// $VERSION in the key path is a placeholder for the version number,
130/// causing the highest value path to be searched for and used.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000131/// I.e. "SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
132/// There can be additional characters in the component. Only the numeric
133/// characters are compared. This function only searches HKLM.
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000134static bool getSystemRegistryString(const char *keyPath, const char *valueName,
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000135 std::string &value, std::string *phValue) {
Alp Tokerfcce1832014-06-22 03:27:45 +0000136#ifndef USE_WIN32
137 return false;
138#else
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000139 HKEY hRootKey = HKEY_LOCAL_MACHINE;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000140 HKEY hKey = NULL;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000141 long lResult;
142 bool returnValue = false;
143
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000144 const char *placeHolder = strstr(keyPath, "$VERSION");
145 std::string bestName;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000146 // If we have a $VERSION placeholder, do the highest-version search.
147 if (placeHolder) {
148 const char *keyEnd = placeHolder - 1;
149 const char *nextKey = placeHolder;
150 // Find end of previous key.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000151 while ((keyEnd > keyPath) && (*keyEnd != '\\'))
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000152 keyEnd--;
153 // Find end of key containing $VERSION.
154 while (*nextKey && (*nextKey != '\\'))
155 nextKey++;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000156 size_t partialKeyLength = keyEnd - keyPath;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000157 char partialKey[256];
Daniel Marjamakie1146692016-01-27 07:33:50 +0000158 if (partialKeyLength >= sizeof(partialKey))
159 partialKeyLength = sizeof(partialKey) - 1;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000160 strncpy(partialKey, keyPath, partialKeyLength);
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000161 partialKey[partialKeyLength] = '\0';
162 HKEY hTopKey = NULL;
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000163 lResult = RegOpenKeyExA(hRootKey, partialKey, 0, KEY_READ | KEY_WOW64_32KEY,
164 &hTopKey);
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000165 if (lResult == ERROR_SUCCESS) {
166 char keyName[256];
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000167 double bestValue = 0.0;
168 DWORD index, size = sizeof(keyName) - 1;
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000169 for (index = 0; RegEnumKeyExA(hTopKey, index, keyName, &size, NULL, NULL,
170 NULL, NULL) == ERROR_SUCCESS;
171 index++) {
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000172 const char *sp = keyName;
Jordan Rosea7d03842013-02-08 22:30:41 +0000173 while (*sp && !isDigit(*sp))
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000174 sp++;
175 if (!*sp)
176 continue;
177 const char *ep = sp + 1;
Jordan Rosea7d03842013-02-08 22:30:41 +0000178 while (*ep && (isDigit(*ep) || (*ep == '.')))
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000179 ep++;
180 char numBuf[32];
181 strncpy(numBuf, sp, sizeof(numBuf) - 1);
182 numBuf[sizeof(numBuf) - 1] = '\0';
Hans Wennborgd2192312013-10-10 18:03:08 +0000183 double dvalue = strtod(numBuf, NULL);
184 if (dvalue > bestValue) {
185 // Test that InstallDir is indeed there before keeping this index.
186 // Open the chosen key path remainder.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000187 bestName = keyName;
Hans Wennborgd2192312013-10-10 18:03:08 +0000188 // Append rest of key.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000189 bestName.append(nextKey);
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000190 lResult = RegOpenKeyExA(hTopKey, bestName.c_str(), 0,
191 KEY_READ | KEY_WOW64_32KEY, &hKey);
Hans Wennborgd2192312013-10-10 18:03:08 +0000192 if (lResult == ERROR_SUCCESS) {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000193 lResult = readFullStringValue(hKey, valueName, value);
Hans Wennborgd2192312013-10-10 18:03:08 +0000194 if (lResult == ERROR_SUCCESS) {
Hans Wennborgd2192312013-10-10 18:03:08 +0000195 bestValue = dvalue;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000196 if (phValue)
197 *phValue = bestName;
Hans Wennborgd2192312013-10-10 18:03:08 +0000198 returnValue = true;
199 }
200 RegCloseKey(hKey);
201 }
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000202 }
203 size = sizeof(keyName) - 1;
204 }
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000205 RegCloseKey(hTopKey);
206 }
207 } else {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000208 lResult =
Aaron Ballmanb06a3592016-06-23 14:33:53 +0000209 RegOpenKeyExA(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000210 if (lResult == ERROR_SUCCESS) {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000211 lResult = readFullStringValue(hKey, valueName, value);
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000212 if (lResult == ERROR_SUCCESS)
213 returnValue = true;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000214 if (phValue)
215 phValue->clear();
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000216 RegCloseKey(hKey);
217 }
218 }
219 return returnValue;
Alp Tokerfcce1832014-06-22 03:27:45 +0000220#endif // USE_WIN32
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000221}
222
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000223// Convert LLVM's ArchType
224// to the corresponding name of Windows SDK libraries subfolder
225static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) {
226 switch (Arch) {
227 case llvm::Triple::x86:
228 return "x86";
229 case llvm::Triple::x86_64:
230 return "x64";
231 case llvm::Triple::arm:
232 return "arm";
233 default:
234 return "";
235 }
236}
237
Igor Kudrinf2e75242015-09-24 05:16:36 +0000238// Find the most recent version of Universal CRT or Windows 10 SDK.
239// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
240// directory by name and uses the last one of the list.
241// So we compare entry names lexicographically to find the greatest one.
242static bool getWindows10SDKVersion(const std::string &SDKPath,
243 std::string &SDKVersion) {
244 SDKVersion.clear();
245
246 std::error_code EC;
247 llvm::SmallString<128> IncludePath(SDKPath);
248 llvm::sys::path::append(IncludePath, "Include");
249 for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
250 DirIt != DirEnd && !EC; DirIt.increment(EC)) {
251 if (!llvm::sys::fs::is_directory(DirIt->path()))
252 continue;
253 StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
254 // If WDK is installed, there could be subfolders like "wdf" in the
255 // "Include" directory.
256 // Allow only directories which names start with "10.".
257 if (!CandidateName.startswith("10."))
258 continue;
259 if (CandidateName > SDKVersion)
260 SDKVersion = CandidateName;
261 }
262
263 return !SDKVersion.empty();
264}
265
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000266/// \brief Get Windows SDK installation directory.
Igor Kudrinf2e75242015-09-24 05:16:36 +0000267bool MSVCToolChain::getWindowsSDKDir(std::string &Path, int &Major,
268 std::string &WindowsSDKIncludeVersion,
269 std::string &WindowsSDKLibVersion) const {
270 std::string RegistrySDKVersion;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000271 // Try the Windows registry.
Igor Kudrinf2e75242015-09-24 05:16:36 +0000272 if (!getSystemRegistryString(
273 "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
274 "InstallationFolder", Path, &RegistrySDKVersion))
275 return false;
276 if (Path.empty() || RegistrySDKVersion.empty())
277 return false;
278
279 WindowsSDKIncludeVersion.clear();
280 WindowsSDKLibVersion.clear();
281 Major = 0;
282 std::sscanf(RegistrySDKVersion.c_str(), "v%d.", &Major);
283 if (Major <= 7)
284 return true;
285 if (Major == 8) {
286 // Windows SDK 8.x installs libraries in a folder whose names depend on the
287 // version of the OS you're targeting. By default choose the newest, which
288 // usually corresponds to the version of the OS you've installed the SDK on.
289 const char *Tests[] = {"winv6.3", "win8", "win7"};
290 for (const char *Test : Tests) {
291 llvm::SmallString<128> TestPath(Path);
292 llvm::sys::path::append(TestPath, "Lib", Test);
293 if (llvm::sys::fs::exists(TestPath.c_str())) {
294 WindowsSDKLibVersion = Test;
295 break;
296 }
297 }
298 return !WindowsSDKLibVersion.empty();
299 }
300 if (Major == 10) {
301 if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
302 return false;
303 WindowsSDKLibVersion = WindowsSDKIncludeVersion;
304 return true;
305 }
306 // Unsupported SDK version
307 return false;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000308}
309
Zachary Turner10d75b22014-10-22 20:40:43 +0000310// Gets the library path required to link against the Windows SDK.
311bool MSVCToolChain::getWindowsSDKLibraryPath(std::string &path) const {
312 std::string sdkPath;
313 int sdkMajor = 0;
Igor Kudrinf2e75242015-09-24 05:16:36 +0000314 std::string windowsSDKIncludeVersion;
315 std::string windowsSDKLibVersion;
Zachary Turner10d75b22014-10-22 20:40:43 +0000316
317 path.clear();
Igor Kudrinf2e75242015-09-24 05:16:36 +0000318 if (!getWindowsSDKDir(sdkPath, sdkMajor, windowsSDKIncludeVersion,
319 windowsSDKLibVersion))
Zachary Turner10d75b22014-10-22 20:40:43 +0000320 return false;
321
322 llvm::SmallString<128> libPath(sdkPath);
323 llvm::sys::path::append(libPath, "Lib");
324 if (sdkMajor <= 7) {
325 switch (getArch()) {
326 // In Windows SDK 7.x, x86 libraries are directly in the Lib folder.
327 case llvm::Triple::x86:
328 break;
329 case llvm::Triple::x86_64:
330 llvm::sys::path::append(libPath, "x64");
331 break;
332 case llvm::Triple::arm:
333 // It is not necessary to link against Windows SDK 7.x when targeting ARM.
334 return false;
335 default:
336 return false;
337 }
338 } else {
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000339 const StringRef archName = getWindowsSDKArch(getArch());
340 if (archName.empty())
Zachary Turner10d75b22014-10-22 20:40:43 +0000341 return false;
Igor Kudrinf2e75242015-09-24 05:16:36 +0000342 llvm::sys::path::append(libPath, windowsSDKLibVersion, "um", archName);
Zachary Turner10d75b22014-10-22 20:40:43 +0000343 }
344
345 path = libPath.str();
346 return true;
347}
348
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000349// Check if the Include path of a specified version of Visual Studio contains
350// specific header files. If not, they are probably shipped with Universal CRT.
351bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT(
352 std::string &VisualStudioDir) const {
353 llvm::SmallString<128> TestPath(VisualStudioDir);
354 llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h");
355
356 return !llvm::sys::fs::exists(TestPath);
357}
358
359bool MSVCToolChain::getUniversalCRTSdkDir(std::string &Path,
360 std::string &UCRTVersion) const {
361 // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry
362 // for the specific key "KitsRoot10". So do we.
363 if (!getSystemRegistryString(
364 "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10",
365 Path, nullptr))
366 return false;
367
Igor Kudrinf2e75242015-09-24 05:16:36 +0000368 return getWindows10SDKVersion(Path, UCRTVersion);
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000369}
370
371bool MSVCToolChain::getUniversalCRTLibraryPath(std::string &Path) const {
372 std::string UniversalCRTSdkPath;
373 std::string UCRTVersion;
374
375 Path.clear();
376 if (!getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion))
377 return false;
378
379 StringRef ArchName = getWindowsSDKArch(getArch());
380 if (ArchName.empty())
381 return false;
382
383 llvm::SmallString<128> LibPath(UniversalCRTSdkPath);
384 llvm::sys::path::append(LibPath, "Lib", UCRTVersion, "ucrt", ArchName);
385
386 Path = LibPath.str();
387 return true;
388}
389
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000390// Get the location to use for Visual Studio binaries. The location priority
391// is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on
392// system (as reported by the registry).
393bool MSVCToolChain::getVisualStudioBinariesFolder(const char *clangProgramPath,
394 std::string &path) const {
395 path.clear();
396
397 SmallString<128> BinDir;
398
399 // First check the environment variables that vsvars32.bat sets.
400 llvm::Optional<std::string> VcInstallDir =
401 llvm::sys::Process::GetEnv("VCINSTALLDIR");
402 if (VcInstallDir.hasValue()) {
403 BinDir = VcInstallDir.getValue();
404 llvm::sys::path::append(BinDir, "bin");
405 } else {
406 // Next walk the PATH, trying to find a cl.exe in the path. If we find one,
407 // use that. However, make sure it's not clang's cl.exe.
408 llvm::Optional<std::string> OptPath = llvm::sys::Process::GetEnv("PATH");
409 if (OptPath.hasValue()) {
410 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
411 SmallVector<StringRef, 8> PathSegments;
412 llvm::SplitString(OptPath.getValue(), PathSegments, EnvPathSeparatorStr);
413
414 for (StringRef PathSegment : PathSegments) {
415 if (PathSegment.empty())
416 continue;
417
418 SmallString<128> FilePath(PathSegment);
419 llvm::sys::path::append(FilePath, "cl.exe");
Adrian McCarthy8e0879a92016-05-20 15:46:23 +0000420 // Checking if cl.exe exists is a small optimization over calling
421 // can_execute, which really only checks for existence but will also do
422 // extra checks for cl.exe.exe. These add up when walking a long path.
423 if (llvm::sys::fs::exists(FilePath.c_str()) &&
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000424 !llvm::sys::fs::equivalent(FilePath.c_str(), clangProgramPath)) {
425 // If we found it on the PATH, use it exactly as is with no
426 // modifications.
427 path = PathSegment;
428 return true;
429 }
430 }
431 }
432
433 std::string installDir;
434 // With no VCINSTALLDIR and nothing on the PATH, if we can't find it in the
435 // registry then we have no choice but to fail.
436 if (!getVisualStudioInstallDir(installDir))
437 return false;
438
439 // Regardless of what binary we're ultimately trying to find, we make sure
440 // that this is a Visual Studio directory by checking for cl.exe. We use
441 // cl.exe instead of other binaries like link.exe because programs such as
442 // GnuWin32 also have a utility called link.exe, so cl.exe is the least
443 // ambiguous.
444 BinDir = installDir;
445 llvm::sys::path::append(BinDir, "VC", "bin");
446 SmallString<128> ClPath(BinDir);
447 llvm::sys::path::append(ClPath, "cl.exe");
448
449 if (!llvm::sys::fs::can_execute(ClPath.c_str()))
450 return false;
Hans Wennborge6b994e2014-10-20 23:26:03 +0000451 }
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000452
453 if (BinDir.empty())
454 return false;
455
456 switch (getArch()) {
457 case llvm::Triple::x86:
458 break;
459 case llvm::Triple::x86_64:
460 llvm::sys::path::append(BinDir, "amd64");
461 break;
462 case llvm::Triple::arm:
463 llvm::sys::path::append(BinDir, "arm");
464 break;
465 default:
466 // Whatever this is, Visual Studio doesn't have a toolchain for it.
467 return false;
468 }
469 path = BinDir.str();
470 return true;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000471}
472
Adrian McCarthye4b26fc2016-05-13 23:20:11 +0000473VersionTuple MSVCToolChain::getMSVCVersionFromExe() const {
474 VersionTuple Version;
475#ifdef USE_WIN32
476 std::string BinPath;
477 if (!getVisualStudioBinariesFolder("", BinPath))
478 return Version;
NAKAMURA Takumi4b8e3e52016-05-14 08:09:12 +0000479 SmallString<128> ClExe(BinPath);
Adrian McCarthye4b26fc2016-05-13 23:20:11 +0000480 llvm::sys::path::append(ClExe, "cl.exe");
481
482 std::wstring ClExeWide;
483 if (!llvm::ConvertUTF8toWide(ClExe.c_str(), ClExeWide))
484 return Version;
485
486 const DWORD VersionSize = ::GetFileVersionInfoSizeW(ClExeWide.c_str(),
487 nullptr);
488 if (VersionSize == 0)
489 return Version;
490
491 SmallVector<uint8_t, 4 * 1024> VersionBlock(VersionSize);
492 if (!::GetFileVersionInfoW(ClExeWide.c_str(), 0, VersionSize,
493 VersionBlock.data()))
494 return Version;
495
496 VS_FIXEDFILEINFO *FileInfo = nullptr;
497 UINT FileInfoSize = 0;
498 if (!::VerQueryValueW(VersionBlock.data(), L"\\",
499 reinterpret_cast<LPVOID *>(&FileInfo), &FileInfoSize) ||
500 FileInfoSize < sizeof(*FileInfo))
501 return Version;
502
503 const unsigned Major = (FileInfo->dwFileVersionMS >> 16) & 0xFFFF;
504 const unsigned Minor = (FileInfo->dwFileVersionMS ) & 0xFFFF;
505 const unsigned Micro = (FileInfo->dwFileVersionLS >> 16) & 0xFFFF;
506
507 Version = VersionTuple(Major, Minor, Micro);
508#endif
509 return Version;
510}
511
Alp Tokerfcce1832014-06-22 03:27:45 +0000512// Get Visual Studio installation directory.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000513bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const {
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000514 // First check the environment variables that vsvars32.bat sets.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000515 const char *vcinstalldir = getenv("VCINSTALLDIR");
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000516 if (vcinstalldir) {
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000517 path = vcinstalldir;
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000518 path = path.substr(0, path.find("\\VC"));
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000519 return true;
520 }
521
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000522 std::string vsIDEInstallDir;
523 std::string vsExpressIDEInstallDir;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000524 // Then try the windows registry.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000525 bool hasVCDir =
526 getSystemRegistryString("SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
527 "InstallDir", vsIDEInstallDir, nullptr);
528 if (hasVCDir && !vsIDEInstallDir.empty()) {
529 path = vsIDEInstallDir.substr(0, vsIDEInstallDir.find("\\Common7\\IDE"));
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000530 return true;
531 }
532
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000533 bool hasVCExpressDir =
534 getSystemRegistryString("SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
535 "InstallDir", vsExpressIDEInstallDir, nullptr);
536 if (hasVCExpressDir && !vsExpressIDEInstallDir.empty()) {
537 path = vsExpressIDEInstallDir.substr(
538 0, vsIDEInstallDir.find("\\Common7\\IDE"));
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000539 return true;
540 }
541
542 // Try the environment.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000543 const char *vs120comntools = getenv("VS120COMNTOOLS");
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000544 const char *vs100comntools = getenv("VS100COMNTOOLS");
545 const char *vs90comntools = getenv("VS90COMNTOOLS");
546 const char *vs80comntools = getenv("VS80COMNTOOLS");
Alp Tokerfcce1832014-06-22 03:27:45 +0000547
548 const char *vscomntools = nullptr;
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000549
Alp Tokera2074402014-06-22 03:27:52 +0000550 // Find any version we can
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000551 if (vs120comntools)
552 vscomntools = vs120comntools;
553 else if (vs100comntools)
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000554 vscomntools = vs100comntools;
555 else if (vs90comntools)
556 vscomntools = vs90comntools;
557 else if (vs80comntools)
558 vscomntools = vs80comntools;
559
560 if (vscomntools && *vscomntools) {
561 const char *p = strstr(vscomntools, "\\Common7\\Tools");
562 path = p ? std::string(vscomntools, p) : vscomntools;
563 return true;
564 }
565 return false;
566}
567
Igor Kudrinf2e75242015-09-24 05:16:36 +0000568void MSVCToolChain::AddSystemIncludeWithSubfolder(
569 const ArgList &DriverArgs, ArgStringList &CC1Args,
570 const std::string &folder, const Twine &subfolder1, const Twine &subfolder2,
571 const Twine &subfolder3) const {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000572 llvm::SmallString<128> path(folder);
Igor Kudrinf2e75242015-09-24 05:16:36 +0000573 llvm::sys::path::append(path, subfolder1, subfolder2, subfolder3);
Yaron Keren92e1b622015-03-18 10:17:07 +0000574 addSystemInclude(DriverArgs, CC1Args, path);
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000575}
576
Saleem Abdulrasool819f3912014-10-22 02:37:29 +0000577void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
578 ArgStringList &CC1Args) const {
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000579 if (DriverArgs.hasArg(options::OPT_nostdinc))
580 return;
581
582 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
Igor Kudrinf2e75242015-09-24 05:16:36 +0000583 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, getDriver().ResourceDir,
584 "include");
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000585 }
586
Nico Weberfd3e1ad2016-04-12 19:04:37 +0000587 // Add %INCLUDE%-like directories from the -imsvc flag.
588 for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
589 addSystemInclude(DriverArgs, CC1Args, Path);
590
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000591 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
592 return;
593
Joao Matos792d7af2012-09-04 17:29:52 +0000594 // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat.
595 if (const char *cl_include_dir = getenv("INCLUDE")) {
596 SmallVector<StringRef, 8> Dirs;
Reid Kleckner77b45ba2014-04-23 00:15:01 +0000597 StringRef(cl_include_dir)
598 .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
599 for (StringRef Dir : Dirs)
600 addSystemInclude(DriverArgs, CC1Args, Dir);
601 if (!Dirs.empty())
602 return;
Joao Matos792d7af2012-09-04 17:29:52 +0000603 }
604
605 std::string VSDir;
Joao Matos792d7af2012-09-04 17:29:52 +0000606
607 // When built with access to the proper Windows APIs, try to actually find
608 // the correct include paths first.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000609 if (getVisualStudioInstallDir(VSDir)) {
610 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include");
611
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000612 if (useUniversalCRT(VSDir)) {
613 std::string UniversalCRTSdkPath;
614 std::string UCRTVersion;
615 if (getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion)) {
Igor Kudrinf2e75242015-09-24 05:16:36 +0000616 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, UniversalCRTSdkPath,
617 "Include", UCRTVersion, "ucrt");
Reid Kleckner7531f7d2015-09-11 00:09:39 +0000618 }
619 }
620
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000621 std::string WindowsSDKDir;
Igor Kudrinf2e75242015-09-24 05:16:36 +0000622 int major;
623 std::string windowsSDKIncludeVersion;
624 std::string windowsSDKLibVersion;
625 if (getWindowsSDKDir(WindowsSDKDir, major, windowsSDKIncludeVersion,
626 windowsSDKLibVersion)) {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000627 if (major >= 8) {
Igor Kudrinf2e75242015-09-24 05:16:36 +0000628 // Note: windowsSDKIncludeVersion is empty for SDKs prior to v10.
629 // Anyway, llvm::sys::path::append is able to manage it.
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000630 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
Igor Kudrinf2e75242015-09-24 05:16:36 +0000631 "include", windowsSDKIncludeVersion,
632 "shared");
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000633 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
Igor Kudrinf2e75242015-09-24 05:16:36 +0000634 "include", windowsSDKIncludeVersion,
635 "um");
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000636 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
Igor Kudrinf2e75242015-09-24 05:16:36 +0000637 "include", windowsSDKIncludeVersion,
638 "winrt");
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000639 } else {
640 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
641 "include");
642 }
Reid Kleckner77b45ba2014-04-23 00:15:01 +0000643 } else {
Zachary Turner0eaf8fc2014-10-22 20:40:28 +0000644 addSystemInclude(DriverArgs, CC1Args, VSDir);
Reid Kleckner77b45ba2014-04-23 00:15:01 +0000645 }
Joao Matos792d7af2012-09-04 17:29:52 +0000646 return;
647 }
Joao Matos792d7af2012-09-04 17:29:52 +0000648
649 // As a fallback, select default install paths.
Alp Tokerfcce1832014-06-22 03:27:45 +0000650 // FIXME: Don't guess drives and paths like this on Windows.
Joao Matos792d7af2012-09-04 17:29:52 +0000651 const StringRef Paths[] = {
652 "C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
653 "C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
654 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
655 "C:/Program Files/Microsoft Visual Studio 8/VC/include",
656 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
657 };
658 addSystemIncludes(DriverArgs, CC1Args, Paths);
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000659}
660
Saleem Abdulrasool819f3912014-10-22 02:37:29 +0000661void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
662 ArgStringList &CC1Args) const {
Chandler Carruth1fc603e2011-12-17 23:10:01 +0000663 // FIXME: There should probably be logic here to find libc++ on Windows.
664}
David Majnemere11d3732015-06-08 00:22:46 +0000665
666std::string
667MSVCToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
668 types::ID InputType) const {
669 std::string TripleStr =
670 ToolChain::ComputeEffectiveClangTriple(Args, InputType);
671 llvm::Triple Triple(TripleStr);
672 VersionTuple MSVT =
Adrian McCarthye4b26fc2016-05-13 23:20:11 +0000673 tools::visualstudio::getMSVCVersion(/*D=*/nullptr, *this, Triple, Args,
David Majnemere11d3732015-06-08 00:22:46 +0000674 /*IsWindowsMSVC=*/true);
675 if (MSVT.empty())
676 return TripleStr;
677
678 MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().getValueOr(0),
679 MSVT.getSubminor().getValueOr(0));
680
David Majnemer75fdd6b2015-06-09 06:30:01 +0000681 if (Triple.getEnvironment() == llvm::Triple::MSVC) {
682 StringRef ObjFmt = Triple.getEnvironmentName().split('-').second;
683 if (ObjFmt.empty())
684 Triple.setEnvironmentName((Twine("msvc") + MSVT.getAsString()).str());
685 else
686 Triple.setEnvironmentName(
687 (Twine("msvc") + MSVT.getAsString() + Twine('-') + ObjFmt).str());
688 }
David Majnemere11d3732015-06-08 00:22:46 +0000689 return Triple.getTriple();
690}
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000691
692SanitizerMask MSVCToolChain::getSupportedSanitizers() const {
693 SanitizerMask Res = ToolChain::getSupportedSanitizers();
694 Res |= SanitizerKind::Address;
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000695 return Res;
696}
David Majnemer015ce0f2015-07-27 07:32:11 +0000697
Hans Wennborg21d73d22016-01-12 23:17:03 +0000698static void TranslateOptArg(Arg *A, llvm::opt::DerivedArgList &DAL,
699 bool SupportsForcingFramePointer,
700 const char *ExpandChar, const OptTable &Opts) {
701 assert(A->getOption().matches(options::OPT__SLASH_O));
702
703 StringRef OptStr = A->getValue();
704 for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
705 const char &OptChar = *(OptStr.data() + I);
706 switch (OptChar) {
707 default:
708 break;
709 case '1':
710 case '2':
711 case 'x':
712 case 'd':
713 if (&OptChar == ExpandChar) {
714 if (OptChar == 'd') {
715 DAL.AddFlagArg(A, Opts.getOption(options::OPT_O0));
716 } else {
717 if (OptChar == '1') {
718 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "s");
719 } else if (OptChar == '2' || OptChar == 'x') {
720 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
721 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "2");
722 }
David Majnemer259d71a2016-01-21 23:01:11 +0000723 if (SupportsForcingFramePointer &&
724 !DAL.hasArgNoClaim(options::OPT_fno_omit_frame_pointer))
Hans Wennborg21d73d22016-01-12 23:17:03 +0000725 DAL.AddFlagArg(A,
726 Opts.getOption(options::OPT_fomit_frame_pointer));
727 if (OptChar == '1' || OptChar == '2')
728 DAL.AddFlagArg(A,
729 Opts.getOption(options::OPT_ffunction_sections));
730 }
731 }
732 break;
733 case 'b':
Hans Wennborg3270bdb2016-05-24 21:23:29 +0000734 if (I + 1 != E && isdigit(OptStr[I + 1])) {
735 switch (OptStr[I + 1]) {
736 case '0':
737 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_inline));
738 break;
739 case '1':
Hans Wennborg44d061a2016-06-22 16:56:16 +0000740 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_hint_functions));
Hans Wennborg3270bdb2016-05-24 21:23:29 +0000741 break;
742 case '2':
743 DAL.AddFlagArg(A, Opts.getOption(options::OPT_finline_functions));
744 break;
745 }
Hans Wennborg21d73d22016-01-12 23:17:03 +0000746 ++I;
Hans Wennborg3270bdb2016-05-24 21:23:29 +0000747 }
Hans Wennborg21d73d22016-01-12 23:17:03 +0000748 break;
749 case 'g':
750 break;
751 case 'i':
752 if (I + 1 != E && OptStr[I + 1] == '-') {
753 ++I;
754 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fno_builtin));
755 } else {
756 DAL.AddFlagArg(A, Opts.getOption(options::OPT_fbuiltin));
757 }
758 break;
759 case 's':
760 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "s");
761 break;
762 case 't':
763 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_O), "2");
764 break;
765 case 'y': {
766 bool OmitFramePointer = true;
767 if (I + 1 != E && OptStr[I + 1] == '-') {
768 OmitFramePointer = false;
769 ++I;
770 }
771 if (SupportsForcingFramePointer) {
772 if (OmitFramePointer)
773 DAL.AddFlagArg(A,
774 Opts.getOption(options::OPT_fomit_frame_pointer));
775 else
776 DAL.AddFlagArg(
777 A, Opts.getOption(options::OPT_fno_omit_frame_pointer));
Nico Weber9c3fca32016-03-23 15:37:41 +0000778 } else {
779 // Don't warn about /Oy- in 64-bit builds (where
780 // SupportsForcingFramePointer is false). The flag having no effect
781 // there is a compiler-internal optimization, and people shouldn't have
782 // to special-case their build files for 64-bit clang-cl.
783 A->claim();
Hans Wennborg21d73d22016-01-12 23:17:03 +0000784 }
785 break;
786 }
787 }
788 }
789}
790
791static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL,
792 const OptTable &Opts) {
793 assert(A->getOption().matches(options::OPT_D));
794
795 StringRef Val = A->getValue();
796 size_t Hash = Val.find('#');
797 if (Hash == StringRef::npos || Hash > Val.find('=')) {
798 DAL.append(A);
799 return;
800 }
801
802 std::string NewVal = Val;
803 NewVal[Hash] = '=';
804 DAL.AddJoinedArg(A, Opts.getOption(options::OPT_D), NewVal);
805}
806
David Majnemer015ce0f2015-07-27 07:32:11 +0000807llvm::opt::DerivedArgList *
808MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
809 const char *BoundArch) const {
810 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
811 const OptTable &Opts = getDriver().getOpts();
812
David Majnemer7ab76f22015-08-25 00:46:45 +0000813 // /Oy and /Oy- only has an effect under X86-32.
814 bool SupportsForcingFramePointer = getArch() == llvm::Triple::x86;
815
David Majnemer015ce0f2015-07-27 07:32:11 +0000816 // The -O[12xd] flag actually expands to several flags. We must desugar the
817 // flags so that options embedded can be negated. For example, the '-O2' flag
818 // enables '-Oy'. Expanding '-O2' into its constituent flags allows us to
819 // correctly handle '-O2 -Oy-' where the trailing '-Oy-' disables a single
820 // aspect of '-O2'.
821 //
822 // Note that this expansion logic only applies to the *last* of '[12xd]'.
823
824 // First step is to search for the character we'd like to expand.
825 const char *ExpandChar = nullptr;
826 for (Arg *A : Args) {
827 if (!A->getOption().matches(options::OPT__SLASH_O))
828 continue;
829 StringRef OptStr = A->getValue();
830 for (size_t I = 0, E = OptStr.size(); I != E; ++I) {
Hans Wennborgdebfed92016-05-25 00:43:45 +0000831 char OptChar = OptStr[I];
832 char PrevChar = I > 0 ? OptStr[I - 1] : '0';
833 if (PrevChar == 'b') {
834 // OptChar does not expand; it's an argument to the previous char.
835 continue;
836 }
David Majnemer015ce0f2015-07-27 07:32:11 +0000837 if (OptChar == '1' || OptChar == '2' || OptChar == 'x' || OptChar == 'd')
838 ExpandChar = OptStr.data() + I;
839 }
840 }
841
David Majnemer015ce0f2015-07-27 07:32:11 +0000842 for (Arg *A : Args) {
Hans Wennborg21d73d22016-01-12 23:17:03 +0000843 if (A->getOption().matches(options::OPT__SLASH_O)) {
844 // The -O flag actually takes an amalgam of other options. For example,
845 // '/Ogyb2' is equivalent to '/Og' '/Oy' '/Ob2'.
846 TranslateOptArg(A, *DAL, SupportsForcingFramePointer, ExpandChar, Opts);
847 } else if (A->getOption().matches(options::OPT_D)) {
848 // Translate -Dfoo#bar into -Dfoo=bar.
849 TranslateDArg(A, *DAL, Opts);
850 } else {
David Majnemer015ce0f2015-07-27 07:32:11 +0000851 DAL->append(A);
David Majnemer015ce0f2015-07-27 07:32:11 +0000852 }
853 }
Hans Wennborg21d73d22016-01-12 23:17:03 +0000854
David Majnemer015ce0f2015-07-27 07:32:11 +0000855 return DAL;
856}