Ver código fonte

* additional fix for r48449

git-svn-id: trunk@48461 -
florian 4 anos atrás
pai
commit
8496690ed0
1 arquivos alterados com 14 adições e 3 exclusões
  1. 14 3
      compiler/nmem.pas

+ 14 - 3
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