]> granicus.if.org Git - clang/commitdiff
clang-cl: Accept MSVC 2015's `/source-charset:utf-8` flag.
authorNico Weber <nicolasweber@gmx.de>
Tue, 23 Aug 2016 16:47:09 +0000 (16:47 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 23 Aug 2016 16:47:09 +0000 (16:47 +0000)
clang already treats all inputs as utf-8. Warn if anything but utf-8 is passed.

Do this by mapping source-charset to finput-charset, which already behaves like
this. Slightly tweak finput-charset to accept "utf-8" case-insensitively. This
matches gcc's and cl.exe's behavior, and IANA says that character set names are
case-insensitive.

https://reviews.llvm.org/D23807

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

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

index b1d2459f71cfba4f73120da99e54dd196fe12964..864a3489c5218c4035c26ec9144b34b8a7a24f73 100644 (file)
@@ -120,6 +120,8 @@ def _SLASH_Qvec_ : CLFlag<"Qvec-">,
 def _SLASH_showIncludes : CLFlag<"showIncludes">,
   HelpText<"Print info about included files to stderr">,
   Alias<show_includes>;
+def _SLASH_source_charset : CLCompileJoined<"source-charset:">,
+  HelpText<"Source encoding, supports only UTF-8">, Alias<finput_charset_EQ>;
 def _SLASH_std : CLCompileJoined<"std:">,
   HelpText<"Language standard to compile for">;
 def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,
index a814df3c64c6d214f201d27d3976fe6afaf319b4..747f3ea57a12fe7dce375f02b3e1ab38d54d840c 100644 (file)
@@ -5801,7 +5801,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // -finput_charset=UTF-8 is default. Reject others
   if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) {
     StringRef value = inputCharset->getValue();
-    if (value != "UTF-8")
+    if (value.lower() != "utf-8")
       D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
                                           << value;
   }
index 4d9416b1f87c73b7ab39860b1af24e1dad53599a..3e207f2c95e809ac98c6a77440cfc98b473ac56b 100644 (file)
 // RUN: %clang_cl /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s
 // showIncludes_E: warning: argument unused during compilation: '--show-includes'
 
+// /source-charset: should warn on everything except UTF-8.
+// RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s
+// source-charset-utf-16: invalid value 'utf-16'
+
 // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
 // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
 // U: "-U" "mymacro"
 // RUN:    /RTC1 \
 // RUN:    /sdl \
 // RUN:    /sdl- \
+// RUN:    /source-charset:utf-8 \
 // RUN:    /vmg \
 // RUN:    /volatile:iso \
 // RUN:    /w12345 \