Bug 99802 - [11 regression] assignment of aggregate done component-by-component
Summary: [11 regression] assignment of aggregate done component-by-component
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 11.0
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2021-03-28 16:16 UTC by simon
Modified: 2021-03-29 22:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-03-29 00:00:00


Attachments
Demonstrator, with output assembler (7.78 KB, application/zip)
2021-03-28 16:16 UTC, simon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description simon 2021-03-28 16:16:35 UTC
Created attachment 50481 [details]
Demonstrator, with output assembler

In arm-eabi-gcc version 11.0.1 20210303 (experimental) (GCC),
assigning an aggregate to a memory-mapped register is performed by
assigning the components of the aggregate one-by-one to the register
rather than as a whole word.
The same bug is present in the x86_64-apple-darwin compiler.

In compiler releases up to & including 10, this was done using a
whole-word assignment.

   with ATSAM3X8E; use ATSAM3X8E;
   with ATSAM3X8E.PMC; use ATSAM3X8E.PMC;
   procedure Clock is
   begin
      PMC_Periph.CKGR_MOR :=
        (KEY      => 16#37#,
         MOSCXTEN => 1,     -- main crystal oscillator enable
         MOSCRCEN => 1,     -- main on-chip rc osc. enable
         MOSCXTST => 8,     -- startup time
         others   => <>);
   end Clock;

The register is a component of a record:

   type PMC_Peripheral is record
      ...
      CKGR_MOR   : aliased CKGR_MOR_Register;
      pragma Volatile_Full_Access (CKGR_MOR);
      ...
   end record
     with Volatile;

with object as so:

   PMC_Periph : aliased PMC_Peripheral
     with Import, Address => PMC_Base;

and the write respects the Volatile_Full_Access *as it writes each
component separately to the register*! This fails, in this case,
because the PMC hardware requires each write to this register to be
accompanied by a valid value of the KEY field.

The attached aggregate_assignment.zip contains Ada source, and the
10.1.0 and 11.0.1 versions of the arm-eabi cortex-m3 assembler output
by -S.

I've tried compiling the source in aggregate_assignment.zip with the
x86_64-apple-darwin compiler, and the same bug seems to be present.

NOTE, this bug is also present in GNAT CE 2020.
Comment 1 Eric Botcazou 2021-03-29 17:32:19 UTC
Confirmed, this was working by chance before.
Comment 2 Eric Botcazou 2021-03-29 17:32:55 UTC
Fixing.
Comment 3 GCC Commits 2021-03-29 22:46:00 UTC
The master branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

https://gcc.gnu.org/g:471babd88668dbe4f9ff4dba6d2036ecef09653b

commit r11-7900-g471babd88668dbe4f9ff4dba6d2036ecef09653b
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Tue Mar 30 00:41:46 2021 +0200

    Fix wrong assignment of aggregate to full-access component
    
    This is a regression present on the mainline: the compiler (front-end) fails
    to assign an aggregate to a full-access component (i.e. Atomic or VFA) as a
    whole if the type of the component is not full access itself.
    
    gcc/ada/
            PR ada/99802
            * freeze.adb (Is_Full_Access_Aggregate): Call Is_Full_Access_Object
            on the name of an N_Assignment_Statement to spot full access.
Comment 4 Eric Botcazou 2021-03-29 22:47:15 UTC
Thanks for reporting the problem.