From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id 080223886C50 for ; Wed, 30 Jun 2021 09:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 080223886C50 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: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3D6F8116D6E for ; Wed, 30 Jun 2021 05:30:46 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com 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 7XZd7nK+2Lpf for ; Wed, 30 Jun 2021 05:30:46 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 2CD09116D3C for ; Wed, 30 Jun 2021 05:30:46 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 2C0401E7; Wed, 30 Jun 2021 05:30:46 -0400 (EDT) Date: Wed, 30 Jun 2021 05:30:46 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix the -gnatyr switch so it works in record rep clauses Message-ID: <20210630093046.GA2247@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Wed, 30 Jun 2021 09:30:52 -0000 --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The -gnatyr switch is supposed to generate a style warning if the case of a usage name does not match that of the defining_identifier it denotes. The warning was missing for component names appearing in record representation clauses; this patch fixes that bug. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch13.adb (Analyze_Record_Representation_Clause): Call Set_Entity_With_Checks instead of Set_Entity, so we perform the check for correct casing. * style.adb (Check_Identifier): Minor comment improvement. Cleanup overly complicated code. --VbJkn9YxBvnuCH5J Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -8561,7 +8561,7 @@ package body Sem_Ch13 is Generate_Reference (Comp, Component_Name (CC), Set_Ref => False); - Set_Entity (Component_Name (CC), Comp); + Set_Entity_With_Checks (Component_Name (CC), Comp); -- Update Fbit and Lbit to the actual bit number diff --git a/gcc/ada/style.adb b/gcc/ada/style.adb --- a/gcc/ada/style.adb +++ b/gcc/ada/style.adb @@ -136,48 +136,42 @@ package body Style is Tref := Source_Text (Get_Source_File_Index (Sref)); Tdef := Source_Text (Get_Source_File_Index (Sdef)); - -- Ignore operator name case completely. This also catches the - -- case of where one is an operator and the other is not. This - -- is a phenomenon from rewriting of operators as functions, - -- and is to be ignored. + -- Ignore case of operator names. This also catches the case + -- where one is an operator and the other is not. This is a + -- phenomenon from rewriting of operators as functions, and is + -- to be ignored. if Tref (Sref) = '"' or else Tdef (Sdef) = '"' then return; else - while Tref (Sref) = Tdef (Sdef) loop + loop + -- If end of identifiers, all done. Note that they are the + -- same length. - -- If end of identifier, all done + pragma Assert + (Identifier_Char (Tref (Sref)) = + Identifier_Char (Tdef (Sdef))); if not Identifier_Char (Tref (Sref)) then return; - - -- Otherwise loop continues - - else - Sref := Sref + 1; - Sdef := Sdef + 1; end if; - end loop; - -- Fall through loop when mismatch between identifiers - -- If either identifier is not terminated, error. + -- Case mismatch - if Identifier_Char (Tref (Sref)) - or else - Identifier_Char (Tdef (Sdef)) - then - Error_Msg_Node_1 := Def; - Error_Msg_Sloc := Sloc (Def); - Error_Msg -- CODEFIX - ("(style) bad casing of & declared#", Sref, Ref); - return; + if Tref (Sref) /= Tdef (Sdef) then + Error_Msg_Node_1 := Def; + Error_Msg_Sloc := Sloc (Def); + Error_Msg -- CODEFIX + ("(style) bad casing of & declared#", Sref, Ref); + return; + end if; - -- Else end of identifiers, and they match + Sref := Sref + 1; + Sdef := Sdef + 1; + end loop; - else - return; - end if; + pragma Assert (False); end if; end if; --VbJkn9YxBvnuCH5J--