From 8496690ed0f812c72b008f609106c933871be484 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 30 Jan 2021 22:47:38 +0000 Subject: [PATCH] * additional fix for r48449 git-svn-id: trunk@48461 - --- compiler/nmem.pas | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/compiler/nmem.pas b/compiler/nmem.pas index 2f2851f249..00621ecfaf 100644 --- a/compiler/nmem.pas +++ b/compiler/nmem.pas @@ -938,6 +938,7 @@ implementation htype,elementdef,elementptrdef : tdef; newordtyp: tordtype; valid : boolean; + minvalue, maxvalue: Tconstexprint; begin result:=nil; typecheckpass(left); @@ -1054,10 +1055,19 @@ implementation begin { in case of an integer type, we need a new type which covers declaration range and index range, see tests/webtbs/tw38413.pp + + This matters only if we sign extend, if the type exceeds the sint range, we can fall back only + to the index type } - if is_integer(right.resultdef) then - newordtyp:=range_to_basetype(min(TConstExprInt(Tarraydef(left.resultdef).lowrange),torddef(right.resultdef).low), - max(TConstExprInt(Tarraydef(left.resultdef).highrange),torddef(right.resultdef).high)) + if is_integer(right.resultdef) and ((torddef(right.resultdef).low<0) or (TConstExprInt(Tarraydef(left.resultdef).lowrange)<0)) then + begin + minvalue:=min(TConstExprInt(Tarraydef(left.resultdef).lowrange),torddef(right.resultdef).low); + maxvalue:=max(TConstExprInt(Tarraydef(left.resultdef).highrange),torddef(right.resultdef).high); + if maxvalue>torddef(sinttype).high then + newordtyp:=Torddef(right.resultdef).ordtype + else + newordtyp:=range_to_basetype(minvalue,maxvalue); + end else newordtyp:=Torddef(right.resultdef).ordtype; end @@ -1068,6 +1078,7 @@ implementation int64(Tarraydef(left.resultdef).highrange), true )); + printnode(self); end else begin