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.

http://reviews.llvm.org/D21643

Files:
  cmake/modules/HandleLLVMOptions.cmake

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


Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -249,6 +249,12 @@
     -D_SCL_SECURE_NO_WARNINGS
     )
 
+  # Tell MSVC to use the Unicode version of the Win32 APIs instead of ANSI.
+  add_llvm_definitions(
+    -DUNICODE
+    -D_UNICODE
+  )
+
   set(msvc_warning_flags
     # Disabled warnings.
     -wd4141 # Suppress ''modifier' : used more than once' (because of __forceinline combined with inline)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to