From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 645F6385AF96 for ; Tue, 18 Jul 2023 13:13:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 645F6385AF96 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbc63c2e84so56623315e9.3 for ; Tue, 18 Jul 2023 06:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1689686016; x=1690290816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JFZ2nOOQI6F6Xv+KQx5Tp9/mfvQGSfS+0dKsIe6Lv10=; b=d0h1SE3VSAm6X85S9m/ru+d3bhrhkVMBYRfBSs/3hui6LBJB4r/55/xtCtP7n77C/p pN2qKWQLPu5LqiKqAd4ezfjHDo3m0mTom7Ef6s+8dFE1n70ZIO5LKUwqVKlmUhGiGUck +g69UOSgkiWzdM9pXzsU5W7i28guAjcIefgw+MGGWWNEk0cZAIehTin7OQikIn+Mea5m dp7+Rc+8XUsF3gYGyY079KH2F9K94XenYPLTH4ekfFXRCFaGvhP/Vk/sUUEHdML0a/jr NJhzqTiUUNazH1cgIblTjBL3QoujwvcFRfH7W1YZd2kMS3DCXs391XTjsY74HjVKYoC1 TfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689686016; x=1690290816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JFZ2nOOQI6F6Xv+KQx5Tp9/mfvQGSfS+0dKsIe6Lv10=; b=XMOW58BE6nSd9CS68lwnQcSjElOO9z59tFxmW9hUbpcc9CrfjFUrmDd7jiW+RX8544 Nt33mBlxUJ31oq9suwIZTvsFmRCkDV/tgSJNkpdoXMO4yCDJYBLW1nJBYSywRsR7Rmh6 JGU2ToJCBp9FhSs5X+yaNmEteJQbLiT/3wa+Eg5vWKuSnjME1IdxMu0rAsjzyhUSVXXT aw7FqtohL4Jr8zM6UhWDyppVw7+NyWkriU5rAur1/SLXdeZz+X5IaGrklRvN/lxqbFce Hv5nLMDohZt1GqdYanGbncnIM3uwoGN/5E1sdklTlSrbX8n12Gklb92qc5SCMiLflc+l n0sg== X-Gm-Message-State: ABy/qLZ61ILY+Sxub6b1kFEEhetuaa7pyq7HtkTvwVVu/rjuHTrF5XSQ TzR0PwTNfT3xTZ+OJ/78v8WJ8SPxIcYPWPVq+xD47Q== X-Google-Smtp-Source: APBJJlE7RZD9wvzfuA1YTHkrX/TGXQm+WmJieKJthGMGTuk6TBjZzR9zFZ0BrtSWJ6BwTQ69y9NJSg== X-Received: by 2002:a7b:ca4c:0:b0:3f8:fc96:6bfd with SMTP id m12-20020a7bca4c000000b003f8fc966bfdmr1803853wml.17.1689686016188; Tue, 18 Jul 2023 06:13:36 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id h14-20020a1ccc0e000000b003fbb618f7adsm2157231wmb.15.2023.07.18.06.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 06:13:35 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Constraint_Error caused by interface conversion Date: Tue, 18 Jul 2023 15:13:35 +0200 Message-Id: <20230718131335.81230-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,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 List-Id: From: Javier Miranda When the sources have a type conversion from an interface type T2 to some ancestor interface type T1 (that is, T2 extends T1) the tag check added by the compiler may fail at runtime. gcc/ada/ * exp_disp.adb (Has_Dispatching_Constructor_Call): Removed. (Expand_Interface_Conversion): Reverse patch. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_disp.adb | 94 ++------------------------------------------ 1 file changed, 4 insertions(+), 90 deletions(-) diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 9381ceee60c..9e0c87a5095 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -1242,92 +1242,9 @@ package body Exp_Disp is procedure Expand_Interface_Conversion (N : Node_Id) is - function Has_Dispatching_Constructor_Call - (Expr : Node_Id) return Boolean; - -- Determines if the expression has a dispatching constructor call - function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id; -- Return the underlying record type of Typ - -------------------------------------- - -- Has_Dispatching_Constructor_Call -- - -------------------------------------- - - function Has_Dispatching_Constructor_Call (Expr : Node_Id) return Boolean - is - function Is_Dispatching_Constructor_Call (N : Node_Id) return Boolean; - -- Determines if N is a dispatching constructor call - - function Process (Nod : Node_Id) return Traverse_Result; - -- Traverse the expression searching for constructor calls - - ------------------------------------- - -- Is_Dispatching_Constructor_Call -- - ------------------------------------- - - function Is_Dispatching_Constructor_Call (N : Node_Id) return Boolean - is - Param : Node_Id; - Param_Type : Entity_Id; - Assoc_Node : Node_Id; - Gen_Func_Id : Entity_Id; - - begin - if Nkind (N) = N_Function_Call - and then Present (Parameter_Associations (N)) - then - Param := First (Parameter_Associations (N)); - - if Nkind (Param) = N_Parameter_Association then - Param := Selector_Name (Param); - end if; - - Param_Type := Etype (Param); - - if Is_Itype (Param_Type) then - Assoc_Node := Associated_Node_For_Itype (Param_Type); - - if Nkind (Assoc_Node) = N_Function_Specification - and then Present (Generic_Parent (Assoc_Node)) - then - Gen_Func_Id := Generic_Parent (Assoc_Node); - - if Is_Intrinsic_Subprogram (Gen_Func_Id) - and then Chars (Gen_Func_Id) - = Name_Generic_Dispatching_Constructor - then - return True; - end if; - end if; - end if; - end if; - - return False; - end Is_Dispatching_Constructor_Call; - - ------------- - -- Process -- - ------------- - - function Process (Nod : Node_Id) return Traverse_Result is - begin - if Nkind (Nod) = N_Function_Call - and then Is_Dispatching_Constructor_Call (Nod) - then - return Abandon; - end if; - - return OK; - end Process; - - function Traverse_Expression is new Traverse_Func (Process); - - -- Start of processing for Has_Dispatching_Constructor_Call - - begin - return Traverse_Expression (Expr) = Abandon; - end Has_Dispatching_Constructor_Call; - ---------------------------- -- Underlying_Record_Type -- ---------------------------- @@ -1430,16 +1347,13 @@ package body Exp_Disp is -- object to reference the corresponding secondary dispatch table -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)). - -- Under regular runtime this is a minor optimization that improves - -- the generated code; under configurable runtime (where generic - -- dispatching constructors are not supported) this optimization - -- allows supporting this interface conversion, which otherwise - -- would require calling the runtime routine to displace the - -- pointer to the object. + -- Under configurable runtime it is safe to skip generating code to + -- displace the pointer to the object, because generic dispatching + -- constructors are not supported. elsif Is_Interface (Iface_Typ) and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True) - and then not Has_Dispatching_Constructor_Call (Operand) + and then not RTE_Available (RE_Displace) then return; end if; -- 2.40.0