diff mbox series

[Ada] Invalid memory access on finalization of class-wide type

Message ID 20211202162911.GA2160047@adacore.com
State New
Headers show
Series [Ada] Invalid memory access on finalization of class-wide type | expand

Commit Message

Pierre-Marie de Rodat Dec. 2, 2021, 4:29 p.m. UTC
This patch is the first part of a correction for issues in the compiler
whereby finalization of a heap-allocated class-wide type may cause an
invalid memory read at runtime when the type in question contains a
component whose type has alignment specified.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* gcc-interface/decl.c (gnat_to_gnu_entity): Skip normal
	processing for Itypes that are E_Class_Wide_Subtype with
	Equivalent_Type set.
diff mbox series

Patch

diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -335,11 +335,14 @@  gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 
   /* Since a use of an itype is a definition, process it as such if it is in
      the main unit, except for E_Access_Subtype because it's actually a use
-     of its base type, see below.  */
+     of its base type, and for E_Class_Wide_Subtype with an Equivalent_Type
+     because it's actually a use of the latter type.  */
   if (!definition
       && is_type
       && Is_Itype (gnat_entity)
       && Ekind (gnat_entity) != E_Access_Subtype
+      && !(Ekind (gnat_entity) == E_Class_Wide_Subtype
+	   && Present (Equivalent_Type (gnat_entity)))
       && !present_gnu_tree (gnat_entity)
       && In_Extended_Main_Code_Unit (gnat_entity))
     {