[cfe-commits] r86167 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Basic/LangOptions.h include/clang/Basic/TargetInfo.h include/clang/Driver/Options.def lib/Basic/TargetInfo.cpp lib/Driver/Tools.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/Driver/clang_f_opts.c test/Sema/wchar.c tools/clang-cc/clang-cc.cpp
John Thompson
John.Thompson.JTSoftware at gmail.com
Thu Nov 5 12:14:17 PST 2009
Author: jtsoftware
Date: Thu Nov 5 14:14:16 2009
New Revision: 86167
URL: http://llvm.org/viewvc/llvm-project?rev=86167&view=rev
Log:
Adding -fshort-wchar option.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Driver/Options.def
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/Driver/clang_f_opts.c
cfe/trunk/test/Sema/wchar.c
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Thu Nov 5 14:14:16 2009
@@ -162,6 +162,9 @@
def warn_pch_char_signed : Error<
"char was %select{unsigned|signed}0 in the PCH file but "
"is currently %select{unsigned|signed}1">;
+def warn_pch_short_wchar : Error<
+ "-fshort-wchar was %select{disabled|enabled}0 in the PCH file but "
+ "is currently %select{disabled|enabled}1">;
def err_not_a_pch_file : Error<
"'%0' does not appear to be a precompiled header file">, DefaultFatal;
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Thu Nov 5 14:14:16 2009
@@ -83,6 +83,7 @@
unsigned AccessControl : 1; // Whether C++ access control should
// be enabled.
unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
+ unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
unsigned OpenCL : 1; // OpenCL C99 language extensions.
@@ -159,6 +160,7 @@
NoInline = 0;
CharIsSigned = 1;
+ ShortWChar = 0;
MainFileName = 0;
}
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Nov 5 14:14:16 2009
@@ -346,6 +346,11 @@
/// options.
virtual void getDefaultLangOptions(LangOptions &Opts) {}
+ /// setForcedLangOptions - Set forced language options.
+ /// Apply changes to the target information with respect to certain
+ /// language options which change the target configuration.
+ virtual void setForcedLangOptions(LangOptions &Opts);
+
/// getDefaultFeatures - Get the default set of target features for
/// the \args CPU; this should include all legal feature strings on
/// the target.
Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Thu Nov 5 14:14:16 2009
@@ -463,6 +463,7 @@
OPTION("-fprofile-generate", fprofile_generate, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-framework", framework, Separate, INVALID, INVALID, "l", 0, 0, 0)
OPTION("-frtti", frtti, Flag, f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fshort-wchar", fshort_wchar, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fshow-source-location", fshow_source_location, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fsigned-bitfields", fsigned_bitfields, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fsigned-char", fsigned_char, Flag, f_Group, INVALID, "", 0, 0, 0)
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Nov 5 14:14:16 2009
@@ -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;
+ }
+}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Nov 5 14:14:16 2009
@@ -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.
//
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Thu Nov 5 14:14:16 2009
@@ -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]);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Thu Nov 5 14:14:16 2009
@@ -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());
Modified: cfe/trunk/test/Driver/clang_f_opts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/test/Driver/clang_f_opts.c (original)
+++ cfe/trunk/test/Driver/clang_f_opts.c Thu Nov 5 14:14:16 2009
@@ -2,10 +2,11 @@
// RUN: grep -F '"-fblocks"' %t &&
// RUN: grep -F '"--fmath-errno=1"' %t &&
// RUN: grep -F '"-fpascal-strings"' %t &&
-// RUN: clang -### -S -x c /dev/null -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fno-math-errno -fno-common -fno-pascal-strings -fno-show-source-location %s 2> %t &&
+// RUN: clang -### -S -x c /dev/null -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fno-math-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-wchar %s 2> %t &&
// RUN: grep -F '"-fblocks=0"' %t &&
// RUN: grep -F '"-fbuiltin=0"' %t &&
// RUN: grep -F '"-fno-common"' %t &&
// RUN: grep -F '"--fmath-errno=0"' %t &&
// RUN: grep -F '"-fno-show-source-location"' %t &&
+// RUN: grep -F '"-fshort-wchar"' %t &&
// RUN: true
Modified: cfe/trunk/test/Sema/wchar.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/wchar.c?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/test/Sema/wchar.c (original)
+++ cfe/trunk/test/Sema/wchar.c Thu Nov 5 14:14:16 2009
@@ -1,12 +1,20 @@
-// RUN: clang-cc %s -fsyntax-only -verify
+// RUN: clang-cc %s -fsyntax-only -verify &&
+// RUN: clang-cc %s -fsyntax-only -fshort-wchar -verify -DSHORT_WCHAR
+
#include <wchar.h>
-
+
+#if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \
+ || defined(_M_X64) || defined(SHORT_WCHAR)
+ #define WCHAR_T_TYPE unsigned short
+#else
+ #define WCHAR_T_TYPE int
+#endif
+
int check_wchar_size[sizeof(*L"") == sizeof(wchar_t) ? 1 : -1];
-
+
void foo() {
- int t1[] = L"x";
+ WCHAR_T_TYPE t1[] = L"x";
wchar_t tab[] = L"x";
-
- int t2[] = "x"; // expected-error {{initialization}}
+ WCHAR_T_TYPE t2[] = "x"; // expected-error {{initialization}}
char t3[] = L"x"; // expected-error {{initialization}}
}
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86167&r1=86166&r2=86167&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Nov 5 14:14:16 2009
@@ -611,6 +611,10 @@
CharIsSigned("fsigned-char",
llvm::cl::desc("Force char to be a signed/unsigned type"));
+static llvm::cl::opt<bool>
+ShortWChar("fshort-wchar",
+ llvm::cl::desc("Force wchar_t to be a short unsigned int"));
+
static llvm::cl::opt<bool>
Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
@@ -813,6 +817,8 @@
Options.Blocks = EnableBlocks;
if (CharIsSigned.getPosition())
Options.CharIsSigned = CharIsSigned;
+ if (ShortWChar.getPosition())
+ Options.ShortWChar = ShortWChar;
if (!AllowBuiltins)
Options.NoBuiltin = 1;
@@ -877,6 +883,8 @@
if (MainFileName.getPosition())
Options.setMainFileName(MainFileName.c_str());
+
+ Target->setForcedLangOptions(Options);
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list