[PATCH] D23945: clang-cl: Support MSVC2015's /validate-charset flag.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 26 14:53:24 PDT 2016


thakis created this revision.
thakis added a reviewer: hans.
thakis added a subscriber: cfe-commits.

Clang always assumes that files are utf-8. If an invalidly encoded character is used in an identifier, clang always errors. If it's used in a character literal, clang warns Winvalid-source-encoding (on by default). Clang never checks the encoding of things in comments (adding this seems like a nice feature if it doesn't impact performance).

For cl.exe /utf-8 (which enables /validate-charset), if a bad character is used in an identifier, it emits both an error and a warning. If it's used in a literal or a comment, it emits a warning.

So mapping /validate-charset to -Winvalid-source-encoding seems like a fairly decent fit.

https://reviews.llvm.org/D23945

Files:
  include/clang/Driver/CLCompatOptions.td
  test/Driver/cl-options.c

Index: test/Driver/cl-options.c
===================================================================
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -192,6 +192,12 @@
 // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
 // U: "-U" "mymacro"
 
+// RUN: %clang_cl /validate-charset -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset %s
+// validate-charset: -Winvalid-source-encoding
+
+// RUN: %clang_cl /validate-charset- -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset_ %s
+// validate-charset_: -Wno-invalid-source-encoding
+
 // RUN: %clang_cl /vd2 -### -- %s 2>&1 | FileCheck -check-prefix=VD2 %s
 // VD2: -vtordisp-mode=2
 
Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -128,6 +128,10 @@
   HelpText<"Language standard to compile for">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
   MetaVarName<"<macro>">, Alias<U>;
+def _SLASH_validate_charset : CLFlag<"validate-charset">,
+  Alias<W_Joined>, AliasArgs<["invalid-source-encoding"]>;
+def _SLASH_validate_charset_ : CLFlag<"validate-charset-">,
+  Alias<W_Joined>, AliasArgs<["no-invalid-source-encoding"]>;
 def _SLASH_W0 : CLFlag<"W0">, HelpText<"Disable all warnings">, Alias<w>;
 def _SLASH_W1 : CLFlag<"W1">, HelpText<"Enable -Wall">, Alias<Wall>;
 def _SLASH_W2 : CLFlag<"W2">, HelpText<"Enable -Wall">, Alias<Wall>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23945.69437.patch
Type: text/x-patch
Size: 1522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160826/b0e21f70/attachment-0001.bin>


More information about the cfe-commits mailing list