llvm-project/llvm/lib
Reid Kleckner 2b8c69204b [Windows] Convert from UTF-8 to UTF-16 when writing to a Windows console
Summary:
Calling WriteConsoleW is the most reliable way to print Unicode
characters to a Windows console.

If binary data gets printed to the console, attempting to re-encode it
shouldn't be a problem, since garbage in can produce garbage out.

This breaks printing strings in the local codepage, which WriteConsoleA
knows how to handle. For example, this can happen when user source code
is encoded with the local codepage, and an LLVM tool quotes it while
emitting a caret diagnostic. This is unfortunate, but well-behaved tools
should validate that their input is UTF-8 and escape non-UTF-8
characters before sending them to raw_fd_ostream. Clang already does
this, but not all LLVM tools do this.

One drawback to the current implementation is printing a string a byte
at a time doesn't work. Consider this LLVM code:
  for (char C : MyStr) outs() << C;

Because outs() is now unbuffered, we wil try to convert each byte to
UTF-16, which will fail. However, this already didn't work, so I think
we may as well update callers that do that as we find them to print
complete portions of strings. You can see a real example of this in my
patch to SourceMgr.cpp

Fixes PR38669 and PR36267.

Reviewers: zturner, efriedma

Subscribers: llvm-commits, hiraditya

Differential Revision: https://reviews.llvm.org/D51558

llvm-svn: 341433
2018-09-05 00:08:56 +00:00
..
Analysis [NFC] Optionally pass a function to emitInstrCountChangedRemark 2018-08-31 20:54:37 +00:00
AsmParser [x86/SLH] Add a real Clang flag and LLVM IR attribute for Speculative 2018-09-04 12:38:00 +00:00
BinaryFormat Fix undefined behavior in r340457 2018-08-23 02:51:09 +00:00
Bitcode [x86/SLH] Add a real Clang flag and LLVM IR attribute for Speculative 2018-09-04 12:38:00 +00:00
CodeGen DAG: Factor out helper function for odd vector sizes 2018-09-04 18:47:43 +00:00
DebugInfo [dwarfdump] Improve -diff option by hiding more data. 2018-09-04 16:21:37 +00:00
Demangle Remove some debugging code that was accidentally left in. 2018-08-30 21:00:57 +00:00
ExecutionEngine clang-format r341282. 2018-09-02 01:29:29 +00:00
FuzzMutate [IR] Replace `isa<TerminatorInst>` with `isTerminator()`. 2018-08-26 09:51:22 +00:00
Fuzzer
IR [NFC] Improve clarity in emitInstrCountChangedRemark 2018-09-04 21:03:43 +00:00
IRReader
LTO [ThinLTO] Fix memory corruption in ThinLTOCodeGenerator when CodeGenOnly was specified 2018-09-04 22:54:17 +00:00
LineEditor
Linker [NFC] Remove an empty line. 2018-07-27 06:50:45 +00:00
MC [MC] - ConstantPools.cpp: Style consistency, remove redundant braces. NFC. 2018-09-03 03:48:39 +00:00
Object [MachO] Fix inconsistency between error messages when validating LC_DYSYMTAB 2018-09-04 16:31:53 +00:00
ObjectYAML [yaml2obj] - Add a support for changing EntSize. 2018-08-07 08:11:38 +00:00
Option Revert r341329 due to MSAN error 2018-09-03 18:13:46 +00:00
Passes [PGO] Control Height Reduction 2018-09-04 17:19:13 +00:00
ProfileData [Coverage] Ignore 'unused' functions with non-zero execution counts 2018-08-07 22:25:36 +00:00
Support [Windows] Convert from UTF-8 to UTF-16 when writing to a Windows console 2018-09-05 00:08:56 +00:00
TableGen Remove trailing space 2018-07-30 19:41:25 +00:00
Target [WebAssembly] Fixed stale assert message in WebAssemblyMCInstLower 2018-09-04 22:59:05 +00:00
Testing [LLVMTestingSupport] Add explicit linkage to LLVMSupport 2018-04-08 06:49:17 +00:00
ToolDrivers Give llvm-lib rudimentary help output. 2018-07-14 02:29:44 +00:00
Transforms [InstCombine] fix xor-or-xor fold to check uses and handle commutes 2018-09-04 23:22:13 +00:00
WindowsManifest Convert line endings of lib/WindowsManifest/CMakeLists.txt to unix. 2018-04-07 04:28:08 +00:00
XRay [XRay] Update RecordInitializer for PIDRecord 2018-08-31 20:02:55 +00:00
CMakeLists.txt
LLVMBuild.txt