Optimization that repaces

   if expression then
      return true;
   else
      return false;
   end if;

with

   return expression;

is now trivially extended to detect True/False prefixed by Standard.

Found while investigating excessive validity checks.

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

gcc/ada/

        * exp_ch5.adb (Expand_N_If_Statement): Detect True/False
        prefixed with Standard.
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -3743,9 +3743,9 @@ package body Exp_Ch5 is
       --  Another optimization, special cases that can be simplified
 
       --     if expression then
-      --        return true;
+      --        return [standard.]true;
       --     else
-      --        return false;
+      --        return [standard.]false;
       --     end if;
 
       --  can be changed to:
@@ -3755,9 +3755,9 @@ package body Exp_Ch5 is
       --  and
 
       --     if expression then
-      --        return false;
+      --        return [standard.]false;
       --     else
-      --        return true;
+      --        return [standard.]true;
       --     end if;
 
       --  can be changed to:
@@ -3790,9 +3790,9 @@ package body Exp_Ch5 is
                      Else_Expr : constant Node_Id := Expression (Else_Stm);
 
                   begin
-                     if Nkind (Then_Expr) = N_Identifier
+                     if Nkind_In (Then_Expr, N_Expanded_Name, N_Identifier)
                           and then
-                        Nkind (Else_Expr) = N_Identifier
+                        Nkind_In (Else_Expr, N_Expanded_Name, N_Identifier)
                      then
                         if Entity (Then_Expr) = Standard_True
                           and then Entity (Else_Expr) = Standard_False


Reply via email to