9
votes

We have a large Delphi XE codebase we want to port to 64 bit.

I own a Delphi XE2 licence and I cannot find any warning nor hint that can help me to detect valid 32 bit constructions that can now lead to data loss under a 64 bit platform. For instance, THandle to Cardinal assignments which were perfectly valid with the 32 bit compiler don’t raise any warning when compiling for Win64.

When migrating to Unicode with Delphi 2009, we had tons of warnings that helped us a lot to track and fix suspicious code. With XE2, I can’t find anything. I can’t imagine there is nothing integrated on the compiler level to avoid us to do a manual review of all our code.

Do I miss something ? How did you port you projects to 64 bit, if you tried ?

Thanks !

3
THandle is not mapped to integer any more, but to NativeUInt (that is, a cardinal only under Win32). It may help identify the issues.Arnaud Bouchez
I can't seem to get these kind of messages in XE (1) either, for instance assigning an int to a byte...GolezTrol
@GolezTrol : you're right, but from my POV assignments that might lead to different results when they're compiled for Win32 or Win64 should introduce a new class of compiler warnings.Adrien Reboisson

3 Answers

2
votes

You did not miss anything. There is nothing in the product to help you.

I too find this a little disappointing but I fully expect that the Emba designers thought about this. I can only conclude that their experience was that adding such warnings resulted in more noise than signal. The Delphi compiler has never warned when assigning to incompatible integer types. For example it has never been a warning or an error to assign an integer to a byte.

It's time to fire up grep and search for Integer\(.*\), Longint\(.*\), Cardinal\(.*\), Longword\(.*\), THandle etc.


To respond to Arnaud's comment and answer, I offer the following code which compiles free of warnings and errors when targetting 64 bit.

procedure NaughtyCode;
var
  Handle: THandle;
  int: Integer;
  card: Cardinal;
  P: Pointer;
begin
  Handle := high(Handle);
  int := Handle;
  card := Handle;
  P := Pointer(Handle);
  int := Integer(P);
  card := Cardinal(P);
end;
0
votes

About 5 years ago, I ported them to 64-bit Free Pascal. (even if only parts with a simple unit test to instrument them)

Testing with both compilers simply finds more issues.

0
votes

As you stated, most of the potential issues come from:

  • WinAPI changes (but most of the time identical/compatible);
  • THandle not mapped to integer any more, but to NativeUInt (that is, a cardinal only under Win32);
  • In pointer arithmetic, Integer typecast not mapped to NativeInt.

The latest will raise compiler errors, not only warning (it is an explicit type mismatch), and the THandle change should be warned as .

I won't be so hard with Embarcadero about the main compiler - I'm more concerned with the background compilers (e.g. CodeInsight) to be not synchronized with the main compiler. For me, the main compiler works fine, and I never complain about missing warnings. Just explicitly search for THandle is not so difficult.