From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 4314F3857822 for ; Tue, 17 May 2022 08:27:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4314F3857822 Received: by mail-wr1-x42c.google.com with SMTP id r23so7637799wrr.2 for ; Tue, 17 May 2022 01:27:36 -0700 (PDT) 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=BGly8gSxS7mOecGDOWGO33B3PHvaSFObgouRKwWwhmk=; b=1lVYRvpMD7OIf+qPIctW8bjkMbmurhllFz8DVUmXk8mXIpW/YUe8+PkXwFFmCzLtBq H13iy5YQm73cvS6r9fBFJbsZGBNm6GwBKN6ZbwhpxiwLzH7+3/9AR4eY/c/xDd+j3G62 8RdmKcOsWBMRMYKd95aQP21jBFHcTk6PqH+v2p+amvdYaMbKiBfFc5a1wEG2XiQKF/GM X3IMhdDjU5sFR74HM1BwQOqBdluzm0Y8+LqfoYAt05iHeX6FWWf1MaXYfkRWw5VfO/sD G5DYqYwBm2kInYzVQ4WcEpw3jlmqUBR8+0Y01yyqcDiUhtH+dh+fp84zub+bi5Mg1oSi UNFg== X-Gm-Message-State: AOAM530HSfCZWGIVY90gLZlt+k0ppgvvGV5O22clt/8plbnYftbXZ/dn iPl7pv0CgcwLMUH0+nUVu0DtZGN3ipkCqAmS X-Google-Smtp-Source: ABdhPJzurH2KueFE+cWHDzpi6ixyZPvWyQarqodzNVcSJf7vgM3uQBPum5x3kpVQZK9vGKS/UvCGjQ== X-Received: by 2002:a5d:43d2:0:b0:20c:b986:a337 with SMTP id v18-20020a5d43d2000000b0020cb986a337mr16623832wrr.445.1652776055748; Tue, 17 May 2022 01:27:35 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u26-20020adfa19a000000b0020e5b2afb3bsm462959wru.23.2022.05.17.01.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:35 -0700 (PDT) Date: Tue, 17 May 2022 08:27:34 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Streamline implementation of Has_Compatible_Representation Message-ID: <20220517082734.GA1088533@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="NzB8fVQJ5HfG6fxh" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Tue, 17 May 2022 08:27:38 -0000 --NzB8fVQJ5HfG6fxh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The predicate is only concerned with the internal representation of types and this representation is shared by the subtypes of a given type, so the implementation can directly look into the (implementation) base types. No functional changes. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.ads (Has_Compatible_Representation): Minor tweaks. * sem_ch13.adb (Has_Compatible_Representation): Look directly into the (implementation) base types and simplifiy accordingly. * exp_ch5.adb (Change_Of_Representation): Adjust. * exp_ch6.adb (Expand_Actuals): Likewise. --NzB8fVQJ5HfG6fxh Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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 @@ -292,8 +292,8 @@ package body Exp_Ch5 is return Nkind (Rhs) = N_Type_Conversion and then not Has_Compatible_Representation - (Target_Type => Etype (Rhs), - Operand_Type => Etype (Expression (Rhs))); + (Target_Typ => Etype (Rhs), + Operand_Typ => Etype (Expression (Rhs))); end Change_Of_Representation; ------------------------------ diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1576,8 +1576,8 @@ package body Exp_Ch6 is Var := Make_Var (Expression (Actual)); Crep := not Has_Compatible_Representation - (Target_Type => F_Typ, - Operand_Type => Etype (Expression (Actual))); + (Target_Typ => F_Typ, + Operand_Typ => Etype (Expression (Actual))); else V_Typ := Etype (Actual); @@ -2379,8 +2379,8 @@ package body Exp_Ch6 is -- Also pass by copy if change of representation or else not Has_Compatible_Representation - (Target_Type => Etype (Formal), - Operand_Type => Etype (Expression (Actual)))) + (Target_Typ => Etype (Formal), + Operand_Typ => Etype (Expression (Actual)))) then Add_Call_By_Copy_Code; @@ -4556,8 +4556,8 @@ package body Exp_Ch6 is -- warning, and do the change of representation. elsif not Has_Compatible_Representation - (Target_Type => Formal_Typ, - Operand_Type => Parent_Typ) + (Target_Typ => Formal_Typ, + Operand_Typ => Parent_Typ) then Error_Msg_N ("??change of representation required", Actual); diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -13436,56 +13436,40 @@ package body Sem_Ch13 is ----------------------------------- function Has_Compatible_Representation - (Target_Type, Operand_Type : Entity_Id) return Boolean + (Target_Typ, Operand_Typ : Entity_Id) return Boolean is - T1 : constant Entity_Id := Underlying_Type (Target_Type); - T2 : constant Entity_Id := Underlying_Type (Operand_Type); + -- The subtype-specific representation attributes (Size and Alignment) + -- do not affect representation from the point of view of this function. - begin - -- A quick check, if base types are the same, then we definitely have - -- the same representation, because the subtype specific representation - -- attributes (Size and Alignment) do not affect representation from - -- the point of view of this test. - - if Base_Type (T1) = Base_Type (T2) then - return True; + T1 : constant Entity_Id := Implementation_Base_Type (Target_Typ); + T2 : constant Entity_Id := Implementation_Base_Type (Operand_Typ); - elsif Is_Private_Type (Base_Type (T2)) - and then Base_Type (T1) = Full_View (Base_Type (T2)) - then - return True; - - -- If T2 is a generic actual it is declared as a subtype, so - -- check against its base type. + begin + -- Return true immediately for the same base type - elsif Is_Generic_Actual_Type (T1) - and then Has_Compatible_Representation (Base_Type (T1), T2) - then + if T1 = T2 then return True; - end if; -- Tagged types always have the same representation, because it is not -- possible to specify different representations for common fields. - if Is_Tagged_Type (T1) then + elsif Is_Tagged_Type (T1) then return True; - end if; -- Representations are definitely different if conventions differ - if Convention (T1) /= Convention (T2) then + elsif Convention (T1) /= Convention (T2) then return False; - end if; -- Representations are different if component alignments or scalar -- storage orders differ. - if (Is_Record_Type (T1) or else Is_Array_Type (T1)) - and then - (Is_Record_Type (T2) or else Is_Array_Type (T2)) - and then - (Component_Alignment (T1) /= Component_Alignment (T2) - or else Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) + elsif (Is_Record_Type (T1) or else Is_Array_Type (T1)) + and then + (Is_Record_Type (T2) or else Is_Array_Type (T2)) + and then (Component_Alignment (T1) /= Component_Alignment (T2) + or else + Reverse_Storage_Order (T1) /= Reverse_Storage_Order (T2)) then return False; end if; @@ -13512,11 +13496,10 @@ package body Sem_Ch13 is then return True; end if; - end if; - -- For records, representations are different if reorderings differ + -- For records, representations are different if reordering differs - if Is_Record_Type (T1) + elsif Is_Record_Type (T1) and then Is_Record_Type (T2) and then No_Reordering (T1) /= No_Reordering (T2) then diff --git a/gcc/ada/sem_ch13.ads b/gcc/ada/sem_ch13.ads --- a/gcc/ada/sem_ch13.ads +++ b/gcc/ada/sem_ch13.ads @@ -130,12 +130,11 @@ package Sem_Ch13 is -- clause, T is the component type. function Has_Compatible_Representation - (Target_Type, Operand_Type : Entity_Id) return Boolean; - -- Given two types, where the two types are related by possible derivation, - -- determines if the two types have compatible representation, or different - -- representations, requiring the special processing for representation - -- change. A False result is possible only for array, enumeration or - -- record types. + (Target_Typ, Operand_Typ : Entity_Id) return Boolean; + -- Given an explicit or implicit conversion from Operand_Typ to Target_Typ, + -- determine whether the types have compatible or different representation, + -- thus requiring special processing for the conversion in the latter case. + -- A False result is possible only for array, enumeration and record types. procedure Parse_Aspect_Aggregate (N : Node_Id; --NzB8fVQJ5HfG6fxh--