public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2901] ada: Incorrect optimization for unconstrained limited record component type
@ 2023-08-01  8:07 Marc Poulhi?s
  0 siblings, 0 replies; only message in thread
From: Marc Poulhi?s @ 2023-08-01  8:07 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:04c297101019316eb8c3191ffb2ff0bf34f4d869

commit r14-2901-g04c297101019316eb8c3191ffb2ff0bf34f4d869
Author: Steve Baird <baird@adacore.com>
Date:   Thu Jun 8 14:59:32 2023 -0700

    ada: Incorrect optimization for unconstrained limited record component type
    
    If the discriminants of an immutably limited record type have defaults, then
    it is safe to assume that a discriminant of an object of this type will never
    change once it is initialized. In some cases, this means that the default
    discriminant values can be treated like a constraint for purposes of
    determining the amount of storage needed for an unconstrained object.
    However, it is not safe to perform this optimization when determining
    the size needed for an unconstrained component of an enclosing type. This
    optimization was sometimes being incorrectly performed in this case. This could
    save storage in some cases, but in other cases a constraint check could
    incorrectly fail when initializing a component of an aggregate if the
    discriminant values of the component differ from the default values.
    
    gcc/ada/
    
            * sem_ch3.adb (Analyze_Component_Declaration): Remove
            Build_Default_Subtype_OK call and code that could only executed in
            the case where the removed call would have returned True. Other
            calls to Build_Default_Subtype_Ok are unaffected by this change.

Diff:
---
 gcc/ada/sem_ch3.adb | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 85019dfffa5..ed337f5408e 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -1868,7 +1868,6 @@ package body Sem_Ch3 is
    -----------------------------------
 
    procedure Analyze_Component_Declaration (N : Node_Id) is
-      Loc : constant Source_Ptr := Sloc (Component_Definition (N));
       Id  : constant Entity_Id  := Defining_Identifier (N);
       E   : constant Node_Id    := Expression (N);
       Typ : constant Node_Id    :=
@@ -2205,23 +2204,6 @@ package body Sem_Ch3 is
          end if;
       end if;
 
-      --  When possible, build the default subtype
-
-      if Build_Default_Subtype_OK (T) then
-         declare
-            Act_T : constant Entity_Id := Build_Default_Subtype (T, N);
-
-         begin
-            Set_Etype (Id, Act_T);
-
-            --  Rewrite component definition to use the constrained subtype
-
-            Rewrite (Component_Definition (N),
-              Make_Component_Definition (Loc,
-                Subtype_Indication => New_Occurrence_Of (Act_T, Loc)));
-         end;
-      end if;
-
       Set_Original_Record_Component (Id, Id);
 
       if Has_Aspects (N) then

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-01  8:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01  8:07 [gcc r14-2901] ada: Incorrect optimization for unconstrained limited record component type Marc Poulhi?s

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).