public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Spurious error on Lock_Free protected type with discriminants
@ 2022-11-24 10:12 Marc Poulhiès
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Poulhiès @ 2022-11-24 10:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Justin Squirek

From: Justin Squirek <squirek@adacore.com>

This patch corrects an issue in the compiler whereby unprefixed discriminants
appearing in protected subprograms were unable to be properly resolved -
leading to spurious resolution errors.

gcc/ada/

	* sem_ch8.adb
	(Find_Direct_Name): Remove bypass to reanalyze incorrectly
	analyzed discriminals.
	(Set_Entity_Or_Discriminal): Avoid resetting the entity field of a
	discriminant reference to be the internally generated renaming
	when we are in strict preanalysis mode.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch8.adb | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index ca306663791..841076bbd01 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -4891,6 +4891,18 @@ package body Sem_Ch8 is
          then
             null;
 
+         --  Don't replace the discriminant in strict preanalysis mode since
+         --  it can lead to errors during full analysis when the discriminant
+         --  gets referenced later.
+
+         --  This can occur in situations where a protected type contains
+         --  an expression function which references a discriminant.
+
+         elsif Preanalysis_Active
+           and then Inside_Preanalysis_Without_Freezing = 0
+         then
+            null;
+
          else
             Set_Entity (N, Discriminal (E));
          end if;
@@ -6048,21 +6060,6 @@ package body Sem_Ch8 is
          if Is_Type (Entity (N)) then
             Set_Etype (N, Entity (N));
 
-         --  The exception to this general rule are constants associated with
-         --  discriminals of protected types because for each protected op
-         --  a new set of discriminals is internally created by the frontend
-         --  (see Exp_Ch9.Set_Discriminals), and the current decoration of the
-         --  entity pointer may have been set as part of a preanalysis, where
-         --  discriminals still reference the first subprogram or entry to be
-         --  expanded (see Expand_Protected_Body_Declarations).
-
-         elsif Full_Analysis
-           and then Ekind (Entity (N)) = E_Constant
-           and then Present (Discriminal_Link (Entity (N)))
-           and then Is_Protected_Type (Scope (Discriminal_Link (Entity (N))))
-         then
-            goto Find_Name;
-
          else
             declare
                Entyp : constant Entity_Id := Etype (Entity (N));
@@ -6102,8 +6099,6 @@ package body Sem_Ch8 is
          return;
       end if;
 
-      <<Find_Name>>
-
       --  Preserve relevant elaboration-related attributes of the context which
       --  are no longer available or very expensive to recompute once analysis,
       --  resolution, and expansion are over.
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [COMMITTED] ada: Spurious error on Lock_Free protected type with discriminants
@ 2023-01-05 14:39 Marc Poulhiès
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Poulhiès @ 2023-01-05 14:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: Justin Squirek

From: Justin Squirek <squirek@adacore.com>

This patch corrects an issue in the compiler whereby unprefixed discriminants
appearing in protected subprograms were unable to be properly resolved -
leading to spurious resolution errors.

gcc/ada/

	* sem_ch8.adb (Set_Entity_Or_Discriminal): Verify we are actually
	resetting the entity field of a non-prefixed discriminant
	reference.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch8.adb | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 841076bbd01..fe89e1127ee 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -4891,14 +4891,16 @@ package body Sem_Ch8 is
          then
             null;
 
-         --  Don't replace the discriminant in strict preanalysis mode since
-         --  it can lead to errors during full analysis when the discriminant
-         --  gets referenced later.
+         --  Don't replace a non-qualified discriminant in strict preanalysis
+         --  mode since it can lead to errors during full analysis when the
+         --  discriminant gets referenced later.
 
          --  This can occur in situations where a protected type contains
-         --  an expression function which references a discriminant.
+         --  an expression function which references a non-prefixed
+         --  discriminant.
 
-         elsif Preanalysis_Active
+         elsif No (P)
+           and then Preanalysis_Active
            and then Inside_Preanalysis_Without_Freezing = 0
          then
             null;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-05 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24 10:12 [COMMITTED] ada: Spurious error on Lock_Free protected type with discriminants Marc Poulhiès
2023-01-05 14:39 Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).