aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-07-09 07:55:38 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-09 07:55:38 +0000
commit5e0f7ab2fb33372f298ad9333dd2dd2e44cf01cc (patch)
treece93a484c8270a63ed5a2a499fd930e8c764db03 /gcc/ada
parent924e3532dcdabde43f5b49f1ef1a95656f4e37dc (diff)
downloadgcc-5e0f7ab2fb33372f298ad9333dd2dd2e44cf01cc.zip
gcc-5e0f7ab2fb33372f298ad9333dd2dd2e44cf01cc.tar.gz
gcc-5e0f7ab2fb33372f298ad9333dd2dd2e44cf01cc.tar.bz2
[Ada] Access to uninitialized memory by predicate check
This patch fixes an exception or erroneous execution, when the declaration for an object of a composite type that has a dynanic predicate is initialized with an aggregate that requires expansion into individual components. Prior to this patch the predicate check for the object appeared before intialization was performed, thus accessing uninitialized memory. 2019-07-09 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_ch3.adb (Analyze_Object_Declaration): If the object type is a composite type that has a dynamic predicate and, the expression in the declaration is an aggregate, the generated predicate check must appear after the expanded code for the aggregate, which will appear after the rewritten object declarastion. gcc/testsuite/ * gnat.dg/predicate10.adb, gnat.dg/predicate10_pkg.adb, gnat.dg/predicate10_pkg.ads: New testcase. From-SVN: r273293
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog9
-rw-r--r--gcc/ada/sem_ch3.adb28
2 files changed, 33 insertions, 4 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 524adfd..cb2acf3 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,12 @@
+2019-07-09 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch3.adb (Analyze_Object_Declaration): If the object type
+ is a composite type that has a dynamic predicate and, the
+ expression in the declaration is an aggregate, the generated
+ predicate check must appear after the expanded code for the
+ aggregate, which will appear after the rewritten object
+ declarastion.
+
2019-07-09 Justin Squirek <squirek@adacore.com>
* sem_eval.adb (Expr_Value_E): Add conditional to correctly
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 38fab90..9e32cea 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3649,8 +3649,10 @@ package body Sem_Ch3 is
-- Ghost mode.
procedure Analyze_Object_Declaration (N : Node_Id) is
- Loc : constant Source_Ptr := Sloc (N);
- Id : constant Entity_Id := Defining_Identifier (N);
+ Loc : constant Source_Ptr := Sloc (N);
+ Id : constant Entity_Id := Defining_Identifier (N);
+ Next_Decl : constant Node_Id := Next (N);
+
Act_T : Entity_Id;
T : Entity_Id;
@@ -3912,6 +3914,11 @@ package body Sem_Ch3 is
A_Id := Get_Aspect_Id (Chars (Identifier (A)));
while Present (A) loop
if A_Id = Aspect_Alignment or else A_Id = Aspect_Address then
+
+ -- Set flag on object entity, for later processing at
+ -- the freeze point.
+
+ Set_Has_Delayed_Aspects (Id);
return True;
end if;
@@ -4495,8 +4502,21 @@ package body Sem_Ch3 is
null;
else
- Insert_After (N,
- Make_Predicate_Check (T, New_Occurrence_Of (Id, Loc)));
+ -- The check must be inserted after the expanded aggregate
+ -- expansion code, if any.
+
+ declare
+ Check : constant Node_Id :=
+ Make_Predicate_Check (T, New_Occurrence_Of (Id, Loc));
+
+ begin
+ if No (Next_Decl) then
+ Append_To (List_Containing (N), Check);
+
+ else
+ Insert_Before (Next_Decl, Check);
+ end if;
+ end;
end if;
end if;