From patchwork Thu Sep 11 09:19:01 2025 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: 120051 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 EC9E13858C2C for ; Thu, 11 Sep 2025 09:42:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC9E13858C2C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=L7+mQbln X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 1B56D3858416 for ; Thu, 11 Sep 2025 09:19:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B56D3858416 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B56D3858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582380; cv=none; b=u39Qf0xr7/yQ0pCyskxXkyPZdxTu1khbnsw8zAqKBkWSCBCVzvtPKsRAXjSCNugn3VbspJQtPsz2ZzXGfCUpRyiS1Ns1s7PfFWve+Z5vilkDupiRw5xx2plScn/d/t5+S1vHvQtieNzVcPjeGR2meUYrjkTD+nJ4xm2EbvtPa0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582380; c=relaxed/simple; bh=f89yKc39VniSwwmVpkL7vWrdMDqHPN8np5F8WySECjE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gBJZY5kdEd+72cmNQozYd/K0i0AdhDWjA6NO+VFeekbb1CapB0onb/F4f+WYVKWTLwsMtD9S4B06xjsSkJMxv4vG0tS2vhRQEs7dt0d4ho2pIIruUEH2ISwmJ+/6Kaln0tQZ6BwfIsXPZcBQq3Vu3glJA/3bi6YudAuf7G9fVa8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B56D3858416 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3e5190bca95so379280f8f.0 for ; Thu, 11 Sep 2025 02:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582379; x=1758187179; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bt76UUx+jqwgjPmV0PBwG4EC06cwBAYbGDaRmvElRIA=; b=L7+mQblnE1Ld7ty9FAyIOk7pZZxdNK22Ag8hjWKKwD/7X5JDj696Vo2oyE6Dc6DNMD rvl3iOEF0TeSHliGWUHn8tWz6dJhvOXwdGUs0qZmxY9aNbHCMfUEVT0NBvYVDbyNqY57 8HJfmQISlBCAcoTFT/B+YS/xM+5Wk7FeV4NFFsMqV8I5cT50Ct3fkCIWRFzaCMUKpje4 1mIVFOE9PM4LYYIiiAaecTTx5pB0Ac/npWtqSQfF2xbiKAOoGiiXLNwATQ6q0w084jE0 83J3VEvxBql+MVYoztddyYneo01DTzopMqSGaKZKcVD5zHzs5meYlfAHVYlO/TTr0QD3 dmBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582379; x=1758187179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject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T+IH8GaeShJOR7IolFWj1fq3qw9WQAaaUuOw5izQ9pFZMX+waFBncMBm+cZnJpQ9GWviW2lEtLA== X-Received: by 2002:a05:6000:25ca:b0:3e7:5f26:f1e8 with SMTP id ffacd0b85a97d-3e75f26f670mr1998388f8f.5.1757582378744; Thu, 11 Sep 2025 02:19:38 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3e7607cd27dsm1649971f8f.41.2025.09.11.02.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:38 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 29/31] ada: Give a warning for huge imported objects Date: Thu, 11 Sep 2025 11:19:01 +0200 Message-ID: <20250911091904.1505690-29-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911091904.1505690-1-poulhies@adacore.com> References: <20250911091904.1505690-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou This is a follow-up to a recent change, where a warning was implemented for huge library-level objects. However it is not given if the objects are imported, although an indirection is also added for them under the hood to match the export side. gcc/ada/ChangeLog: * gcc-interface/decl.cc (gnat_to_gnu_entity) : Give a warning for huge imported objects as well. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/decl.cc | 61 +++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 771325d8ce6c..00ccac3978e6 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -1388,16 +1388,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) } } - /* If we are at top level and this object is of variable size, - make the actual type a hidden pointer to the real type and - make the initializer be a memory allocation and initialization. - Likewise for objects we aren't defining (presumed to be - external references from other packages), but there we do - not set up an initialization. - - If the object's size overflows, make an allocator too, so that - Storage_Error gets raised. Note that we will never free - such memory, so we presume it never will get allocated. */ + /* If we are at top level and this object is of variable size, make + the actual type a reference to the real type and the initializer + be a memory allocation and initialization. Likewise for an object + that we aren't defining or is imported (presumed to be an external + reference from another package), but in this case we do not set up + an initialization. Likewise if the object's size is constant but + too large. In either case, this will also cause Storage_Error to + be raised if the size ends up overflowing. Note that we will never + free such memory, but it will be allocated only at top level. */ if (!allocatable_size_p (TYPE_SIZE_UNIT (gnu_type), global_bindings_p () || !definition @@ -1411,6 +1410,29 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) || !definition || static_flag))) { + /* Give a warning if the size is constant. */ + if ((TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) == INTEGER_CST + || (gnu_size && TREE_CODE (gnu_size) == INTEGER_CST)) + && definition) + { + if (imported_p) + { + post_error + ("??too large object cannot be imported directly", + gnat_entity); + post_error ("\\??indirect import will be used instead", + gnat_entity); + } + else if (global_bindings_p () || static_flag) + { + post_error + ("??too large object cannot be allocated statically", + gnat_entity); + post_error ("\\??dynamic allocation will be used instead", + gnat_entity); + } + } + if (volatile_flag && !TYPE_VOLATILE (gnu_type)) gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE); gnu_type = build_reference_type (gnu_type); @@ -1453,21 +1475,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) } /* Give a warning if the size is constant but too large. */ - if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST) - { - if (valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type))) - { - post_error - ("??too large object cannot be allocated statically", - gnat_entity); - post_error ("\\??dynamic allocation will be used instead", - gnat_entity); - } - - else - post_error ("??Storage_Error will be raised at run time!", - gnat_entity); - } + if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST + && !valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type))) + post_error ("??Storage_Error will be raised at run time!", + gnat_entity); gnu_expr = build_allocator (gnu_alloc_type, gnu_expr, gnu_type,