From 06267006f3b19ff4e37837839edbc58ec032a4e5 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Fri, 21 Sep 2018 13:24:49 +0000 Subject: [PATCH] * explicitely handle the boolean types to determine the bit size as all of them have the bit size 1 + added test git-svn-id: trunk@39786 - --- .gitattributes | 1 + compiler/symdef.pas | 8 +++++-- tests/tbs/tb0651.pp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/tbs/tb0651.pp diff --git a/.gitattributes b/.gitattributes index c50acd19f0..8b0e4d7dc9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11597,6 +11597,7 @@ tests/tbs/tb0646b.pp svneol=native#text/pascal tests/tbs/tb0648.pp svneol=native#text/pascal tests/tbs/tb0649.pp -text svneol=native#text/pascal tests/tbs/tb0650.pp svneol=native#text/pascal +tests/tbs/tb0651.pp svneol=native#text/pascal tests/tbs/tb205.pp svneol=native#text/plain tests/tbs/tb610.pp svneol=native#text/pascal tests/tbs/tb613.pp svneol=native#text/plain diff --git a/compiler/symdef.pas b/compiler/symdef.pas index c146f3336f..cdc8568ce1 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -2913,8 +2913,12 @@ implementation (high > (system.high(int64) div 2)))) then {$endif cpu64bitalu} result := 64 - else if (low >= 0) and - (high <= 1) then + else if ( + (low >= 0) and + (high <= 1) + ) or ( + ordtype in [pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit] + ) then result := 1 else begin diff --git a/tests/tbs/tb0651.pp b/tests/tbs/tb0651.pp new file mode 100644 index 0000000000..62cb493770 --- /dev/null +++ b/tests/tbs/tb0651.pp @@ -0,0 +1,55 @@ +program tb0651; + +{$mode objfpc}{$H+} + +type + TBooleanArray = array[0..7] of Boolean; + + TBooleanByte = bitpacked array[0..7] of Boolean; + TBoolean16Byte = bitpacked array[0..7] of Boolean16; + TBoolean32Byte = bitpacked array[0..7] of Boolean32; + TBoolean64Byte = bitpacked array[0..7] of Boolean64; + TByteBoolByte = bitpacked array[0..7] of ByteBool; + TWordBoolByte = bitpacked array[0..7] of WordBool; + TLongBoolByte = bitpacked array[0..7] of LongBool; + TQWordBoolByte = bitpacked array[0..7] of QWordBool; + +generic procedure CheckValue(aArr: T; const aExpected: TBooleanArray; aCode: LongInt); +var + i: LongInt; +begin + if SizeOf(T) <> 1 then + Halt(aCode * 10 + 1); + if BitSizeOf(T) <> 8 then + Halt(aCode * 10 + 2); + for i := 0 to High(aArr) do + if aArr[i] <> aExpected[i] then + Halt(aCode * 10 + 3 + i); +end; + +var + exp: TBooleanArray = (True, False, True, False, False, True, False, True); + b: Byte = $A5; + pb8: TBooleanByte absolute b; + pb16: TBoolean16Byte absolute b; + pb32: TBoolean32Byte absolute b; + pb64: TBoolean64Byte absolute b; + bb8: TByteBoolByte absolute b; + bb16: TWordBoolByte absolute b; + bb32: TLongBoolByte absolute b; + bb64: TQWordBoolByte absolute b; +begin + specialize CheckValue(pb8, exp, 0); + specialize CheckValue(pb16, exp, 1); + specialize CheckValue(pb32, exp, 2); +{$ifdef CPU64} + specialize CheckValue(pb64, exp, 3); +{$endif} + specialize CheckValue(bb8, exp, 4); + specialize CheckValue(bb16, exp, 5); + specialize CheckValue(bb32, exp, 6); +{$ifdef CPU64} + specialize CheckValue(bb64, exp, 7); +{$endif} + Writeln('ok'); +end.