Bug 50558 - illegal program not rejected (record component with no supplied value)
Summary: illegal program not rejected (record component with no supplied value)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid, wrong-code
Depends on:
Blocks:
 
Reported: 2011-09-28 13:04 UTC by Eugeniy Meshcheryakov
Modified: 2015-12-06 14:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
File that triggers the bug (311 bytes, application/octet-stream)
2011-09-28 13:04 UTC, Eugeniy Meshcheryakov
Details
Invalid program correctly detected (301 bytes, text/plain)
2011-09-28 13:08 UTC, Eugeniy Meshcheryakov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eugeniy Meshcheryakov 2011-09-28 13:04:51 UTC
Created attachment 25374 [details]
File that triggers the bug

The following invalid program (component 'Reserved' does not have default value) compiles with no error (gcc 4.6.1 and 4.7.0 (snapshot) on Debian):

package Pkg is
   type Byte is mod 2**8;
   type Reserved_24 is mod 2**24;

   type Data_Record is
      record
         Data : Byte;
         Reserved : Reserved_24;
      end record;

   for Data_Record use
      record
         Data at 0 range 0 .. 7;
         Reserved at 0 range 8 .. 31;
      end record;

   for Data_Record'Size use 32;
   for Data_Record'Alignment use 4;
end Pkg;

package Pkg.Reg is
   Data_Register : Data_Record;
   pragma Atomic (Data_Register);
end Pkg.Reg;

with Pkg.Reg;
procedure Test is
begin
   Pkg.Reg.Data_Register := (
      Data => 255,
      others => <> -- expected error: no value supplied for component "Reserved"
   );
end Test;

gnat gives expected error message if definition of Data_Register moved to Pkg. Representation clause for Data_Record and pragma Atomic is not required to trigger this bug, but with them strange assembler code generated at leas on x86_64 and cortex-m3:

_ada_test:
        movl    $0, pkg__reg__data_register(%rip)
        movb    $-1, pkg__reg__data_register(%rip)
        ret

_ada_test:
        ldr     r3, .L2
        movs    r2, #0
        str     r2, [r3, #0]
        movs    r2, #255
        strb    r2, [r3, #0]
        bx      lr

Note that atomic variable is accessed twice. I'm not yet sure if this bug can be reproduced by a valid program.
Comment 1 Eugeniy Meshcheryakov 2011-09-28 13:08:48 UTC
Created attachment 25375 [details]
Invalid program correctly detected

This is test program with definition of Data_Register moved to parent package. gnat correctly detects invalid program:

% gnatmake test.adb
gcc-4.6 -c test.adb
test.adb:5:25: no value supplied for component "Reserved"
gnatmake: "test.adb" compilation error
Comment 2 Eugeniy Meshcheryakov 2011-09-28 13:51:43 UTC
Output with -gnatG looks different for two programs.

For good.ada:

with pkg;

procedure test is
begin
   T1b : pkg__data_record := (
      data => 255);
   pkg.pkg__data_register := T1b;
end test;

test.adb:5:25: no value supplied for component "Reserved"

For test.ada:

with pkg;
with pkg.pkg__reg;

procedure test is
begin
   pkg.pkg__reg.pkg__reg__data_register := (
      data => 255);
   return;
end test;

But manually adding a temporary variable does not help.
Comment 3 Eugeniy Meshcheryakov 2011-09-28 15:58:00 UTC
After reading Ada 2005 rationale I think that the program in attachment 25374 [details] is valid (components with no default values should be left undefined) and the other one is invalid (but I cannot find confirmation in RM, in any case one of the programs is invalid). Then gnat produces incorrect code for atomic variable in valid code.
Comment 4 Eric Botcazou 2015-12-06 14:29:21 UTC
The mainline compiler issues the expected error:
test.adb:5:29: no value supplied for component "Reserved"