From patchwork Sat Sep 3 15:23:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 665435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3sRKXP2FJ5z9sXx for ; Sun, 4 Sep 2016 01:24:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=NFB79rF0; dkim-atps=neutral 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:message-id:date:mime-version:content-type; q=dns; s= default; b=kQU/tPNNnbB8AsGgx64XlcGmrEluzxf9V/zlDZEq8uNEbOKXQ3lUG MVHxzicDRARpO9/hLKFaIze0X9tFn3UFMEMoxgCEHu6M4xAai/2xE2cjnTNeUYl7 4n3LUL9gjMqAHJ9MyPRKSSZ409l66jMwEQOfuLgHK6v0Sc9povAzuI= 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:message-id:date:mime-version:content-type; s= default; bh=ph17SzhhYcvI2TajI89V9LieBCM=; b=NFB79rF0yad9c90K4b2q iT8uBAeylq2vnB1Lq2ilfQigsbP/UN++M2i0wwcPJOBkQzOSmYMghkBiruG+m93I /6ESzzs+YiyqsQyXS6c1Tdok+41dVG1rTjymm8z7HqsgrGNoRc+98XgkUHM0/y1F 2lD+19SrEy2OPK9IO85Hzac= Received: (qmail 7325 invoked by alias); 3 Sep 2016 15:23:53 -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 7315 invoked by uid 89); 3 Sep 2016 15:23:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=sk:RECORD_, sk:record_, tree_node*, sk:implici X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 03 Sep 2016 15:23:42 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1bgCnE-0002xS-LN from Tom_deVries@mentor.com for gcc-patches@gcc.gnu.org; Sat, 03 Sep 2016 08:23:41 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Sat, 3 Sep 2016 16:23:39 +0100 From: Tom de Vries To: GCC Patches Subject: [PATCH, c++, PR77427 ] Set TYPE_STRUCTURAL_EQUALITY for sysv_abi va_list Message-ID: <0c832b5f-9fb8-7fb7-db89-2b504d88b0e9@mentor.com> Date: Sat, 3 Sep 2016 17:23:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Hi, this patch fixes a c++ ICE, a p1 6/7 regression. Consider test.C: ... void bar (__builtin_va_list &); struct c { operator const __builtin_va_list &(); operator __builtin_va_list &(); }; void foo (void) { struct c c1; bar (c1); } ... The compiler ICEs as follows: ... test.C: In function ‘void foo()’: test.C:13:10: internal compiler error: canonical types differ for identical types __va_list_tag [1] and __va_list_tag [1] bar (c1); ^ comptypes(tree_node*, tree_node*, int) src/gcc/cp/typeck.c:1430 reference_related_p(tree_node*, tree_node*) src/gcc/cp/call.c:1415 reference_binding src/gcc/cp/call.c:1559 implicit_conversion src/gcc/cp/call.c:1805 build_user_type_conversion_1 src/gcc/cp/call.c:3776 reference_binding src/gcc/cp/call.c:1664 implicit_conversion src/gcc/cp/call.c:1805 add_function_candidate src/gcc/cp/call.c:2141 add_candidates src/gcc/cp/call.c:5394 perform_overload_resolution src/gcc/cp/call.c:4066 build_new_function_call(tree_node*, vec**, bool, int) src/gcc/cp/call.c:4143 finish_call_expr(tree_node*, vec**, bool, bool, int) src/gcc/cp/semantics.c:2440 ... The regression is caused by the commit for PR70955, that adds a "sysv_abi va_list" attribute to the struct in the va_list type (which is an array of one of struct). The ICE in comptypes happens as follows: we're comparing two versions of va_list type (with identical array element type), each with the canonical type set to themselves. Since the types are considered identical, they're supposed to have identical canonical types, which is not the case, and we run into the ICE. The patch fixes the ICE by setting the canonical type of the va_list struct and array to NULL, forcing structural comparison. This fix causes a regression for test2.C: ... template int fn7 (T ap) { return __builtin_va_arg(ap, int); } int fn8 (__builtin_va_list ap) { return fn7<__builtin_va_list> (ap); } ... It causes this warning to appear: ... test2.C: In function ‘int fn8(__va_list_tag*)’: test2.C:11:36: warning: ignoring attributes applied to ‘__va_list_tag’ after definition [-Wattributes] return fn7<__builtin_va_list> (ap); ... The patch removes the warning by considering the attribute on the va_list struct type as engrained in apply_identity_attributes. Bootstrapped and reg-tested on x86_64. OK for trunk, 6 branch? Thanks, - Tom Set TYPE_STRUCTURAL_EQUALITY for sysv_abi va_list 2016-09-03 Tom de Vries PR c++/77427 * config/i386/i386.c (ix86_build_builtin_va_list_64): Set TYPE_STRUCTURAL_EQUALITY for record and array. * tree.c (apply_identity_attributes): Consider attributes ingrained on records and unions. * g++.dg/pr77427.C: New test. --- gcc/config/i386/i386.c | 6 +++++- gcc/cp/tree.c | 3 ++- gcc/testsuite/g++.dg/pr77427.C | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 4531647..4e00dee 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -10550,9 +10550,13 @@ ix86_build_builtin_va_list_64 (void) TYPE_ATTRIBUTES (record) = tree_cons (get_identifier ("sysv_abi va_list"), NULL_TREE, TYPE_ATTRIBUTES (record)); + SET_TYPE_STRUCTURAL_EQUALITY (record); /* The correct type is an array type of one element. */ - return build_array_type (record, build_index_type (size_zero_node)); + tree res = build_array_type (record, build_index_type (size_zero_node)); + SET_TYPE_STRUCTURAL_EQUALITY (res); + + return res; } /* Setup the builtin va_list data type and for 64-bit the additional diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 6d254dd..0259bbf 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1244,7 +1244,8 @@ apply_identity_attributes (tree result, tree attribs, bool *remove_attributes) tree new_attribs = NULL_TREE; tree *p = &new_attribs; - if (OVERLOAD_TYPE_P (result)) + if (OVERLOAD_TYPE_P (result) + || RECORD_OR_UNION_TYPE_P (result)) { /* On classes and enums all attributes are ingrained. */ gcc_assert (attribs == TYPE_ATTRIBUTES (result)); diff --git a/gcc/testsuite/g++.dg/pr77427.C b/gcc/testsuite/g++.dg/pr77427.C new file mode 100644 index 0000000..544946d --- /dev/null +++ b/gcc/testsuite/g++.dg/pr77427.C @@ -0,0 +1,17 @@ +// { dg-do compile } + +void bar (__builtin_va_list &); + +struct c +{ + operator const __builtin_va_list &(); + operator __builtin_va_list &(); +}; + +void +foo (void) +{ + struct c c1; + + bar (c1); +}