Adding -fshort-wchar option.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86167 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
index 12caf0c..e965b9a 100644
--- a/lib/Basic/TargetInfo.cpp
+++ b/lib/Basic/TargetInfo.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include <cstdlib>
@@ -124,6 +125,15 @@
};
}
+/// setForcedLangOptions - Set forced language options.
+/// Apply changes to the target information with respect to certain
+/// language options which change the target configuration.
+void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
+ if (Opts.ShortWChar) {
+ WCharType = UnsignedShort;
+ WCharWidth = WCharAlign = 16;
+ }
+}
//===----------------------------------------------------------------------===//
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 808c31c..c35ad7c 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -922,6 +922,13 @@
CmdArgs.push_back("-fsigned-char=0");
}
+ // -fshort-wchar default varies depending on platform; only
+ // pass if specified.
+ if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar)) {
+ if (A->getOption().matches(options::OPT_fshort_wchar))
+ CmdArgs.push_back("-fshort-wchar");
+ }
+
// -fno-pascal-strings is default, only pass non-default. If the tool chain
// happened to translate to -mpascal-strings, we want to back translate here.
//
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 26f426b..a812604 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -104,6 +104,7 @@
PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline);
PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control);
PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed);
+ PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar);
if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) {
Reader.Diag(diag::warn_pch_gc_mode)
<< LangOpts.getGCMode() << PPLangOpts.getGCMode();
@@ -1741,6 +1742,7 @@
PARSE_LANGOPT(NoInline);
PARSE_LANGOPT(AccessControl);
PARSE_LANGOPT(CharIsSigned);
+ PARSE_LANGOPT(ShortWChar);
LangOpts.setGCMode((LangOptions::GCMode)Record[Idx]);
++Idx;
LangOpts.setVisibilityMode((LangOptions::VisibilityMode)Record[Idx]);
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index de56166..436428b 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -765,6 +765,7 @@
// be enabled.
Record.push_back(LangOpts.CharIsSigned); // Whether char is a signed or
// unsigned type
+ Record.push_back(LangOpts.ShortWChar); // force wchar_t to be unsigned short
Record.push_back(LangOpts.getGCMode());
Record.push_back(LangOpts.getVisibilityMode());
Record.push_back(LangOpts.getStackProtectorMode());