From patchwork Tue May 23 08:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 97896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1983101vqo; Tue, 23 May 2023 01:33:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OpHhm31MBIBVwXJi5IQa+vsfKisoN7g8kCNNzAtzpHMn0eCao41B+DOfPTeKL5W9mYqqI X-Received: by 2002:a17:906:9c82:b0:96a:a0fd:d43e with SMTP id fj2-20020a1709069c8200b0096aa0fdd43emr12475937ejc.49.1684830829186; Tue, 23 May 2023 01:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684830829; cv=none; d=google.com; s=arc-20160816; b=mcAako6dJMZd58gEHBiy/ebpEArkvQqmPCYTGupsD2/HcPcVD3RsMZcDcebv3M8Hk0 2hUlbHHv87KqW6vn0rR3sZ069/lQwTHJUKUjEtK7nROQI8lF4pdpcSJ/jw94rNJYf1sC l/uqWdeLdqbJxtuSW3EeYL86WnCjBsQKz5fdHIw7KrnoyoeOqzOZtR+RvBKAeoetdF5Q v3RACixngFMk9BqDCcetaYH46huZDg8F5i7BzbQWwLyUFJfWHDkmXHrgSVUV2Sd5XM8h sj5Iw4+URza4LZamgY21EoJktUa8C1jdXRnqJYvxN9jxsOjLaQd6QkXfslkchoqWZXWh zMzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UCFaSjDc+miNAF/ujB5V7exL4byDrVoIwH34CyZwIf0=; b=ZyvwrlCizCS+gvIRfcywodpZiqtd+rSetDg0VKsOwTdf0YUte8ldV2HVwdYBoQDG4O RtvKzQcoc664bnyWdme3l5jXzx+zo+XC8DE/C2fCRsJu5/ow5RPxzpx97CgOihgn2Uz8 rzbdpb3YOuvQwqOHBfar8umkPVzNjwOPhojb2VUq5AYTPRgUnZHDkXylKmL3ZIsmwwhm RcBgE5wikPjnVkc4nYh+k8edQTstWdLV/ITs1NPTP6A/qOLRtwqn1SRzvQ9tvxBkAAQS iZCX7AGjJweg7ZBPYKhIjeasLzGOhpQE/tQw/S0S2P37WRzrYZLIXJKna2YzmzJpMQ1D 2WPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gs2gN7E7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m6-20020a1709066d0600b00969dff1f6d3si4101638ejr.539.2023.05.23.01.33.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:33:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Gs2gN7E7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45844382AD88 for ; Tue, 23 May 2023 08:22:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45844382AD88 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684830123; bh=UCFaSjDc+miNAF/ujB5V7exL4byDrVoIwH34CyZwIf0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Gs2gN7E7Sa75nDyX6F21ELHuJRz2feb+w2N8ediAuHK+JDfaFvjO1EofcXdLWSad2 kh7s5T77aQVi+HhbyjBocXWKZk0o8SsPhyS90VdBeAZIRWLnx5ZdE76KS6Kw/XxAH/ rsXF/crC3lW36RhyC9q283cnutwWMTtNULn8PpW4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 42FC2388215A for ; Tue, 23 May 2023 08:08:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 42FC2388215A Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-30a95ec7744so1525952f8f.3 for ; Tue, 23 May 2023 01:08:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829320; x=1687421320; 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=UCFaSjDc+miNAF/ujB5V7exL4byDrVoIwH34CyZwIf0=; b=VT+idYj961PaMJ9SawxLFnGbNIP0R8Hf+hUs4Unxk/6Gpx2V/PJFYYGZpPFbs9TB77 HDTDQyvy+kjWcj/epNteEu/RtqzjJ3QVhko2yXPl+x0SdZJQ9G1mqH8ZvzkMHlE51ATm FQMlYTucAp8uYC8AgCJu5bkpcScYyFFO29sJF9FTQjaq7zaBG3JKxrcwYAdCvUnIOUH6 2Qr57skTbbgWHuxPiCLlXnMpPMV+RsI4owIYUYhcNOlMzqKyffScT5TGoBtruruUQQTz HJXTCHbB0nIOQFSmHOBaTU61MZU7U9MjgXNdLWX9qTd8bBO5mW3lm+6QZKH0gOsZKUx3 94YA== X-Gm-Message-State: AC+VfDyApq1nTBEOe0ErlMg6KGryafKng8eR5u1cf0pJt6c927fYy6PP jgYs+IRqCnTL4swgWzooEhP5bxxh72mVzD52qgEVwg== X-Received: by 2002:adf:e9c1:0:b0:309:4f39:de4b with SMTP id l1-20020adfe9c1000000b003094f39de4bmr10166375wrn.12.1684829320017; Tue, 23 May 2023 01:08:40 -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 b10-20020adfde0a000000b003021288a56dsm10294410wrm.115.2023.05.23.01.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix address arithmetic issues in the expanded code Date: Tue, 23 May 2023 10:08:38 +0200 Message-Id: <20230523080838.1874043-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766673171616203251?= X-GMAIL-MSGID: =?utf-8?q?1766673171616203251?= From: Eric Botcazou This is most notably the addition of addresses in Expand_Interface_Thunk. There is also a small change to Expand_Dispatching_Call, which was directly accessing a class-wide interface object as a tag, thus giving rise later to unchecked conversions between either the root or the equivalent record type and access types. gcc/ada/ * exp_disp.adb (Expand_Dispatching_Call): In the abstract interface class-wide case, use 'Tag of the object as the controlling tag. (Expand_Interface_Thunk): Perform address arithmetic using operators of System.Storage_Elements. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_disp.adb | 69 ++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/gcc/ada/exp_disp.adb b/gcc/ada/exp_disp.adb index 1fb15fb7b02..e7cae38d553 100644 --- a/gcc/ada/exp_disp.adb +++ b/gcc/ada/exp_disp.adb @@ -1040,10 +1040,11 @@ package body Exp_Disp is -- Ada 2005 (AI-251): Abstract interface class-wide type - elsif Is_Interface (Ctrl_Typ) - and then Is_Class_Wide_Type (Ctrl_Typ) - then - Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg); + elsif Is_Interface (Ctrl_Typ) and then Is_Class_Wide_Type (Ctrl_Typ) then + Controlling_Tag := + Make_Attribute_Reference (Loc, + Prefix => Duplicate_Subexpr (Ctrl_Arg), + Attribute_Name => Name_Tag); elsif Is_Access_Type (Ctrl_Typ) then Controlling_Tag := @@ -2030,8 +2031,8 @@ package body Exp_Disp is then -- Generate: -- type T is access all <> - -- S : Storage_Offset := Storage_Offset!(Formal) - -- + Offset_To_Top (address!(Formal)) + -- S : constant Address := Address!(Formal) + -- + Offset_To_Top (Address!(Formal)) Decl_2 := Make_Full_Type_Declaration (Loc, @@ -2063,16 +2064,20 @@ package body Exp_Disp is Defining_Identifier => Make_Temporary (Loc, 'S'), Constant_Present => True, Object_Definition => - New_Occurrence_Of (RTE (RE_Storage_Offset), Loc), + New_Occurrence_Of (RTE (RE_Address), Loc), Expression => - Make_Op_Add (Loc, - Left_Opnd => - Unchecked_Convert_To - (RTE (RE_Storage_Offset), - New_Occurrence_Of - (Defining_Identifier (Formal), Loc)), - Right_Opnd => - Offset_To_Top)); + Make_Function_Call (Loc, + Name => + Make_Expanded_Name (Loc, + Chars => Name_Op_Add, + Prefix => + New_Occurrence_Of + (RTU_Entity (System_Storage_Elements), Loc), + Selector_Name => + Make_Identifier (Loc, Name_Op_Add)), + Parameter_Associations => New_List ( + New_Copy_Tree (New_Arg), + Offset_To_Top))); Append_To (Decl, Decl_2); Append_To (Decl, Decl_1); @@ -2088,16 +2093,15 @@ package body Exp_Disp is elsif Is_Controlling_Formal (Target_Formal) then -- Generate: - -- S1 : Storage_Offset := Storage_Offset!(Formal'Address) - -- + Offset_To_Top (Formal'Address) - -- S2 : Addr_Ptr := Addr_Ptr!(S1) + -- S1 : constant Address := Formal'Address + -- + Offset_To_Top (Formal'Address) + -- S2 : constant Addr_Ptr := Addr_Ptr!(S1) New_Arg := Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Defining_Identifier (Formal), Loc), - Attribute_Name => - Name_Address); + Attribute_Name => Name_Address); if not RTE_Available (RE_Offset_To_Top) then Offset_To_Top := @@ -2114,19 +2118,20 @@ package body Exp_Disp is Defining_Identifier => Make_Temporary (Loc, 'S'), Constant_Present => True, Object_Definition => - New_Occurrence_Of (RTE (RE_Storage_Offset), Loc), + New_Occurrence_Of (RTE (RE_Address), Loc), Expression => - Make_Op_Add (Loc, - Left_Opnd => - Unchecked_Convert_To - (RTE (RE_Storage_Offset), - Make_Attribute_Reference (Loc, - Prefix => - New_Occurrence_Of - (Defining_Identifier (Formal), Loc), - Attribute_Name => Name_Address)), - Right_Opnd => - Offset_To_Top)); + Make_Function_Call (Loc, + Name => + Make_Expanded_Name (Loc, + Chars => Name_Op_Add, + Prefix => + New_Occurrence_Of + (RTU_Entity (System_Storage_Elements), Loc), + Selector_Name => + Make_Identifier (Loc, Name_Op_Add)), + Parameter_Associations => New_List ( + New_Copy_Tree (New_Arg), + Offset_To_Top))); Decl_2 := Make_Object_Declaration (Loc,