Package: gnat
Version: 4.9
Severity: normal
Tags: upstream

Dear Maintainer,

As said in the bug title gnat fail to reconize some compile time known size
type as it in some circumstances.

Please see below a minimal test case striped down form a real case :

procedure Foo is

   type Unbiased_T is range 0 .. 4
     with Size => 3;

   pragma Warnings
     (Off, "size clause forces biased representation for ""Biased_T""");

   type Biased_T is range 1 .. 4
     with Size => 2;

   pragma Warnings
     (On,  "size clause forces biased representation for ""Biased_T""");

   type Biased_Or_Unbiased_T (Biased : Boolean) is
      record
         case Biased is
            when True  => Biased_Value   : Biased_T;
            when False => Unbiased_Value : Unbiased_T;
         end case;
      end record
     with Unchecked_Union,
          Convention => Ada,
          Size       => 3;
   for Biased_Or_Unbiased_T use
      record
         Biased_Value   at 0 range 1 .. 2;
         Unbiased_Value at 0 range 0 .. 2;
      end record;

   type Hardware_Register_T
     (Value_1_Is_Biased : Boolean;
      Value_2_Is_Biased : Boolean) is
      record
         Value_1 : Biased_Or_Unbiased_T (Value_2_Is_Biased);
         Value_2 : Biased_Or_Unbiased_T (Value_2_Is_Biased);
      end record
     with Size  => 8,
          Volatile;
   for Hardware_Register_T use
      record
         Value_1           at 0 range 0 .. 2;
         Value_2           at 0 range 3 .. 5;
         Value_1_Is_Biased at 0 range 6 .. 6;
         Value_2_Is_Biased at 0 range 7 .. 7;
      end record;

begin

   null;

end Foo;


When invoking gnatmake as this :

gnatmake foo.adb

I get this output :

gcc-4.9 -c foo.adb
foo.adb:38:11: size clause not allowed for variable length type
foo.adb:42:28: component clause not allowed for variable length component
foo.adb:43:28: component clause not allowed for variable length component
gnatmake: "foo.adb" compilation error 


But none of the types here are variable length.

By some little investigation I have found that all of the 3 reported errors
cames from the same place in the compiler code.

The function Size_Known_At_Compile_Time return False and should return True
in the file freeze.adb at line 2832 and line 5228.

I expected at least any type with a static unrejected size attribute or clause
to be considered having a Size_Known_At_Compile_Time.

The function Size_Known_At_Compile_Time itself defined in einfo.adb line 2892
just return a flag which seem to only be manipulated by the procedure
Set_Size_Known_At_Compile_Time also define in einfo.adb at line 5655.

I suspect a call to the procedure Set_Size_Known_At_Compile_Time should be
added somwhere in freese.adb when there is a size clause or attribute for a
type but there I am at my limit in my understanding of the compiler code.


I suspect this bug to be present in all architecture and I can at least
confirme it on gnat-4.9 for x86 and powerpc, gnat-4.6 on x86 and
avr-ada gnat-4.7.

In the hope this bug report will help.

        Henri GEIST


-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 3.16.0-4-686-pae (SMP w/2 CPU cores)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages gnat depends on:
ii  gnat-4.9  4.9.2-1

Versions of packages gnat recommends:
ii  ada-reference-manual-2012  1:2012.2-3
ii  gnat-gps                   5.3dfsg-1

gnat suggests no packages.

-- no debconf information

Reply via email to