diff mbox series

[Ada] Crash on expansion of tagged membership test

Message ID 20211109094616.GA830891@adacore.com
State New
Headers show
Series [Ada] Crash on expansion of tagged membership test | expand

Commit Message

Pierre-Marie de Rodat Nov. 9, 2021, 9:46 a.m. UTC
This patch corrects an issue in the compiler whereby the expansion of a
tagged membership test when one of the types involved is a protected
type can cause a crash a compile-time.

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

gcc/ada/

	* exp_ch4.adb (Tagged_Membership): Use corresponding record type
	when expanding a tagged membership test on protected types.
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -15346,6 +15346,17 @@  package body Exp_Ch4 is
    begin
       SCIL_Node := Empty;
 
+      --  We have to examine the corresponding record type when dealing with
+      --  protected types instead of the original, unexpanded, type.
+
+      if Ekind (Right_Type) = E_Protected_Type then
+         Right_Type := Corresponding_Record_Type (Right_Type);
+      end if;
+
+      if Ekind (Left_Type) = E_Protected_Type then
+         Left_Type := Corresponding_Record_Type (Left_Type);
+      end if;
+
       --  In the case where the type is an access type, the test is applied
       --  using the designated types (needed in Ada 2012 for implicit anonymous
       --  access conversions, for AI05-0149).