From patchwork Sat Jun 2 10:52:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 924455 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-478954-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="vCz5rzeI"; 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 40ydMs6nZwz9s02 for ; Sat, 2 Jun 2018 20:53:12 +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=nwcx0KqokjqvDDm5 W8D+RXAQg0CHwG+fmmv2Rwlx87c3G9S3NX8vITB6DIKAJpm4x7K/eTGRdVudmP80 8iK8zzslxpLd2DpH3jY/zpQp8LfM55govQrRaWvZd0zoWszou0F6kIDaZb3HEWYI c/SdNJKZBIiAfHfopGi8C13q+cY= 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=xPasLtIuH7hQlDRxYSkYFY 4X/fY=; b=vCz5rzeIsG95ma5O6QDXBKHzV0ODa+D7ZVrUTf4xqFd6C8BjMfuI6Y l5C3Bj8A1gh4C+r73iIkh8vduZ0tgSy+k8lyrsh1t1s8JSt/vnAGkcL8Y2Gdh9bm eiqLaugDMaiPr1lWZrN8H+xcgSfy3c0Ho/A2mLvwVtQDwwqtWOo6A= Received: (qmail 119209 invoked by alias); 2 Jun 2018 10:53:04 -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 119191 invoked by uid 89); 2 Jun 2018 10:53:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=latent, VAR_DECL, var_decl, TYPE_DECL 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, 02 Jun 2018 10:53:02 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id EAE4B813A1 for ; Sat, 2 Jun 2018 12:52:59 +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 8Y-UU7c3ycgE for ; Sat, 2 Jun 2018 12:52:59 +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 B91F381398 for ; Sat, 2 Jun 2018 12:52:59 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix crash on instantiation of Vectors package at -O3 Date: Sat, 02 Jun 2018 12:52:57 +0200 Message-ID: <4034715.75IqBAYnSB@polaris> MIME-Version: 1.0 This is a regression present on the mainline, 8 and 7 branches. It's a latent tree sharing issue exposed by the use of SSA names during gimplification that has been introduced in the GCC 7 development phase. Fixed thusly, tested on x86-64/Linux, applied on mainline, 8 and 7 branches. 2018-06-02 Eric Botcazou * gcc-interface/ada-tree.h (TYPE_PADDING_FOR_COMPONENT): New macro. * gcc-interface/decl.c (gnat_to_gnu_component_type): Cache the padding type built for an aliased component with variable size. 2018-06-02 Eric Botcazou * gnat.dg/specs/opt3.ads: New test. * gnat.dg/specs/opt3_pkg.ads: New helper. Index: gcc-interface/ada-tree.h =================================================================== --- gcc-interface/ada-tree.h (revision 261101) +++ gcc-interface/ada-tree.h (working copy) @@ -6,7 +6,7 @@ * * * C Header File * * * - * Copyright (C) 1992-2017, Free Software Foundation, Inc. * + * Copyright (C) 1992-2018, Free Software Foundation, Inc. * * * * GNAT is free software; you can redistribute it and/or modify it under * * terms of the GNU General Public License as published by the Free Soft- * @@ -235,6 +235,11 @@ do { \ refer to the routine gnat_to_gnu_entity. */ #define TYPE_CI_CO_LIST(NODE) TYPE_LANG_SLOT_1 (FUNCTION_TYPE_CHECK (NODE)) +/* For an ARRAY_TYPE with variable size, this is the padding type built for + the array type when it is itself the component type of another array. */ +#define TYPE_PADDING_FOR_COMPONENT(NODE) \ + (TYPE_LANG_SLOT_1 (ARRAY_TYPE_CHECK (NODE))) + /* For a VECTOR_TYPE, this is the representative array type. */ #define TYPE_REPRESENTATIVE_ARRAY(NODE) \ TYPE_LANG_SLOT_1 (VECTOR_TYPE_CHECK (NODE)) Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 261101) +++ gcc-interface/decl.c (working copy) @@ -5031,17 +5031,6 @@ gnat_to_gnu_component_type (Entity_Id gn Is_Bit_Packed_Array (gnat_array) ? TYPE_DECL : VAR_DECL, true, Has_Component_Size_Clause (gnat_array)); - /* If the array has aliased components and the component size can be zero, - force at least unit size to ensure that the components have distinct - addresses. */ - if (!gnu_comp_size - && Has_Aliased_Components (gnat_array) - && (integer_zerop (TYPE_SIZE (gnu_type)) - || (TREE_CODE (gnu_type) == ARRAY_TYPE - && !TREE_CONSTANT (TYPE_SIZE (gnu_type))))) - gnu_comp_size - = size_binop (MAX_EXPR, TYPE_SIZE (gnu_type), bitsize_unit_node); - /* If the component type is a RECORD_TYPE that has a self-referential size, then use the maximum size for the component size. */ if (!gnu_comp_size @@ -5049,6 +5038,13 @@ gnat_to_gnu_component_type (Entity_Id gn && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type))) gnu_comp_size = max_size (TYPE_SIZE (gnu_type), true); + /* If the array has aliased components and the component size is zero, force + the unit size to ensure that the components have distinct addresses. */ + if (!gnu_comp_size + && Has_Aliased_Components (gnat_array) + && integer_zerop (TYPE_SIZE (gnu_type))) + gnu_comp_size = bitsize_unit_node; + /* Honor the component size. This is not needed for bit-packed arrays. */ if (gnu_comp_size && !Is_Bit_Packed_Array (gnat_array)) { @@ -5071,6 +5067,30 @@ gnat_to_gnu_component_type (Entity_Id gn gnat_array); } + /* This is a very special case where the array has aliased components and the + component size might be zero at run time. As explained above, we force at + least the unit size but we don't want to build a distinct padding type for + each invocation (they are not canonicalized if they have variable size) so + we cache this special padding type as TYPE_PADDING_FOR_COMPONENT. */ + else if (Has_Aliased_Components (gnat_array) + && TREE_CODE (gnu_type) == ARRAY_TYPE + && !TREE_CONSTANT (TYPE_SIZE (gnu_type))) + { + if (TYPE_PADDING_FOR_COMPONENT (gnu_type)) + gnu_type = TYPE_PADDING_FOR_COMPONENT (gnu_type); + else + { + gnu_comp_size + = size_binop (MAX_EXPR, TYPE_SIZE (gnu_type), bitsize_unit_node); + TYPE_PADDING_FOR_COMPONENT (gnu_type) + = maybe_pad_type (gnu_type, gnu_comp_size, 0, gnat_array, + true, false, definition, true); + gnu_type = TYPE_PADDING_FOR_COMPONENT (gnu_type); + create_type_decl (TYPE_NAME (gnu_type), gnu_type, true, debug_info_p, + gnat_array); + } + } + if (Has_Atomic_Components (gnat_array) || Is_Atomic_Or_VFA (gnat_type)) check_ok_for_atomic_type (gnu_type, gnat_array, true);