diff options
author | Arnaud Charlet <charlet@gcc.gnu.org> | 2014-08-04 15:19:06 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2014-08-04 15:19:06 +0200 |
commit | 9a9d35ffaa1445248ca6449bfedae640659def22 (patch) | |
tree | 36cad7bd8435dccb490025727dad4822aa8c3c27 | |
parent | c2a2dbcc6ba197d3e6921ac220a097ac617c1493 (diff) | |
download | gcc-9a9d35ffaa1445248ca6449bfedae640659def22.zip gcc-9a9d35ffaa1445248ca6449bfedae640659def22.tar.gz gcc-9a9d35ffaa1445248ca6449bfedae640659def22.tar.bz2 |
[multiple changes]
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
-rw-r--r-- | gcc/ada/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/ada/gnat_rm.texi | 59 | ||||
-rw-r--r-- | gcc/ada/sem_ch3.adb | 8 |
3 files changed, 78 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 2423d29..ca0d4e8 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,16 @@ 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. * gnat_rm.texi: Add documentation for aspect Obsolescent. * sem_ch13.adb (Analyze_Aspect_Specifications): Implement aspect diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index c782ea3..f1f0ccf 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -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 diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 695b27e..dd71672 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -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. |