From patchwork Tue Sep 16 02:36:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 389926 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 C3F0E140111 for ; Tue, 16 Sep 2014 12:36:20 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=tHJPgabm3lQkRW+8mfxjnsYNXbHAGbiIRWPVK7cFh+k zKfteZDmSqcTkiUOKOfr+6VN5I/4zOFMNbHQB+LSg3ISXmoa/tFchKyeWMhCpli8 GOoi23/1TQIxI3rRiVgOsWb0kdU+cUITyhfpjaXYZL9NvCPaCjdo9PL3cdXE2g6c = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=+MY7RolBks7bB4nTNTezO4q3mXI=; b=AhafASJ4Wx5gw4rIu HduLtova0qum3/OAI5JJ2vyYPMOlJOk5Kz8wg+TuD0OzyWrbRUtffqnZTUedJEN3 D0aDM/fc009fQFCQ9dOckLf2lapuYdoQbUWC/DJPYaeLMOqVHwyytOc3IvcsXOLr 5Ci9wOdf2r81ZMHRkve47x/a3M= Received: (qmail 10031 invoked by alias); 16 Sep 2014 02:36:13 -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 10003 invoked by uid 89); 16 Sep 2014 02:36:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 16 Sep 2014 02:36:09 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8G2a6aA008705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 15 Sep 2014 22:36:06 -0400 Received: from [10.10.116.16] ([10.10.116.16]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8G2a52w032631; Mon, 15 Sep 2014 22:36:06 -0400 Message-ID: <5417A211.6010101@redhat.com> Date: Mon, 15 Sep 2014 22:36:01 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: gcc-patches List CC: Jonathan Wakely Subject: C++ PATCH to template argument abi_tag handling Jon sent me a test that crashed with an abi_tag on a template argument. We need to propagate tags from template arguments when we first look up the specialization, not wait until instantiation. Tested x86_64-pc-linux-gnu, applying to trunk. commit 44db0cad1ad6b651616ab144896c358274eacf4f Author: Jason Merrill Date: Sat Sep 13 10:52:56 2014 -0400 * pt.c (lookup_template_class_1): Splice out abi_tag attribute if necessary. Call inherit_targ_abi_tags here. * class.c (check_bases_and_members): Not here. (inherit_targ_abi_tags): Check CLASS_TYPE_P. * cp-tree.h: Declare inherit_targ_abi_tags. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 09f946f..6b86ef4 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1441,7 +1441,8 @@ check_abi_tags (tree t, tree subob) void inherit_targ_abi_tags (tree t) { - if (CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE) + if (!CLASS_TYPE_P (t) + || CLASSTYPE_TEMPLATE_INFO (t) == NULL_TREE) return; mark_type_abi_tags (t, true); @@ -5460,9 +5461,6 @@ check_bases_and_members (tree t) bool saved_nontrivial_dtor; tree fn; - /* Pick up any abi_tags from our template arguments before checking. */ - inherit_targ_abi_tags (t); - /* By default, we use const reference arguments and generate default constructors. */ cant_have_const_ctor = 0; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 19f5232..5d8badc 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5206,6 +5206,7 @@ extern bool type_has_user_declared_move_assign(tree); extern bool type_build_ctor_call (tree); extern bool type_build_dtor_call (tree); extern void explain_non_literal_class (tree); +extern void inherit_targ_abi_tags (tree); extern void defaulted_late_check (tree); extern bool defaultable_fn_check (tree); extern void fixup_type_variants (tree); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 008879b..b3a9c95 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7823,9 +7823,18 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, if (OVERLOAD_TYPE_P (t) && !DECL_ALIAS_TEMPLATE_P (gen_tmpl)) - if (tree attributes - = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (template_type))) - TYPE_ATTRIBUTES (t) = attributes; + { + if (tree attributes + = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (template_type))) + { + if (!TREE_CHAIN (attributes)) + TYPE_ATTRIBUTES (t) = attributes; + else + TYPE_ATTRIBUTES (t) + = build_tree_list (TREE_PURPOSE (attributes), + TREE_VALUE (attributes)); + } + } /* Let's consider the explicit specialization of a member of a class template specialization that is implicitly instantiated, @@ -7950,6 +7959,8 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, TREE_PUBLIC (type_decl) = 1; determine_visibility (type_decl); + inherit_targ_abi_tags (t); + return t; } } diff --git a/gcc/testsuite/g++.dg/abi/abi-tag10.C b/gcc/testsuite/g++.dg/abi/abi-tag10.C new file mode 100644 index 0000000..f320828 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/abi-tag10.C @@ -0,0 +1,28 @@ +#ifndef ABI_TAG +#define ABI_TAG __attribute__((__abi_tag__("cxx11"))) +#endif + +typedef unsigned long size_t; + +template +struct char_traits { }; +template +struct allocator { }; + +template, typename A = allocator > +struct ABI_TAG basic_string { }; + +typedef basic_string string; + +template +struct hash +{ + size_t + operator()(T val) const; +}; + +template<> +size_t +hash::operator()(string) const { return 0; } + +// { dg-final { scan-assembler "_ZNK4hashI12basic_stringB5cxx11Ic11char_traitsIcE9allocatorIcEEEclES5_" } }