* fixed packed bitsize calculation for types with a negative lower bound and

and upper bound just below the next power of two (mantis #34971)

git-svn-id: trunk@41161 -
This commit is contained in:
Jonas Maebe 2019-02-01 17:31:53 +00:00
parent 71559c83a6
commit 0db9ff5c39
3 changed files with 30 additions and 4 deletions

1
.gitattributes vendored
View File

@ -16485,6 +16485,7 @@ tests/webtbs/tw3490.pp svneol=native#text/plain
tests/webtbs/tw3491.pp svneol=native#text/plain
tests/webtbs/tw3492.pp svneol=native#text/plain
tests/webtbs/tw3494.pp svneol=native#text/plain
tests/webtbs/tw34971.pp svneol=native#text/plain
tests/webtbs/tw3499.pp svneol=native#text/plain
tests/webtbs/tw3504.pp svneol=native#text/plain
tests/webtbs/tw3506.pp svneol=native#text/plain

View File

@ -2716,8 +2716,8 @@ implementation
if (minval>=0) then
sizeval:=maxval
else
{ don't count 0 twice }
sizeval:=(cutils.max(-minval,maxval)*2)-1;
{ don't count 0 twice, but take into account that range goes from -n-1..n }
sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
{ 256 must become 512 etc. }
nextpowerof2(sizeval+1,power);
result := power;
@ -2939,8 +2939,8 @@ implementation
if (low>=0) then
sizeval:=high
else
{ don't count 0 twice }
sizeval:=(cutils.max(-low,high)*2)-1;
{ don't count 0 twice, but take into account that range goes from -n-1..n }
sizeval:=(cutils.max(-low,high+1)*2)-1;
{ 256 must become 512 etc. }
nextpowerof2(sizeval+1,power);
result := power;

25
tests/webtbs/tw34971.pp Normal file
View File

@ -0,0 +1,25 @@
type
t1 = -1..1;
t2 = -4..3;
t3 = -3..4;
type
r1 = bitpacked record
f: t1;
end;
r2 = bitpacked record
f: t2;
end;
r3 = bitpacked record
f: t3;
end;
begin
if bitsizeof(r1.f)<>2 then
halt(1);
if bitsizeof(r2.f)<>3 then
halt(2);
if bitsizeof(r3.f)<>4 then
halt(3);
end.