From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.eu.adacore.com (mel.act-europe.fr [IPv6:2a02:2ab8:224:1::a0a:d2]) by sourceware.org (Postfix) with ESMTPS id D819F387701A for ; Wed, 11 Mar 2020 07:49:22 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id B805281386 for ; Wed, 11 Mar 2020 08:49:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at eu.adacore.com 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 SxlQnMnPi66z for ; Wed, 11 Mar 2020 08:49:21 +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 9458281385 for ; Wed, 11 Mar 2020 08:49:21 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix middle-end/93961 Date: Wed, 11 Mar 2020 08:49:19 +0100 Message-ID: <2013248.zzpuD0pr01@polaris> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart9780447.2Tt25oM3X4" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2020 07:49:24 -0000 This is a multi-part message in MIME format. --nextPart9780447.2Tt25oM3X4 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, this is a GIMPLE verification failure in LTO mode on Ada code: /vol/gcc/src/hg/master/local/gcc/testsuite/gnat.dg/lto24_pkg1.ads:9:8: error: type mismatch in 'component_ref' lto24_pkg1__rec___b___XVN lto24_pkg1__rec___b___XVN The __XVN fields are the fields with QUAL_UNION_TYPE in Ada, which is the only language using this type. The issue is that tree_is_indexable doesn't return the same result for a FIELD_DECL with QUAL_UNION_TYPE and the QUAL_UNION_TYPE, resulting in two instances of the QUAL_UNION_TYPE in the bytecode. The result for the type is the correct one (false, since it is variably modified) while the result for the field is falsely true because: else if (TREE_CODE (t) == FIELD_DECL && lto_variably_modified_type_p (DECL_CONTEXT (t))) return false; is not satisfied. The reason for this is that the DECL_QUALIFIER of fields of a QUAL_UNION_TYPE depends on a discriminant in Ada, which means that the size of the type does too (CONTAINS_PLACEHOLDER_P), which in turn means that it is reset to a mere PLACEHOLDER_EXPR by free_lang_data, which finally means that the size of DECL_CONTEXT is too, so RETURN_TRUE_IF_VAR is false. In other words, the CONTAINS_PLACEHOLDER_P property of the DECL_QUALIFIER of fields of a QUAL_UNION_TYPE hides the variably_modified_type_p property of these fields, if you look from the outside. This was clearly overlooked (by me) when the handling of PLACEHOLDER_EXPR was added to LTO a decade ago, but I think that it's now too late to fundamentally change how this is done, so I propose the attached fix. Tested on SPARC/Solaris and x86-64/Linux, OK for the mainline? It's not a regression, but the fix is a no-op except for Ada and we have been using it internally for some time without any issue so far. 2020-03-11 Eric Botcazou PR middle-end/93961 * tree.c (variably_modified_type_p) : Recurse into fields whose type is a qualified union. -- Eric Botcazou --nextPart9780447.2Tt25oM3X4 Content-Disposition: attachment; filename="pr93961.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="pr93961.diff" diff --git a/gcc/tree.c b/gcc/tree.c index 66d52c71c99..905563fa4be 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -9206,8 +9206,18 @@ variably_modified_type_p (tree type, tree fn) RETURN_TRUE_IF_VAR (DECL_SIZE (t)); RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t)); + /* If the type is a qualified union, then the DECL_QUALIFIER + of fields can also be an expression containing a variable. */ if (TREE_CODE (type) == QUAL_UNION_TYPE) RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t)); + + /* If the field is a qualified union, then it's only a container + for what's inside so we look into it. That's necessary in LTO + mode because the sizes of the field tested above have been set + to PLACEHOLDER_EXPRs by free_lang_data. */ + if (TREE_CODE (TREE_TYPE (t)) == QUAL_UNION_TYPE + && variably_modified_type_p (TREE_TYPE (t), fn)) + return true; } break; --nextPart9780447.2Tt25oM3X4--