]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Another case where freezing incorrectly suppresses checks
authorSteve Baird <baird@adacore.com>
Wed, 4 May 2022 23:23:40 +0000 (16:23 -0700)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 1 Jun 2022 08:43:18 +0000 (08:43 +0000)
Avoid improperly suppressing checks for the wrapper subprogram that is
built when a null type extension inherits (and does not override) a
function with a controlling result. This is a follow-up to other changes
already made on this ticket.

gcc/ada/

* exp_ch3.adb (Make_Controlling_Function_Wrappers): Set the
Corresponding_Spec field of a wrapper subprogram body before
analyzing the subprogram body; the field will be set (again)
during analysis, but we need it to be set earlier.
* exp_ch13.adb (Expand_N_Freeze_Entity): Add wrapper subprogram
bodies to the list of declarations for which we do not want to
suppress checks.

gcc/ada/exp_ch13.adb
gcc/ada/exp_ch3.adb

index 6b6da818387257c5bc1a4946a52a6562a96b6841..d2be185aa56b4bf1d818b93cebcb397e41377f58 100644 (file)
@@ -626,10 +626,10 @@ package body Exp_Ch13 is
       end if;
 
       --  Analyze actions generated by freezing. The init_proc contains source
-      --  expressions that may raise Constraint_Error, and the assignment
+      --  expressions that may raise Constraint_Error, the assignment
       --  procedure for complex types needs checks on individual component
-      --  assignments, but all other freezing actions should be compiled with
-      --  all checks off.
+      --  assignments, and wrappers may need checks. Other freezing actions
+      --  should be compiled with all checks off.
 
       if Present (Actions (N)) then
          Decl := First (Actions (N));
@@ -637,7 +637,11 @@ package body Exp_Ch13 is
             if Nkind (Decl) = N_Subprogram_Body
               and then (Is_Init_Proc (Defining_Entity (Decl))
                           or else
-                            Chars (Defining_Entity (Decl)) = Name_uAssign)
+                            Chars (Defining_Entity (Decl)) = Name_uAssign
+                          or else
+                            (Present (Corresponding_Spec (Decl))
+                               and then Is_Wrapper
+                                          (Corresponding_Spec (Decl))))
             then
                Analyze (Decl);
 
index 03ff9258926426e15565a9e15712097881b5ebca..5403f3b4f6442e974159dc75f03750a9d91f1784 100644 (file)
@@ -10031,6 +10031,13 @@ package body Exp_Ch3 is
             Mutate_Ekind (Func_Id, E_Function);
             Set_Is_Wrapper (Func_Id);
 
+            --  Corresponding_Spec will be set again to the same value during
+            --  analysis, but we need this information earlier.
+            --  Expand_N_Freeze_Entity needs to know whether a subprogram body
+            --  is a wrapper's body in order to get check suppression right.
+
+            Set_Corresponding_Spec (Func_Body, Func_Id);
+
             Override_Dispatching_Operation (Tag_Typ, Subp, New_Op => Func_Id);
          end if;