From patchwork Thu Jul 8 13:50:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1502300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=gEwMReDE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLHyV2dNvz9sRf for ; Fri, 9 Jul 2021 00:01:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7A47398B89C for ; Thu, 8 Jul 2021 14:01:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 24A32398B88A for ; Thu, 8 Jul 2021 13:50:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24A32398B88A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x12a.google.com with SMTP id x25so3056223lfu.13 for ; Thu, 08 Jul 2021 06:50:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=SNGfDiIpbceQdA1wSUvAqSpQr/e68gGHY/Kh0hR0Xnw=; b=gEwMReDENOPv/+arD8BmfRoDcpd6F4ZcutvVexKN4Gt0TwHJ81MdCRHM0yoMnGeZ7b o1pm5wDelhUl0ubBNELy0b4zC5sqVIl/cocKeypD3rr/J1c+DHYpVRSbbrUufaldHqXa Sj64RlGsfJJKsIsRrdolGGy0+a7petyDoTQmyw9E5BxX4NpHt5H/eYuR+u8ilvlGBRae yfDJXjlKVepfqvlDE/0DomAWlOlOwu1j+ijqm4m5Gc4g0jPVIqm24xpgaYNxGrlfUyEe mThDHgxZxrCYjGVX0F5RfW5d+huXC2UeD1JLND1kSVVgTUx8eEtwpRjzUQqmG2ur6Hmn /4PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=SNGfDiIpbceQdA1wSUvAqSpQr/e68gGHY/Kh0hR0Xnw=; b=mKx1drRGdncX67dKWsPFDhSgrLvvtHNDh9VtJ879iiW9SUCLlWkuKeXPv6bpd82cKa gP18SrW2/2S37v9ewCqAX9M1R00N5+Kg16Xb2ob85+MabOXDqB4uQiyW7kCiMJLI9eel zkTEdj2hX0CZOkGmpmpHtMFLsgXg95puuHk5I40ltaJorq6YWBiheShhyAcJbJO7vdZb PFlLKuKeqTW6QAC4hopoLPPn8fDnX4uV4j8RwUo2xsx/iSnBnjas86SwW/sBiufFc6qr K2fN3kVMUL3uW+1pqcZAI+n+hSnSm7/3264Lc5mIu4P6pbp5UuvF1uwkDslz+j/ZWtiG rfLQ== X-Gm-Message-State: AOAM530NnbE06JVNRdZNNZeRHT8phxnewJDoyrOxNQmtVg28Ox9JCFCe 0kz5CHxSPnb7W/UP/CSTR6kPjCPhc03rhg== X-Google-Smtp-Source: ABdhPJwIJL+K03R0rZDNJy1y3n/KMZCuZ+8KYMbKlmU733KXGi0QLdvVqTj2dzEKNUVIk7qV3bAWbA== X-Received: by 2002:a2e:9845:: with SMTP id e5mr12722639ljj.441.1625752230261; Thu, 08 Jul 2021 06:50:30 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id j26sm98066ljg.91.2021.07.08.06.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 06:50:29 -0700 (PDT) Date: Thu, 8 Jul 2021 13:50:28 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Spurious warning in generic instance Message-ID: <20210708135028.GA2465904@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Arnaud Charlet Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In the case of complex generic instantiations, the warning on component not being present can be spurious (corresponding to dead code for the given instance), so we disable it. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.ads, sem_util.adb (Apply_Compile_Time_Constraint_Error): New parameter Emit_Message. * sem_ch4.adb (Analyze_Selected_Component): Disable warning within an instance. diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -5471,7 +5471,9 @@ package body Sem_Ch4 is Apply_Compile_Time_Constraint_Error (N, "component not present in }??", CE_Discriminant_Check_Failed, - Ent => Prefix_Type); + Ent => Prefix_Type, + Emit_Message => + SPARK_Mode = On or not In_Instance_Not_Visible); return; end if; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1510,13 +1510,14 @@ package body Sem_Util is ----------------------------------------- procedure Apply_Compile_Time_Constraint_Error - (N : Node_Id; - Msg : String; - Reason : RT_Exception_Code; - Ent : Entity_Id := Empty; - Typ : Entity_Id := Empty; - Loc : Source_Ptr := No_Location; - Warn : Boolean := False) + (N : Node_Id; + Msg : String; + Reason : RT_Exception_Code; + Ent : Entity_Id := Empty; + Typ : Entity_Id := Empty; + Loc : Source_Ptr := No_Location; + Warn : Boolean := False; + Emit_Message : Boolean := True) is Stat : constant Boolean := Is_Static_Expression (N); R_Stat : constant Node_Id := @@ -1530,8 +1531,10 @@ package body Sem_Util is Rtyp := Typ; end if; - Discard_Node - (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn)); + if Emit_Message then + Discard_Node + (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn)); + end if; -- Now we replace the node by an N_Raise_Constraint_Error node -- This does not need reanalyzing, so set it as analyzed now. diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -161,13 +161,14 @@ package Sem_Util is -- part of the current package. procedure Apply_Compile_Time_Constraint_Error - (N : Node_Id; - Msg : String; - Reason : RT_Exception_Code; - Ent : Entity_Id := Empty; - Typ : Entity_Id := Empty; - Loc : Source_Ptr := No_Location; - Warn : Boolean := False); + (N : Node_Id; + Msg : String; + Reason : RT_Exception_Code; + Ent : Entity_Id := Empty; + Typ : Entity_Id := Empty; + Loc : Source_Ptr := No_Location; + Warn : Boolean := False; + Emit_Message : Boolean := True); -- N is a subexpression that will raise Constraint_Error when evaluated -- at run time. Msg is a message that explains the reason for raising the -- exception. The last character is ? if the message is always a warning, @@ -189,6 +190,7 @@ package Sem_Util is -- when the caller wants to parameterize whether an error or warning is -- given), or when the message should be treated as a warning even when -- SPARK_Mode is On (which otherwise would force an error). + -- If Emit_Message is False, then do not emit any message. function Async_Readers_Enabled (Id : Entity_Id) return Boolean; -- Id should be the entity of a state abstraction, an object, or a type.