From patchwork Mon Oct 25 15:09:20 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: 46632 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A58B3858424 for ; Mon, 25 Oct 2021 15:22:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A58B3858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635175329; bh=hcgEMBBS2YMOa2fGqg4Ztn7ouHaVPXSyvch7tpAtTco=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=AcrZbG3Pjz8jb76fGkthzMKSGkmJ/SEbyWTt6kTdep+WUpLVGplW3Tlf/B7juYd44 BtXFj9Z73QgzGlQh8WlhSkA+t7nJrW//4mWSPlMUvt/bgtnLSUViMkmIkugHXjxklp YdggIXo03yOnh9LEQ2hBv0wHtURl9sTMUZa3xbUA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id AA2D0385801A for ; Mon, 25 Oct 2021 15:09:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA2D0385801A Received: by mail-lj1-x235.google.com with SMTP id f13so1709359ljo.12 for ; Mon, 25 Oct 2021 08:09:25 -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=hcgEMBBS2YMOa2fGqg4Ztn7ouHaVPXSyvch7tpAtTco=; b=k6hlvoQZDMrrIX6N7oHuP2gY9OmJnXPDHcDgOu0b5VZlAE/DXhr7D8f+8OY36XqrbF 3EwQo1CtOL2nj36dTDiNipz8mY1P4Q0awWwWcXAreN+BgjqSjrzByPQ0OoeBwbJKRpSD e50/H0DVmC/8Vgw08nwMU+LJuhKLKMrT5ZHK/122M9mv3nKsXCgs+SO74iJYwFZOjIKf CvEu1NHj00rU3WD36Jkwux5siu7YIf2nU5alm78DX6vX+GnLeIM4OPxfUsWIR6KWB336 qIU4ILd46BfozYtxR7NwG+pxSmI/i1mDAxWy0BuzdsA3VXnoeFxaPpKnuybnGofTCF8w UJzQ== X-Gm-Message-State: AOAM533lGvMkrY2HWyrEcl5zUx8oeKx0cKsGwjgP1gKdwW0u0JRc8LSu w7Nao0J4KYRVq9Y8UaxM71+Oh/nFIEK1TO0o X-Google-Smtp-Source: ABdhPJxco7Aj6M3SOxjZURy3KS3uOZb8IRPOk/hW/V3F3tdPg3zWO/mTzHJJI4+ApmcENmvNRFSwIw== X-Received: by 2002:a2e:8891:: with SMTP id k17mr19559542lji.503.1635174563231; Mon, 25 Oct 2021 08:09:23 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id r9sm1688126ljk.101.2021.10.25.08.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 08:09:22 -0700 (PDT) Date: Mon, 25 Oct 2021 15:09:20 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Make Declaration_Node return nondeclarations in fewer cases Message-ID: <20211025150920.GA346653@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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 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: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Bob Duff Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch changes Declaration_Node to avoid returning certain strange node kinds. We don't avoid them all (in particular N_Null_Statement), but we document what it's returning with a pragma Assert. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * einfo-utils.adb (Declaration_Node): Avoid returning the following node kinds: N_Assignment_Statement, N_Integer_Literal, N_Procedure_Call_Statement, N_Subtype_Indication, and N_Type_Conversion. Assert that the result is in N_Is_Decl or empty. * gen_il-gen-gen_nodes.adb (N_Is_Decl): Modify to match the things that Declaration_Node can return. diff --git a/gcc/ada/einfo-utils.adb b/gcc/ada/einfo-utils.adb --- a/gcc/ada/einfo-utils.adb +++ b/gcc/ada/einfo-utils.adb @@ -698,6 +698,30 @@ package body Einfo.Utils is P := Empty; end if; + -- Declarations are sometimes removed by replacing them with other + -- irrelevant nodes. For example, a declare expression can be turned + -- into a literal by constant folding. In these cases we want to + -- return Empty. + + if Nkind (P) in + N_Assignment_Statement + | N_Integer_Literal + | N_Procedure_Call_Statement + | N_Subtype_Indication + | N_Type_Conversion + then + P := Empty; + end if; + + -- The following Assert indicates what kinds of nodes can be returned; + -- they are not all "declarations". + + if Serious_Errors_Detected = 0 then + pragma Assert + (Nkind (P) in N_Is_Decl | N_Empty, + "Declaration_Node incorrect kind: " & Node_Kind'Image (Nkind (P))); + end if; + return P; end Declaration_Node; diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb --- a/gcc/ada/gen_il-gen-gen_nodes.adb +++ b/gcc/ada/gen_il-gen-gen_nodes.adb @@ -1675,16 +1675,29 @@ begin -- Gen_IL.Gen.Gen_Nodes Union (N_Is_Decl, Children => - (N_Declaration, + (N_Aggregate, + N_Block_Statement, + N_Declaration, N_Discriminant_Specification, + N_Entry_Index_Specification, N_Enumeration_Type_Definition, N_Exception_Handler, + N_Explicit_Dereference, + N_Expression_With_Actions, + N_Extension_Aggregate, + N_Identifier, + N_Iterated_Component_Association, N_Later_Decl_Item, + N_Loop_Statement, + N_Null_Statement, + N_Number_Declaration, N_Package_Specification, N_Parameter_Specification, N_Renaming_Declaration, - N_Subprogram_Specification)); - -- Nodes that can be returned by Declaration_Node + N_Quantified_Expression)); + -- Nodes that can be returned by Declaration_Node; it can also return + -- Empty. Not all of these are true "declarations", but Declaration_Node + -- can return them in some cases. Union (N_Is_Range, Children =>