<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/161679>161679</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLVM] encoding problem of `ExecuteAndWait` on windows
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
16bit-ykiko
</td>
</tr>
</table>
<pre>
I am developing a new tool based on llvm. When I use `ExecuteAndWait` to execute a program and the error occurs in the execution
https://github.com/llvm/llvm-project/blob/11b0cf8fbeaf8b2384f3ab4d7f6fe97bc7d3db63/llvm/lib/Support/Program.cpp#L32-L54
I get error message `Couldn't execute program 'clang++.exe': �������� (0x57)`. This is clearly an encoding error, as my console is UTF-8 encoded. After reviewing the relevant code, I've located the source of the error.
https://github.com/llvm/llvm-project/blob/11b0cf8fbeaf8b2384f3ab4d7f6fe97bc7d3db63/llvm/lib/Support/Windows/Program.inc#L111-L128
This function uses the system's default ANSI codepage for formatting error messages. For my region (Simplified Chinese), this codepage is GBK, which results in encoding errors when the output is consumed by UTF-8 applications.
Ideally, I would like to retrieve the error message in UTF-8 encoding.
Considering that the prefix for the error message is already in English, should we consider forcing the returned system message to always be in English to avoid these encoding issues?
Alternatively, perhaps we could add a new parameter to allow users to request the error message in UTF-8 specifically?
My main motivation is to avoid writing platform-specific code in my own project. As a user of this library, I want to avoid explicitly checking for Windows (e.g., `#ifdef _WIN32`), including `<Windows.h>`, and handling the encoding conversion myself.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVcFu4zYQ_Rr6MoggUbIlH3xwvHFhNLsokG1zLChyJLGhSJWkrOjvC1KykwKLAkUPPQSxx-TTm_feaJhzstWIB7J9JNsvGzb6zthDtqulf5jf5JvZ1EbMhwuwHgReUZlB6hYYaJzAG6OgZg4FGA1KXfsEXjvUcIHRIZBd-vSOfPR41OKVSU92KXgDuBSBwWBNa1k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