Commit b3b5c6a2 by Eric Botcazou Committed by Arnaud Charlet

sem_ch13.adb (Analyze_Attribute_Definition_Clause): For a variable, if this is…

sem_ch13.adb (Analyze_Attribute_Definition_Clause): For a variable, if this is not an overlay, set on Treat_As_Volatile on it.

2015-11-12  Eric Botcazou  <ebotcazou@adacore.com>

	* sem_ch13.adb (Analyze_Attribute_Definition_Clause): For a
	variable, if this is not an overlay, set on Treat_As_Volatile on it.
	* gcc-interface/decl.c (E_Variable): Do not force the type to volatile
	for address clauses. Tweak and adjust various RM references.

2015-11-12  Eric Botcazou  <ebotcazou@adacore.com>

	* checks.ads: Minor comment fix.

From-SVN: r230233
parent 637535d7
2015-11-12 Eric Botcazou <ebotcazou@adacore.com>
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): For a
variable, if this is not an overlay, set on Treat_As_Volatile on it.
* gcc-interface/decl.c (E_Variable): Do not force the type to volatile
for address clauses. Tweak and adjust various RM references.
2015-11-12 Eric Botcazou <ebotcazou@adacore.com>
* checks.ads: Minor comment fix.
2015-11-12 Arnaud Charlet <charlet@adacore.com> 2015-11-12 Arnaud Charlet <charlet@adacore.com>
* gnat_rm.texi, gnat_ugn.texi, * gnat_rm.texi, gnat_ugn.texi,
......
...@@ -573,7 +573,7 @@ package Checks is ...@@ -573,7 +573,7 @@ package Checks is
-- For scalar types, constructs a range check action that first tests that -- For scalar types, constructs a range check action that first tests that
-- the expression is contained in the Target_Typ range. The difference -- the expression is contained in the Target_Typ range. The difference
-- between this and Apply_Scalar_Range_Check is that the latter generates -- between this and Apply_Scalar_Range_Check is that the latter generates
-- the actual checking code in gigi against the Etype of the expression. -- the actual checking code against the Etype of the expression.
-- --
-- For constrained array types, construct series of range check actions -- For constrained array types, construct series of range check actions
-- to check that each Expr range is properly contained in the range of -- to check that each Expr range is properly contained in the range of
......
...@@ -1068,14 +1068,12 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1068,14 +1068,12 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
} }
/* Make a volatile version of this object's type if we are to make /* Make a volatile version of this object's type if we are to make
the object volatile. We also interpret 13.3(19) conservatively the object volatile. We also implement RM 13.3(19) for exported
and disallow any optimizations for such a non-constant object. */ and imported (non-constant) objects by making them volatile. */
if ((Treat_As_Volatile (gnat_entity) if ((Treat_As_Volatile (gnat_entity)
|| (!const_flag || (!const_flag
&& gnu_type != except_type_node && gnu_type != except_type_node
&& (Is_Exported (gnat_entity) && (Is_Exported (gnat_entity) || imported_p)))
|| imported_p
|| Present (Address_Clause (gnat_entity)))))
&& !TYPE_VOLATILE (gnu_type)) && !TYPE_VOLATILE (gnu_type))
{ {
const int quals const int quals
...@@ -1118,7 +1116,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1118,7 +1116,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
gnu_expr = convert (gnu_type, gnu_expr); gnu_expr = convert (gnu_type, gnu_expr);
/* If this is a pointer that doesn't have an initializing expression, /* If this is a pointer that doesn't have an initializing expression,
initialize it to NULL, unless the object is imported. */ initialize it to NULL, unless the object is declared imported as
per RM B.1(24). */
if (definition if (definition
&& (POINTER_TYPE_P (gnu_type) || TYPE_IS_FAT_POINTER_P (gnu_type)) && (POINTER_TYPE_P (gnu_type) || TYPE_IS_FAT_POINTER_P (gnu_type))
&& !gnu_expr && !gnu_expr
...@@ -1141,7 +1140,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1141,7 +1140,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
save_gnu_tree (gnat_entity, NULL_TREE, false); save_gnu_tree (gnat_entity, NULL_TREE, false);
/* Convert the type of the object to a reference type that can /* Convert the type of the object to a reference type that can
alias everything as per 13.3(19). */ alias everything as per RM 13.3(19). */
gnu_type gnu_type
= build_reference_type_for_mode (gnu_type, ptr_mode, true); = build_reference_type_for_mode (gnu_type, ptr_mode, true);
gnu_address = convert (gnu_type, gnu_address); gnu_address = convert (gnu_type, gnu_address);
...@@ -1206,11 +1205,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1206,11 +1205,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
as an indirect object. Likewise for Stdcall objects that are as an indirect object. Likewise for Stdcall objects that are
imported. */ imported. */
if ((!definition && Present (Address_Clause (gnat_entity))) if ((!definition && Present (Address_Clause (gnat_entity)))
|| (Is_Imported (gnat_entity) || (imported_p && Has_Stdcall_Convention (gnat_entity)))
&& Has_Stdcall_Convention (gnat_entity)))
{ {
/* Convert the type of the object to a reference type that can /* Convert the type of the object to a reference type that can
alias everything as per 13.3(19). */ alias everything as per RM 13.3(19). */
gnu_type gnu_type
= build_reference_type_for_mode (gnu_type, ptr_mode, true); = build_reference_type_for_mode (gnu_type, ptr_mode, true);
used_by_ref = true; used_by_ref = true;
...@@ -1402,10 +1400,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1402,10 +1400,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
/* If this name is external or a name was specified, use it, but don't /* If this name is external or a name was specified, use it, but don't
use the Interface_Name with an address clause (see cd30005). */ use the Interface_Name with an address clause (see cd30005). */
if ((Present (Interface_Name (gnat_entity)) if ((Is_Public (gnat_entity) && !Is_Imported (gnat_entity))
&& No (Address_Clause (gnat_entity))) || (Present (Interface_Name (gnat_entity))
|| (Is_Public (gnat_entity) && No (Address_Clause (gnat_entity))))
&& (!Is_Imported (gnat_entity) || Is_Exported (gnat_entity))))
gnu_ext_name = create_concat_name (gnat_entity, NULL); gnu_ext_name = create_concat_name (gnat_entity, NULL);
/* If this is an aggregate constant initialized to a constant, force it /* If this is an aggregate constant initialized to a constant, force it
...@@ -4618,7 +4615,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -4618,7 +4615,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
save_gnu_tree (gnat_entity, NULL_TREE, false); save_gnu_tree (gnat_entity, NULL_TREE, false);
/* Convert the type of the object to a reference type that can /* Convert the type of the object to a reference type that can
alias everything as per 13.3(19). */ alias everything as per RM 13.3(19). */
gnu_type gnu_type
= build_reference_type_for_mode (gnu_type, ptr_mode, true); = build_reference_type_for_mode (gnu_type, ptr_mode, true);
if (gnu_address) if (gnu_address)
......
...@@ -4724,10 +4724,24 @@ package body Sem_Ch13 is ...@@ -4724,10 +4724,24 @@ package body Sem_Ch13 is
Find_Overlaid_Entity (N, O_Ent, Off); Find_Overlaid_Entity (N, O_Ent, Off);
-- If the object overlays a constant view, mark it so if Present (O_Ent) then
-- If the object overlays a constant object, mark it so
if Present (O_Ent) and then Is_Constant_Object (O_Ent) then if Is_Constant_Object (O_Ent) then
Set_Overlays_Constant (U_Ent); Set_Overlays_Constant (U_Ent);
end if;
else
-- If this is not an overlay, mark a variable as being
-- volatile to prevent unwanted optimizations. It's a
-- conservative interpretation of RM 13.3(19) for the
-- cases where the compiler cannot detect potential
-- aliasing issues easily and it also covers the case
-- of an absolute address where the volatile aspect is
-- kind of implicit.
if Ekind (U_Ent) = E_Variable then
Set_Treat_As_Volatile (U_Ent);
end if;
end if; end if;
-- Overlaying controlled objects is erroneous. -- Overlaying controlled objects is erroneous.
......
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