From patchwork Tue Jun 12 09:40:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 928212 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-479523-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Ly+//pUZ"; 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 414lHc2Fkzz9s0W for ; Tue, 12 Jun 2018 19:40:43 +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=W7T1NhINW5RIrTnS PYtnlTC6WGbg+fbL3hPGZDmpCLmovFRFODKZBRiL2IVX7MxGiV5ptZmN4qraSDmT uDso+93KKqG1QEQXDD26AUt91r1xmbFFPlFPT/oULBJzNoxFURbXSddTTXfKZ+EQ 2O7w8IY522kuO+XvujfhHnur1FA= 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=izDiH4xhHN68AS3iksUJmf q0o1I=; b=Ly+//pUZ1JjbGAjCaKMjlppn3J9Jzf5jmbq/HVGTnVtKsV4trFo901 q3+1ExxPdMbWul/eI5FkXu2jj0yWTky3phbwQ7Y41rFA9CfrCfzP+BhAa8ml2gec jrPjVwSYU3jmgZLvxlqKFBBQQ8f0RjA9GPE6Lli62NzfgHjpi2zts= Received: (qmail 81218 invoked by alias); 12 Jun 2018 09:40:35 -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 81202 invoked by uid 89); 12 Jun 2018 09:40:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 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=lay 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; Tue, 12 Jun 2018 09:40:34 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 01EDD81397 for ; Tue, 12 Jun 2018 11:40:32 +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 YIi_4KmTDNzB for ; Tue, 12 Jun 2018 11:40:31 +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 D1D4181399 for ; Tue, 12 Jun 2018 11:40:31 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix wrong code for initialization of fat pointer with -Og Date: Tue, 12 Jun 2018 11:40:29 +0200 Message-ID: <8943318.RRoB7mNhNt@polaris> MIME-Version: 1.0 This fixes a long-standing issue with the initialization of fat pointer types. The compiler incorrectly optimizes out the initialization to Null of a variable of an access-to-unconstrained-array type, if the variable is declared in the same declarative part as the access type and the array type, there is no other related declaration between the three aforementioned declarations. Fixed thusly, tested on x86-64/Linux, applied on mainline, 8 and 7 branches. 2018-06-12 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Reuse the existing fields of a dummy fat pointer type, if any. Clear the TYPE_DECL_SUPPRESS_DEBUG on the fat pointer type after completing it. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 261430) +++ gcc-interface/decl.c (revision 261431) @@ -2055,11 +2055,16 @@ gnat_to_gnu_entity (Entity_Id gnat_entit { gnu_fat_type = TYPE_MAIN_VARIANT (TYPE_POINTER_TO (gnu_type)); TYPE_NAME (gnu_fat_type) = NULL_TREE; - /* Save the contents of the dummy type for update_pointer_to. */ - TYPE_POINTER_TO (gnu_type) = copy_type (gnu_fat_type); gnu_ptr_template = - TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_fat_type))); + TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_fat_type))); gnu_template_type = TREE_TYPE (gnu_ptr_template); + + /* Save the contents of the dummy type for update_pointer_to. */ + TYPE_POINTER_TO (gnu_type) = copy_type (gnu_fat_type); + TYPE_FIELDS (TYPE_POINTER_TO (gnu_type)) + = copy_node (TYPE_FIELDS (gnu_fat_type)); + DECL_CHAIN (TYPE_FIELDS (TYPE_POINTER_TO (gnu_type))) + = copy_node (DECL_CHAIN (TYPE_FIELDS (gnu_fat_type))); } else { @@ -2080,29 +2085,39 @@ gnat_to_gnu_entity (Entity_Id gnat_entit /* Build the fat pointer type. Use a "void *" object instead of a pointer to the array type since we don't have the array type - yet (it will reference the fat pointer via the bounds). */ - tem - = create_field_decl (get_identifier ("P_ARRAY"), ptr_type_node, - gnu_fat_type, NULL_TREE, NULL_TREE, 0, 0); - DECL_CHAIN (tem) - = create_field_decl (get_identifier ("P_BOUNDS"), gnu_ptr_template, - gnu_fat_type, NULL_TREE, NULL_TREE, 0, 0); + yet (it will reference the fat pointer via the bounds). Note + that we reuse the existing fields of a dummy type because for: + + type Arr is array (Positive range <>) of Element_Type; + type Array_Ref is access Arr; + Var : Array_Ref := Null; + in a declarative part, Arr will be frozen only after Var, which + means that the fields used in the CONSTRUCTOR built for Null are + those of the dummy type, which in turn means that COMPONENT_REFs + of Var may be built with these fields. Now if COMPONENT_REFs of + Var are also built later with the fields of the final type, the + aliasing machinery may consider that the accesses are distinct + if the FIELD_DECLs are distinct as objects. */ if (COMPLETE_TYPE_P (gnu_fat_type)) { - /* We are going to lay it out again so reset the alias set. */ - alias_set_type alias_set = TYPE_ALIAS_SET (gnu_fat_type); - TYPE_ALIAS_SET (gnu_fat_type) = -1; - finish_fat_pointer_type (gnu_fat_type, tem); - TYPE_ALIAS_SET (gnu_fat_type) = alias_set; + tem = TYPE_FIELDS (gnu_fat_type); + TREE_TYPE (tem) = ptr_type_node; + TREE_TYPE (DECL_CHAIN (tem)) = gnu_ptr_template; + TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_fat_type)) = 0; for (t = gnu_fat_type; t; t = TYPE_NEXT_VARIANT (t)) - { - TYPE_FIELDS (t) = tem; - SET_TYPE_UNCONSTRAINED_ARRAY (t, gnu_type); - } + SET_TYPE_UNCONSTRAINED_ARRAY (t, gnu_type); } else { + tem + = create_field_decl (get_identifier ("P_ARRAY"), + ptr_type_node, gnu_fat_type, + NULL_TREE, NULL_TREE, 0, 0); + DECL_CHAIN (tem) + = create_field_decl (get_identifier ("P_BOUNDS"), + gnu_ptr_template, gnu_fat_type, + NULL_TREE, NULL_TREE, 0, 0); finish_fat_pointer_type (gnu_fat_type, tem); SET_TYPE_UNCONSTRAINED_ARRAY (gnu_fat_type, gnu_type); }