From patchwork Tue Dec 6 14:01:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 30304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2837302wrr; Tue, 6 Dec 2022 06:03:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QQ/EdMUcjtXuNzo+nMaEAlCnNf5TAyzgkladGpAX9ua8YrQl3Fu7PUsTyGeyP3mrRw5aY X-Received: by 2002:a2e:964c:0:b0:279:f197:440d with SMTP id z12-20020a2e964c000000b00279f197440dmr4093170ljh.517.1670335395341; Tue, 06 Dec 2022 06:03:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670335395; cv=none; d=google.com; s=arc-20160816; b=Y8z1ULqGLVuYiYgOfXrcHlLBmBpgNYNWTketzoBFDJfF3w3JCDG9Z1KqG105kBx4CP YquOCgdDxRdA/UjmdPPceBKWncfYZFApOC6vpynAPFBWDogoOsIfa8tBGQNioAKwa36f Xn0282ncLhXZkExx35CrFIXfj8knpfWlAqOuy91g3bsxHZQYbwdxBukh5s3EVTzxwnE2 5vJxGivY5R/8oP3DdHU1Km+aAVpVBLRw8ayoypMiNGtNWzXyAKQnN06yqHalbl4OXgOv rDXLKH9pk3aGjRN7Dc1rLKOfQ+8aedecIBTfF12uV6GmBtSmEH1Opo54/h+1UOEDnl8z DyJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=YebmQGEWVGgLykD3OJrgEuQGCQOP4cPqfrJ5iBDOrrs=; b=aKVJFV2E1mk1zStr7w+gOSdJcO3IcelcD3LNEpvt5wy4w2zfBqTK80cuvxHNCgyAC8 DoUfPdZgZctNMMpTu9LmkEa9CiJ/itmrl/WJAQ+TtcL+F8DIDoUE6WZj1ONACpONbISL oSIedICjWOGg/GpodNundoAzs2LyHphibii2M9C/o+2R4JqEKkF2bUK5basVNfOch8Sa 6YMz5xblHO/E9LGfp+9EcQ5f4IlAOX2RWq1ybovmSi04BgOXCAenQukQlG8XNGTyqiH2 x32E4/d3JwCnHY5KcV0lVsiQ1rtc5QbuELYH0KXpoq6ZpY4MY7uNLbOdPSPYGFTOhHPg QBRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s9lujtN1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h11-20020aa7cdcb000000b0046c5b50650esi1908695edw.47.2022.12.06.06.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:03:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=s9lujtN1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 829C8383B6DA for ; Tue, 6 Dec 2022 14:02:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 829C8383B6DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335347; bh=YebmQGEWVGgLykD3OJrgEuQGCQOP4cPqfrJ5iBDOrrs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=s9lujtN1iqAH9ygBnit/SEzWxAeL237O8iObMwenonneFBJ0WgECiCaynytTATprp C7aLsC1CnvKSTL5rPvtqk6Zjrn6rZ40HAcrVmVakSv/Dw90Yu8I2oCm76fiTVaAaB/ GikbupEXw5hhWS1ZyXLmc7rPv85jyonm7TMp7mPo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id F2B503848E2F for ; Tue, 6 Dec 2022 14:01:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F2B503848E2F Received: by mail-wr1-x42f.google.com with SMTP id d1so23558302wrs.12 for ; Tue, 06 Dec 2022 06:01:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=YebmQGEWVGgLykD3OJrgEuQGCQOP4cPqfrJ5iBDOrrs=; b=3eWi7Cbcmmi2TMdJO9NEEY+a/83gAVZImAPy4dhbVnX2CFayV90SInVeFvQ6aL6a4W Xhp/5zT0ZjGv4opyZOeGdT+B98ucPIA7K5MuCme4c4aeOLMTbAfXshVxPuko5w0/Mbh1 MTSgaGER1nTeYov+je6lsZDlh61WYWqPNDBrOyAMblNhjpLc0p+1r3a3jqAZ6q3HhXtm dIE6kZeCbGzSP+rAS+pD6M4NnzA3YiYEhcPvFcVnh89HJsVoY4+NzAni7Nfhk2qynY7s IWRM7OINh70axJPDZcotWi5Lcq0ExTKqAy6N5m5f21Pkb4mEE/HsjWr5NslUmOF92DNM VSEw== X-Gm-Message-State: ANoB5pkbXTpphCshsM3H7rtviM1Qfbduny6KuhLMxsp8jP7plQL2Q4p9 4OYEfHaTjaPhCJl2uh8U2anHl8hlua3Qi+mB X-Received: by 2002:a5d:4f0d:0:b0:242:65d:b750 with SMTP id c13-20020a5d4f0d000000b00242065db750mr32539032wru.367.1670335291890; Tue, 06 Dec 2022 06:01:31 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id p15-20020a05600c358f00b003c6b874a0dfsm29469511wmq.14.2022.12.06.06.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:01:31 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Liaiss Merzougue Subject: [COMMITTED] ada: Add Codepeer Exemption + simplify TO_C code. Date: Tue, 6 Dec 2022 15:01:26 +0100 Message-Id: <20221206140126.716950-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751473607061987105?= X-GMAIL-MSGID: =?utf-8?q?1751473607061987105?= From: Liaiss Merzougue This patch simplify the TO_C code to have a single branch for raising exception. Furthermore, adding pragma annotate for codepeer to ignore uninitialized value since this is caused because we have input check before the initialization. gcc/ada/ * libgnat/i-c.adb (To_C): Simplify code for having a single exception raise. Add pragma annotate about uninitialized value which happen only on exception raising. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/i-c.adb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gcc/ada/libgnat/i-c.adb b/gcc/ada/libgnat/i-c.adb index 4b50d18a5a1..28660219b6e 100644 --- a/gcc/ada/libgnat/i-c.adb +++ b/gcc/ada/libgnat/i-c.adb @@ -186,7 +186,7 @@ is (Item : char_array; Trim_Nul : Boolean := True) return String is - Count : Natural; + Count : Natural := 0; From : size_t; begin @@ -1177,7 +1177,7 @@ is To : size_t; begin - if Target'Length < Item'Length then + if Target'Length < Item'Length + (if Append_Nul then 1 else 0) then raise Constraint_Error; else @@ -1210,17 +1210,14 @@ is Target'First + (Item'Length - 1))'Initialized); if Append_Nul then - if To > Target'Last then - raise Constraint_Error; - else - Target (To) := char32_nul; - Count := Item'Length + 1; - end if; - + Target (To) := char32_nul; + Count := Item'Length + 1; else Count := Item'Length; end if; end if; end To_C; + pragma Annotate (CodePeer, False_Positive, "validity check", + "Count is only uninitialized on abnormal return."); end Interfaces.C;