diff options
author | Ed Schonberg <schonberg@adacore.com> | 2018-05-24 13:06:21 +0000 |
---|---|---|
committer | Pierre-Marie de Rodat <pmderodat@gcc.gnu.org> | 2018-05-24 13:06:21 +0000 |
commit | 5a5925ee30a8f8b43d045726aa7b2a82c6a6af61 (patch) | |
tree | 3c3ed10b6f2e11f6b552dc77ea3e78407c8b6750 | |
parent | e15bbd5fb974c6cc8760bee1c640c01d6c9a8b68 (diff) | |
download | gcc-5a5925ee30a8f8b43d045726aa7b2a82c6a6af61.zip gcc-5a5925ee30a8f8b43d045726aa7b2a82c6a6af61.tar.gz gcc-5a5925ee30a8f8b43d045726aa7b2a82c6a6af61.tar.bz2 |
[Ada] Infinite loop in the compiler when warning on redundant constructs
This patch fixes an infinite loop in the compiler when warnings on redundant
constructs are enabled (-gnatwr) and the constructs are use_type clauses
that appear (redundantly) in a parent unit and a child unit.
The following command:
gcc -c -gnatwr root-child.ads
must yield:
root-child.ads:2:01: warning: "Pack.Typ" is already use-visible through
previous use_type_clause at root.ads:2
The following must compile quietly:
gcc -c -gnatwr root-child-grand.ads
----
package Pack is
type Typ is new Integer;
end Pack;
----
with Pack;
use type Pack.Typ;
package Root is
Thing1 : Pack.Typ;
end Root;
----
with pack;
use type pack.typ;
package Root.Child is
Thing2 : Pack.Typ := Root.Thing1 * 3;
end;
----
with Pack;
use type Pack.Typ;
package Root.Child.Grand is
Thing3 : Pack.Typ := Thing1 + Thing2;
end;
2018-05-24 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_ch8.adb (Analyze_Use_Type): Do not assign the Prev_Use_Clause
link to a use_type clause if this would cause an infinite loop in the
machinery that detects redundant use clauses. This may happen when the
redundant clauses appear in the context of a child unit and the context
of its parent.
From-SVN: r260663
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/sem_ch8.adb | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index ae80df8..8f7e51d 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2018-05-24 Ed Schonberg <schonberg@adacore.com> + + * sem_ch8.adb (Analyze_Use_Type): Do not assign the Prev_Use_Clause + link to a use_type clause if this would cause an infinite loop in the + machinery that detects redundant use clauses. This may happen when the + redundant clauses appear in the context of a child unit and the context + of its parent. + 2018-05-24 Piotr Trojanek <trojanek@adacore.com> * sinfo.ads: Fix grammar in comment. diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 36172d0..8f8b03a 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -3916,10 +3916,14 @@ package body Sem_Ch8 is -- manipulation of the scope stack so we much guard against those cases -- here, otherwise, we must add the new use_type_clause to the previous -- use_type_clause chain in order to mark redundant use_type_clauses as - -- used. + -- used. When the redundant use-type clauses appear in a parent unit and + -- a child unit we must prevent a circularity in the chain that would + -- otherwise result from the separate steps of analysis and installation + -- of the parent context. if Present (Current_Use_Clause (E)) and then Current_Use_Clause (E) /= N + and then Prev_Use_Clause (Current_Use_Clause (E)) /= N and then No (Prev_Use_Clause (N)) then Set_Prev_Use_Clause (N, Current_Use_Clause (E)); |