Browse Source

* prevent that a absolute symbol references itself, resolves #39604

florian 3 years ago
parent
commit
ae89261008
5 changed files with 366 additions and 344 deletions
  1. 3 1
      compiler/msg/errore.msg
  2. 3 2
      compiler/msgidx.inc
  3. 340 337
      compiler/msgtxt.inc
  4. 9 4
      compiler/pdecvar.pas
  5. 11 0
      tests/webtbf/tw39604.pp

+ 3 - 1
compiler/msg/errore.msg

@@ -445,7 +445,7 @@ scan_e_unexpected_endif=02108_E_$ENDIF directive found without a matching $IF(N)
 #
 # Parser
 #
-# 03362 is the last used one
+# 03363 is the last used one
 #
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
@@ -1637,6 +1637,8 @@ parser_e_raise_with_noreturn_not_allowed=03361_E_Raise in subroutines declared a
 % goto or any other mean. While the compiler cannot detect all such cases some are trivial and the compiler gives an error.
 parser_e_section_directive_not_allowed_for_target=03362_E_Directive section not allowed for this target
 % Only some targets (e.g. Embedded and FreeRTOS) support the section directive.
+parser_e_absolute_sym_cannot_reference_itself=03363_E_Absolute variable cannot reference itself
+% Declarations like \var{var i: Integer absolute i;} are not allowed
 %
 % \end{description}
 %

+ 3 - 2
compiler/msgidx.inc

@@ -476,6 +476,7 @@ const
   parser_e_constructurs_cannot_take_type_parameters=03360;
   parser_e_raise_with_noreturn_not_allowed=03361;
   parser_e_section_directive_not_allowed_for_target=03362;
+  parser_e_absolute_sym_cannot_reference_itself=03363;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -1149,9 +1150,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 89374;
+  MsgTxtSize = 89424;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,109,363,131,99,63,148,37,223,69,
+    28,109,364,131,99,63,148,37,223,69,
     65,20,30,1,1,1,1,1,1,1
   );

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


+ 9 - 4
compiler/pdecvar.pas

@@ -1307,10 +1307,15 @@ implementation
                   { we should check the result type of loadn }
                   if not (tloadnode(hp).symtableentry.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym,absolutevarsym]) then
                     Message(parser_e_absolute_only_to_var_or_const);
-                  abssym:=cabsolutevarsym.create(vs.realname,vs.vardef);
-                  abssym.fileinfo:=vs.fileinfo;
-                  abssym.abstyp:=tovar;
-                  abssym.ref:=node_to_propaccesslist(pt);
+                  if vs=tloadnode(hp).symtableentry then
+                    Message(parser_e_absolute_sym_cannot_reference_itself)
+                  else
+                    begin
+                      abssym:=cabsolutevarsym.create(vs.realname,vs.vardef);
+                      abssym.fileinfo:=vs.fileinfo;
+                      abssym.abstyp:=tovar;
+                      abssym.ref:=node_to_propaccesslist(pt);
+                    end;
 
                   { if the sizes are different, can't be a regvar since you }
                   { can't be "absolute upper 8 bits of a register" (except  }

+ 11 - 0
tests/webtbf/tw39604.pp

@@ -0,0 +1,11 @@
+{ %fail }
+
+program Project1;
+
+var
+  Buf: integer absolute Buf;
+
+begin
+  writeln(Buf);    //uncomment and get: test.pas(12,14) Error: Internal error 200104143
+  Buf := 1;        //uncomment and get: test.pas(14,1) Error: Undefined symbol: U_$P$PROJECT1
+end.  //line 14

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