GNAT 14.3 is unable to query record's `'Object_Size` at compile time

I found following bug in GNAT 14.3 when trying to query a record’s 'Object_Size at compile time. Using this example:

procedure Test is
   type Rec is record
      A : Integer;
   end record;

   pragma Compile_Time_Error (Rec'Object_Size /= 32, "WRONG SIZE");
begin
   null;
end Test;

GNAT 14.3 (current default in Debian stable/testing) fails with this error:

test.adb:6:47: error: condition is not known at compile time

Problem is not present in neither GNAT 15.3/16.1.

Is this a known issue? If not, should I report it? Is GNAT 14.x still supported?

EDIT: it seems the issue is not limited to records, it also fails with (at least) the following types:

type T is null record;
type T is new String (1..10);
type T is array (1..1) of Integer;

So, it seems it’s a problem with “compound” types (??)

Thanks for the details. Just out of curiosity, is there a particular reason you’re using GNAT 14.3?

No need to report it to Debian — they’re packaging an older compiler version, and unfortunately this would likely be given very low priority. The Ada community has already fixed the issue in newer GNAT releases (15.3 and 16.1).

The only exception would be if you have an AdaCore support contract and really need to stay on version 14 for some reason. Then you can report to AdaCore.

Let me know if you need help updating or anything else!

Martin

First of all, I’m currently learning Ada and doing lots of exploration to better understand Ada semantics and GNAT implementation details (features supported, how they’re actually implemented, optimizations applied at the assembly level, etc). So I tend to compare different versions of GNAT. For instance, recently I found an optimization regression in GCC 14+ (which turned out to be a known regression) when looking at the assembly code produced by GNAT (14+) of something like this:

type R is record
   A, B, C, D : Integer
end record;

function Init (X : Integer) return R is
   (R'(X+1, X+2, X+3, X+4));

Some people might say none of this is necessary to use Ada effectively, and it’s probably true to a certain degree, but I’m a systems programmer (coming from C) and that’s what I intent to use Ada for, so I can’t help it, my minds needs to understand all this :slight_smile:.

Second, there is a problem with Alire. alr toolchain --select only looks for binary gnat in PATH to detect the “external” toolchain. Although Debian ships different versions of GNAT (including 15/16), GNAT 14 is the default, and installed binary gnat points to GNAT 14. GNAT 15/16 packages install binaries gnat-15/gnat-16, but I couldn’t find a way to tell Alire to look for gnat-* binaries. So, by default, Alire will only be able to detect system/“external” GNAT 14. If I want to use system GNAT 15/16 with Alire I need to apply some dirty workaround: manually create a gnat symlink or something pointing to GNAT 15/16, put it somewhere in PATH, then run alr tooschain --select. I rather don’t use Alire at all (it’s great it exists but I rather use packages provided by the system package manager when possible), but I still need it to use other Ada-related packages not shipped by Debian (gnatprove, gnatdoc, gnatformat, etc). I wish Alire was able to detect multiple system/external toolchains.

An alternative is to drop the system packages entirely and just download everything with Alire. I’m not too happy with this because it downloads redundant binaries (e.g. GCC, which I already have installed in my system) and, honestly, I trust more the packages shipped by Debian, in that they will be better supported/integrated into the whole system. But also, the toolchains downloaded by Alire can only be used through alr, within an Alire project. Again, I have to apply dirty workarounds to my environment if I want to use standalone gprbuild/gnatmake/gnat/gnatprove/etc from Alire.

So, for general Ada exploration, it’s easier for me to just install system GNAT (14) and use Alire with it.

Debian testing ships packages gnat-11/12/13/14/15/16 (same as gcc-11/12/13/14/15/16), but the default gnat package depends on gnat-14. So GNAT 14 is the default, official GNAT package in Debian stable (production release) and testing (next-to-be-production release). Any Ada package meant to be shipped by Debian has to be compiled by the default GNAT (i.e GNAT 14). GNAT 14 is even the default GNAT version in Debian unstable (the experimental branch), although it’s using GNAT 14.4 there (vs 14.3 in testing). This means GNAT 14 is still supported, at least by Debian, and probably will continue to be supported for a long time (as I understand, Debian follows upstream GCC/GNAT releases/support). So I would say this is relevant, and needs to be fixed.

Although you’re probably right in that the default GNAT version should be bumped to (at least) GNAT 15. GCC 15 is already the default GCC there after all.

So, how does GNAT dev/support work between GCC team and AdaCore? If I were to file a bug against upstream GCC/GNAT (https://gcc.gnu.org/bugs/#gnat), would it be picked by AdaCore or how does it work?

Thanks! As explained above, I don’t have a problem with upgrading GNAT. But would appreciate any info on how to tell Alire, if possible at all, to:

  • Look for “external” binaries other than gnat.
  • Support multiple external toolchains.
  • When downloading a toolchain, use system GCC (and other dependencies) rather than downloading them too.

Have you tried update-alternatives?

Yes, I tried that, unfortunately there’s no gnat alternative. The Debian Ada Policy stipulates that package gnat (which depends on gnat-14) is the default Ada compiler, and that all Ada packages/libraries shipped by Debian must be compiled with the same compiler to maintain ABI compatibility. This is also documented in /usr/share/doc/gnat-14/ada/README.gnat:

If you want to develop Ada programs and libraries on Debian, please
read the Debian Policy for Ada:

http://people.debian.org/~lbrenta/debian-ada-policy.html

The default Ada compiler is and always will be the package `gnat'.
Debian contains many programs and libraries compiled with it, which
are all ABI-compatible.

Thank you for the detailed explanation — I really appreciate it! Your reply was quite extensive and helps me understand the situation (and the motivations behind it) much better.

From what I know, roughly 90% of the GNAT work is done by AdaCore, and paying customers generally receive fixes first.

Yes, it should be picked up, though paying customers naturally have priority.

I wish I could help more with that, but I mostly work on macOS and Windows, where GNAT isn’t preinstalled. In those environments (and even on Linux), I always rely on Alire to download and manage the right toolchain for me — especially useful for embedded work since it pulls the correct cross-compiler.

To bad that update-alternatives doesn’t work. That would make it so much easier. I guess the only option then is to symlink all gcc binaries into empty an directory (stripping the version number) and set this directory as first entry of ${path}. (That’s similar to what MacPorts does to handle multiple compiler)

Ask you favourite AI to whip up a script for you. It’s simple enough and AI will add sanity checks which humans often forget.

Martin

I don’t have need for cross-compiler for now, but if that were the case, Debian also ships cross-compilers for several architectures :slightly_smiling_face:.

Yes, that’s what I’ve been doing so far.

Thanks for you input, I appreciate it.