From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 78F293858031 for ; Wed, 10 Nov 2021 08:58:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78F293858031 Received: by mail-lj1-x235.google.com with SMTP id m5so3911966ljp.4 for ; Wed, 10 Nov 2021 00:58:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=CG8bV7xIYBInz2/Ta0KRtwBDxc7YgkCVt1H1bKlOeTY=; b=Rple0+31Uf1fNrONTQsI24mP8++WeTHxpin7TLK0K7W6+IpjMD1OhWzWg5AeeJkt4k U77482FFLrE8Znj9sTH1IkV+zRmrTfrRNeoB1wXUesSvkDm5JzvzQ7OtctQ7jCpqHjx9 IW0sgI4t0yBw15zE0vpHU4bGvSaa/y27IqDDzaqeqOpztZlEtcrP9MmbFJ+tHpaywHaZ itO91ISOWgI030F4kSrH8xAT+rJQwFneSImKFeKrXhF3nghFhg6B6z0GB+iIlQ63tvVq 82uEaKrxue/elHIQBsmnEj3IijmJBxF/1mRZAmEb6tZPUlWCMM0wtEX3+dfDMZMxM1Wf +juA== X-Gm-Message-State: AOAM533Q6IH66xuUFvIGRicXUqKY/qjUiyI2VrAmejq5DyLQgJKIRjXu ICHQOCFLN0f8qR5KvWRigxGIV0KOmA0k2mJ+ X-Google-Smtp-Source: ABdhPJyfgqzT2ymPT8IV/ISnDz5FPliQ+UFxDy165+OOWIZvWYfkVXuWOEbnPtKKmhtr+9dp376axQ== X-Received: by 2002:a2e:7114:: with SMTP id m20mr14340553ljc.229.1636534717393; Wed, 10 Nov 2021 00:58:37 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id d12sm531843lfg.84.2021.11.10.00.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 00:58:36 -0800 (PST) Date: Wed, 10 Nov 2021 08:58:35 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Use predefined equality for arrays inside records Message-ID: <20211110085835.GA2811104@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9amGYk9869ThD9tj" Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Nov 2021 08:58:40 -0000 --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The equality of arrays inside records always applies the predefined equality, just like for elementary types. In Expand_Composite_Equality we had some dedicated code for arrays inside records which was failing to duplicate a similar code in Expand_N_Op_Eq, e.g. it was failing to apply validity checks. This patch removes this dedicated and unnecessarily duplicated code. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_Composite_Equality): Handle arrays inside records just like scalars; only records inside records need dedicated handling. --9amGYk9869ThD9tj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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 @@ -2475,75 +2475,9 @@ package body Exp_Ch4 is Full_Type := Underlying_Type (Full_Type); end if; - -- Case of array types - - if Is_Array_Type (Full_Type) then - - -- If the operand is an elementary type other than a floating-point - -- type, then we can simply use the built-in block bitwise equality, - -- since the predefined equality operators always apply and bitwise - -- equality is fine for all these cases. - - if Is_Elementary_Type (Component_Type (Full_Type)) - and then not Is_Floating_Point_Type (Component_Type (Full_Type)) - then - return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs); - - -- For composite component types, and floating-point types, use the - -- expansion. This deals with tagged component types (where we use - -- the applicable equality routine) and floating-point (where we - -- need to worry about negative zeroes), and also the case of any - -- composite type recursively containing such fields. - - else - declare - Comp_Typ : Entity_Id; - Hi : Node_Id; - Indx : Node_Id; - Ityp : Entity_Id; - Lo : Node_Id; - - begin - -- Do the comparison in the type (or its full view) and not in - -- its unconstrained base type, because the latter operation is - -- more complex and would also require an unchecked conversion. - - if Is_Private_Type (Typ) then - Comp_Typ := Underlying_Type (Typ); - else - Comp_Typ := Typ; - end if; - - -- Except for the case where the bounds of the type depend on a - -- discriminant, or else we would run into scoping issues. - - Indx := First_Index (Comp_Typ); - while Present (Indx) loop - Ityp := Etype (Indx); - - Lo := Type_Low_Bound (Ityp); - Hi := Type_High_Bound (Ityp); - - if (Nkind (Lo) = N_Identifier - and then Ekind (Entity (Lo)) = E_Discriminant) - or else - (Nkind (Hi) = N_Identifier - and then Ekind (Entity (Hi)) = E_Discriminant) - then - Comp_Typ := Full_Type; - exit; - end if; - - Next_Index (Indx); - end loop; - - return Expand_Array_Equality (Nod, Lhs, Rhs, Bodies, Comp_Typ); - end; - end if; - -- Case of tagged record types - elsif Is_Tagged_Type (Full_Type) then + if Is_Tagged_Type (Full_Type) then Eq_Op := Find_Primitive_Eq (Typ); pragma Assert (Present (Eq_Op)); @@ -2734,7 +2668,7 @@ package body Exp_Ch4 is return Expand_Record_Equality (Nod, Full_Type, Lhs, Rhs, Bodies); end if; - -- Non-composite types (always use predefined equality) + -- Case of non-record types (always use predefined equality) else return Make_Op_Eq (Loc, Left_Opnd => Lhs, Right_Opnd => Rhs); --9amGYk9869ThD9tj--