From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-x332.google.com with SMTP id 5b1f17b1804b1-3f41d087b3bso71187765e9.0 for ; Tue, 23 May 2023 01:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684829326; x=1687421326; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=prMeLTxqQ55miwf2QeSTGZ0nxL/NPvJRzuAZZL23JXU=; b=XU2dfEEPtacJrtJ7Koz0U/BUp7j7ZQTDuYwTXX+HnIcSljg7dKW1YFsRHBUECYW5pA iclRzLYK1Vs3WC3S7O5gyIW4aaS1AIEyKwhmlXt2nGfhPyqTSMJRCHxIWOpJTPO7b663 81C6GS1ugTP3kbr+mX7TUoAGa/Jo8uNmbvGi0O3kSOZxaFyLMa7b0TVzfiFYZfsbFuI7 c4B2j56TgoU38PHqrzI6A4Qw6xVyuHX3wto8x4HnycMrijchfRD4/qsG+WXBTrt5fzqT ptCTfXc5iq3hi0KHG9PrXQmJKe+j7sxXFILSjNbY7a8sgGwbejWgfOpEqe3aTUQbCEq7 xPWQ== 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-Google-Smtp-Source: ACHHUZ7swZJOzZYu53gI9DqS3t6s3nsHT8mxy0If6LG4GWUegsMql4qS0qffSU6uftr7fZOZJvUCCA== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.40.0