From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Relax restrictions on volatile components
Date: Mon, 22 May 2017 08:46:00 -0000 [thread overview]
Message-ID: <115036059.M0ml5omx4d@polaris> (raw)
[-- Attachment #1: Type: text/plain, Size: 540 bytes --]
GNAT has historically enforced strong restrictions on volatile components, but
this is no basis for that in the RM.
Tested on x86_64-suse-linux, applied on the mainline.
2017-05-22 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_field): Do not enforce strict
alignment for simple volatile fields and remove associated errors.
2017-05-22 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/volatile1.ads: Remove obsolete errors.
* gnat.dg/specs/clause_on_volatile.ads: Likewise.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 5407 bytes --]
Index: ada/gcc-interface/decl.c
===================================================================
--- ada/gcc-interface/decl.c (revision 248140)
+++ ada/gcc-interface/decl.c (working copy)
@@ -6783,19 +6783,24 @@ gnat_to_gnu_field (Entity_Id gnat_field,
{
const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field));
const Entity_Id gnat_field_type = Etype (gnat_field);
- const bool is_aliased
- = Is_Aliased (gnat_field);
const bool is_atomic
= (Is_Atomic_Or_VFA (gnat_field) || Is_Atomic_Or_VFA (gnat_field_type));
+ const bool is_aliased = Is_Aliased (gnat_field);
const bool is_independent
= (Is_Independent (gnat_field) || Is_Independent (gnat_field_type));
const bool is_volatile
= (Treat_As_Volatile (gnat_field) || Treat_As_Volatile (gnat_field_type));
+ const bool is_strict_alignment = Strict_Alignment (gnat_field_type);
+ /* We used to consider that volatile fields also require strict alignment,
+ but that was an interpolation and would cause us to reject a pragma
+ volatile on a packed record type containing boolean components, while
+ there is no basis to do so in the RM. In such cases, the writes will
+ involve load-modify-store sequences, but that's OK for volatile. The
+ only constraint is the implementation advice whereby only the bits of
+ the components should be accessed if they both start and end on byte
+ boundaries, but that should be guaranteed by the GCC memory model. */
const bool needs_strict_alignment
- = (is_aliased
- || is_independent
- || is_volatile
- || Strict_Alignment (gnat_field_type));
+ = (is_atomic || is_aliased || is_independent || is_strict_alignment);
tree gnu_field_type = gnat_to_gnu_type (gnat_field_type);
tree gnu_field_id = get_entity_name (gnat_field);
tree gnu_field, gnu_size, gnu_pos;
@@ -6917,9 +6922,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
s = "position of aliased field& must be multiple of ^ bits";
else if (is_independent)
s = "position of independent field& must be multiple of ^ bits";
- else if (is_volatile)
- s = "position of volatile field& must be multiple of ^ bits";
- else if (Strict_Alignment (gnat_field_type))
+ else if (is_strict_alignment)
s = "position of & with aliased or tagged part must be"
" multiple of ^ bits";
else
@@ -6947,9 +6950,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
s = "size of aliased field& must be ^ bits";
else if (is_independent)
s = "size of independent field& must be at least ^ bits";
- else if (is_volatile)
- s = "size of volatile field& must be at least ^ bits";
- else if (Strict_Alignment (gnat_field_type))
+ else if (is_strict_alignment)
s = "size of & with aliased or tagged part must be"
" at least ^ bits";
else
@@ -6969,10 +6970,7 @@ gnat_to_gnu_field (Entity_Id gnat_field,
if (is_independent)
s = "size of independent field& must be multiple of"
" Storage_Unit";
- else if (is_volatile)
- s = "size of volatile field& must be multiple of"
- " Storage_Unit";
- else if (Strict_Alignment (gnat_field_type))
+ else if (is_strict_alignment)
s = "size of & with aliased or tagged part must be"
" multiple of Storage_Unit";
else
@@ -7079,9 +7077,9 @@ gnat_to_gnu_field (Entity_Id gnat_field,
/* Now create the decl for the field. */
gnu_field
= create_field_decl (gnu_field_id, gnu_field_type, gnu_record_type,
- gnu_size, gnu_pos, packed, Is_Aliased (gnat_field));
+ gnu_size, gnu_pos, packed, is_aliased);
Sloc_to_locus (Sloc (gnat_field), &DECL_SOURCE_LOCATION (gnu_field));
- DECL_ALIASED_P (gnu_field) = Is_Aliased (gnat_field);
+ DECL_ALIASED_P (gnu_field) = is_aliased;
TREE_SIDE_EFFECTS (gnu_field) = TREE_THIS_VOLATILE (gnu_field) = is_volatile;
if (Ekind (gnat_field) == E_Discriminant)
Index: testsuite/gnat.dg/specs/clause_on_volatile.ads
===================================================================
--- testsuite/gnat.dg/specs/clause_on_volatile.ads (revision 248140)
+++ testsuite/gnat.dg/specs/clause_on_volatile.ads (working copy)
@@ -57,7 +57,7 @@ package Clause_On_Volatile is
end record;
For V1'Alignment use 4;
for V1 use record
- VW at 0 range 0 .. 15; -- { dg-error "must be at least" }
+ VW at 0 range 0 .. 15;
end record;
type V2 is record
@@ -67,7 +67,7 @@ package Clause_On_Volatile is
For V2'Alignment use 4;
for V2 use record
B at 0 range 0 .. 7;
- VW at 1 range 0 .. 31; -- { dg-error "must be multiple" }
+ VW at 1 range 0 .. 31;
end record;
type V3 is record
@@ -77,7 +77,7 @@ package Clause_On_Volatile is
For V3'Alignment use 4;
for V3 use record
B at 0 range 0 .. 7;
- VW at 1 range 0 .. 15; -- { dg-error "must be (multiple|at least)" }
+ VW at 1 range 0 .. 15;
end record;
end Clause_On_Volatile;
Index: testsuite/gnat.dg/specs/volatile1.ads
===================================================================
--- testsuite/gnat.dg/specs/volatile1.ads (revision 248140)
+++ testsuite/gnat.dg/specs/volatile1.ads (working copy)
@@ -19,7 +19,7 @@ package Volatile1 is
pragma Volatile (C);
end record;
for R2 use record
- C at 0 range 0 .. 10; -- { dg-error "size of volatile field" }
+ C at 0 range 0 .. 10;
end record;
end Volatile1;
reply other threads:[~2017-05-22 8:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=115036059.M0ml5omx4d@polaris \
--to=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).