The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,421 other followers

Archive for April 12th, 2018

David Heffernan was on a bug reporting spree. Compiler unit tests could have detected these much faster.

Posted by jpluimers on 2018/04/12

For my archive, most bugs around UInt64 handling, lots of them in the Windows x64 compiler, all by David Heffernan:

  1. [WayBack] Who can guess what value is returned by StrToFloat(‘߀’) if the PUREPASCAL version of StrToFloat is used ……. Make sure that you copy and paste the… – David Heffernan – Google+
  2. [WayBack] Another day, another bug. This one a rather nasty one in the x64 compiler. Consider this program: {$APPTYPE CONSOLE} uses System.SysUtils; var … – David Heffernan – Google+
  3. And my run of bugs continues: https://quality.embarcadero.com/browse/RSP-20351 This program: {$APPTYPE CONSOLE} var D: Double; U64: UInt64; begin … – David Heffernan – Google+
  4. [WayBack] Final bug of my day: https://quality.embarcadero.com/browse/RSP-20353 {$APPTYPE CONSOLE} var I: Integer; U64: UInt64; D: Double; begin I := 1;… – David Heffernan – Google+

I also learned that quite a while ago, [Archive.is] System.TFloatSpecial – XE2 API Documentation got introduced.

1: Who can guess what value is returned by

StrToFloat('߀')

if the PUREPASCAL version of StrToFloat is used …….

Make sure that you copy and paste the code above rather than re-typing it.

To spoil the surprise read this: https://stackoverflow.com/a/49736812/

2: Another day, another bug. This one a rather nasty one in the x64 compiler.

Consider this program:

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

var
  D: Double;
begin
  Writeln(fsZero=D.SpecialType);
  Writeln(fsNZero=D.SpecialType);
  D := -D;
  Writeln(fsZero=D.SpecialType);
  Writeln(fsNZero=D.SpecialType);
Readln;
end.

It should output

TRUE
FALSE
FALSE
TRUE

It does so on x86. On x64 it outputs

TRUE
FALSE
TRUE
FALSE

The reason being that Emba implemented floating point negation on x64 by compiling

-d

as

0 - d

Which is a different thing.

The right thing to do is to load the value into an XMM register, and then xor it with 8000000000000000h.

https://quality.embarcadero.com/browse/RSP-20350

That’s three bugs in two days!

3: And my run of bugs continues: https://quality.embarcadero.com/browse/RSP-20351

This program:

{$APPTYPE CONSOLE}
var
  D: Double;
  U64: UInt64;
begin
  D := high(UInt64);
  Writeln(D);

  U64 := high(UInt64);
  D := U64;
  Writeln(D);

  Readln;
end.

should output

1.84467440737096E+0019
1.84467440737096E+0019

but in fact outputs

-1.00000000000000E+0000
1.84467440737096E+0019

I guess the compiler generates code as if the constant value was treated as a signed Int64.

Shout out to +Stefan Glienke for bringing this one to my attention.

I have one more bug that I have seen, but not yet submitted.

Quite amazing what can be found with a little bit of effort. Imagine if the Emba team put in some serious testing effort?

4. Final bug of my day: https://quality.embarcadero.com/browse/RSP-20353

{$APPTYPE CONSOLE}
var
I: Integer;
U64: UInt64;
D: Double;
begin
I := 1;
U64 := $8000000000000000;
D := I * U64;
Writeln(D);

U64 := $7fffffffffffffff;
D := I * U64;
Writeln(D);

Readln;
end.

Under dcc32 all is well, the output is

9.22337203685478E+0018
9.22337203685478E+0018

but under dcc64 it all goes south

-9.22337203685478E+0018
9.22337203685478E+0018

Looks like the compiler authors still haven’t found all the parts of the code that treat UInt64 as though it were Int64.

All these bugs (5 reports, but more bugs) from one simple SO question yesterday about StrToFloat……..

Posted in Delphi, Development, Software Development | 2 Comments »

Delphi attributes cannot use `const x: array of string` as argument

Posted by jpluimers on 2018/04/12

[WayBack] I want to annotate some of my enumerated types with human facing names. So I want to write: type[Names(‘Explicit time domain’, ‘Implicit time domain’,… – David Heffernan – Google+

This does not work:

constructor Create(const Values: array of string);

It seems to be in QC.

The reason is not obvious until you realise (thanks Stefan for wording that) that attribute constructor arguments are limited to anything that can be const. Open arrays nor dynamic arrays can be const (yes, nowadays you can have “consts” that are dynamic arrays but in fact they are compiler protected variables).

An alternative you might think works, but fails us using one attribute per enumeration element. But that’s where Delphi RTTI leaves you in the dark: it does not expose the RTTI for enumeration elements (likely doesn’t even generate it), only the the enumeration type itself.

So this fails:

type
  NameAttribute = class( TCustomAttribute )
  private
    FName: String;
  public
    constructor Create( AName : String );
    property Name: String read FName;
  end;

  TMyEnumeration = (
    [Name('One')]
    meOne,
    [Name('Two')]
    meTwo
  );

–jeroen

 

Posted in Delphi, Delphi 10 Seattle, Delphi 10.1 Berlin (BigBen), Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

Improve Android and iOS debug compilation speed – grijjy blog – Set the Debug information option to Limited Debug information

Posted by jpluimers on 2018/04/12

If you develop mobile apps with Delphi, you know it: compiling for Android and iOS is sloooooooooooooow, especially for debug builds. This little tip makes compiling Debug builds much faster……

Set the Debug information option to Limited Debug information

When I read a thing like that, I always think “how come I never thought about that before?” Well done Erik!

[WayBackImprove Android and iOS debug compilation speed – grijjy blog

via: [WayBack] Here’s a quick tip to improve the compilation speed of debug builds for iOS and Android… – Erik van Bilsen – Google+

–jeroen

Posted in Android, Delphi, Development, iOS Development, Mobile Development, Software Development | Leave a Comment »

 
%d bloggers like this: