From patchwork Tue Aug 18 21:52:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1347293 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sWv4uuWZ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BWPlR5W09z9sPf for ; Wed, 19 Aug 2020 07:52:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DEBA13858D38; Tue, 18 Aug 2020 21:52:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 0A50C3858D37 for ; Tue, 18 Aug 2020 21:52:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0A50C3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x72d.google.com with SMTP id b14so19808813qkn.4 for ; Tue, 18 Aug 2020 14:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=gZRuDSjtadMTqtQR6E3Rv/4wPP+AbSvJ0hZRx3zFq5g=; b=sWv4uuWZeYD82jnyIIDpKTR3mvGAQWs5I9G90xo/M7OcSp6h0fO3gzAnDXd8hJ08lP /YsoP4xSEgl1Yjff6MzCEgthV910BM3Hn52w0yMAvrm+zgkTDxZEBrDrw8oSmkDuHJ3x nI3837CG7UbTBYpmvg6K+GfhSl+5idpyfr9uExIpEZIoE+08iVFNj2rBxTLUdC89HCGy 7hTUxSBsDBMFOjAxoQ493uz9WOVQqCqtfYh2CJIS+TEMbEOSpl2i4vt4w4SgaaDejtyQ UcdG310ZM7IKk1TQpH1nzyIWDdAgNX2YX17+ySyuF7n0IWzZd1WIVVOOlt5eG8WKqhLc VWvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=gZRuDSjtadMTqtQR6E3Rv/4wPP+AbSvJ0hZRx3zFq5g=; b=P+ESj/iehEJf3YmgzthCM6KS4CuQaa8Jf83waRUsusufSyFcCexJquJrE+pr/6hlOe haHXUzsYoFA/Y2QkOPfuxshdlaJdUGHe0AU71EdltlbfR4dh2OcxWbSCmiZY6D/5lBtn xRiKeYaUVmUpS/QdquVtIQozCybDLDxXuiCT/y3xuRNk4UnD06mjtamytB+akSCPFdYk 1knhy+gWRf7MZvSTA3oqRZXYmVlFIJUDHp82tUgmdaPMAFqk09IaBI/pq+T7GucwWyxJ RPxOpLMg9cmnjSWu5+sH37v1YMvvlwauNcUPfBmNSXZW6/BM3cuWkpbjABYEEHcTzGAB X/Yg== X-Gm-Message-State: AOAM530lMRtw55jwEoz1V4irOUV5NX/qSSE4Nc0efU+pz0A2ybNWq4xG aMf+OttG0vYJ5cY6dtKSF5k= X-Google-Smtp-Source: ABdhPJzV1FxLTSDVI1Sfd5LLmByGQk7Mj6obhwaoOewI4cwOi54tNPImSorEYN2zfd3PNYqQuZH0QA== X-Received: by 2002:a05:620a:201a:: with SMTP id c26mr18582636qka.155.1597787534311; Tue, 18 Aug 2020 14:52:14 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:2409:d99a:6a31:3631? ([2620:10d:c091:480::1:d440]) by smtp.googlemail.com with ESMTPSA id c142sm22002025qkg.71.2020.08.18.14.52.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Aug 2020 14:52:13 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: alias template template_info setting Message-ID: <0bf8ca9b-70d8-202b-e672-1e275d73aaab@acm.org> Date: Tue, 18 Aug 2020 17:52:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" During the construction of alias templates we can alter its template_info. This is really weird, because that's morally immutable data. In this case it's ok, but let's not create a duplicate template_info, and add asserts to make sure it is changing in exactly the way we expect. Needless to say modules fell over the duplicated template_info and got very confused. gcc/cp/ * cp-tree.h (SET_TYPE_TEMPLTE_INFO): Do not deal with ALIAS templates. * pt.c (lookup_template_class_1): Special-case alias template template_info setting. diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 04758574019..5f2c7e574c4 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -3485,13 +3485,12 @@ struct GTY(()) lang_decl { ? TYPE_ALIAS_TEMPLATE_INFO (NODE) \ : TYPE_TEMPLATE_INFO (NODE)) -/* Set the template information for an ENUMERAL_, RECORD_, or - UNION_TYPE to VAL. */ +/* Set the template information for a non-alias n ENUMERAL_, RECORD_, + or UNION_TYPE to VAL. ALIAS's are dealt with separately. */ #define SET_TYPE_TEMPLATE_INFO(NODE, VAL) \ - (TREE_CODE (NODE) == ENUMERAL_TYPE \ - || (CLASS_TYPE_P (NODE) && !TYPE_ALIAS_P (NODE)) \ - ? (TYPE_LANG_SLOT_1 (NODE) = (VAL)) \ - : (DECL_TEMPLATE_INFO (TYPE_NAME (NODE)) = (VAL))) + (gcc_checking_assert (TREE_CODE (NODE) == ENUMERAL_TYPE \ + || (CLASS_TYPE_P (NODE) && !TYPE_ALIAS_P (NODE))), \ + (TYPE_LANG_SLOT_1 (NODE) = (VAL))) \ #define TI_TEMPLATE(NODE) \ ((struct tree_template_info*)TEMPLATE_INFO_CHECK (NODE))->tmpl diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index b80fe0a5cc5..ada0438f272 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -10088,8 +10088,26 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, } } - // Build template info for the new specialization. - SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist)); + /* Build template info for the new specialization. */ + if (TYPE_ALIAS_P (t)) + { + /* This is constructed during instantiation of the alias + decl. But for member templates of template classes, that + is not correct as we need to refer to the partially + instantiated template, not the most general template. + The incorrect knowledge will not have escaped this + instantiation process, so we're good just updating the + template_info we made then. */ + tree ti = DECL_TEMPLATE_INFO (TYPE_NAME (t)); + gcc_checking_assert (template_args_equal (TI_ARGS (ti), arglist)); + if (TI_TEMPLATE (ti) != found) + { + gcc_checking_assert (DECL_TI_TEMPLATE (found) == TI_TEMPLATE (ti)); + TI_TEMPLATE (ti) = found; + } + } + else + SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist)); elt.spec = t; slot = type_specializations->find_slot_with_hash (&elt, hash, INSERT);