[PATCH] D21643: Default to using the Unicode version of Win32 APIs

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 23 08:05:59 PDT 2016

aaron.ballman created this revision.
aaron.ballman added reviewers: rnk, majnemer, chapuni, zturner.
aaron.ballman added subscribers: llvm-commits, cfe-commits.

We currently default to using the multibyte character versions of Win32 APIs, commonly suffixed with an "A". However, this causes problems because many of the Win32 APIs that we use are for things like file paths, where non-ASCII characters are commonly expected. This patch defaults us to using the "W" versions of the Win32 APIs, which helps to remind us to properly handle non-ASCII input. We can still fall back on the multibyte APIs by explicitly specifying the "A" version of the function, but we no longer run into issues where we call a Win32 API without a suffix and accidentally wind up using the A version on UTF-8 data (which will fail) instead of using the W version on UTF-16 data (which will succeed).

I have tested this patch with MSVC 2015 and LLVM, Clang, and clang-tools-extra all compile cleanly (after a few cleanup patches) and all tests pass. I have not tried other projects as I do not have them locally, but hopefully they: work with this patch as-is, require minimal changes to support this patch, or can override the behavior with their own CMake settings. Before committing, I plan to make sure these projects all continue to compile, but I wanted to make sure the community was okay with this direction before doing that work.



Index: cmake/modules/HandleLLVMOptions.cmake
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -249,6 +249,12 @@
+  # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
+  add_llvm_definitions(
+  )
     # Disabled warnings.
     -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21643.61673.patch
Type: text/x-patch
Size: 557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160623/cca1226a/attachment.bin>

More information about the cfe-commits mailing list