From 5c890b59e3d68fa8aaa90f826e3cc2fd105d5c94 Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Tue, 20 Feb 2024 23:51:29 +0100 Subject: [PATCH] * fix #40655: apply changes to packrecords, packenum and setalloc using the recordpending*() functions so that they are applied correctly in case of them being used directly after a {$POP}{$PUSH} sequence + added test --- compiler/scandir.pas | 34 +++++++++++++++++----------------- compiler/switches.pas | 10 ++++++---- tests/webtbs/tw40655.pp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 tests/webtbs/tw40655.pp diff --git a/compiler/scandir.pas b/compiler/scandir.pas index 48443b5669..4bbc59191c 100644 --- a/compiler/scandir.pas +++ b/compiler/scandir.pas @@ -1146,16 +1146,16 @@ unit scandir; begin hs:=current_scanner.readid; if (hs='NORMAL') or (hs='DEFAULT') then - current_settings.packenum:=4 + recordpendingpackenum(4) else Message1(scan_e_illegal_pack_enum, hs); end else begin case current_scanner.readval of - 1 : current_settings.packenum:=1; - 2 : current_settings.packenum:=2; - 4 : current_settings.packenum:=4; + 1 : recordpendingpackenum(1); + 2 : recordpendingpackenum(2); + 4 : recordpendingpackenum(4); else Message1(scan_e_illegal_pack_enum, pattern); end; @@ -1184,22 +1184,22 @@ unit scandir; hs:=current_scanner.readid; { C has the special recordalignmax of C_alignment } if (hs='C') then - current_settings.packrecords:=C_alignment + recordpendingpackrecords(C_alignment) else if (hs='NORMAL') or (hs='DEFAULT') then - current_settings.packrecords:=default_settings.packrecords + recordpendingpackrecords(default_settings.packrecords) else Message1(scan_e_illegal_pack_records,hs); end else begin case current_scanner.readval of - 1 : current_settings.packrecords:=1; - 2 : current_settings.packrecords:=2; - 4 : current_settings.packrecords:=4; - 8 : current_settings.packrecords:=8; - 16 : current_settings.packrecords:=16; - 32 : current_settings.packrecords:=32; + 1 : recordpendingpackrecords(1); + 2 : recordpendingpackrecords(2); + 4 : recordpendingpackrecords(4); + 8 : recordpendingpackrecords(8); + 16 : recordpendingpackrecords(16); + 32 : recordpendingpackrecords(32); else Message1(scan_e_illegal_pack_records,pattern); end; @@ -1216,17 +1216,17 @@ unit scandir; begin hs:=current_scanner.readid; if (hs='FIXED') or (hs='DEFAULT') OR (hs='NORMAL') then - current_settings.setalloc:=0 {Fixed mode, sets are 4 or 32 bytes} + recordpendingsetalloc(0) {Fixed mode, sets are 4 or 32 bytes} else Message(scan_e_only_packset); end else begin case current_scanner.readval of - 1 : current_settings.setalloc:=1; - 2 : current_settings.setalloc:=2; - 4 : current_settings.setalloc:=4; - 8 : current_settings.setalloc:=8; + 1 : recordpendingsetalloc(1); + 2 : recordpendingsetalloc(2); + 4 : recordpendingsetalloc(4); + 8 : recordpendingsetalloc(8); else Message(scan_e_only_packset); end; diff --git a/compiler/switches.pas b/compiler/switches.pas index ecb838aed8..70f7a8cd8a 100644 --- a/compiler/switches.pas +++ b/compiler/switches.pas @@ -174,10 +174,12 @@ begin begin case typesw of alignsw: - if state='+' then - current_settings.packrecords:=4 - else - current_settings.packrecords:=1; + begin + if state='+' then + recordpendingpackrecords(4) + else + recordpendingpackrecords(1); + end; optimizersw : begin if state='+' then diff --git a/tests/webtbs/tw40655.pp b/tests/webtbs/tw40655.pp new file mode 100644 index 0000000000..2f24fe4fe9 --- /dev/null +++ b/tests/webtbs/tw40655.pp @@ -0,0 +1,37 @@ +{ %NORUN } + +program tw40655; + +type + + MIDITimeStamp = UInt64; + +{$push} +{$packrecords 4} + MIDIPacket = record + timeStamp: MIDITimeStamp; + length: UInt16; + data: packed array [0..255] of Byte; + end; + MIDIPacketPtr = ^MIDIPacket; +{$pop} + + +{$push} +{$packrecords 4} + MIDIPacketList = record + numPackets: UInt32; + packet: array [0..0] of MIDIPacket; + end; +{$pop} + +{$if SizeOf(MIDIPacket) <> 268} +{$message fatal 'Size of MIDIPacket is not 268'} +{$endif} + +{$if SizeOf(MIDIPacketList) <> 272} +{$message fatal 'Size of MIDIPacketList is not 272'} +{$endif} + +begin +end.