From patchwork Mon Dec 9 12:22:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1206165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515509-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="TL/Wpbwm"; 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 47Wj5S512Sz9sNH for ; Mon, 9 Dec 2019 23:23:07 +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=iLfcAeZRRZ/rA6ne ehkig93TZ25TGQovqZ/iFyGkLlCzbuP1trUSW9FEbeJ5YUQYtBhUyBRhpGCCsygZ JujCrGG1wCVlZ6ScOt0ljzGsezlIJM9uNxBtbyPhVFQAH+X9t2wNTV0ZhjCkO4Ey qf+nU/S1PBpGL41LBYkqWxh6iEc= 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=YjEG7PcLO05VTr+s+8qyAY eJ/ys=; b=TL/Wpbwm+G6PJ0lSzDLT0jVUMJvylQiopVHeoApp//dUvLEySOHF7U odxgSJWmO+R6gGBqhl2UxaT/PsZrQ3go5sPya9g95Hq1AMjEpDpRiPM473IARNgF M4dz0nGPQZNSX4/INK03NkAJNXlMLxPA6trqROVIZ4DL/OxHSQTiI= Received: (qmail 37636 invoked by alias); 9 Dec 2019 12:23:00 -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 37303 invoked by uid 89); 9 Dec 2019 12:23:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=2009, equality, surprising 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; Mon, 09 Dec 2019 12:22:58 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 97A9A81388 for ; Mon, 9 Dec 2019 13:22:55 +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 fAHbv9ht2RbG for ; Mon, 9 Dec 2019 13:22:55 +0100 (CET) Received: from polaris.localnet (unknown [IPv6:2a01:e0a:41b:9230:1a03:73ff:fe45:373a]) (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 6C4D981380 for ; Mon, 9 Dec 2019 13:22:55 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix ICE on VLA in LTO mode Date: Mon, 09 Dec 2019 13:22:53 +0100 Message-ID: <14329479.qMsKKfkivG@polaris> MIME-Version: 1.0 Hi, this is a regression present on the mainline and 9 branch: the compiler gives an ICE for the attached Ada testcase on the following assertion: if (DECL_P (ref)) { /* We shouldn't have true variables here. */ gcc_assert (TREE_READONLY (ref)); subst = ref; } in self_referential_size because the size function machinery is invoked again by the *free_lang_data pass, more precisely from fld_process_array_type: if (!existed) { array = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t), false, false); TYPE_CANONICAL (array) = TYPE_CANONICAL (t); if (!fld->pset.add (array)) add_tree_to_fld_list (array, fld); } through the call to build_array_type_1, and more precisely through the recursive call made for computing TYPE_CANONICAL: if (TYPE_CANONICAL (t) == t) { if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) || in_lto_p) SET_TYPE_STRUCTURAL_EQUALITY (t); else if (TYPE_CANONICAL (elt_type) != elt_type || (index_type && TYPE_CANONICAL (index_type) != index_type)) TYPE_CANONICAL (t) = build_array_type_1 (TYPE_CANONICAL (elt_type), index_type ? TYPE_CANONICAL (index_type) : NULL_TREE, typeless_storage, shared, set_canonical); } That's a bit surprising because t2 is an incomplete type and we have these lines in build_array_type_1 just before: /* If the element type is incomplete at this point we get marked for structural equality. Do not record these types in the canonical type hashtable. */ if (TYPE_STRUCTURAL_EQUALITY_P (t)) return t; so the computation of TYPE_CANONICAL should be skipped. But it turns out that these lines from 2009 are obsolete because layout_type no longer forces the TYPE_STRUCTURAL_EQUALITY_P on the array when the element type is incomplete. Since fld_process_array_type overwrites TYPE_CANONICAL just after the call to build_array_type_1, there is no point for the latter in computing it so the proposed fix is to add a new SET_CANONICAL parameter to build_array_type_1. Tested on x86_64-suse-linux, OK for mainline and 9 branch? 2019-12-09 Eric Botcazou * tree.c (build_array_type_1): Add SET_CANONICAL parameter and compute TYPE_CANONICAL from the element type only if it is set. Remove obsolete lines and adjust recursive call. (fld_process_array_type): Adjust call to build_array_type_1. (build_array_type): Likewise. (build_nonshared_array_type): Likewise. 2019-12-09 Eric Botcazou * gnat.dg/lto23.adb: New test. Index: tree.c =================================================================== --- tree.c (revision 278938) +++ tree.c (working copy) @@ -266,7 +266,7 @@ static void print_type_hash_statistics ( static void print_debug_expr_statistics (void); static void print_value_expr_statistics (void); -static tree build_array_type_1 (tree, tree, bool, bool); +static tree build_array_type_1 (tree, tree, bool, bool, bool); tree global_trees[TI_MAX]; tree integer_types[itk_none]; @@ -5303,8 +5303,9 @@ fld_process_array_type (tree t, tree t2, = map->get_or_insert (t, &existed); if (!existed) { - array = build_array_type_1 (t2, TYPE_DOMAIN (t), - TYPE_TYPELESS_STORAGE (t), false); + array + = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t), + false, false); TYPE_CANONICAL (array) = TYPE_CANONICAL (t); if (!fld->pset.add (array)) add_tree_to_fld_list (array, fld); @@ -8155,11 +8156,12 @@ subrange_type_for_debug_p (const_tree ty /* Construct, lay out and return the type of arrays of elements with ELT_TYPE and number of elements specified by the range of values of INDEX_TYPE. If TYPELESS_STORAGE is true, TYPE_TYPELESS_STORAGE flag is set on the type. - If SHARED is true, reuse such a type that has already been constructed. */ + If SHARED is true, reuse such a type that has already been constructed. + If SET_CANONICAL is true, compute TYPE_CANONICAL from the element type. */ static tree build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage, - bool shared) + bool shared, bool set_canonical) { tree t; @@ -8176,19 +8178,13 @@ build_array_type_1 (tree elt_type, tree TYPE_TYPELESS_STORAGE (t) = typeless_storage; layout_type (t); - /* If the element type is incomplete at this point we get marked for - structural equality. Do not record these types in the canonical - type hashtable. */ - if (TYPE_STRUCTURAL_EQUALITY_P (t)) - return t; - if (shared) { hashval_t hash = type_hash_canon_hash (t); t = type_hash_canon (hash, t); } - if (TYPE_CANONICAL (t) == t) + if (TYPE_CANONICAL (t) == t && set_canonical) { if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) @@ -8200,7 +8196,7 @@ build_array_type_1 (tree elt_type, tree = build_array_type_1 (TYPE_CANONICAL (elt_type), index_type ? TYPE_CANONICAL (index_type) : NULL_TREE, - typeless_storage, shared); + typeless_storage, shared, set_canonical); } return t; @@ -8211,7 +8207,8 @@ build_array_type_1 (tree elt_type, tree tree build_array_type (tree elt_type, tree index_type, bool typeless_storage) { - return build_array_type_1 (elt_type, index_type, typeless_storage, true); + return + build_array_type_1 (elt_type, index_type, typeless_storage, true, true); } /* Wrapper around build_array_type_1 with SHARED set to false. */ @@ -8219,7 +8216,7 @@ build_array_type (tree elt_type, tree in tree build_nonshared_array_type (tree elt_type, tree index_type) { - return build_array_type_1 (elt_type, index_type, false, false); + return build_array_type_1 (elt_type, index_type, false, false, true); } /* Return a representation of ELT_TYPE[NELTS], using indices of type