Commit 4c24ec6d by Eric Botcazou Committed by Eric Botcazou

decl.c (gnat_to_gnu_field): Do not enforce strict alignment for simple volatile…

decl.c (gnat_to_gnu_field): Do not enforce strict alignment for simple volatile fields and remove...

	* gcc-interface/decl.c (gnat_to_gnu_field): Do not enforce strict
	alignment for simple volatile fields and remove associated errors.
testsuite/
	* gnat.dg/specs/volatile1.ads: Remove obsolete errors.
	* gnat.dg/specs/clause_on_volatile.ads: Likewise.

From-SVN: r248320
parent 772cd694
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-15 Eric Botcazou <ebotcazou@adacore.com> 2017-05-15 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/gigi.h (get_elaboration_procedure): Delete. * gcc-interface/gigi.h (get_elaboration_procedure): Delete.
......
...@@ -6783,19 +6783,24 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -6783,19 +6783,24 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
{ {
const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field)); const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field));
const Entity_Id gnat_field_type = Etype (gnat_field); const Entity_Id gnat_field_type = Etype (gnat_field);
const bool is_aliased
= Is_Aliased (gnat_field);
const bool is_atomic const bool is_atomic
= (Is_Atomic_Or_VFA (gnat_field) || Is_Atomic_Or_VFA (gnat_field_type)); = (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 const bool is_independent
= (Is_Independent (gnat_field) || Is_Independent (gnat_field_type)); = (Is_Independent (gnat_field) || Is_Independent (gnat_field_type));
const bool is_volatile const bool is_volatile
= (Treat_As_Volatile (gnat_field) || Treat_As_Volatile (gnat_field_type)); = (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 const bool needs_strict_alignment
= (is_aliased = (is_atomic || is_aliased || is_independent || is_strict_alignment);
|| is_independent
|| is_volatile
|| Strict_Alignment (gnat_field_type));
tree gnu_field_type = gnat_to_gnu_type (gnat_field_type); tree gnu_field_type = gnat_to_gnu_type (gnat_field_type);
tree gnu_field_id = get_entity_name (gnat_field); tree gnu_field_id = get_entity_name (gnat_field);
tree gnu_field, gnu_size, gnu_pos; tree gnu_field, gnu_size, gnu_pos;
...@@ -6917,9 +6922,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -6917,9 +6922,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
s = "position of aliased field& must be multiple of ^ bits"; s = "position of aliased field& must be multiple of ^ bits";
else if (is_independent) else if (is_independent)
s = "position of independent field& must be multiple of ^ bits"; s = "position of independent field& must be multiple of ^ bits";
else if (is_volatile) else if (is_strict_alignment)
s = "position of volatile field& must be multiple of ^ bits";
else if (Strict_Alignment (gnat_field_type))
s = "position of & with aliased or tagged part must be" s = "position of & with aliased or tagged part must be"
" multiple of ^ bits"; " multiple of ^ bits";
else else
...@@ -6947,9 +6950,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -6947,9 +6950,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
s = "size of aliased field& must be ^ bits"; s = "size of aliased field& must be ^ bits";
else if (is_independent) else if (is_independent)
s = "size of independent field& must be at least ^ bits"; s = "size of independent field& must be at least ^ bits";
else if (is_volatile) else if (is_strict_alignment)
s = "size of volatile field& must be at least ^ bits";
else if (Strict_Alignment (gnat_field_type))
s = "size of & with aliased or tagged part must be" s = "size of & with aliased or tagged part must be"
" at least ^ bits"; " at least ^ bits";
else else
...@@ -6969,10 +6970,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -6969,10 +6970,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
if (is_independent) if (is_independent)
s = "size of independent field& must be multiple of" s = "size of independent field& must be multiple of"
" Storage_Unit"; " Storage_Unit";
else if (is_volatile) else if (is_strict_alignment)
s = "size of volatile field& must be multiple of"
" Storage_Unit";
else if (Strict_Alignment (gnat_field_type))
s = "size of & with aliased or tagged part must be" s = "size of & with aliased or tagged part must be"
" multiple of Storage_Unit"; " multiple of Storage_Unit";
else else
...@@ -7079,9 +7077,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -7079,9 +7077,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
/* Now create the decl for the field. */ /* Now create the decl for the field. */
gnu_field gnu_field
= create_field_decl (gnu_field_id, gnu_field_type, gnu_record_type, = 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)); 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; TREE_SIDE_EFFECTS (gnu_field) = TREE_THIS_VOLATILE (gnu_field) = is_volatile;
if (Ekind (gnat_field) == E_Discriminant) if (Ekind (gnat_field) == E_Discriminant)
......
2017-05-22 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/volatile1.ads: Remove obsolete errors.
* gnat.dg/specs/clause_on_volatile.ads: Likewise.
2017-05-21 Paolo Carlini <paolo.carlini@oracle.com> 2017-05-21 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/70265 PR c++/70265
......
...@@ -57,7 +57,7 @@ package Clause_On_Volatile is ...@@ -57,7 +57,7 @@ package Clause_On_Volatile is
end record; end record;
For V1'Alignment use 4; For V1'Alignment use 4;
for V1 use record for V1 use record
VW at 0 range 0 .. 15; -- { dg-error "must be at least" } VW at 0 range 0 .. 15;
end record; end record;
type V2 is record type V2 is record
...@@ -67,7 +67,7 @@ package Clause_On_Volatile is ...@@ -67,7 +67,7 @@ package Clause_On_Volatile is
For V2'Alignment use 4; For V2'Alignment use 4;
for V2 use record for V2 use record
B at 0 range 0 .. 7; 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; end record;
type V3 is record type V3 is record
...@@ -77,7 +77,7 @@ package Clause_On_Volatile is ...@@ -77,7 +77,7 @@ package Clause_On_Volatile is
For V3'Alignment use 4; For V3'Alignment use 4;
for V3 use record for V3 use record
B at 0 range 0 .. 7; 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 record;
end Clause_On_Volatile; end Clause_On_Volatile;
...@@ -19,7 +19,7 @@ package Volatile1 is ...@@ -19,7 +19,7 @@ package Volatile1 is
pragma Volatile (C); pragma Volatile (C);
end record; end record;
for R2 use 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 record;
end Volatile1; end Volatile1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment