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" @@ -57,17 +58,36 @@ static cl::opt ProgramTestStringArg2("program-test-string-arg2"); -static void CopyEnvironment(std::vector &out) { +static std::vector +CopyEnvironment(std::vector &Storage) { + std::vector out; +#ifdef LLVM_ON_WIN32 + // On Windows we have to take UTF16 encoded env vars and convert them to UTF8. + _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 + (void)Storage; #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 + return out; } #ifdef LLVM_ON_WIN32 @@ -90,8 +110,8 @@ }; // Add LLVM_PROGRAM_TEST_LONG_PATH to the environment of the child. - std::vector EnvP; - CopyEnvironment(EnvP); + std::vector EnvStorage; + auto EnvP = CopyEnvironment(EnvStorage); EnvP.push_back("LLVM_PROGRAM_TEST_LONG_PATH=1"); EnvP.push_back(nullptr); @@ -140,8 +160,8 @@ }; // Add LLVM_PROGRAM_TEST_CHILD to the environment of the child. - std::vector envp; - CopyEnvironment(envp); + std::vector EnvStorage; + auto envp = CopyEnvironment(EnvStorage); envp.push_back("LLVM_PROGRAM_TEST_CHILD=1"); envp.push_back(nullptr); @@ -178,8 +198,8 @@ }; // Add LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT to the environment of the child. - std::vector envp; - CopyEnvironment(envp); + std::vector EnvStorage; + auto envp = CopyEnvironment(EnvStorage); envp.push_back("LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT=1"); envp.push_back(nullptr); @@ -239,8 +259,8 @@ }; // Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child. - std::vector envp; - CopyEnvironment(envp); + std::vector EnvStorage; + auto envp = CopyEnvironment(EnvStorage); envp.push_back("LLVM_PROGRAM_TEST_TIMEOUT=1"); envp.push_back(nullptr);