Index: include/clang/Basic/LangOptions.def =================================================================== --- include/clang/Basic/LangOptions.def +++ include/clang/Basic/LangOptions.def @@ -306,8 +306,8 @@ COMPATIBLE_VALUE_LANGOPT(FunctionAlignment, 5, 0, "Default alignment for functions") LANGOPT(FixedPoint, 1, 0, "fixed point types") -LANGOPT(SameFBits, 1, 0, - "unsigned and signed fixed point type having the same number of fractional bits") +LANGOPT(PaddingOnUnsignedFixedPoint, 1, 0, + "unsigned fixed point types having one extra padding bit") #undef LANGOPT #undef COMPATIBLE_LANGOPT Index: include/clang/Basic/TargetInfo.h =================================================================== --- include/clang/Basic/TargetInfo.h +++ include/clang/Basic/TargetInfo.h @@ -84,10 +84,11 @@ unsigned char LongFractWidth, LongFractAlign; // If true, unsigned fixed point types have the same number of fractional bits - // as their signed counterparts. Otherwise, unsigned fixed point types have + // as their signed counterparts, forcing the unsigned types to have one extra + // bit of padding. Otherwise, unsigned fixed point types have // one more fractional bit than its corresponding signed type. This is false // by default. - bool SameFBits; + bool PaddingOnUnsignedFixedPoint; // Fixed point integral and fractional bit sizes // Saturated types share the same integral/fractional bits as their @@ -95,7 +96,7 @@ // For simplicity, the fractional bits in a _Fract type will be one less the // width of that _Fract type. This leaves all signed _Fract types having no // padding and unsigned _Fract types will only have 1 bit of padding after the - // sign if SameFBits is set. + // sign if PaddingOnUnsignedFixedPoint is set. unsigned char ShortAccumScale; unsigned char AccumScale; unsigned char LongAccumScale; @@ -436,30 +437,33 @@ /// getUnsignedShortAccumScale/IBits - Return the number of /// fractional/integral bits in a 'unsigned short _Accum' type. unsigned getUnsignedShortAccumScale() const { - return SameFBits ? ShortAccumScale : ShortAccumScale + 1; + return PaddingOnUnsignedFixedPoint ? ShortAccumScale : ShortAccumScale + 1; } unsigned getUnsignedShortAccumIBits() const { - return SameFBits ? getShortAccumIBits() - : ShortAccumWidth - getUnsignedShortAccumScale(); + return PaddingOnUnsignedFixedPoint + ? getShortAccumIBits() + : ShortAccumWidth - getUnsignedShortAccumScale(); } /// getUnsignedAccumScale/IBits - Return the number of fractional/integral /// bits in a 'unsigned _Accum' type. unsigned getUnsignedAccumScale() const { - return SameFBits ? AccumScale : AccumScale + 1; + return PaddingOnUnsignedFixedPoint ? AccumScale : AccumScale + 1; } unsigned getUnsignedAccumIBits() const { - return SameFBits ? getAccumIBits() : AccumWidth - getUnsignedAccumScale(); + return PaddingOnUnsignedFixedPoint ? getAccumIBits() + : AccumWidth - getUnsignedAccumScale(); } /// getUnsignedLongAccumScale/IBits - Return the number of fractional/integral /// bits in a 'unsigned long _Accum' type. unsigned getUnsignedLongAccumScale() const { - return SameFBits ? LongAccumScale : LongAccumScale + 1; + return PaddingOnUnsignedFixedPoint ? LongAccumScale : LongAccumScale + 1; } unsigned getUnsignedLongAccumIBits() const { - return SameFBits ? getLongAccumIBits() - : LongAccumWidth - getUnsignedLongAccumScale(); + return PaddingOnUnsignedFixedPoint + ? getLongAccumIBits() + : LongAccumWidth - getUnsignedLongAccumScale(); } /// getShortFractScale - Return the number of fractional bits @@ -477,19 +481,21 @@ /// getUnsignedShortFractScale - Return the number of fractional bits /// in a 'unsigned short _Fract' type. unsigned getUnsignedShortFractScale() const { - return SameFBits ? getShortFractScale() : getShortFractScale() + 1; + return PaddingOnUnsignedFixedPoint ? getShortFractScale() + : getShortFractScale() + 1; } /// getUnsignedFractScale - Return the number of fractional bits /// in a 'unsigned _Fract' type. unsigned getUnsignedFractScale() const { - return SameFBits ? getFractScale() : getFractScale() + 1; + return PaddingOnUnsignedFixedPoint ? getFractScale() : getFractScale() + 1; } /// getUnsignedLongFractScale - Return the number of fractional bits /// in a 'unsigned long _Fract' type. unsigned getUnsignedLongFractScale() const { - return SameFBits ? getLongFractScale() : getLongFractScale() + 1; + return PaddingOnUnsignedFixedPoint ? getLongFractScale() + : getLongFractScale() + 1; } /// Determine whether the __int128 type is supported on this target. Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -36,6 +36,10 @@ def mfpmath : Separate<["-"], "mfpmath">, HelpText<"Which unit to use for fp math">; +def fpadding_on_unsigned_fixed_point : Flag<["-"], "fpadding-on-unsigned-fixed-point">, + HelpText<"Force each unsigned fixed point type to have an extra bit of padding to align their scales with those of signed fixed point types">; +def fno_padding_on_unsigned_fixed_point : Flag<["-"], "fno-padding-on-unsigned-fixed-point">; + //===----------------------------------------------------------------------===// // Analyzer Options //===----------------------------------------------------------------------===// Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -893,10 +893,6 @@ Flags<[CC1Option]>, HelpText<"Enable fixed point types">; def fno_fixed_point : Flag<["-"], "fno-fixed-point">, Group, HelpText<"Disable fixed point types">; -def fsame_fbits : Flag<["-"], "fsame-fbits">, Group, - Flags<[CC1Option]>, - HelpText<"Force each unsigned fixed point type to have the same number of fractional bits as its corresponding signed type">; -def fno_same_fbits : Flag<["-"], "fno-same-fbits">, Group; // Begin sanitizer flags. These should all be core options exposed in all driver // modes. Index: lib/Basic/TargetInfo.cpp =================================================================== --- lib/Basic/TargetInfo.cpp +++ lib/Basic/TargetInfo.cpp @@ -53,7 +53,7 @@ // We give the _Accum 1 fewer fractional bits than their corresponding _Fract // types by default to have the same number of fractional bits between _Accum // and _Fract types. - SameFBits = false; + PaddingOnUnsignedFixedPoint = false; ShortAccumScale = 7; AccumScale = 15; LongAccumScale = 31; @@ -377,7 +377,7 @@ // Each unsigned fixed point type has the same number of fractional bits as // its corresponding signed type. - SameFBits |= Opts.SameFBits; + PaddingOnUnsignedFixedPoint |= Opts.PaddingOnUnsignedFixedPoint; CheckFixedPointBits(); } Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3765,11 +3765,6 @@ /*Default=*/false)) Args.AddLastArg(CmdArgs, options::OPT_ffixed_point); - if (Args.hasFlag(options::OPT_fsame_fbits, - options::OPT_fno_same_fbits, - /*Default=*/false)) - Args.AddLastArg(CmdArgs, options::OPT_fsame_fbits); - // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} // (-ansi is equivalent to -std=c89 or -std=c++98). // Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -2338,8 +2338,9 @@ Opts.FixedPoint = Args.hasFlag(OPT_ffixed_point, OPT_fno_fixed_point, /*Default=*/false) && !Opts.CPlusPlus; - Opts.SameFBits = - Args.hasFlag(OPT_fsame_fbits, OPT_fno_same_fbits, + Opts.PaddingOnUnsignedFixedPoint = + Args.hasFlag(OPT_fpadding_on_unsigned_fixed_point, + OPT_fno_padding_on_unsigned_fixed_point, /*Default=*/false) && Opts.FixedPoint; Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -3358,7 +3358,7 @@ bool Overflowed = Literal.GetFixedPointValue(Val, scale); // Do not use bit_width since some types may have padding like _Fract or - // unsigned _Accums if SameFBits is set. + // unsigned _Accums if PaddingOnUnsignedFixedPoint is set. auto MaxVal = llvm::APInt::getMaxValue(ibits + scale).zextOrSelf(bit_width); if (Literal.isFract && Val == MaxVal + 1) // Clause 6.4.4 - The value of a constant shall be in the range of Index: test/Frontend/fixed_point_same_fbits.c =================================================================== --- test/Frontend/fixed_point_same_fbits.c +++ test/Frontend/fixed_point_same_fbits.c @@ -1,5 +1,5 @@ // RUN: %clang -ffixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=DEFAULT -// RUN: %clang -ffixed-point -fsame-fbits -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME +// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm -o - %s | FileCheck %s -check-prefix=SAME /* The scale for unsigned fixed point types should be the same as that of signed * fixed point types when -fsame-fbits is enabled. */