From patchwork Fri Jul 28 07:30:52 2023 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: 127389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp262203vqg; Fri, 28 Jul 2023 00:41:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUNRyg1BKC7wk2xyhJcLQnWErAOeyPjynPJPJ+ouq1KPWwuzzKWZRR6aDsyu2wy7iXwsfG X-Received: by 2002:a17:907:a043:b0:993:d632:2c3 with SMTP id gz3-20020a170907a04300b00993d63202c3mr1732007ejc.21.1690530102548; Fri, 28 Jul 2023 00:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690530102; cv=none; d=google.com; s=arc-20160816; b=UP3vIUCTK28I5G0k5jaFANDbJ65SG7wLJtmKuLKvQp28RZL3aWYX28RAnbAntVe92J /u2ldMusVRo7PBLrMFTQ5aU7+td/uFlQHmhQl7lr+xnAKNDtH00If9xnPW46N3gQ5GYb wQfN6Jijz5mh+7B5sm50tfK6r239bldBifUBuOERccfv89wjSXw9feSXlHvwKq5lC34J H8NdCFuSrnx5z6350TOtOND4hdgVCKX7oGmDA41cB4EjcelsjhgMMRDk+4zQQwtS8U0V H5+S/p4f1iXrcTuESRVf+sPl3H0vySKkL+WzVGmd/iPM1q0X/rgwDgoVBZXeb1QTR5Lu 6R1w== 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=y2Nub66/DF3z2a9IHABvUGkrEIV6A/PtAHJMSLlXg1s=; fh=/3KX5nH+f3PGIzCwnuf//1E+cbLgxv/xavy4NboKqC4=; b=dGKUnE0OMx03+ewjdG/NCcHGBZVEcQZkgohPqtdG2B6zsZhgaT5/qF3DBU/vOntUWo W/g85TSsXtgQJvibdShKxZYPCRXoiANDrEJS7fFV7DaFF4zqAdZKGCym6sPC7ElrmgOJ 13VuZYXLo142eiFDAJeD9wr2sPGTcpJFosR6Qrv/1SgeAAQ90HEAk9tJ0DLDk3NFtpLb PJUuagug9PMGDqekd2GbtOHcbvo25Htwb62EdEams0XdqcYsWJ85LzLcn1+iKVWb/eQR meyS3X4wQvWY0SxTMWLTg0+0lKbABEF2+OS5fTiLNb1ERAQ3SwDzJ+83Rk8cw5sG3q5h 6BrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YYLvkhUQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n22-20020a17090695d600b0099279210464si2118467ejy.420.2023.07.28.00.41.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 00:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YYLvkhUQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 9E7C03834642 for ; Fri, 28 Jul 2023 07:35:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E7C03834642 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690529733; bh=y2Nub66/DF3z2a9IHABvUGkrEIV6A/PtAHJMSLlXg1s=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YYLvkhUQYZp7gyw4aZTE1DJnMMm0H5sKXyKGzMgpRxYOMKj3lC6Y4ya66Fw/k7U+w F4s/qDlJDO5RuD+RPUlg2VDYIuF3zkZbZe/JSy+eR8Nr/4lLDxqBmQdk5LvJkPkgio emxXb1kAHvcdc0OUiFRMODPETsZrBlLoZcS5JRx4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 8CED43856951 for ; Fri, 28 Jul 2023 07:30:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8CED43856951 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbab0d0b88so20565585e9.0 for ; Fri, 28 Jul 2023 00:30:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690529454; x=1691134254; 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=y2Nub66/DF3z2a9IHABvUGkrEIV6A/PtAHJMSLlXg1s=; b=eLWG4FxYnMyHjXqFTbpuC7ByF43R5X4MSZISn0CLbVP2+vCROjxYKkKeUMMFBZw4Nl NFC013jRaE8f8bFbkMwZpa07XpK+nc3xLS6CSypH32MiMG8+jQuXz8c9rJtaIfYuc7cw oqVwzkJgDreUZTDJHO2gMNtYxQ3KXyPIIKmnPQyZSORlBZNZin9vG0qg0G0KypzERUpa rFpfllg0+fCCIZRCWt6K7osvw/yOJwUOYEOQScQwsHm+scLLInjW5oy7OhBtH+oxTEGf AFaxTHE7DbSA/zc50BB8YHNjnxXb9N4x3PLqQOGcyUqHlf06Dzt4nFc2okQWZYUjmxGt CP8Q== X-Gm-Message-State: ABy/qLY8wWEhhwcoNz+gFt697fsZHjzDaFHXdILOZnDjpeuu8kg6Tjgb xHvtJcmCFeQx7L95E8F4hoW0XwJ59P+6N6pUZkf+1Q== X-Received: by 2002:a7b:cd0e:0:b0:3fd:2f7d:425f with SMTP id f14-20020a7bcd0e000000b003fd2f7d425fmr1254738wmj.18.1690529454327; Fri, 28 Jul 2023 00:30:54 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:792d:7d2b:d7e:14a3]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c114f00b003fbb5506e54sm3496524wmz.29.2023.07.28.00.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 00:30:53 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix memory explosion on aggregate of nested packed array type Date: Fri, 28 Jul 2023 09:30:52 +0200 Message-Id: <20230728073052.1852535-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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: =?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: INBOX X-GMAIL-THRID: 1772649293027573643 X-GMAIL-MSGID: 1772649293027573643 From: Eric Botcazou It occurs at compile time on an aggregate of a 2-dimensional packed array type whose component type is itself a packed array, because the compiler is trying to pack the intermediate aggregate and ends up rewriting a bunch of subcomponents. This optimization was originally devised for the case of a scalar component type so the change adds this restriction. gcc/ada/ * exp_aggr.adb (Is_Two_Dim_Packed_Array): Return true only if the component type of the array is scalar. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index dffc5ab721d..cd5cc0b7669 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -306,7 +306,7 @@ package body Exp_Aggr is -- N is the N_Aggregate node to be expanded. function Is_Two_Dim_Packed_Array (Typ : Entity_Id) return Boolean; - -- For two-dimensional packed aggregates with constant bounds and constant + -- For 2D packed array aggregates with constant bounds and constant scalar -- components, it is preferable to pack the inner aggregates because the -- whole matrix can then be presented to the back-end as a one-dimensional -- list of literals. This is much more efficient than expanding into single @@ -8563,9 +8563,11 @@ package body Exp_Aggr is function Is_Two_Dim_Packed_Array (Typ : Entity_Id) return Boolean is C : constant Uint := Component_Size (Typ); + begin return Number_Dimensions (Typ) = 2 and then Is_Bit_Packed_Array (Typ) + and then Is_Scalar_Type (Component_Type (Typ)) and then C in Uint_1 | Uint_2 | Uint_4; -- False if No_Uint end Is_Two_Dim_Packed_Array;