From patchwork Mon Oct 4 14:10:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 66679 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 C46ABB6EE8 for ; Tue, 5 Oct 2010 01:10:18 +1100 (EST) Received: (qmail 8179 invoked by alias); 4 Oct 2010 14:10:11 -0000 Received: (qmail 7538 invoked by uid 22791); 4 Oct 2010 14:10:07 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 14:10:02 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 3D832CB0245; Mon, 4 Oct 2010 16:10:00 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6V-CtZfMKnt1; Mon, 4 Oct 2010 16:10:00 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id 2A491CB0244; Mon, 4 Oct 2010 16:10:00 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 0C621D9BB4; Mon, 4 Oct 2010 16:10:00 +0200 (CEST) Date: Mon, 4 Oct 2010 16:10:00 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Clean up handling of msgs for biasing Message-ID: <20101004141000.GA8229@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes 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 factors code and cleans up the handling of warnings for biased representation. It also removes the useless and wrong attempt to use biased representation in the case of an enumeration rep clause. This attempt never succeeded anyway. The following test shows the new form of the warning messages: 1. package biasname is 2. type b is new integer range 7 .. 8; 3. type r is record 4. c : b; 5. end record; 6. for r use record 7. c at 0 range 0 .. 0; | >>> warning: component clause forces biased representation for "c" 8. end record; 9. type a is array (1 .. 16) of b; 10. for a'component_size use 1; | >>> warning: component size clause forces biased representation for subtype of "b" 11. type p is new integer range 7 .. 8; 12. for p'size use 1; | >>> warning: size clause forces biased representation for "p" 13. end biasname; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-10-04 Robert Dewar * sem_ch13.adb (Set_Biased): New procedure, now used throughout, adds name of entity to biased warning msg. (Analyze_Enumeration_Representation_Clause): Remove attempt to use biased rep (wrong and never worked anyway). Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 164939) +++ sem_ch13.adb (working copy) @@ -106,6 +106,16 @@ package body Sem_Ch13 is -- renaming_as_body. For tagged types, the specification is one of the -- primitive specs. + procedure Set_Biased + (E : Entity_Id; + N : Node_Id; + Msg : String; + Biased : Boolean := True); + -- If Biased is True, sets Has_Biased_Representation flag for E, and + -- outputs a warning message at node N if Warn_On_Biased_Representation is + -- is True. This warning inserts the string Msg to describe the construct + -- causing biasing. + ---------------------------------------------- -- Table for Validate_Unchecked_Conversions -- ---------------------------------------------- @@ -1342,17 +1352,11 @@ package body Sem_Ch13 is Set_Esize (New_Ctyp, Csize); Set_RM_Size (New_Ctyp, Csize); Init_Alignment (New_Ctyp); - Set_Has_Biased_Representation (New_Ctyp, True); Set_Is_Itype (New_Ctyp, True); Set_Associated_Node_For_Itype (New_Ctyp, U_Ent); Set_Component_Type (Btype, New_Ctyp); - - if Warn_On_Biased_Representation then - Error_Msg_N - ("?component size clause forces biased " - & "representation", N); - end if; + Set_Biased (New_Ctyp, N, "component size clause"); end if; Set_Component_Size (Btype, Csize); @@ -1574,12 +1578,7 @@ package body Sem_Ch13 is or else Has_Small_Clause (U_Ent) then Check_Size (Expr, Etyp, Size, Biased); - Set_Has_Biased_Representation (U_Ent, Biased); - - if Biased and Warn_On_Biased_Representation then - Error_Msg_N - ("?size clause forces biased representation", N); - end if; + Set_Biased (U_Ent, N, "size clause", Biased); end if; -- For types set RM_Size and Esize if possible @@ -1953,12 +1952,7 @@ package body Sem_Ch13 is else if Is_Elementary_Type (U_Ent) then Check_Size (Expr, U_Ent, Size, Biased); - Set_Has_Biased_Representation (U_Ent, Biased); - - if Biased and Warn_On_Biased_Representation then - Error_Msg_N - ("?value size clause forces biased representation", N); - end if; + Set_Biased (U_Ent, N, "value size clause", Biased); end if; Set_RM_Size (U_Ent, Size); @@ -2362,7 +2356,8 @@ package body Sem_Ch13 is -- If biasing worked, indicate that we now have biased rep else - Set_Has_Biased_Representation (Enumtype); + Set_Biased + (Enumtype, Size_Clause (Enumtype), "size clause"); end if; end if; @@ -2807,13 +2802,8 @@ package body Sem_Ch13 is Esize (Comp), Biased); - Set_Has_Biased_Representation (Comp, Biased); - - if Biased and Warn_On_Biased_Representation then - Error_Msg_F - ("?component clause forces biased " - & "representation", CC); - end if; + Set_Biased + (Comp, First_Node (CC), "component clause", Biased); if Present (Ocomp) then Set_Component_Clause (Ocomp, CC); @@ -2825,6 +2815,10 @@ package body Sem_Ch13 is Set_Normalized_Position_Max (Ocomp, Normalized_Position (Ocomp)); + -- Note: we don't use Set_Biased here, because we + -- already gave a warning above if needed, and we + -- would get a duplicate for the same name here. + Set_Has_Biased_Representation (Ocomp, Has_Biased_Representation (Comp)); end if; @@ -4856,7 +4850,6 @@ package body Sem_Ch13 is -- cases were already dealt with. elsif Is_Enumeration_Type (T1) then - Enumeration_Case : declare L1, L2 : Entity_Id; @@ -4884,6 +4877,27 @@ package body Sem_Ch13 is end if; end Same_Representation; + ---------------- + -- Set_Biased -- + ---------------- + + procedure Set_Biased + (E : Entity_Id; + N : Node_Id; + Msg : String; + Biased : Boolean := True) + is + begin + if Biased then + Set_Has_Biased_Representation (E); + + if Warn_On_Biased_Representation then + Error_Msg_NE + ("?" & Msg & " forces biased representation for&", N, E); + end if; + end if; + end Set_Biased; + -------------------- -- Set_Enum_Esize -- --------------------