[Ada] Fix invalid expanded code for entry families

Message ID 20220519141605.GA3723246@adacore.com
State Committed
Commit ca03325fb3a5fbf9c8af853d4c7f199e1adb08e3
Headers
Series [Ada] Fix invalid expanded code for entry families |

Commit Message

Pierre-Marie de Rodat May 19, 2022, 2:16 p.m. UTC
  Expansion of entry families created a slightly illegal AST with
Elsif_Parts being an empty list. Cleanup uncovered by the work on
detection of uninitialized scalars.

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

gcc/ada/

	* exp_ch9.adb (Build_Find_Body_Index): Remove empty Elsif_Parts
	from the constructed IF statement.
  

Patch

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -2800,6 +2800,15 @@  package body Exp_Ch9 is
             begin
                Remove (Nod);
                Set_Else_Statements (Ret, Then_Statements (Nod));
+
+               --  If Elsif_Parts becomes empty then remove it entirely, as
+               --  otherwise we would violate the invariant of If_Statement
+               --  node described in Sinfo.
+
+               if Is_Empty_List (Elsif_Parts (Ret)) then
+                  pragma Assert (Elsif_Parts (Ret) /= No_List);
+                  Set_Elsif_Parts (Ret, No_List);
+               end if;
             end;
          end if;
       end if;