r186903 - Integers which are too large should be an error.

Eli Friedman eli.friedman at gmail.com
Mon Jul 22 17:25:18 PDT 2013


Author: efriedma
Date: Mon Jul 22 19:25:18 2013
New Revision: 186903

URL: http://llvm.org/viewvc/llvm-project?rev=186903&view=rev
Log:
Integers which are too large should be an error.

Switch some warnings over to errors which should never have been warnings
in the first place.  (Also, a minor fix to the preprocessor rules for
integer literals while I'm here.)

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    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/CodeGen/statements.c
    cfe/trunk/test/CodeGen/string-literal-unicode-conversion.c
    cfe/trunk/test/Lexer/constants.c
    cfe/trunk/test/Misc/warning-flags.c
    cfe/trunk/test/Sema/128bitint.c
    cfe/trunk/test/Sema/alloc_size.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Mon Jul 22 19:25:18 2013
@@ -99,10 +99,10 @@ def ext_cxx11_longlong : Extension<
 def warn_cxx98_compat_longlong : Warning<
   "'long long' is incompatible with C++98">,
   InGroup<CXX98CompatPedantic>, DefaultIgnore;
-def warn_integer_too_large : Warning<
-  "integer constant is too large for its type">;
-def warn_integer_too_large_for_signed : Warning<
-  "integer constant is so large that it is unsigned">;
+def err_integer_too_large : Error<
+  "integer constant is larger than the largest unsigned integer type">;
+def err_integer_too_large_for_signed : Error<
+  "integer constant is larger than the largest signed integer type">;
 
 // Sema && AST
 def note_invalid_subexpr_in_const_expr : Note<

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Mon Jul 22 19:25:18 2013
@@ -180,8 +180,8 @@ def warn_cxx11_compat_binary_literal : W
   "binary integer literals are incompatible with C++ standards before C++1y">,
   InGroup<CXXPre1yCompatPedantic>, DefaultIgnore;
 def err_pascal_string_too_long : Error<"Pascal string is too long">;
-def warn_octal_escape_too_large : ExtWarn<"octal escape sequence out of range">;
-def warn_hex_escape_too_large : ExtWarn<"hex escape sequence out of range">;
+def err_octal_escape_too_large : Error<"octal escape sequence out of range">;
+def err_hex_escape_too_large : Error<"hex escape sequence out of range">;
 def ext_string_too_long : Extension<"string literal of length %0 exceeds "
   "maximum length %1 that %select{C90|ISO C99|C++}2 compilers are required to "
   "support">, InGroup<OverlengthStrings>;

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Mon Jul 22 19:25:18 2013
@@ -157,7 +157,7 @@ static unsigned ProcessCharEscape(const
     // Check for overflow.
     if (Overflow && Diags)   // Too many digits to fit in
       Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
-           diag::warn_hex_escape_too_large);
+           diag::err_hex_escape_too_large);
     break;
   }
   case '0': case '1': case '2': case '3':
@@ -180,7 +180,7 @@ static unsigned ProcessCharEscape(const
     if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
       if (Diags)
         Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
-             diag::warn_octal_escape_too_large);
+             diag::err_octal_escape_too_large);
       ResultChar &= ~0U >> (32-CharWidth);
     }
     break;

Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Mon Jul 22 19:25:18 2013
@@ -245,7 +245,7 @@ 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::warn_integer_too_large);
+      if (ValueLive) PP.Diag(PeekTok, diag::err_integer_too_large);
       Result.Val.setIsUnsigned(true);
     } else {
       // Set the signedness of the result to match whether there was a U suffix
@@ -257,9 +257,9 @@ static bool EvaluateValue(PPValue &Resul
       // large that it is unsigned" e.g. on 12345678901234567890 where intmax_t
       // is 64-bits.
       if (!Literal.isUnsigned && Result.Val.isNegative()) {
-        // Don't warn for a hex literal: 0x8000..0 shouldn't warn.
-        if (ValueLive && Literal.getRadix() != 16)
-          PP.Diag(PeekTok, diag::warn_integer_too_large_for_signed);
+        // Don't warn for a hex or octal literal: 0x8000..0 shouldn't warn.
+        if (ValueLive && Literal.getRadix() == 10)
+          PP.Diag(PeekTok, diag::err_integer_too_large_for_signed);
         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=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jul 22 19:25:18 2013
@@ -2909,7 +2909,7 @@ ExprResult Sema::ActOnNumericConstant(co
       } else {
         llvm::APInt ResultVal(Context.getTargetInfo().getLongLongWidth(), 0);
         if (Literal.GetIntegerValue(ResultVal))
-          Diag(Tok.getLocation(), diag::warn_integer_too_large);
+          Diag(Tok.getLocation(), diag::err_integer_too_large);
         Lit = IntegerLiteral::Create(Context, ResultVal, CookedTy,
                                      Tok.getLocation());
       }
@@ -3002,8 +3002,8 @@ ExprResult Sema::ActOnNumericConstant(co
     llvm::APInt ResultVal(MaxWidth, 0);
 
     if (Literal.GetIntegerValue(ResultVal)) {
-      // If this value didn't fit into uintmax_t, warn and force to ull.
-      Diag(Tok.getLocation(), diag::warn_integer_too_large);
+      // If this value didn't fit into uintmax_t, error and force to ull.
+      Diag(Tok.getLocation(), diag::err_integer_too_large);
       Ty = Context.UnsignedLongLongTy;
       assert(Context.getTypeSize(Ty) == ResultVal.getBitWidth() &&
              "long long is not intmax_t?");
@@ -3079,7 +3079,7 @@ 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::warn_integer_too_large_for_signed);
+        Diag(Tok.getLocation(), diag::err_integer_too_large_for_signed);
         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=186903&r1=186902&r2=186903&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 Mon Jul 22 19:25:18 2013
@@ -9,7 +9,7 @@ int &i2 = 45_x1;
 template<char...> char &operator "" _x1 ();
 int &i3 = 0377_x1;
 
-int &i4 = 90000000000000000000000000000000000000000000000_x1; // expected-warning {{integer constant is too large}}
+int &i4 = 90000000000000000000000000000000000000000000000_x1; // expected-error {{integer constant is larger than the largest unsigned integer type}}
 
 double &operator "" _x2 (const char *);
 double &i5 = 123123123123123123123123123123123123123123123_x2;

Modified: cfe/trunk/test/CodeGen/statements.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/statements.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/statements.c (original)
+++ cfe/trunk/test/CodeGen/statements.c Mon Jul 22 19:25:18 2013
@@ -1,13 +1,6 @@
 // RUN: %clang_cc1 -Wno-error=return-type %s -emit-llvm-only
 // REQUIRES: LP64
 
-void test1(int x) {
-switch (x) {
-case 111111111111111111111111111111111111111:
-bar();
-}
-}
-
 // Mismatched type between return and function result.
 int test2() { return; }
 void test3() { return 4; }

Modified: cfe/trunk/test/CodeGen/string-literal-unicode-conversion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/string-literal-unicode-conversion.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/string-literal-unicode-conversion.c (original)
+++ cfe/trunk/test/CodeGen/string-literal-unicode-conversion.c Mon Jul 22 19:25:18 2013
@@ -31,10 +31,11 @@ void f() {
   wchar_t const *b = L"Кошка";
 
   // CHECK-C: private unnamed_addr constant [4 x i32] [i32 20320, i32 22909, i32 66304, i32 0], align 4
-  // CHECK-SHORTWCHAR: private unnamed_addr constant [4 x i16] [i16 20320, i16 22909, i16 768, i16 0], align 2
   // CHECK-CPP0X: private unnamed_addr constant [4 x i32] [i32 20320, i32 22909, i32 66304, i32 0], align 4
+#if __WCHAR_MAX__ == 2147483647
   wchar_t const *b2 = L"\x4f60\x597d\x10300";
-  
+#endif
+
 #if __cplusplus >= 201103L
   
   // CHECK-CPP0X: private unnamed_addr constant [12 x i8] c"1\D0\9A\D0\BE\D1\88\D0\BA\D0\B0\00", align 1

Modified: cfe/trunk/test/Lexer/constants.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/constants.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/constants.c (original)
+++ cfe/trunk/test/Lexer/constants.c Mon Jul 22 19:25:18 2013
@@ -13,7 +13,12 @@ float Y = 08.123456;
 // PR2252
 #if -0x8000000000000000  // should not warn.
 #endif
-
+#if -01000000000000000000000  // should not warn.
+#endif
+#if 9223372036854775808 // expected-error {{integer constant is larger than the largest signed integer type}}
+#endif
+#if 0x10000000000000000 // expected-error {{integer constant is larger than the largest unsigned integer type}}
+#endif
 
 int c[] = {
   'df',   // expected-warning {{multi-character character constant}}

Modified: cfe/trunk/test/Misc/warning-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/Misc/warning-flags.c (original)
+++ cfe/trunk/test/Misc/warning-flags.c Mon Jul 22 19:25:18 2013
@@ -18,7 +18,7 @@ This test serves two purposes:
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (140):
+CHECK: Warnings without flags (136):
 CHECK-NEXT:   ext_delete_void_ptr_operand
 CHECK-NEXT:   ext_enum_friend
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -81,14 +81,11 @@ CHECK-NEXT:   warn_fe_cc_log_diagnostics
 CHECK-NEXT:   warn_fe_cc_print_header_failure
 CHECK-NEXT:   warn_fe_macro_contains_embedded_newline
 CHECK-NEXT:   warn_file_asm_volatile
-CHECK-NEXT:   warn_hex_escape_too_large
 CHECK-NEXT:   warn_ignoring_ftabstop_value
 CHECK-NEXT:   warn_implements_nscopying
 CHECK-NEXT:   warn_incompatible_qualified_id
 CHECK-NEXT:   warn_initializer_string_for_char_array_too_long
 CHECK-NEXT:   warn_inline_namespace_reopened_noninline
-CHECK-NEXT:   warn_integer_too_large
-CHECK-NEXT:   warn_integer_too_large_for_signed
 CHECK-NEXT:   warn_invalid_asm_cast_lvalue
 CHECK-NEXT:   warn_many_braces_around_scalar_init
 CHECK-NEXT:   warn_maynot_respond
@@ -104,7 +101,6 @@ CHECK-NEXT:   warn_nonnull_pointers_only
 CHECK-NEXT:   warn_not_compound_assign
 CHECK-NEXT:   warn_objc_property_copy_missing_on_block
 CHECK-NEXT:   warn_objc_protocol_qualifier_missing_id
-CHECK-NEXT:   warn_octal_escape_too_large
 CHECK-NEXT:   warn_on_superclass_use
 CHECK-NEXT:   warn_param_default_argument_redefinition
 CHECK-NEXT:   warn_partial_specs_not_deducible

Modified: cfe/trunk/test/Sema/128bitint.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/128bitint.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/Sema/128bitint.c (original)
+++ cfe/trunk/test/Sema/128bitint.c Mon Jul 22 19:25:18 2013
@@ -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-warning {{integer constant is too large for its type}}
+long long SignedTooBig = 123456789012345678901234567890; // expected-error {{constant is larger than the largest 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-warning {{integer constant is too large for its type}}
+unsigned long long UnsignedTooBig = 123456789012345678901234567890; // expected-error {{constant is larger than the largest 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}}
 

Modified: cfe/trunk/test/Sema/alloc_size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc_size.c?rev=186903&r1=186902&r2=186903&view=diff
==============================================================================
--- cfe/trunk/test/Sema/alloc_size.c (original)
+++ cfe/trunk/test/Sema/alloc_size.c Mon Jul 22 19:25:18 2013
@@ -19,7 +19,7 @@ void* fn7(unsigned) __attribute__((alloc
 
 void *fn8(int, int) __attribute__((alloc_size(1, 1))); // OK
 
-void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // expected-warning {{integer constant is too large for its type}} // expected-error {{attribute parameter 1 is out of bounds}}
+void* fn9(unsigned) __attribute__((alloc_size(12345678901234567890123))); // expected-error {{integer constant is larger than the largest unsigned integer type}} // expected-error {{attribute parameter 1 is out of bounds}}
 
 void* fn10(size_t, size_t) __attribute__((alloc_size(1,2))); // expected-error{{redefinition of parameter}} \
                                                              // expected-error{{a parameter list without types is only allowed in a function definition}} \





More information about the cfe-commits mailing list