aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-05-20 18:08:07 +0200
committerMarc Poulhiès <poulhies@adacore.com>2024-06-20 10:50:55 +0200
commit3a16f19777f882f98b6d901a81157779e898f636 (patch)
tree05ed358f8fa76ba736ee00a560894e26f1b4c584 /gcc/ada
parent9cf95147c04c64344466f6e41ce5be32fbde96e0 (diff)
downloadgcc-3a16f19777f882f98b6d901a81157779e898f636.zip
gcc-3a16f19777f882f98b6d901a81157779e898f636.tar.gz
gcc-3a16f19777f882f98b6d901a81157779e898f636.tar.bz2
ada: Fix bogus error with "=" operator on array of private unchecked union
The code is legal and, therefore, must be accepted by the compiler, but it must raise Program_Error at run time due to operands not having inferable discriminants and a warning be given at compile time (RM B.3.3(22-23)). gcc/ada/ * exp_ch4.adb (Expand_Array_Equality.Component_Equality): Copy the Comes_From_Source flag from the original test to the new one, and remove obsolete code dealing with unchecked unions. * sem_util.adb (Has_Inferable_Discriminants): Return False for an incomplete or private nominal subtype.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/exp_ch4.adb27
-rw-r--r--gcc/ada/sem_util.adb7
2 files changed, 14 insertions, 20 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 7349dfc..983f662 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -1570,26 +1570,17 @@ package body Exp_Ch4 is
(Outer_Type => Typ, Nod => Nod, Comp_Type => Component_Type (Typ),
Lhs => L, Rhs => R);
- -- If some (sub)component is an unchecked_union, the whole operation
- -- will raise program error.
+ -- This is necessary to give the warning about Program_Error being
+ -- raised when some (sub)component is an unchecked_union.
- if Nkind (Test) = N_Raise_Program_Error then
+ Preserve_Comes_From_Source (Test, Nod);
- -- This node is going to be inserted at a location where a
- -- statement is expected: clear its Etype so analysis will set
- -- it to the expected Standard_Void_Type.
-
- Set_Etype (Test, Empty);
- return Test;
-
- else
- return
- Make_Implicit_If_Statement (Nod,
- Condition => Make_Op_Not (Loc, Right_Opnd => Test),
- Then_Statements => New_List (
- Make_Simple_Return_Statement (Loc,
- Expression => New_Occurrence_Of (Standard_False, Loc))));
- end if;
+ return
+ Make_Implicit_If_Statement (Nod,
+ Condition => Make_Op_Not (Loc, Right_Opnd => Test),
+ Then_Statements => New_List (
+ Make_Simple_Return_Statement (Loc,
+ Expression => New_Occurrence_Of (Standard_False, Loc))));
end Component_Equality;
------------------
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 8425359..4cdac94 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -12119,11 +12119,14 @@ package body Sem_Util is
and then Is_Constrained (Etype (Subtype_Mark (N)));
-- For all other names, it is sufficient to have a constrained
- -- Unchecked_Union nominal subtype.
+ -- Unchecked_Union nominal subtype, unless it is incomplete or
+ -- private because it cannot have a known discriminant part in
+ -- this case (RM B.3.3 (11/2)).
else
return Is_Unchecked_Union (Etype (N))
- and then Is_Constrained (Etype (N));
+ and then Is_Constrained (Etype (N))
+ and then not Is_Incomplete_Or_Private_Type (Etype (N));
end if;
end Has_Inferable_Discriminants;