From patchwork Thu Sep 15 10:23:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 114774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 03279B6F81 for ; Thu, 15 Sep 2011 20:23:25 +1000 (EST) Received: (qmail 14102 invoked by alias); 15 Sep 2011 10:23:21 -0000 Received: (qmail 14094 invoked by uid 22791); 15 Sep 2011 10:23:20 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Sep 2011 10:23:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5B9072BAE91; Thu, 15 Sep 2011 06:23:03 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id V1-HcnsF6EuI; Thu, 15 Sep 2011 06:23:03 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 325932BADC1; Thu, 15 Sep 2011 06:23:03 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 18DF992BF6; Thu, 15 Sep 2011 06:23:03 -0400 (EDT) Date: Thu, 15 Sep 2011 06:23:02 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Warnings on unused formals of expression functions Message-ID: <20110915102302.GA15455@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch simplifies the expansion of expression functions, and ensures that proper warnings are generated for unused formals, if present. The following compilation: gcc -c -gnat12 -gnatwa -gnatc ada12.ads must yield: ada12.ads:6:24: warning: formal parameter "Self" is not referenced ada12.ads:9:35: warning: formal parameter "Self" is not referenced --- package Ada12 is type T is tagged record Value : Integer := 17; end record; function Template (Self : T) return String is ("foo.thtml"); type T2 is new T with null record; overriding function Template (Self : T2) return String is ("bar.thtml"); end Ada12; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-09-15 Ed Schonberg * sem_ch6.adb (Analyze_Expression_Function): Code cleanup: if the expression function is not a completion, create a new specification for the generated declaration, and keep the original specification in the generated body. Shorter code also ensures that proper warnings are generated for unused formals in all cases. Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 178876) +++ sem_ch6.adb (working copy) @@ -268,6 +268,7 @@ Loc : constant Source_Ptr := Sloc (N); LocX : constant Source_Ptr := Sloc (Expression (N)); Def_Id : constant Entity_Id := Defining_Entity (Specification (N)); + Expr : constant Node_Id := Expression (N); New_Body : Node_Id; New_Decl : Node_Id; @@ -315,31 +316,28 @@ Set_Is_Inlined (Prev); Analyze (N); - -- If this is not a completion, create both a declaration and a body, - -- so that the expression can be inlined whenever possible. + -- If this is not a completion, create both a declaration and a body, so + -- that the expression can be inlined whenever possible. The spec of the + -- new subprogram declaration is a copy of the original specification, + -- which is now part of the subprogram body. else New_Decl := Make_Subprogram_Declaration (Loc, - Specification => Specification (N)); + Specification => Copy_Separate_Tree (Specification (N))); Rewrite (N, New_Decl); Analyze (N); Set_Is_Inlined (Defining_Entity (New_Decl)); - -- Create new set of formals for specification in body. - - Set_Specification (New_Body, - Make_Function_Specification (Loc, - Defining_Unit_Name => - Make_Defining_Identifier (Loc, Chars (Defining_Entity (N))), - Parameter_Specifications => - Copy_Parameter_List (Defining_Entity (New_Decl)), - Result_Definition => - New_Copy_Tree (Result_Definition (Specification (New_Decl))))); - Insert_After (N, New_Body); Analyze (New_Body); end if; + + -- If the return expression is a static constant, we suppress warning + -- messages on unused formals, which in most cases will be noise. + + Set_Is_Trivial_Subprogram (Defining_Entity (New_Body), + Is_OK_Static_Expression (Expr)); end Analyze_Expression_Function; ----------------------------------------