From patchwork Sun Jan 27 18:16:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1031612 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-494801-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="xiJTdMxT"; 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 43ngvs6fN8z9s9h for ; Mon, 28 Jan 2019 05:17:12 +1100 (AEDT) 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=ixvRcqYeYhHYuCcT C0w3VUJEK0M6d/yavAcYG5+yBXs46dtwNY/haWMmFnehwUsTheJozKOWgYp7JP7u cNnrsAXQyKeG/m05yet9D6p6nBZPq4eDbcYRYL7sKyuyhjfrHFL6aORy7DdJOHYm GkbycTBXVjPOC/5eU1W4me2YMoI= 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=aKkMvtBms5F+tZRiHvDEo6 JsKBo=; b=xiJTdMxTdy9iurWd9hCOnEpt++TvEcKrok28UT4+VEpCI/NhgMpqOT xtpdb6ikCg44FqgwLq38rA4ArSMLq+oHHkTtMv0ieUD8BJoZlVaZ1dMFP8A43Zoj 6tqoGWSZmA+XvGc5hqB+7dIPWFPmdkVtZSMNL4Bp1t+PWKYRutGj8= Received: (qmail 98187 invoked by alias); 27 Jan 2019 18:17:05 -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 98179 invoked by uid 89); 27 Jan 2019 18:17:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:system., tre 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; Sun, 27 Jan 2019 18:17:03 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BD1BF81368 for ; Sun, 27 Jan 2019 19:17:00 +0100 (CET) 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 mcCpqTiAnTZ8 for ; Sun, 27 Jan 2019 19:17:00 +0100 (CET) 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 8C1B581354 for ; Sun, 27 Jan 2019 19:17:00 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix bogus CE raised on elaboration of multidimensional array Date: Sun, 27 Jan 2019 19:16:58 +0100 Message-ID: <2816075.FCe4BPizGZ@polaris> MIME-Version: 1.0 This is a regression present on all active branches: the compiler may generate elaboration code that wrongly raises a Constraint_Error for a multidimensional array whose component type is controlled if the unit is compiled at -O3. Tested on x86_64-suse-linux, applied on all active branches. 2019-01-27 Eric Botcazou * gcc-interface/decl.c (array_type_has_nonaliased_component): Return the same value for every dimension of a multidimensional array type. 2019-01-27 Eric Botcazou * gnat.dg/opt75.adb: New test. * gnat.dg/opt75_pkg.ad[sb]: New helper. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 268309) +++ gcc-interface/decl.c (working copy) @@ -6237,12 +6237,6 @@ same_discriminant_p (Entity_Id discr1, E static bool array_type_has_nonaliased_component (tree gnu_type, Entity_Id gnat_type) { - /* If the array type is not the innermost dimension of the GNAT type, - then it has a non-aliased component. */ - if (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE - && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type))) - return true; - /* If the array type has an aliased component in the front-end sense, then it also has an aliased component in the back-end sense. */ if (Has_Aliased_Components (gnat_type)) @@ -6253,15 +6247,17 @@ array_type_has_nonaliased_component (tre if (Is_Derived_Type (gnat_type)) { tree gnu_parent_type = gnat_to_gnu_type (Etype (gnat_type)); - int index; if (TREE_CODE (gnu_parent_type) == UNCONSTRAINED_ARRAY_TYPE) gnu_parent_type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_parent_type)))); - for (index = Number_Dimensions (gnat_type) - 1; index > 0; index--) - gnu_parent_type = TREE_TYPE (gnu_parent_type); return TYPE_NONALIASED_COMPONENT (gnu_parent_type); } + /* For a multi-dimensional array type, find the component type. */ + while (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE + && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type))) + gnu_type = TREE_TYPE (gnu_type); + /* Consider that an array of pointers has an aliased component, which is sort of logical and helps with Taft Amendment types in LTO mode. */ if (POINTER_TYPE_P (TREE_TYPE (gnu_type)))