[PATCH] D50199: [MinGW] Predefine UNICODE if -municode is specified during compilation

Martin Storsjรถ via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 2 12:51:25 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: rnk, compnerd, pcc, pirama.

Repository:
  rC Clang

https://reviews.llvm.org/D50199

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/Basic/Targets.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Preprocessor/predefined-win-macros.c


Index: test/Preprocessor/predefined-win-macros.c
===================================================================
--- test/Preprocessor/predefined-win-macros.c
+++ test/Preprocessor/predefined-win-macros.c
@@ -73,12 +73,17 @@
 // RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW
 
+// CHECK-X86-MINGW-NOT: #define UNICODE 1
 // CHECK-X86-MINGW: #define WIN32 1
 // CHECK-X86-MINGW-NOT: #define WIN64 1
 // CHECK-X86-MINGW: #define WINNT 1
 // CHECK-X86-MINGW: #define _WIN32 1
 // CHECK-X86-MINGW-NOT: #define _WIN64 1
 
+// RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - -municode \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW-UNICODE
+// CHECK-X86-MINGW-UNICODE: #define UNICODE 1
+
 // RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW
 
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2460,6 +2460,7 @@
   Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
   Opts.PIE = Args.hasArg(OPT_pic_is_pie);
   Opts.Static = Args.hasArg(OPT_static_define);
+  Opts.Unicode = Args.hasArg(OPT_municode);
   Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);
   Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple
                         || Args.hasArg(OPT_fdump_record_layouts);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3346,6 +3346,9 @@
   if (Args.hasArg(options::OPT_static))
     CmdArgs.push_back("-static-define");
 
+  if (Args.hasArg(options::OPT_municode))
+    CmdArgs.push_back("-municode");
+
   if (isa<AnalyzeJobAction>(JA))
     RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -109,6 +109,8 @@
   }
   Builder.defineMacro("__MSVCRT__");
   Builder.defineMacro("__MINGW32__");
+  if (Opts.Unicode)
+    Builder.defineMacro("UNICODE");
   addCygMingDefines(Opts, Builder);
 }
 
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1927,7 +1927,7 @@
 def mconsole : Joined<["-"], "mconsole">, Group<m_Group>, Flags<[DriverOption]>;
 def mwindows : Joined<["-"], "mwindows">, Group<m_Group>, Flags<[DriverOption]>;
 def mdll : Joined<["-"], "mdll">, Group<m_Group>, Flags<[DriverOption]>;
-def municode : Joined<["-"], "municode">, Group<m_Group>, Flags<[DriverOption]>;
+def municode : Joined<["-"], "municode">, Group<m_Group>, Flags<[DriverOption, CC1Option]>;
 def mthreads : Joined<["-"], "mthreads">, Group<m_Group>, Flags<[DriverOption]>;
 def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group<m_Group>;
Index: include/clang/Basic/LangOptions.def
===================================================================
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -164,6 +164,7 @@
 COMPATIBLE_LANGOPT(Optimize          , 1, 0, "__OPTIMIZE__ predefined macro")
 COMPATIBLE_LANGOPT(OptimizeSize      , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")
 COMPATIBLE_LANGOPT(Static            , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")
+COMPATIBLE_LANGOPT(Unicode           , 1, 0, "UNICODE predefined macro")
 VALUE_LANGOPT(PackStruct  , 32, 0,
               "default struct packing maximum alignment")
 VALUE_LANGOPT(MaxTypeAlign  , 32, 0,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50199.158820.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180802/591d58ad/attachment.bin>


More information about the cfe-commits mailing list