From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 47BDF385B503 for ; Tue, 23 May 2023 08:08:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47BDF385B503 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f427118644so69781525e9.0 for ; Tue, 23 May 2023 01:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684829303; x=1687421303; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PW9bGq9muiHH9Dtyuj9kE1qPlNk6CP0ypKpsIhJl0G0=; b=kyHs+vJSUksGyLTtN14hD2Ep00jL8vNQ9qSFlJ0VjZshYxQogyAEzl1/1vHV9hus5Q scK+oS7tKzS1smnl6/tBiOIcKpCLWxjST8Pt5Mkdi2Ukl/6I0fKWAYHrVPNOM3iRHhEB t2OtZrnUSon38I/BbaitVvPjOrShN+x6ZSAapXKJJ2INElvDfkyYoFklaU+w2WdPCnA9 jAmKOnJGZCT+av7CfpMhZ2PGCptIi77exw2GvlWB7DayAJaqQ8nBHiK1/+e27lGz4S7v m/q5mgBYYfyvkw/3KxCXlmebNv7ABmkm8iNq5UijbSAuBqo4+BbkS3iO+q54luiWCFuR W4bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829303; x=1687421303; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PW9bGq9muiHH9Dtyuj9kE1qPlNk6CP0ypKpsIhJl0G0=; b=ebfvH7iHl7DootGY39kGB2+vZ6rpq91zC+p0Ireao1eBYeX3fPnSLfqX8ueX4bbpts nXHf/gEYq8lDJPdWwD/ioZvOtLNJL+Cok4LtfKG29CoFl0YTX/be2lLhcw8Pd1uGPHBQ a0N3ZFCB50kqqBdVxq83SPC0NfTDvs/hmiGNNQb3H/SfH6ST53z2v7q0D0DxHORpECiW kWhSo9Al8TH8Igu3symfx1DlmVdHNB8vcirth2z7gXWLeIaVVbD7au9QfKvtrcnrxfaX lWYS+LxZc/ShS2kRFNHkC8v0Mtnot4/XRO5e8CrxheMS28jwTGgYPIB5AdgpYweNf0AC hWpA== X-Gm-Message-State: AC+VfDwX+5HxL8KfNiW43RjG3hrnuB/ALZ247HXUyKQEmSTFts3nQ//k 9Fjj1owwVe5tvT2+q5Xi2iSJ8r/rlxEs46zyPmH1bg== X-Google-Smtp-Source: ACHHUZ49yJ7XDZO/qd8HBWMwh2IQW3TbB3VIUvx+arPhKI5XsDFeBhMZBYaAWbu7S7r+jzmsr3CQlQ== X-Received: by 2002:a1c:f217:0:b0:3f4:2c71:b9ad with SMTP id s23-20020a1cf217000000b003f42c71b9admr9592180wmc.30.1684829302908; Tue, 23 May 2023 01:08:22 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id n11-20020a5d484b000000b00307c0afc030sm10390514wrs.4.2023.05.23.01.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:22 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Turn assertions into defensive code in error locations Date: Tue, 23 May 2023 10:08:21 +0200 Message-Id: <20230523080821.1873611-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.6 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Piotr Trojanek We pretty-print numeric literals that do not come from source by relying on their Sloc. This generally works well, but sporadically the Sloc is set wrongly. We might want to trace and fix such occurrences, but for now it is simpler to replace an otherwise reasonable assertions with defensive code. gcc/ada/ * errout.adb (Last_Sloc): Refactor a heavily repeated "S := S + 1" statement into a subprogram; replace assertions with defensive code; fix few more off-by-one errors. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/errout.adb | 89 +++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 6531410f0d2..1c6222b3a29 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -1994,6 +1994,20 @@ package body Errout is --------------- function Last_Sloc (N : Node_Id) return Source_Ptr is + procedure Skip_Char (S : in out Source_Ptr); + -- Skip one character of the source buffer at location S + + --------------- + -- Skip_Char -- + --------------- + + procedure Skip_Char (S : in out Source_Ptr) is + begin + S := S + 1; + end Skip_Char; + + -- Local variables + SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N)); SF : constant Source_Ptr := Source_First (SI); SL : constant Source_Ptr := Source_Last (SI); @@ -2001,6 +2015,8 @@ package body Errout is F : Node_Id; S : Source_Ptr; + -- Start of processing for Last_Sloc + begin F := Last_Node (N); S := Sloc (F); @@ -2035,7 +2051,7 @@ package body Errout is while S < SL and then Src (S + 1) in '0' .. '9' | '_' loop - S := S + 1; + Skip_Char (S); end loop; -- Skip past #based_numeral#, if present @@ -2043,30 +2059,36 @@ package body Errout is if S < SL and then Src (S + 1) = '#' then - S := S + 1; + Skip_Char (S); while S < SL and then Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' loop - S := S + 1; + Skip_Char (S); end loop; - pragma Assert (S < SL and then Src (S + 1) = '#'); - - S := S + 1; + if S < SL + and then Src (S + 1) = '#' + then + Skip_Char (S); + end if; end if; -- Skip past exponent, if present - if S < SL + 1 + if S < SL and then Src (S + 1) in 'e' | 'E' then + Skip_Char (S); + -- For positive exponents the plus sign is optional, but we -- can simply skip past both plus and minus. - if Src (S + 2) in '+' | '-' then - S := S + 1; + if S < SL + and then Src (S + 1) in '+' | '-' + then + Skip_Char (S); end if; -- Skip past the numeral part @@ -2074,7 +2096,7 @@ package body Errout is while S < SL and then Src (S + 1) in '0' .. '9' | '_' loop - S := S + 1; + Skip_Char (S); end loop; end if; @@ -2085,55 +2107,66 @@ package body Errout is while S < SL and then Src (S + 1) in '0' .. '9' | '_' loop - S := S + 1; + Skip_Char (S); end loop; if S < SL then + + -- Skip the dot and continue with a decimal literal + if Src (S + 1) = '.' then + Skip_Char (S); + while S < SL and then Src (S + 1) in '0' .. '9' | '_' loop - S := S + 1; + Skip_Char (S); end loop; - else - pragma Assert (Src (S + 1) = '#'); - S := S + 1; + -- Skip the hash and continue with a based literal + + elsif Src (S + 1) = '#' then + Skip_Char (S); while S < SL and then Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' loop - S := S + 1; + Skip_Char (S); end loop; - pragma Assert (S < SL and then Src (S + 1) = '.'); - - S := S + 1; + if S < SL + and then Src (S + 1) = '.' + then + Skip_Char (S); + end if; while S < SL and then Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' loop - S := S + 1; + Skip_Char (S); end loop; - pragma Assert (S < SL and then Src (S + 1) = '#'); - - S := S + 1; + if S < SL + and then Src (S + 1) = '#' + then + Skip_Char (S); + end if; end if; end if; -- Skip past exponent, if present - if S < SL + 1 + if S < SL and then Src (S + 1) in 'e' | 'E' then + Skip_Char (S); -- For positive exponents the plus sign is optional, but we -- can simply skip past both plus and minus. - if Src (S + 2) in '+' | '-' then - S := S + 1; + if Src (S + 1) in '+' | '-' then + Skip_Char (S); end if; -- Skip past the numeral part @@ -2141,7 +2174,7 @@ package body Errout is while S < SL and then Src (S + 1) in '0' .. '9' | '_' loop - S := S + 1; + Skip_Char (S); end loop; end if; @@ -2153,7 +2186,7 @@ package body Errout is in '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_' loop - S := S + 1; + Skip_Char (S); end loop; end case; -- 2.40.0