From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-x32c.google.com with SMTP id 5b1f17b1804b1-3fbab0d0b88so20565585e9.0 for ; Fri, 28 Jul 2023 00:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690529454; x=1691134254; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=y2Nub66/DF3z2a9IHABvUGkrEIV6A/PtAHJMSLlXg1s=; b=E79sImkJzj8hlY2Bo36x2bhhBf01Y7Th4zq+iy2keHV2eVdIFzCXXNg9UFT430V61L m7pS2wM1xFB/bQfGzHsSjNF3Kd0/hVjTefNYBVC/rfocjA4xQBOf6Z5sIt6stMT8BmmD u2thhy9zlzzW0+YZA/IHOFr96UGn1z3webEYdILUlrSipmj+xP3MLpidBP4B1SoLAtwB cLXVegBjkoGTDfgoEH9vmQLR7sEHDEelTkhOjKyuM/w0FILHmTXQHgVjY0gqlgVlDwv2 iSkScgg/dKFrp9z9t7y4/NjNbFganHNuDWUiLDvxD3/vlOv5lKnKD3U55q8G1aMMGBEq DrAA== 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-Google-Smtp-Source: APBJJlF0yf4746xu7fLnwmQ/b3185Lhkh2pmp9AQOIzafoRFbmboMpLQ5c4/U8cGbWLiPikabocctQ== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; -- 2.40.0