Browse Source

* forbid cyclic pointer definitions, resolves #39634

florian 3 years ago
parent
commit
559fcdf736
5 changed files with 391 additions and 361 deletions
  1. 8 1
      compiler/msg/errore.msg
  2. 3 2
      compiler/msgidx.inc
  3. 358 358
      compiler/msgtxt.inc
  4. 10 0
      compiler/ptype.pas
  5. 12 0
      tests/webtbf/tw39634.pp

+ 8 - 1
compiler/msg/errore.msg

@@ -445,7 +445,7 @@ scan_e_unexpected_endif=02108_E_$ENDIF directive found without a matching $IF(N)
 #
 # Parser
 #
-# 03364 is the last used one
+# 03365 is the last used one
 #
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
@@ -1642,6 +1642,13 @@ parser_e_syscall_format_not_support=03364_E_Syntax of syscall directive not supp
 % On a certain target, not all syntax variants of the syscall directive make sense and thus those making
 % no sense are not supported
 % Declarations like \var{var i: Integer absolute i;} are not allowed
+parser_e_cyclic_pointertypes_are_not_allowed=03365_E_Cyclic definitions of pointers are not allowed
+% Pointers may not be defined cyclic like:
+% \begin{verbatim}
+% type
+%  tp1 = ^tp2;
+%  tp2 = ^tp1;
+% \end{verbatim}
 %
 % \end{description}
 %

+ 3 - 2
compiler/msgidx.inc

@@ -478,6 +478,7 @@ const
   parser_e_section_directive_not_allowed_for_target=03362;
   parser_e_absolute_sym_cannot_reference_itself=03363;
   parser_e_syscall_format_not_support=03364;
+  parser_e_cyclic_pointertypes_are_not_allowed=03365;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -1152,9 +1153,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 89619;
+  MsgTxtSize = 89674;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,109,365,131,99,63,148,37,223,70,
+    28,109,366,131,99,63,148,37,223,70,
     65,20,30,1,1,1,1,1,1,1
   );

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


+ 10 - 0
compiler/ptype.pas

@@ -213,6 +213,16 @@ implementation
                               fileinfo:=srsym.fileinfo;
                             MessagePos(fileinfo,parser_e_no_generics_as_types);
                           end;
+                        hpd:=tabstractpointerdef(def).pointeddef;
+                        while assigned(hpd) and (hpd.typ=pointerdef) do
+                          begin
+                            if def=hpd then
+                              begin
+                                MessagePos(def.typesym.fileinfo,parser_e_cyclic_pointertypes_are_not_allowed);
+                                break;
+                              end;
+                            hpd:=tabstractpointerdef(hpd).pointeddef;
+                          end;
                       end
                      else
                       begin

+ 12 - 0
tests/webtbf/tw39634.pp

@@ -0,0 +1,12 @@
+{ %fail }
+program Project1;
+{$mode objfpc}{$H+}
+type
+  TRecursePtrA1 = ^TRecursePtrA2;
+  TRecursePtrA2 = ^TRecursePtrA1;
+var
+ RecursePtrA1:  TRecursePtrA1;
+ RecursePtrA2:  TRecursePtrA2;
+begin
+  RecursePtrA2 := RecursePtrA1;
+end.

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