diff --git a/.gitattributes b/.gitattributes index d137b63317..000e331429 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ncgmem.pas b/compiler/ncgmem.pas index 41b197ca0b..bbe6c8ffd9 100644 --- a/compiler/ncgmem.pas +++ b/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 diff --git a/tests/webtbs/tw16377.pp b/tests/webtbs/tw16377.pp new file mode 100644 index 0000000000..e6fe2ea91a --- /dev/null +++ b/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.