diff options
author | Ed Schonberg <schonberg@adacore.com> | 2019-07-04 08:05:03 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2019-07-04 08:05:03 +0000 |
commit | dcd59a994affdd191d7025269b18a1043f80a47f (patch) | |
tree | c4d4b85eb61b80dc45905445311c72dce2f31268 /gcc/ada | |
parent | ee7904e91fcdafd4211f89e0244354467d78a3c2 (diff) | |
download | gcc-dcd59a994affdd191d7025269b18a1043f80a47f.zip gcc-dcd59a994affdd191d7025269b18a1043f80a47f.tar.gz gcc-dcd59a994affdd191d7025269b18a1043f80a47f.tar.bz2 |
[Ada] Spurious dimensionality error on aggregate with "others" assoc.
This patch fixes a spurious dimensionality error on an array aggregate
with a single "others' clause whose expression is a dimensioned entity,
The expansion of the aggregate may create copies of the expression, and
the dimensionality check must use the type of the expression to retrieve
the proper dimension information to check against the dimensions of the
array component type.
2019-07-04 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_dim.adb (Analyze_Dimension_Array_Aggregate): If the
component is an entity name, its dimensions are those of its
type.
gcc/testsuite/
* gnat.dg/dimensions2.adb, gnat.dg/dimensions2_phys.ads,
gnat.dg/dimensions2_real_numbers.ads: New testcase.
From-SVN: r273043
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/ada/sem_dim.adb | 15 |
2 files changed, 18 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c28a942..62f031c 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2019-07-04 Ed Schonberg <schonberg@adacore.com> + + * sem_dim.adb (Analyze_Dimension_Array_Aggregate): If the + component is an entity name, its dimensions are those of its + type. + 2019-07-03 Bob Duff <duff@adacore.com> * doc/gnat_ugn/gnat_utility_programs.rst: Document new flags in diff --git a/gcc/ada/sem_dim.adb b/gcc/ada/sem_dim.adb index 43b1f23..26c8008 100644 --- a/gcc/ada/sem_dim.adb +++ b/gcc/ada/sem_dim.adb @@ -1233,8 +1233,9 @@ package body Sem_Dim is Dims_Of_Comp_Typ : constant Dimension_Type := Dimensions_Of (Comp_Typ); Exps : constant List_Id := Expressions (N); - Comp : Node_Id; - Expr : Node_Id; + Comp : Node_Id; + Dims_Of_Expr : Dimension_Type; + Expr : Node_Id; Error_Detected : Boolean := False; -- This flag is used in order to indicate if an error has been detected @@ -1281,11 +1282,19 @@ package body Sem_Dim is -- (may happen when an aggregate is converted into a positional -- aggregate). We also must verify that this is a scalar component, -- and not a subaggregate of a multidimensional aggregate. + -- The expression may be an identifier that has been copied several + -- times during expansion, its dimensions are those of its type. + + if Is_Entity_Name (Expr) then + Dims_Of_Expr := Dimensions_Of (Etype (Expr)); + else + Dims_Of_Expr := Dimensions_Of (Expr); + end if; if Comes_From_Source (Original_Node (Expr)) and then Present (Etype (Expr)) and then Is_Numeric_Type (Etype (Expr)) - and then Dimensions_Of (Expr) /= Dims_Of_Comp_Typ + and then Dims_Of_Expr /= Dims_Of_Comp_Typ and then Sloc (Comp) /= Sloc (Prev (Comp)) then -- Check if an error has already been encountered so far |