Improve test for unaligned access

(cherry picked from commit 11a390117c)
This commit is contained in:
Pierre Muller 2023-04-21 20:46:11 +00:00
parent 91aad00398
commit 36c7b7b655

View File

@ -9,6 +9,12 @@ type
rec : array[1..REC_SIZE] of int64;
end;
tunaligned = packed record
x, y : byte;
a, b : int64;
c,d : qword;
end;
const
x_val = 45634;
b_val = 56;
@ -21,11 +27,17 @@ const
rec : (rec1_val,rec2_val,rec3_val)
);
const
has_errors : boolean = false;
var
i : longint;
const
has_errors : boolean = false;
tu : tunaligned;
ia,ib : int64;
uc,ud : qword;
{$R-}
{$Q-}
begin
writeln('t.x=',t.x);
@ -62,6 +74,45 @@ begin
has_errors:=true;
end;
with tu do
begin
a:=$0123456789ABCDEF;
ia:=a;
b:=swapendian(a);
ib:=swapendian(ia);
writeln('a=',hexstr(a,2*sizeof(a)));
writeln('b=',hexstr(b,2*sizeof(b)));
writeln('ib=',hexstr(ib,2*sizeof(ib)));
if (b<>ib) then
begin
writeln('b<>ib!!');
has_errors:=true;
end;
c:=$F123456789ABCDEF;
uc:=c;
d:=swapendian(c);
ud:=swapendian(uc);
writeln('c=',hexstr(c,2*sizeof(c)));
writeln('d=',hexstr(d,2*sizeof(d)));
writeln('ud=',hexstr(ud,2*sizeof(ud)));
if (d<>ud) then
begin
writeln('d<>ud!!');
has_errors:=true;
end;
end;
if (tu.a<>ia) then
begin
writeln('tu.a is different from ia');
has_errors:=true;
end;
if (tu.c<>uc) then
begin
writeln('tu.c is different from uc');
has_errors:=true;
end;
if has_errors then
begin
writeln('Wrong code is generated');