r213657 - Provide extra information in the "integer constant is too large" diagnostic. This will be used to improve other diagnostics.
Richard Smith
richard at metafoo.co.uk
Tue Jul 22 13:34:45 PDT 2014
On 22 Jul 2014 07:22, "Aaron Ballman" <aaron at aaronballman.com> wrote:
>
> Author: aaronballman
> Date: Tue Jul 22 09:08:09 2014
> New Revision: 213657
>
> URL: http://llvm.org/viewvc/llvm-project?rev=213657&view=rev
> Log:
> Provide extra information in the "integer constant is too large"
diagnostic. This will be used to improve other diagnostics.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
> cfe/trunk/lib/Lex/PPExpressions.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p3.cpp
> cfe/trunk/test/Lexer/constants.c
> cfe/trunk/test/Sema/128bitint.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Tue Jul 22
09:08:09 2014
> @@ -103,9 +103,9 @@ def warn_cxx98_compat_longlong : Warning
> "'long long' is incompatible with C++98">,
> InGroup<CXX98CompatPedantic>, DefaultIgnore;
> def err_integer_too_large : Error<
> - "integer constant is larger than the largest unsigned integer type">;
> + "integer constant is larger than the largest %0-bit unsigned integer
type">;
The wording here could be better -- all 32-bit integer types are the same
size, by definition.
Perhaps "integer constant evaluates to value %0 that cannot be represented
as a %1-bit %select{signed|unsigned}2 integer"?
> def ext_integer_too_large_for_signed : ExtWarn<
> - "integer constant is larger than the largest signed integer type">,
> + "integer constant is larger than the largest %0-bit signed integer
type">,
> InGroup<DiagGroup<"implicitly-unsigned-literal">>;
>
> // Sema && AST
>
> Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
> +++ cfe/trunk/lib/Lex/PPExpressions.cpp Tue Jul 22 09:08:09 2014
> @@ -244,7 +244,9 @@ static bool EvaluateValue(PPValue &Resul
> // Parse the integer literal into Result.
> if (Literal.GetIntegerValue(Result.Val)) {
> // Overflow parsing integer literal.
> - if (ValueLive) PP.Diag(PeekTok, diag::err_integer_too_large);
> + if (ValueLive)
> + PP.Diag(PeekTok, diag::err_integer_too_large)
> + << Result.Val.getBitWidth();
> Result.Val.setIsUnsigned(true);
> } else {
> // Set the signedness of the result to match whether there was a U
suffix
> @@ -259,7 +261,8 @@ static bool EvaluateValue(PPValue &Resul
> // Octal, hexadecimal, and binary literals are implicitly
unsigned if
> // the value does not fit into a signed integer type.
> if (ValueLive && Literal.getRadix() == 10)
> - PP.Diag(PeekTok, diag::ext_integer_too_large_for_signed);
> + PP.Diag(PeekTok, diag::ext_integer_too_large_for_signed)
> + << Result.Val.getBitWidth();
> Result.Val.setIsUnsigned(true);
> }
> }
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul 22 09:08:09 2014
> @@ -3117,7 +3117,8 @@ ExprResult Sema::ActOnNumericConstant(co
> } else {
> llvm::APInt
ResultVal(Context.getTargetInfo().getLongLongWidth(), 0);
> if (Literal.GetIntegerValue(ResultVal))
> - Diag(Tok.getLocation(), diag::err_integer_too_large);
> + Diag(Tok.getLocation(), diag::err_integer_too_large)
> + << ResultVal.getBitWidth();
> Lit = IntegerLiteral::Create(Context, ResultVal, CookedTy,
> Tok.getLocation());
> }
> @@ -3210,7 +3211,8 @@ ExprResult Sema::ActOnNumericConstant(co
>
> if (Literal.GetIntegerValue(ResultVal)) {
> // If this value didn't fit into uintmax_t, error and force to ull.
> - Diag(Tok.getLocation(), diag::err_integer_too_large);
> + Diag(Tok.getLocation(), diag::err_integer_too_large)
> + << ResultVal.getBitWidth();
> Ty = Context.UnsignedLongLongTy;
> assert(Context.getTypeSize(Ty) == ResultVal.getBitWidth() &&
> "long long is not intmax_t?");
> @@ -3290,7 +3292,8 @@ ExprResult Sema::ActOnNumericConstant(co
> // If we still couldn't decide a type, we probably have something
that
> // does not fit in a signed long long, but has no U suffix.
> if (Ty.isNull()) {
> - Diag(Tok.getLocation(), diag::ext_integer_too_large_for_signed);
> + Diag(Tok.getLocation(), diag::ext_integer_too_large_for_signed)
> + << ResultVal.getBitWidth();
> Ty = Context.UnsignedLongLongTy;
> Width = Context.getTargetInfo().getLongLongWidth();
> }
>
> Modified: cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p3.cpp
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p3.cpp?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p3.cpp (original)
> +++ cfe/trunk/test/CXX/lex/lex.literal/lex.ext/p3.cpp Tue Jul 22 09:08:09
2014
> @@ -9,7 +9,7 @@ int &i2 = 45_x1;
> template<char...> char &operator "" _x1 ();
> int &i3 = 0377_x1;
>
> -int &i4 = 90000000000000000000000000000000000000000000000_x1; //
expected-error {{integer constant is larger than the largest unsigned
integer type}}
> +int &i4 = 90000000000000000000000000000000000000000000000_x1; //
expected-error {{integer constant is larger than the largest 64-bit
unsigned integer type}}
>
> double &operator "" _x2 (const char *);
> double &i5 = 123123123123123123123123123123123123123123123_x2;
>
> Modified: cfe/trunk/test/Lexer/constants.c
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/constants.c?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/test/Lexer/constants.c (original)
> +++ cfe/trunk/test/Lexer/constants.c Tue Jul 22 09:08:09 2014
> @@ -15,9 +15,9 @@ float Y = 08.123456;
> #endif
> #if -01000000000000000000000 // should not warn.
> #endif
> -#if 9223372036854775808 // expected-warning {{integer constant is larger
than the largest signed integer type}}
> +#if 9223372036854775808 // expected-warning {{integer constant is larger
than the largest 64-bit signed integer type}}
> #endif
> -#if 0x10000000000000000 // expected-error {{integer constant is larger
than the largest unsigned integer type}}
> +#if 0x10000000000000000 // expected-error {{integer constant is larger
than the largest 64-bit unsigned integer type}}
> #endif
>
> int c[] = {
>
> Modified: cfe/trunk/test/Sema/128bitint.c
> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/128bitint.c?rev=213657&r1=213656&r2=213657&view=diff
>
==============================================================================
> --- cfe/trunk/test/Sema/128bitint.c (original)
> +++ cfe/trunk/test/Sema/128bitint.c Tue Jul 22 09:08:09 2014
> @@ -16,10 +16,10 @@ __uint128_t b = (__uint128_t)-1;
> __int128 i = (__int128)0;
> unsigned __int128 u = (unsigned __int128)-1;
>
> -long long SignedTooBig = 123456789012345678901234567890; //
expected-error {{constant is larger than the largest unsigned integer type}}
> +long long SignedTooBig = 123456789012345678901234567890; //
expected-error {{integer constant is larger than the largest 64-bit
unsigned integer type}}
> __int128_t Signed128 = 123456789012345678901234567890i128;
> long long Signed64 = 123456789012345678901234567890i128; //
expected-warning {{implicit conversion from '__int128' to 'long long'
changes value from 123456789012345678901234567890 to -4362896299872285998}}
> -unsigned long long UnsignedTooBig = 123456789012345678901234567890; //
expected-error {{constant is larger than the largest unsigned integer type}}
> +unsigned long long UnsignedTooBig = 123456789012345678901234567890; //
expected-error {{integer constant is larger than the largest 64-bit
unsigned integer type}}
> __uint128_t Unsigned128 = 123456789012345678901234567890Ui128;
> unsigned long long Unsigned64 = 123456789012345678901234567890Ui128; //
expected-warning {{implicit conversion from 'unsigned __int128' to
'unsigned long long' changes value from 123456789012345678901234567890 to
14083847773837265618}}
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140722/4d22cdc2/attachment.html>
More information about the cfe-commits
mailing list