From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id D238F385DC09 for ; Mon, 4 Jul 2022 07:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D238F385DC09 Received: by mail-ej1-x62c.google.com with SMTP id fw3so15209403ejc.10 for ; Mon, 04 Jul 2022 00:50:11 -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=dvwfWVKpXiGzc0vZ+sRsBFXgnC4M5GHmsslFg+bUmGs=; b=YYF2bhO7mDdlilFQ+x7rdSwdLiYOlyubMXT+4IJIeSF/OKV5nO05BrM2jPyH96T6bJ oxBuzSq7prpKcytzMaVv2VAGcEHCRrxfPKIzU1pBW53KimlXN7qshkaEUxUbSn10t7vS dIIv8IEAwOBCOs0j3Cv9UPw3d/hjJLrRmMmFTuQxF1s3u3dyPFbwwJmcpYX1acO7sFpL Dq8hNV2n08svtMjZbfRj1oy5Fum1/6Pt8bk6nBMCghefiICq/tihAKUXYYMR/1RtT+Ej I5eInpPW6bEbYG5/yAYHya3FIl0t9RXn+i0+w9f92VaD2Qr0LwPO0g38oH+2cSDbbQC6 1heQ== X-Gm-Message-State: AJIora9leQYntZdojVAkL10Em+EjG2y7K8OPrzHJaJIDENajzZYG3YWM cUKnWcheao1lh7Rm4gvqWoKG01hVxwXWpA== X-Google-Smtp-Source: AGRyM1tfp2954qHPFoxjruhnF4lbz61WhVeoehRDT09cFItbGAjKIkcwIUUy949fdwGY9frNt7C3yg== X-Received: by 2002:a17:906:f284:b0:726:efe5:b8f2 with SMTP id gu4-20020a170906f28400b00726efe5b8f2mr28003762ejb.647.1656921010586; Mon, 04 Jul 2022 00:50:10 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id o7-20020a170906860700b00722d5f07864sm13670567ejx.225.2022.07.04.00.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:10 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:09 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Give missing error on ambiguous operand of equality operator Message-ID: <20220704075009.GA99061@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" 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: Mon, 04 Jul 2022 07:50:13 -0000 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline When the code responsible for giving errors on ambiguous operands of comparison and equality operators was moved from the 1st phase (analysis) to the 2nd phase (resolution) of semantic processing, it was incorrectly restricted to the operator case, which was valid during the 1st phase but is not during the 2nd phase. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_res.adb (Resolve_Comparison_Op): Deal with ambiguous operands in all cases. (Resolve_Equality_Op): Likewise, except for the case of the implicit inequality operator created for a user-defined operator that is not an intrinsic subprogram. --cNdxnHkX5QqsyA0e Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -7539,9 +7539,7 @@ package body Sem_Res is if T = Any_Type then -- Deal with explicit ambiguity of operands - if Ekind (Entity (N)) = E_Operator - and then (Is_Overloaded (L) or else Is_Overloaded (R)) - then + if Is_Overloaded (L) or else Is_Overloaded (R) then Ambiguous_Operands (N); end if; @@ -8563,6 +8561,16 @@ package body Sem_Res is L : constant Node_Id := Left_Opnd (N); R : constant Node_Id := Right_Opnd (N); + Implicit_NE_For_User_Defined_Operator : constant Boolean := + Nkind (N) = N_Op_Ne + and then Ekind (Entity (N)) = E_Function + and then not Comes_From_Source (Entity (N)) + and then not + Is_Intrinsic_Subprogram (Corresponding_Equality (Entity (N))); + -- Whether this is a call to the implicit inequality operator created + -- for a user-defined operator that is not an intrinsic subprogram, in + -- which case we need to skip some processing. + T : Entity_Id := Find_Unique_Type (L, R); procedure Check_Access_Attribute (N : Node_Id); @@ -8833,9 +8841,12 @@ package body Sem_Res is Generate_Reference (T, N, ' '); if T = Any_Type then - -- Deal with explicit ambiguity of operands + -- Deal with explicit ambiguity of operands, unless this is a call + -- to the implicit inequality operator created for a user-defined + -- operator that is not an intrinsic subprogram, since the common + -- resolution of operands done here does not apply to it. - if Ekind (Entity (N)) = E_Operator + if not Implicit_NE_For_User_Defined_Operator and then (Is_Overloaded (L) or else Is_Overloaded (R)) then Ambiguous_Operands (N); @@ -9009,17 +9020,11 @@ package body Sem_Res is Generate_Operator_Reference (N, T); Check_Low_Bound_Tested (N); - -- If this is an inequality, it may be the implicit inequality - -- created for a user-defined operation, in which case the corres- - -- ponding equality operation is not intrinsic, and the operation - -- cannot be constant-folded. Else fold. + -- Unless this is a call to the implicit inequality operator created + -- for a user-defined operator that is not an intrinsic subprogram, + -- try to fold the operation. - if Nkind (N) = N_Op_Eq - or else Comes_From_Source (Entity (N)) - or else Ekind (Entity (N)) = E_Operator - or else - Is_Intrinsic_Subprogram (Corresponding_Equality (Entity (N))) - then + if not Implicit_NE_For_User_Defined_Operator then Analyze_Dimension (N); Eval_Relational_Op (N); --cNdxnHkX5QqsyA0e--