From patchwork Tue Jan 11 13:32:20 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: 49856 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A94938A940A for ; Tue, 11 Jan 2022 13:57:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A94938A940A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641909428; bh=aHFNlddpPAuU5GEAuKZoQgZ9msFTffPncb6Tt5od6Cs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bO1QIto1RBVab9slzZt+U1RbWJh9yW+b5CSw+7qqONEc1sz8z4CN82NaGZp7y//dN faT40OFGp+zWkExbn9CHfBWowDkzweoNbY4Hz0fqO/p9aDwf70N6yJ03WyCSSROYJE jWvIP9wnbtKrj5pR9qvpZx03pLwpVPOWHuumOOP4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 65ECA38A9432 for ; Tue, 11 Jan 2022 13:32:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65ECA38A9432 Received: by mail-wr1-x432.google.com with SMTP id e9so31498295wra.2 for ; Tue, 11 Jan 2022 05:32:23 -0800 (PST) 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=aHFNlddpPAuU5GEAuKZoQgZ9msFTffPncb6Tt5od6Cs=; b=VlXgnWIPaPVoEVlq/SQAn/et0mHLHh01I0+bisMPao74I/fImrwUgGLVKhyocwiLVV CPHw4gmMk70tawPLQZZSQeA2ItGUg75UV9vb0x90Bpj2DUwYWFnVZSpb4JRb+KQc66Hi 5E0Z/nX74FMpxP9PLk/59JZChd3DcAfwX6Qg76f/xLAAD4/atbLn7jRkIcnj6j878NWE BySModrpe5ZnzbaATzF8IvEEq3s3xP+txo/9ejoVQTWwZqjaLYCfCdqP0ynTLdfmlsXQ SQ49WmXQWKfqVLSw+ESglFJVGu0A96UMckaiNdrVs+d/pRcOA5cRlWkIeRMSnO8tCdva KZ/Q== X-Gm-Message-State: AOAM530vD99LTP2xa4qdqZPnKMEkNuPQsgdFlXmMpJqdIJQ+lHFOA3AX m3RdkAS5UdrMaT2lDtQ6ciQdWpznLDm7HA== X-Google-Smtp-Source: ABdhPJwzGG0PXiZTu1fBefBZ7vBLhCb2RImC4+LizI14ZKBnQ6vFZGglUPOu16elmj8TWBGyQE7G+g== X-Received: by 2002:a05:6000:178b:: with SMTP id e11mr3821531wrg.294.1641907942493; Tue, 11 Jan 2022 05:32:22 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id l2sm10011006wrs.43.2022.01.11.05.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:32:21 -0800 (PST) Date: Tue, 11 Jan 2022 13:32:20 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Remove unnecessary block in code for expansion of allocators Message-ID: <20220111133220.GA748779@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Cleanup related to handling of allocators in GNATprove; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Size_In_Storage_Elements): Remove unnecessary DECLARE block; refill code and comments. diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -4345,116 +4345,110 @@ package body Exp_Ch4 is ------------------------------ function Size_In_Storage_Elements (E : Entity_Id) return Node_Id is + Idx : Node_Id := First_Index (E); + Len : Node_Id; + Res : Node_Id := Empty; + begin -- Logically this just returns E'Max_Size_In_Storage_Elements. - -- However, the reason for the existence of this function is - -- to construct a test for sizes too large, which means near the - -- 32-bit limit on a 32-bit machine, and precisely the trouble - -- is that we get overflows when sizes are greater than 2**31. + -- However, the reason for the existence of this function is to + -- construct a test for sizes too large, which means near the 32-bit + -- limit on a 32-bit machine, and precisely the trouble is that we + -- get overflows when sizes are greater than 2**31. -- So what we end up doing for array types is to use the expression: -- number-of-elements * component_type'Max_Size_In_Storage_Elements -- which avoids this problem. All this is a bit bogus, but it does - -- mean we catch common cases of trying to allocate arrays that - -- are too large, and which in the absence of a check results in + -- mean we catch common cases of trying to allocate arrays that are + -- too large, and which in the absence of a check results in -- undetected chaos ??? - declare - Idx : Node_Id := First_Index (E); - Len : Node_Id; - Res : Node_Id := Empty; + for J in 1 .. Number_Dimensions (E) loop - begin - for J in 1 .. Number_Dimensions (E) loop + if not Is_Modular_Integer_Type (Etype (Idx)) then + Len := + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (E, Loc), + Attribute_Name => Name_Length, + Expressions => New_List (Make_Integer_Literal (Loc, J))); - if not Is_Modular_Integer_Type (Etype (Idx)) then - Len := - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), - Attribute_Name => Name_Length, - Expressions => New_List - (Make_Integer_Literal (Loc, J))); + -- For indexes that are modular types we cannot generate code to + -- compute 'Length since for large arrays 'Last -'First + 1 causes + -- overflow; therefore we compute 'Last - 'First (which is not the + -- exact number of components but it is valid for the purpose of + -- this runtime check on 32-bit targets). - -- For indexes that are modular types we cannot generate code - -- to compute 'Length since for large arrays 'Last -'First + 1 - -- causes overflow; therefore we compute 'Last - 'First (which - -- is not the exact number of components but it is valid for - -- the purpose of this runtime check on 32-bit targets). + else + declare + Len_Minus_1_Expr : Node_Id; + Test_Gt : Node_Id; - else - declare - Len_Minus_1_Expr : Node_Id; - Test_Gt : Node_Id; + begin + Test_Gt := + Make_Op_Gt (Loc, + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (E, Loc), + Attribute_Name => Name_Last, + Expressions => + New_List (Make_Integer_Literal (Loc, J))), + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (E, Loc), + Attribute_Name => Name_First, + Expressions => + New_List (Make_Integer_Literal (Loc, J)))); - begin - Test_Gt := - Make_Op_Gt (Loc, - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), - Attribute_Name => Name_Last, - Expressions => - New_List (Make_Integer_Literal (Loc, J))), - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), - Attribute_Name => Name_First, - Expressions => - New_List (Make_Integer_Literal (Loc, J)))); - - Len_Minus_1_Expr := - Convert_To (Standard_Unsigned, - Make_Op_Subtract (Loc, - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), - Attribute_Name => Name_Last, - Expressions => - New_List - (Make_Integer_Literal (Loc, J))), - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (E, Loc), - Attribute_Name => Name_First, - Expressions => - New_List - (Make_Integer_Literal (Loc, J))))); - - -- Handle superflat arrays, i.e. arrays with such bounds - -- as 4 .. 2, to ensure that the result is correct. - - -- Generate: - -- (if X'Last > X'First then X'Last - X'First else 0) - - Len := - Make_If_Expression (Loc, - Expressions => New_List ( - Test_Gt, - Len_Minus_1_Expr, - Make_Integer_Literal (Loc, Uint_0))); - end; - end if; + Len_Minus_1_Expr := + Convert_To (Standard_Unsigned, + Make_Op_Subtract (Loc, + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (E, Loc), + Attribute_Name => Name_Last, + Expressions => + New_List (Make_Integer_Literal (Loc, J))), + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (E, Loc), + Attribute_Name => Name_First, + Expressions => + New_List (Make_Integer_Literal (Loc, J))))); - if J = 1 then - Res := Len; + -- Handle superflat arrays, i.e. arrays with such bounds as + -- 4 .. 2, to ensure that the result is correct. - else - pragma Assert (Present (Res)); - Res := - Make_Op_Multiply (Loc, - Left_Opnd => Res, - Right_Opnd => Len); - end if; + -- Generate: + -- (if X'Last > X'First then X'Last - X'First else 0) - Next_Index (Idx); - end loop; + Len := + Make_If_Expression (Loc, + Expressions => New_List ( + Test_Gt, + Len_Minus_1_Expr, + Make_Integer_Literal (Loc, Uint_0))); + end; + end if; - return - Make_Op_Multiply (Loc, - Left_Opnd => Len, - Right_Opnd => - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Component_Type (E), Loc), - Attribute_Name => Name_Max_Size_In_Storage_Elements)); - end; + if J = 1 then + Res := Len; + + else + pragma Assert (Present (Res)); + Res := + Make_Op_Multiply (Loc, + Left_Opnd => Res, + Right_Opnd => Len); + end if; + + Next_Index (Idx); + end loop; + + return + Make_Op_Multiply (Loc, + Left_Opnd => Len, + Right_Opnd => + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (Component_Type (E), Loc), + Attribute_Name => Name_Max_Size_In_Storage_Elements)); end Size_In_Storage_Elements; -- Local variables