Index: unittests/Support/ProgramTest.cpp =================================================================== --- unittests/Support/ProgramTest.cpp +++ unittests/Support/ProgramTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/ConvertUTF.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -58,16 +59,33 @@ ProgramTestStringArg2("program-test-string-arg2"); static void CopyEnvironment(std::vector &out) { +#ifdef LLVM_ON_WIN32 + // On Windows we have to take UTF16 encoded env vars and convert them to UTF8. + static std::vector storage; // Helper storage for converted vars. + storage.clear(); + _wgetenv(L"TMP"); // Populate _wenviron, initially is null + wchar_t **envp = _wenviron; + assert(envp); + while (*envp != nullptr) { + auto pathLen = wcslen(*envp); + ArrayRef ref{reinterpret_cast(*envp), + pathLen * sizeof(wchar_t)}; + storage.emplace_back(); + convertUTF16ToUTF8String(ref, storage.back()); + out.emplace_back(storage.back().c_str()); + ++envp; + } +#else #ifdef __APPLE__ char **envp = *_NSGetEnviron(); #else - // environ seems to work for Windows and most other Unices. char **envp = environ; #endif while (*envp != nullptr) { out.push_back(*envp); ++envp; } +#endif } #ifdef LLVM_ON_WIN32