aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@gcc.gnu.org>2020-06-23 18:33:28 +0200
committerEric Botcazou <ebotcazou@gcc.gnu.org>2020-06-23 18:35:48 +0200
commitd63fbcf80081d6fc6b746667fcacc8eb6e34f306 (patch)
tree0bdd3e645ad6a2cbf1c7dce9aef254e117ff0ade
parentb523ee1f4b139532ecffb2bf707e65cfc5a837fe (diff)
downloadgcc-d63fbcf80081d6fc6b746667fcacc8eb6e34f306.zip
gcc-d63fbcf80081d6fc6b746667fcacc8eb6e34f306.tar.gz
gcc-d63fbcf80081d6fc6b746667fcacc8eb6e34f306.tar.bz2
Fix memory corruption with vector and variant record
The problem is that Has_Constrained_Partial_View must be tested on the base type of the designated type of an allocator. gcc/ada/ChangeLog: * gcc-interface/trans.c (gnat_to_gnu) <N_Allocator>: Minor tweaks. Call Has_Constrained_Partial_View on base type of designated type.
-rw-r--r--gcc/ada/gcc-interface/trans.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index c32bdb9..f74e0e7 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -7154,9 +7154,8 @@ gnat_to_gnu (Node_Id gnat_node)
case N_Allocator:
{
- tree gnu_init = NULL_TREE;
- tree gnu_type;
- bool ignore_init_type = false;
+ tree gnu_type, gnu_init;
+ bool ignore_init_type;
gnat_temp = Expression (gnat_node);
@@ -7165,15 +7164,22 @@ gnat_to_gnu (Node_Id gnat_node)
contains both the type and an initial value for the object. */
if (Nkind (gnat_temp) == N_Identifier
|| Nkind (gnat_temp) == N_Expanded_Name)
- gnu_type = gnat_to_gnu_type (Entity (gnat_temp));
+ {
+ ignore_init_type = false;
+ gnu_init = NULL_TREE;
+ gnu_type = gnat_to_gnu_type (Entity (gnat_temp));
+ }
+
else if (Nkind (gnat_temp) == N_Qualified_Expression)
{
const Entity_Id gnat_desig_type
= Designated_Type (Underlying_Type (Etype (gnat_node)));
- ignore_init_type = Has_Constrained_Partial_View (gnat_desig_type);
- gnu_init = gnat_to_gnu (Expression (gnat_temp));
+ /* The flag is effectively only set on the base types. */
+ ignore_init_type
+ = Has_Constrained_Partial_View (Base_Type (gnat_desig_type));
+ gnu_init = gnat_to_gnu (Expression (gnat_temp));
gnu_init = maybe_unconstrained_array (gnu_init);
gigi_checking_assert (!Do_Range_Check (Expression (gnat_temp)));