diff --git a/driver/configfile.cpp b/driver/configfile.cpp index ef12f0b665..15f19557aa 100644 --- a/driver/configfile.cpp +++ b/driver/configfile.cpp @@ -20,8 +20,10 @@ #include #if _WIN32 #define WIN32_LEAN_AND_MEAN +#include "llvm/Support/ConvertUTF.h" #include #include +#include // Prevent name clash with LLVM #undef GetCurrentDirectory #endif @@ -55,16 +57,23 @@ static bool ReadPathFromRegistry(llvm::SmallString<128> &p) { HKEY hkey; bool res = false; // FIXME: Version number should be a define. - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\ldc-developers\\LDC\\0.11.0", + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\ldc-developers\\LDC\\0.11.0"), NULL, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { DWORD length; - if (RegGetValue(hkey, NULL, "Path", RRF_RT_REG_SZ, NULL, NULL, &length) == + if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, NULL, &length) == ERROR_SUCCESS) { - char *data = static_cast(_alloca(length)); - if (RegGetValue(hkey, NULL, "Path", RRF_RT_REG_SZ, NULL, data, &length) == + TCHAR *data = static_cast(_alloca(length * sizeof(TCHAR))); + if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, data, &length) == ERROR_SUCCESS) { +#if UNICODE + std::string out; + res = llvm::convertUTF16ToUTF8String( + llvm::ArrayRef(reinterpret_cast(data), length), out); + p = out; +#else p = std::string(data); res = true; +#endif } } RegCloseKey(hkey); diff --git a/driver/linker.cpp b/driver/linker.cpp index 6595d1ac13..b6f9f1c8ed 100644 --- a/driver/linker.cpp +++ b/driver/linker.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/SourceMgr.h" #if _WIN32 #include "llvm/Support/SystemUtils.h" +#include "llvm/Support/ConvertUTF.h" #include #endif @@ -426,9 +427,17 @@ int executeAndWait(const char *commandLine) { DWORD exitCode; +#if UNICODE + std::wstring wcommandLine; + if (!llvm::ConvertUTF8toWide(commandLine, wcommandLine)) + return -3; + auto cmdline = const_cast(wcommandLine.data()); +#else + auto cmdline = const_cast(commandLine); +#endif // according to MSDN, only CreateProcessW (unicode) may modify the passed // command line - if (!CreateProcess(NULL, const_cast(commandLine), NULL, NULL, TRUE, 0, + if (!CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { exitCode = -1; } else {