]> granicus.if.org Git - clang/commitdiff
clang-cl: Support MSVC2015's /validate-charset flag.
authorNico Weber <nicolasweber@gmx.de>
Fri, 26 Aug 2016 21:51:14 +0000 (21:51 +0000)
committerNico Weber <nicolasweber@gmx.de>
Fri, 26 Aug 2016 21:51:14 +0000 (21:51 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279872 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fab12be830926416e4dbca8268149ed93802b071..cb2745afb7e4c4111ab5f9f032792d2b54d1a1e0 100644 (file)
@@ -128,6 +128,10 @@ def _SLASH_std : CLCompileJoined<"std:">,
   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>;
index ba70378b2f219be78e1714c50ff95ba95f4c88f7..e5e540207cf6eb53efe410a7b958d5edcfc04aa1 100644 (file)
 // 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