Browse Source

* give an error if an explicit enumeration valid exceeds the valid range, resolves #34633

git-svn-id: trunk@43191 -
florian 5 years ago
parent
commit
626ef4ae0c
6 changed files with 386 additions and 365 deletions
  1. 1 0
      .gitattributes
  2. 3 0
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 370 363
      compiler/msgtxt.inc
  5. 2 0
      compiler/ptype.pas
  6. 7 0
      tests/webtbf/tw34633.pp

+ 1 - 0
.gitattributes

@@ -16049,6 +16049,7 @@ tests/webtbf/tw3395.pp svneol=native#text/plain
 tests/webtbf/tw3395a.pp svneol=native#text/plain
 tests/webtbf/tw34355.pp svneol=native#text/pascal
 tests/webtbf/tw3450.pp svneol=native#text/plain
+tests/webtbf/tw34633.pp svneol=native#text/pascal
 tests/webtbf/tw34691.pp svneol=native#text/pascal
 tests/webtbf/tw3473.pp svneol=native#text/plain
 tests/webtbf/tw3480.pp svneol=native#text/plain

+ 3 - 0
compiler/msg/errore.msg

@@ -1600,6 +1600,9 @@ parser_e_callthrough_varargs=03350_E_Cannot redeclare C-style variadic function
 % platforms. Even on platforms where it is supported, this is quite inefficient.
 parser_e_unbound_attribute=03351_E_Unbound custom attribute: "$1".
 % A custom attribute is defined, but there is no identifier to bind it to.
+parser_e_enumeration_out_of_range=03352_E_Enumeration symbols can only have values in the range of -2^31 to 2^31-1
+% The size of enumeration values is limited to 4 bytes. As the value can be signed, the range
+% of valid values is limited to a signed 32 Bit value (i.e. \var{longint}).
 %
 % \end{description}
 %

+ 3 - 2
compiler/msgidx.inc

@@ -462,6 +462,7 @@ const
   parser_e_only_static_members_via_object_type=03349;
   parser_e_callthrough_varargs=03350;
   parser_e_unbound_attribute=03351;
+  parser_e_enumeration_out_of_range=03352;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -1113,9 +1114,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 83621;
+  MsgTxtSize = 83702;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,106,352,126,99,61,143,34,221,68,
+    28,106,353,126,99,61,143,34,221,68,
     62,20,30,1,1,1,1,1,1,1
   );

File diff suppressed because it is too large
+ 370 - 363
compiler/msgtxt.inc


+ 2 - 0
compiler/ptype.pas

@@ -1718,6 +1718,8 @@ implementation
                     begin
                       storepos:=current_tokenpos;
                       current_tokenpos:=defpos;
+                      if (l.svalue<low(longint)) or (l.svalue>high(longint)) then
+                        Message(parser_e_enumeration_out_of_range);
                       tenumsymtable(aktenumdef.symtable).insert(cenumsym.create(s,aktenumdef,longint(l.svalue)));
                       if not (cs_scopedenums in current_settings.localswitches) then
                         tstoredsymtable(aktenumdef.owner).insert(cenumsym.create(s,aktenumdef,longint(l.svalue)));

+ 7 - 0
tests/webtbf/tw34633.pp

@@ -0,0 +1,7 @@
+{ %fail }
+{$mode delphi}
+type tenum = (b0, b1, b2, bMax = high(dword)); 
+
+begin
+  writeln(sizeof(tenum));
+end.

Some files were not shown because too many files changed in this diff