mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 02:45:58 +02:00
Improve test for unaligned access
This commit is contained in:
parent
dc04a8a677
commit
11a390117c
@ -9,6 +9,12 @@ type
|
|||||||
rec : array[1..REC_SIZE] of int64;
|
rec : array[1..REC_SIZE] of int64;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
tunaligned = packed record
|
||||||
|
x, y : byte;
|
||||||
|
a, b : int64;
|
||||||
|
c,d : qword;
|
||||||
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
x_val = 45634;
|
x_val = 45634;
|
||||||
b_val = 56;
|
b_val = 56;
|
||||||
@ -21,11 +27,17 @@ const
|
|||||||
rec : (rec1_val,rec2_val,rec3_val)
|
rec : (rec1_val,rec2_val,rec3_val)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const
|
||||||
|
has_errors : boolean = false;
|
||||||
|
|
||||||
var
|
var
|
||||||
i : longint;
|
i : longint;
|
||||||
const
|
tu : tunaligned;
|
||||||
has_errors : boolean = false;
|
ia,ib : int64;
|
||||||
|
uc,ud : qword;
|
||||||
|
|
||||||
|
{$R-}
|
||||||
|
{$Q-}
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writeln('t.x=',t.x);
|
writeln('t.x=',t.x);
|
||||||
@ -62,6 +74,45 @@ begin
|
|||||||
has_errors:=true;
|
has_errors:=true;
|
||||||
end;
|
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
|
if has_errors then
|
||||||
begin
|
begin
|
||||||
writeln('Wrong code is generated');
|
writeln('Wrong code is generated');
|
||||||
|
Loading…
Reference in New Issue
Block a user