llvm / llvm/llvm-project

[LLVM Support] encoding problem of `ExecuteAndWait` on windows

Open
#161,679 1 comment 0 reactions 0 assignees View on GitHub
llvm:support platform:windows
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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 ``, and handling the encoding conversion myself.

Contributor guide

Open the contributing guide

Research direction

Read llvm/lib/Support/Windows/Program.inc lines 111-128 and llvm/lib/Support/Program.cpp lines 32-54; trace how ExecuteAndWait surfaces Windows errors. Compare the proposed approaches and define completion as an error message that UTF-8 consumers can use without caller-side Windows-specific conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.