2
0
Эх сурвалжийг харах

* don't generate range checking code for pointers-indexed-as-arrays when
using non-constant indices (mantis #16377)

git-svn-id: trunk@15221 -

Jonas Maebe 15 жил өмнө
parent
commit
3f280c34cb

+ 1 - 0
.gitattributes

@@ -10353,6 +10353,7 @@ tests/webtbs/tw16326.pp svneol=native#text/plain
 tests/webtbs/tw16328.pp svneol=native#text/plain
 tests/webtbs/tw1634.pp svneol=native#text/plain
 tests/webtbs/tw16366.pp svneol=native#text/plain
+tests/webtbs/tw16377.pp svneol=native#text/plain
 tests/webtbs/tw1658.pp svneol=native#text/plain
 tests/webtbs/tw1677.pp svneol=native#text/plain
 tests/webtbs/tw1681.pp svneol=native#text/plain

+ 4 - 8
compiler/ncgmem.pas

@@ -1017,19 +1017,15 @@ implementation
               else if (right.location.loc = LOC_JUMP) then
                 internalerror(2006010801);
 
-              { only range check now, we can't range check loc_flags/loc_jump }
-              if cs_check_range in current_settings.localswitches then
-               begin
-                 if left.resultdef.typ=arraydef then
-                   rangecheck_array;
-               end;
-
             { produce possible range check code: }
               if cs_check_range in current_settings.localswitches then
                begin
                  if left.resultdef.typ=arraydef then
                    begin
-                     { done defore (PM) }
+		     { do not do any range checking when this is an array access to a pointer which has been
+		       typecasted from an array }
+		     if (not (ado_isconvertedpointer in tarraydef(left.resultdef).arrayoptions)) then
+                       rangecheck_array
                    end
                  else if (left.resultdef.typ=stringdef) then
                    begin

+ 14 - 0
tests/webtbs/tw16377.pp

@@ -0,0 +1,14 @@
+program project1;
+const
+  S: string = '123';
+var
+  I: Integer;
+  P: PChar;
+begin
+  {$RANGECHECKS ON}
+  P := PChar(@S[2]);
+  I := -1;
+  if (P[-1]<>'1') or
+     (P[I]<>'1') then
+   halt(1);
+end.