forked from OSchip/llvm-project
Implement -fshort-enums (rdar://8490496).
llvm-svn: 116020
This commit is contained in:
parent
09f2265eac
commit
74825bcfb9
|
@ -243,6 +243,9 @@ def warn_pch_char_signed : Error<
|
|||
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 warn_pch_short_enums : Error<
|
||||
"-fshort-enums 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;
|
||||
|
|
|
@ -89,6 +89,9 @@ public:
|
|||
unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
|
||||
unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
|
||||
|
||||
unsigned ShortEnums : 1; // The enum type will be equivalent to the
|
||||
// smallest integer type with enough room.
|
||||
|
||||
unsigned OpenCL : 1; // OpenCL C99 language extensions.
|
||||
|
||||
unsigned AssumeSaneOperatorNew : 1; // Whether to add __attribute__((malloc))
|
||||
|
@ -182,6 +185,7 @@ public:
|
|||
|
||||
CharIsSigned = 1;
|
||||
ShortWChar = 0;
|
||||
ShortEnums = 0;
|
||||
CatchUndefined = 0;
|
||||
DumpRecordLayouts = 0;
|
||||
DumpVTableLayouts = 0;
|
||||
|
|
|
@ -478,6 +478,8 @@ def fno_validate_pch : Flag<"-fno-validate-pch">,
|
|||
HelpText<"Disable validation of precompiled headers">;
|
||||
def fshort_wchar : Flag<"-fshort-wchar">,
|
||||
HelpText<"Force wchar_t to be a short unsigned int">;
|
||||
def fshort_enums : Flag<"-fshort-enums">,
|
||||
HelpText<"Allocate to an enum type only as many bytes as it needs for the declared range of possible values">;
|
||||
def static_define : Flag<"-static-define">,
|
||||
HelpText<"Should __STATIC__ be defined">;
|
||||
def stack_protector : Separate<"-stack-protector">,
|
||||
|
|
|
@ -333,6 +333,7 @@ def fno_objc_legacy_dispatch : Flag<"-fno-objc-legacy-dispatch">, Group<f_Group>
|
|||
def fno_omit_frame_pointer : Flag<"-fno-omit-frame-pointer">, Group<f_Group>;
|
||||
def fno_pascal_strings : Flag<"-fno-pascal-strings">, Group<f_Group>;
|
||||
def fno_rtti : Flag<"-fno-rtti">, Group<f_Group>;
|
||||
def fno_short_enums : Flag<"-fno-short-enums">, Group<f_Group>;
|
||||
def fno_show_column : Flag<"-fno-show-column">, Group<f_Group>;
|
||||
def fno_show_source_location : Flag<"-fno-show-source-location">, Group<f_Group>;
|
||||
def fno_spell_checking : Flag<"-fno-spell-checking">, Group<f_Group>;
|
||||
|
@ -376,7 +377,7 @@ def framework : Separate<"-framework">, Flags<[LinkerInput]>;
|
|||
def frandom_seed_EQ : Joined<"-frandom-seed=">, Group<clang_ignored_f_Group>;
|
||||
def frtti : Flag<"-frtti">, Group<f_Group>;
|
||||
def fsched_interblock : Flag<"-fsched-interblock">, Group<clang_ignored_f_Group>;
|
||||
def fshort_enums : Flag<"-fshort-enums">, Group<clang_ignored_f_Group>;
|
||||
def fshort_enums : Flag<"-fshort-enums">, Group<f_Group>;
|
||||
def freorder_blocks : Flag<"-freorder-blocks">, Group<clang_ignored_f_Group>;
|
||||
def fshort_wchar : Flag<"-fshort-wchar">, Group<f_Group>;
|
||||
def fshow_overloads_EQ : Joined<"-fshow-overloads=">, Group<f_Group>;
|
||||
|
|
|
@ -1002,8 +1002,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
if (!Args.hasArg(options::OPT_fallow_unsupported)) {
|
||||
Arg *Unsupported;
|
||||
if ((Unsupported = Args.getLastArg(options::OPT_MG)) ||
|
||||
(Unsupported = Args.getLastArg(options::OPT_iframework)) ||
|
||||
(Unsupported = Args.getLastArg(options::OPT_fshort_enums)))
|
||||
(Unsupported = Args.getLastArg(options::OPT_iframework)))
|
||||
D.Diag(clang::diag::err_drv_clang_unsupported)
|
||||
<< Unsupported->getOption().getName();
|
||||
|
||||
|
@ -1258,6 +1257,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti))
|
||||
CmdArgs.push_back("-fno-rtti");
|
||||
|
||||
// -fshort-enums=0 is default.
|
||||
// FIXME: Are there targers where -fshort-enums is on by default ?
|
||||
if (Args.hasFlag(options::OPT_fshort_enums,
|
||||
options::OPT_fno_short_enums, false))
|
||||
CmdArgs.push_back("-fshort-enums");
|
||||
|
||||
// -fsigned-char is default.
|
||||
if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char,
|
||||
isSignedCharDefault(getToolChain().getTriple())))
|
||||
|
|
|
@ -1352,6 +1352,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
|
|||
Opts.Blocks = Args.hasArg(OPT_fblocks);
|
||||
Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char);
|
||||
Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar);
|
||||
Opts.ShortEnums = Args.hasArg(OPT_fshort_enums);
|
||||
Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
|
||||
Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
|
||||
Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
|
||||
|
|
|
@ -7083,6 +7083,10 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc,
|
|||
QualType BestPromotionType;
|
||||
|
||||
bool Packed = Enum->getAttr<PackedAttr>() ? true : false;
|
||||
// -fshort-enums is the equivalent to specifying the packed attribute on all
|
||||
// enum definitions.
|
||||
if (LangOpts.ShortEnums)
|
||||
Packed = true;
|
||||
|
||||
if (NumNegativeBits) {
|
||||
// If there is a negative value, figure out the smallest integer type (of
|
||||
|
|
|
@ -118,6 +118,7 @@ PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) {
|
|||
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);
|
||||
PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums);
|
||||
if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) {
|
||||
Reader.Diag(diag::warn_pch_gc_mode)
|
||||
<< LangOpts.getGCMode() << PPLangOpts.getGCMode();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS1 %s
|
||||
// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-wchar %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
|
||||
// RUN: %clang -### -fshort-enums %s 2>&1 | FileCheck -check-prefix=CHECK-SHORT-ENUMS %s
|
||||
// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-enums -fshort-wchar %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
|
||||
|
||||
// CHECK-OPTIONS1: -fgnu-keywords
|
||||
// CHECK-OPTIONS1: -fblocks
|
||||
|
@ -9,8 +8,7 @@
|
|||
// CHECK_OPTIONS2: -fno-gnu-keywords
|
||||
// CHECK-OPTIONS2: -fmath-errno
|
||||
// CHECK-OPTIONS2: -fno-builtin
|
||||
// CHECK-OPTIONS2: -fshort-enums
|
||||
// CHECK-OPTIONS2: -fshort-wchar
|
||||
// CHECK-OPTIONS2: -fno-common
|
||||
// CHECK-OPTIONS2: -fno-show-source-location
|
||||
|
||||
// CHECK-SHORT-ENUMS: compiler does not support '-fshort-enums'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// RUN: not %clang_cc1 -fsyntax-only %s -verify
|
||||
// RUN: %clang_cc1 -fshort-enums -fsyntax-only %s -verify
|
||||
|
||||
enum x { A };
|
||||
int t0[sizeof(enum x) == 1 ? 1 : -1];
|
Loading…
Reference in New Issue