From patchwork Tue Jul 5 08:29:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1652344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=WnROu1bH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LcbWv3rxkz9s1l for ; Tue, 5 Jul 2022 18:32:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B48C38337A0 for ; Tue, 5 Jul 2022 08:32:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B48C38337A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1657009945; bh=G/8T30uz6efxwvsId//qdqPp1xZIIXFkw4nqwAMVOJo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WnROu1bH2WE5lnORqnMH0sieHPp3Sclji86KVe6kaxdoSYcmJ23QKV5gM2AK4mzUr 7RMzx/Cn4HPP0qtxSFgIJ+ZQ8YRS9vJSmvIBnOJCfcI9nKWwTVzxvtOXdafUUCeMJJ rxGiV8HcnbzamGdOC81ZzCWtn8NSEbCR7AjN2R7Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4893A385274C for ; Tue, 5 Jul 2022 08:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4893A385274C Received: by mail-wm1-x333.google.com with SMTP id m6-20020a05600c3b0600b003a0489f412cso7089669wms.1 for ; Tue, 05 Jul 2022 01:29:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=G/8T30uz6efxwvsId//qdqPp1xZIIXFkw4nqwAMVOJo=; b=NLL9GNzSNABwOXslZAzJNuBgw1BK5H93MIZNvQ9+Y+uMF6b3Qkuzv7IIPFMxQdi+aL KQLcqHHFuYtz0oxpGzY2QEyn+h7GQITrWnDVOYRTg0FWGlEBRSWRi2+AdwgxQC0MhBhT gSfOaXe/ulHC47jBzga4PqTn+qqnIhWtDwY4XNDJZWCTMz4t+5wUVsoUmTqCizk2z3Y5 eHQeAf6fPTZrZhh1C7DvfH2flKD3oMWTu1uEouz1T9vHUH9GUMHeqPMAkub93mOb8krw 25Z04/LzvG3TAwxO2nrJBa6a1zveWUJMFUHuFFAJn4KCPMqz71DcAY+h7kAeWP9CYzUP hWyg== X-Gm-Message-State: AJIora9Q00FPjuOT2TUOg3eJzhFeilSouh80RJzOgNUwrXrccOFqg+eW hIxywyd5DnPA59YmvwhngXHGk3Rtea3rfQ== X-Google-Smtp-Source: AGRyM1vBrd+/v1XYELTQ+RX4X63+iY1eP3CFBZiUR6b+76qje51O0z1OEoahPvdOgBIu/9eaEva8+w== X-Received: by 2002:a05:600c:1d03:b0:3a1:7ab1:8dbe with SMTP id l3-20020a05600c1d0300b003a17ab18dbemr30810772wms.202.1657009797998; Tue, 05 Jul 2022 01:29:57 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u1-20020a5d6ac1000000b0021b95bcaf7fsm4656111wrw.59.2022.07.05.01.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jul 2022 01:29:57 -0700 (PDT) Date: Tue, 5 Jul 2022 08:29:57 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Cleanup repeated code for aggregate constraints checks Message-ID: <20220705082957.GA3186956@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.3 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 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Code cleanup related to examining uses of Check_Unset_Reference for improved detection of uninitialised scalar objects. Semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Aggregate_Constraint_Checks): Fix whitespace; refactor repeated code; replace a ??? comment with an explanation based on the comment for the routine spec. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1153,7 +1153,7 @@ package body Sem_Util is (Exp : Node_Id; Check_Typ : Entity_Id) is - Exp_Typ : constant Entity_Id := Etype (Exp); + Exp_Typ : constant Entity_Id := Etype (Exp); begin if Raises_Constraint_Error (Exp) then @@ -1236,12 +1236,12 @@ package body Sem_Util is and then Is_Scalar_Type (Check_Typ) and then Exp_Typ /= Check_Typ then + -- If expression is a constant, it is worthwhile checking whether it + -- is a bound of the type. + if Is_Entity_Name (Exp) and then Ekind (Entity (Exp)) = E_Constant then - -- If expression is a constant, it is worthwhile checking whether - -- it is a bound of the type. - if (Is_Entity_Name (Type_Low_Bound (Check_Typ)) and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ))) or else @@ -1249,20 +1249,15 @@ package body Sem_Util is and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ))) then return; - - else - Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); - Analyze_And_Resolve (Exp, Check_Typ); - Check_Unset_Reference (Exp); end if; + end if; - -- Could use a comment on this case ??? + -- Change Exp into Check_Typ'(Exp) to ensure that range checks are + -- performed at run time. - else - Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); - Analyze_And_Resolve (Exp, Check_Typ); - Check_Unset_Reference (Exp); - end if; + Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp))); + Analyze_And_Resolve (Exp, Check_Typ); + Check_Unset_Reference (Exp); end if; end Aggregate_Constraint_Checks;