From patchwork Sat Sep 9 12:19:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 811954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461769-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HszhwWXt"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xqCtm71xBz9s7f for ; Sat, 9 Sep 2017 22:19:59 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=BkphqR2yoriUdocu SlXkPV5yliGzXAgKuA9BWPUuoaGWrfLHFSVSZ+9XTcBdNbFicHELTda+wW1E6uXT 4kmxUzEoVAyGGXT462UKfIhn8iPpVy9Yw2dDeqvnqo3ed3ogDH/hZg2Lgwvr/kVa n7RoTN//sAp2zTHkNeRm3gBF9wQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=IvI4nFsaEd/nQKLr1HC9f2 3lmHk=; b=HszhwWXtFMPSa1RmzyCFtq54XAkZ7MgfmsHQ4ZZWXcRGEgaP8r/Bst wCtGVXkTP6rvRota8NfiSwbbYijeXZK6IlfORf18rTyjHsKRekpcBjj0O9xx2MvP 3yjd7TUOFdewg6CtGqMrmbQLiIHCcZg0vjGXt8FvIkmha5+AoqwWw= Received: (qmail 68344 invoked by alias); 9 Sep 2017 12:19:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67796 invoked by uid 89); 9 Sep 2017 12:19:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=nominal, Hx-languages-length:1994 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Sep 2017 12:19:49 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id E3007822BB for ; Sat, 9 Sep 2017 14:19:47 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ihAPiv91NruA for ; Sat, 9 Sep 2017 14:19:47 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id B968482278 for ; Sat, 9 Sep 2017 14:19:47 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Improve handling of aliased constant of UNC array type Date: Sat, 09 Sep 2017 14:19:47 +0200 Message-ID: <4314331.1FEQJGTmnu@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Tested on x86_64-suse-linux, applied on the mainline and 7 branch. 2017-09-09 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Apply the promotion to static memory earlier in the processing. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 251927) +++ gcc-interface/decl.c (working copy) @@ -1423,6 +1423,19 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_size = NULL_TREE; } + /* If this is an aggregate constant initialized to a constant, force it + to be statically allocated. This saves an initialization copy. */ + if (!static_flag + && const_flag + && gnu_expr + && TREE_CONSTANT (gnu_expr) + && AGGREGATE_TYPE_P (gnu_type) + && tree_fits_uhwi_p (TYPE_SIZE_UNIT (gnu_type)) + && !(TYPE_IS_PADDING_P (gnu_type) + && !tree_fits_uhwi_p (TYPE_SIZE_UNIT + (TREE_TYPE (TYPE_FIELDS (gnu_type)))))) + static_flag = true; + /* If this is an aliased object with an unconstrained array nominal subtype, we make its type a thin reference, i.e. the reference counterpart of a thin pointer, so it points to the array part. @@ -1474,18 +1487,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entit && No (Address_Clause (gnat_entity)))) gnu_ext_name = create_concat_name (gnat_entity, NULL); - /* If this is an aggregate constant initialized to a constant, force it - to be statically allocated. This saves an initialization copy. */ - if (!static_flag - && const_flag - && gnu_expr && TREE_CONSTANT (gnu_expr) - && AGGREGATE_TYPE_P (gnu_type) - && tree_fits_uhwi_p (TYPE_SIZE_UNIT (gnu_type)) - && !(TYPE_IS_PADDING_P (gnu_type) - && !tree_fits_uhwi_p (TYPE_SIZE_UNIT - (TREE_TYPE (TYPE_FIELDS (gnu_type)))))) - static_flag = true; - /* Deal with a pragma Linker_Section on a constant or variable. */ if ((kind == E_Constant || kind == E_Variable) && Present (Linker_Section_Pragma (gnat_entity)))