From patchwork Tue May 23 08:08:45 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: 97897 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1983628vqo; Tue, 23 May 2023 01:34:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ672nRN+SLfq6/WcRe13vRXKlGs6GCqqKHyJJViG6sD37FoA1X92nnQStMWakwzm5RYXPJw X-Received: by 2002:a17:907:a01:b0:94f:395b:df1b with SMTP id bb1-20020a1709070a0100b0094f395bdf1bmr11275077ejc.21.1684830896216; Tue, 23 May 2023 01:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684830896; cv=none; d=google.com; s=arc-20160816; b=pPX1k9A/wSDc8byT71LHINoFNtFWFht0kkwIuFLDPwwKHH9wMc4KcXM+CLhfPIzhAz sP90ilBZ4fx9X+K+UtvX5oOdUcwn48U9IPNnOlZrjGuuyXjpKHRV5zaP3p3zr5wMvng6 H2lG5tvulr1GXyeUm+ie0FrD0Gh4GGPGdpSpBc4K6X25X6hRn+zl986gInMg0wggtw0n CbALyB9jHs6MUqNKgqpzhSx9/rDiylxzE9f35NEVZ3dzTcMmdnoqTsRcRHxik2rXAC63 CS8f2A/ViJkBToMIvoRdMQR1n2FRzWdxJn4noQwD6q/w+IKNahngzZD+okIiAGisPcWh WBtw== 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=prMeLTxqQ55miwf2QeSTGZ0nxL/NPvJRzuAZZL23JXU=; b=N2xyLO4fwSs8pbMRknguG8vvvxGQGSPbEffsmdpjUXeEl24PD6yzuIRaVagKPPUprP NcVwkxVkia5gM+MSdXCaWenEkILK5sMiv7W3V+59uKbpHbUfH2taoR8UVXNL0sRgycn+ 1TqPLW4/LgUsWrBXc+ds9lHJ+XbFwCr9Hyu74QtGp7c7PMwGqreJjX/XTwikkzrooreA 5jZStsBpKNxdjE3vvr4YJsC+NwCOsNuT3BRvcGnKAacArLEvZkaAU7Yhb7c8t3C0yQCN 1T2CxpsoXKGYp7GFda9RCMDpA9VqCU3jkzCFriDRnEaNNla2Fea1jdBkcQeE+Cfy8caH VU+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ZsnZM2kh; 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 gi33-20020a1709070ca100b009538b4dacc8si1019742ejc.541.2023.05.23.01.34.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:34:56 -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=ZsnZM2kh; 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 740D2395C046 for ; Tue, 23 May 2023 08:23:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 740D2395C046 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684830193; bh=prMeLTxqQ55miwf2QeSTGZ0nxL/NPvJRzuAZZL23JXU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZsnZM2khLsFJtqgY+SeSvmChHjoeyM0JOPiZHQIy9FSzOyBqTb3F3JwXjfX++wbSh zlTmtqjUEP87l9L8gtqCd13Nlq4XqpJV8EZ0nMXxfS/PJhuvEjLZbBEFNB/dhwPMf+ Ab1UN8w30T+A3JvNp/Ijxz3anRmIyS0DiIKSPJ/I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 1D7D53857709 for ; Tue, 23 May 2023 08:08:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D7D53857709 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f41d087b3bso71187765e9.0 for ; Tue, 23 May 2023 01:08:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829326; x=1687421326; 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=prMeLTxqQ55miwf2QeSTGZ0nxL/NPvJRzuAZZL23JXU=; b=iSnE5y3wy6wnIN8Fcf8z0ty0kvwfzdoFeiXfgx1vOqwYjv7ueBP1pXBkqnedB6tcUu g6QssR8g1I7EiUwpCx0H6Jif4gLGgpYPYdPArcTnceLS/ZxXCffBCTzAkECjcCkjc5Ic XrEhaBcO8Q/wK/MHVodh5XYgjKOX0mkkP9p3bwXxq3OzGTOvrzTxIM+qniF6O6vx9hVN Exs3SF115bxbfRNnxTMhFmpPe7y9tRfwPUa9lawW/vg2mjjyDngeBeumN1+C9nIObQNW wbHTgbyB6ospYCXK6P9bhMCKAmLaWZ3nrDZNaQqORt7ITuz3cpcaJ1VFTrSVw3iZOH+e Carw== X-Gm-Message-State: AC+VfDx0w0sFZ3nKxjp2ydkL+ygiJbcaL6FVqm4XldXc095hcIKXs6rh QhHHXDU0e/Bb5JWz7foxoptxcO7FNDnu3U+6I/CIew== X-Received: by 2002:a7b:cb91:0:b0:3f6:1a9:b9db with SMTP id m17-20020a7bcb91000000b003f601a9b9dbmr5589089wmi.21.1684829326617; Tue, 23 May 2023 01:08:46 -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 f21-20020a1c6a15000000b003f601a31ca2sm8320923wmc.33.2023.05.23.01.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix resolution of mod operator of System.Storage_Elements Date: Tue, 23 May 2023 10:08:45 +0200 Message-Id: <20230523080845.1874226-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?1766673242158624377?= X-GMAIL-MSGID: =?utf-8?q?1766673242158624377?= From: Eric Botcazou This operator is special because the left operand is of Address type while the right operand and the result are of Storage_Offset type (but we raise Constraint_Error if the right operand is not positive) and it needs to be resolved to the type of the left operand to implement the correct semantics. gcc/ada/ * exp_ch4.adb (Expand_N_Op_Mod): Adjust the detection of the special operator of System.Storage_Elements. Do not rewrite it into a rem. * sem_res.adb (Resolve_Intrinsic_Operator): Use the base type of the left operand for the special mod operator of System.Storage_Elements Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 11 +++++++---- gcc/ada/sem_res.adb | 23 +++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index c974a9e8d44..c7727904df2 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -9561,9 +9561,10 @@ package body Exp_Ch4 is DDC : constant Boolean := Do_Division_Check (N); Is_Stoele_Mod : constant Boolean := - Is_RTE (First_Subtype (Typ), RE_Storage_Offset) - and then Nkind (Left_Opnd (N)) = N_Unchecked_Type_Conversion - and then Is_RTE (Etype (Expression (Left_Opnd (N))), RE_Address); + Is_RTE (Typ, RE_Address) + and then Nkind (Right_Opnd (N)) = N_Unchecked_Type_Conversion + and then + Is_RTE (Etype (Expression (Right_Opnd (N))), RE_Storage_Offset); -- True if this is the special mod operator of System.Storage_Elements Left : Node_Id; @@ -9633,6 +9634,7 @@ package body Exp_Ch4 is and then ((Llo >= 0 and then Rlo >= 0) or else (Lhi <= 0 and then Rhi <= 0)) + and then not Is_Stoele_Mod then Rewrite (N, Make_Op_Rem (Sloc (N), @@ -9683,7 +9685,8 @@ package body Exp_Ch4 is Make_Raise_Constraint_Error (Loc, Condition => Make_Op_Le (Loc, - Left_Opnd => Duplicate_Subexpr_No_Checks (Right), + Left_Opnd => + Duplicate_Subexpr_No_Checks (Expression (Right)), Right_Opnd => Make_Integer_Literal (Loc, 0)), Reason => CE_Overflow_Check_Failed)); return; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index a99bed00118..f1d9a97452a 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -9710,10 +9710,19 @@ package body Sem_Res is -------------------------------- procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is - Btyp : constant Entity_Id := Implementation_Base_Type (Typ); - Op : Entity_Id; - Arg1 : Node_Id; - Arg2 : Node_Id; + Is_Stoele_Mod : constant Boolean := + Nkind (N) = N_Op_Mod + and then Is_RTE (First_Subtype (Typ), RE_Storage_Offset) + and then Is_RTE (Etype (Left_Opnd (N)), RE_Address); + -- True if this is the special mod operator of System.Storage_Elements, + -- which needs to be resolved to the type of the left operand in order + -- to implement the correct semantics. + + Btyp : constant Entity_Id := + (if Is_Stoele_Mod + then Implementation_Base_Type (Etype (Left_Opnd (N))) + else Implementation_Base_Type (Typ)); + -- The base type to be used for the operator function Convert_Operand (Opnd : Node_Id) return Node_Id; -- If the operand is a literal, it cannot be the expression in a @@ -9742,6 +9751,12 @@ package body Sem_Res is return Res; end Convert_Operand; + -- Local variables + + Arg1 : Node_Id; + Arg2 : Node_Id; + Op : Entity_Id; + -- Start of processing for Resolve_Intrinsic_Operator begin