Special boolean QWordBool/LongBool/WordBool/ByteBool -- broken in INLINE FUNCTIONS, in FPC264
Appears to be fixed in FPC 320.
So issue can be Closed right away, unless a fix can be backported to FPC264, or easy workaround provided.
The bug renders these special boolean types unusable with inline functions.
Noting it here for reference, since I did not find another bug with this exact effect.
Possibly related to: #25255 (closed) Upper dword of qwordbool is not handled properly
The workaround I have for now is, Inline functions should instead use Boolean64 Boolean32 Boolean16 Boolean.
{
Demonstrate bug with QWordBool, LongBool, WordBool, ByteBool types, in INLINE FUNCTIONS, in FPC264
Appears to be fixed in FPC 320.
The bug renders these special boolean types unusable with inline functions.
Noting it here for reference, since I did not find another issue with this exact effect.
Possibly related to: #25255 Upper dword of qwordbool is not handled properly
COMPILE
/usr/local/fpc-2.6.4/bin/fpc -Si bugInlineQWordBool.pas
Note Errors are induced just from presence of the 'inline;' flag, with or without -Si or $INLINE ON
}
{$mode objfpc}
{$h+}
program bugInlineQWordBool;
uses
CTypes,
SysUtils;
type
TArgBoolean = QWordBool; // doesnt matter, same effect w Boolean; ByteBool; WordBool; LongBool; QWordBool;
// Also tested this series on Boolean64 Boolean32 Boolean16 Boolean ==> those work ok.
// INLINE, all error. When x is false, the function wrongly returns true.
function testboolInlineByteBool(x : TArgBoolean) : Boolean; inline;
begin writeln(Int64(x)); if x = ByteBool(0) then Result := false else Result := true; end;
function testboolInlineWordBool(x : TArgBoolean) : Boolean; inline;
begin writeln(Int64(x)); if x = WordBool(0) then Result := false else Result := true; end;
function testboolInlineLongBool(x : TArgBoolean) : Boolean; inline;
begin writeln(Int64(x)); if x = LongBool(0) then Result := false else Result := true; end;
function testboolInlineQWordBool(x : TArgBoolean) : Boolean; inline;
begin writeln(Int64(x)); if x = QWordBool(0) then Result := false else Result := true; end;
// NOT INLINE, these work ok.
function testboolNotInlineByteBool(x : TArgBoolean) : Boolean;
begin writeln(Int64(x)); if x = ByteBool(0) then Result := false else Result := true; end;
function testboolNotInlineWordBool(x : TArgBoolean) : Boolean;
begin writeln(Int64(x)); if x = WordBool(0) then Result := false else Result := true; end;
function testboolNotInlineLongBool(x : TArgBoolean) : Boolean;
begin writeln(Int64(x)); if x = LongBool(0) then Result := false else Result := true; end;
function testboolNotInlineQWordBool(x : TArgBoolean) : Boolean;
begin writeln(Int64(x)); if x = QWordBool(0) then Result := false else Result := true; end;
begin
Writeln ('Compiler version: ',{$I %FPCVERSION%});
Writeln ('Target CPU: ',{$I %FPCTARGET%});
writeln('===============');
writeln('ERRORS with INLINE: QWordBool, LongBool, WordBool, ByteBool, all wrong');
writeln('ByteBool');
writeln(testboolInlineByteBool(true));
writeln(testboolInlineByteBool(false));
writeln('WordBool');
writeln(testboolInlineWordBool(true));
writeln(testboolInlineWordBool(false));
writeln('LongBool');
writeln(testboolInlineLongBool(true));
writeln(testboolInlineLongBool(false));
writeln('QWordBool');
writeln(testboolInlineQWordBool(true));
writeln(testboolInlineQWordBool(false));
writeln('===============');
writeln('NOT INLINE, here they work ok');
writeln('ByteBool');
writeln(testboolNotInlineByteBool(true));
writeln(testboolNotInlineByteBool(false));
writeln('WordBool');
writeln(testboolNotInlineWordBool(true));
writeln(testboolNotInlineWordBool(false));
writeln('LongBool');
writeln(testboolNotInlineLongBool(true));
writeln(testboolNotInlineLongBool(false));
writeln('QWordBool');
writeln(testboolNotInlineQWordBool(true));
writeln(testboolNotInlineQWordBool(false));
end.
OUTPUT
Compiler version: 2.6.4
Target CPU: x86_64
===============
ERRORS with INLINE: QWordBool, LongBool, WordBool, ByteBool, all wrong
ByteBool
-1
TRUE
0
TRUE
WordBool
-1
TRUE
0
TRUE
LongBool
-1
TRUE
0
TRUE
QWordBool
-1
TRUE
0
TRUE
===============
NOT INLINE, here they work ok
ByteBool
-1
TRUE
0
FALSE
WordBool
-1
TRUE
0
FALSE
LongBool
-1
TRUE
0
FALSE
QWordBool
-1
TRUE
0
FALSE