]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2014 13:19:06 +0000 (15:19 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2014 13:19:06 +0000 (15:19 +0200)
2014-08-04  Robert Dewar  <dewar@adacore.com>

* gnat_rm.texi: Add section on use of address clause for memory
mapped I/O.

2014-08-04  Ed Schonberg  <schonberg@adacore.com>

* sem_ch3.adb (Analyze_Subtype_Declaration): A subtype, in
particular the subtype created for a generic actual, inherits
invariant information from the base type.

From-SVN: r213589

gcc/ada/ChangeLog
gcc/ada/gnat_rm.texi
gcc/ada/sem_ch3.adb

index 2423d29a62e9a8e658f699165b04ee5a51a0283d..ca0d4e8429f21bd11ae864015f04cde34dbc5c5c 100644 (file)
@@ -1,3 +1,14 @@
+2014-08-04  Robert Dewar  <dewar@adacore.com>
+
+       * gnat_rm.texi: Add section on use of address clause for memory
+       mapped I/O.
+
+2014-08-04  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch3.adb (Analyze_Subtype_Declaration): A subtype, in
+       particular the subtype created for a generic actual, inherits
+       invariant information from the base type.
+
 2014-08-04  Robert Dewar  <dewar@adacore.com>
 
        * aspects.ads, aspects.adb: Add entries for aspect Obsolescent.
index c782ea3b65cc278f49fffe3796c14960742b487e..f1f0ccf13e80a7e6d0d1870a80e654997d57ba1b 100644 (file)
@@ -14813,6 +14813,7 @@ source file location.
 * Handling of Records with Holes::
 * Enumeration Clauses::
 * Address Clauses::
+* Use of Address Clauses for Memory-Mapped I/O::
 * Effect of Convention on Representation::
 * Conventions and Anonymous Access Types::
 * Determining the Representations chosen by GNAT::
@@ -16606,6 +16607,64 @@ end Overwrite_Array;
 then the program compiles without the warning and when run will generate
 the output @code{X was not clobbered}.
 
+@node Use of Address Clauses for Memory-Mapped I/O
+@section Use of Address Clauses for Memory-Mapped I/O
+@cindex Memory-mapped I/O
+
+A common pattern is to use an address clause to map an atomic variable to
+a location in memory that corresponds to a memory-mapped I/O operation or
+operations, for example:
+
+@smallexample @c ada
+    type Mem_Word is record
+       A,B,C,D : Byte;
+    end record;
+    pragma Atomic (Mem_Word);
+    for Mem_Word_Size use 32;
+
+    Mem : Mem_Word;
+    for Mem'Address use some-address;
+    ...
+    Temp := Mem;
+    Temp.A := 32;
+    Mem := Temp;
+@end smallexample
+
+@noindent
+For a full access (reference or modification) of the variable (Mem) in
+this case, as in the above examples, GNAT guarantees that the entire atomic
+word will be accessed. It is not clear whether the RM requires this. For
+example in the above, can the compiler reference only the Mem.A field as
+an optimization? Whatever the answer to this question is, GNAT makes the
+guarantee that for such a reference, the entire word is read or written.
+
+A problem arises with a component access such as:
+
+@smallexample @c ada
+    Mem.A := 32;
+@end smallexample
+
+@noindent
+Note that the component A is not declared as atomic. This means that it is
+not clear what this assignment means. It could correspond to full word read
+and write as given in the first example, or on architectures that supported
+such an operation it might be a single byte store instruction. The RM does
+not have anything to say in this situation, and GNAT does not make any
+guarantee. The code generated may vary from target to target. GNAT will issue
+a warning in such a case:
+
+@smallexample @c ada
+    Mem.A := 32;
+    |
+    >>> warning: access to non-atomic component of atomic array,
+        may cause unexpected accesses to atomic object
+@end smallexample
+
+@noindent
+It is best to be explicit in this situation, by either declaring the
+components to be atomic if you want the byte store, or explicitly writing
+the full word access sequence if that is what the hardware requires.
+
 @node Effect of Convention on Representation
 @section Effect of Convention on Representation
 @cindex Convention, effect on representation
index 695b27ef169fb32c7f104f0ccaba233fb0b7ccb6..dd71672d39b0988d16dafe5b8c2b9ef7ab75ad83 100644 (file)
@@ -4944,6 +4944,14 @@ package body Sem_Ch3 is
          end if;
       end if;
 
+      --  A type invariant applies to any subtype in its scope, in particular
+      --  to a generic actual.
+
+      if Has_Invariants (T) and then In_Open_Scopes (Scope (T)) then
+         Set_Has_Invariants (Id);
+         Set_Invariant_Procedure (Id, Invariant_Procedure (T));
+      end if;
+
       --  Make sure that generic actual types are properly frozen. The subtype
       --  is marked as a generic actual type when the enclosing instance is
       --  analyzed, so here we identify the subtype from the tree structure.