[COMMITTED,17/35] ada: Spurious error when compiling in Syntax and Semantics Only mode

Message ID 20241025091107.485741-17-poulhies@adacore.com
State Committed
Commit d0a072e1f8b46eccf8fcc014e25cd47f17b86496
Headers
Series [COMMITTED,01/35] ada: Pass parameters of full access unconstrained array types by copy in calls |

Commit Message

Marc Poulhiès Oct. 25, 2024, 9:10 a.m. UTC
  From: Javier Miranda <miranda@adacore.com>

Compiling under switch -gnatc, the frontend reports spurious errors
accessing components of class-wide tagged types.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Record_Type_Definition): For tagged types, add
	the missing decoration to the First_Entity in the corresponding
	class-wide type entity.

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

---
 gcc/ada/sem_ch3.adb | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
  

Patch

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index ea0a97bd39f..00d5fe256d9 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -23074,6 +23074,23 @@  package body Sem_Ch3 is
          if Present (Variant_Part (Component_List (Def))) then
             Analyze (Variant_Part (Component_List (Def)));
          end if;
+
+         --  For tagged types, when compiling in Generate_Code mode, the _Tag
+         --  component is added before the creation of the class-wide entity
+         --  and it is shared by that entity once it is built.
+
+         --  However, when compiling in Check_Syntax or Check_Semantics modes,
+         --  since the _Tag component is not added to the tagged type entity,
+         --  the First_Entity of its class-wide type remains empty, and must
+         --  be explicitly set to prevent spurious errors from being reported.
+
+         if Operating_Mode <= Check_Semantics
+           and then Is_Tagged_Type (T)
+           and then Present (First_Entity (T))
+           and then No (First_Entity (Class_Wide_Type (T)))
+         then
+            Set_First_Entity (Class_Wide_Type (T), First_Entity (T));
+         end if;
       end if;
 
       --  After completing the semantic analysis of the record definition,