From patchwork Thu Apr 16 15:47:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1271767 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=8.43.85.97; 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=MrxgPvwV; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4933XJ2Q79zB41r for ; Fri, 17 Apr 2020 01:47:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27EFE385C426; Thu, 16 Apr 2020 15:47:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by sourceware.org (Postfix) with ESMTPS id 2FC56385B835 for ; Thu, 16 Apr 2020 15:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2FC56385B835 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-x732.google.com with SMTP id v7so21833103qkc.0 for ; Thu, 16 Apr 2020 08:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:cc:from:subject:message-id:date:user-agent:mime-version :content-language; bh=vhzKD31hPsLIkJaJW2NZ3OxT2DYbSoJkrwVXybeFK0E=; b=MrxgPvwVDO3qGLmOjCJwe9Dr7TrXDFoiFYVCFy74cR6OYXpYOMbR8BsFGxmyyfU+ZN jEBpMfHXwt6KUvNdbZgAEFPGNrKhFkspUTgXkUmt6/+m3UaJg+JfHZyRrz3iBuJZqUmi GQiCvavI4dPEsbd6BjyETz0dmr8yydPMrHXIAIE0pw1IdvxoIjLypvFds0NTWDu/WKr7 bb4xErw+Oyvkp+nAbqyt4mKXlupBFgpVOJN8Jtlp/wNUfyexyGDv+wDEe/b0CzF0NucA 95OPQH1NinIpXUPPAMfFz3eNqWuKEylBk1tvYKczyUQ9o1q4Atk2zvC/cAQ2kDtrcc4h OuCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=vhzKD31hPsLIkJaJW2NZ3OxT2DYbSoJkrwVXybeFK0E=; b=QoYAGeBgQi6rC8FQLPaaKZo7VDdjPH1RnEigcmmajEGtIZafYKtBzWP0FLrvXHzdMa rZgEZ/RCppuiUjEuP2jY5tIjGVuVdftCVw/mHrZ7aa45vnHZY4r3fmiko4Gb1g8Ny/pS VjCNQMo/Apmzq7dIXzdJr2XHDHBUCr1XlviwEEPEtcgSetqjZcIIWo/xtpI+lPGsZ22j bgNokayLaJ+K0DNKd6QyuDnN4y2DyBv/mqJtawXN/A5Exvc0wXV/yjcmnlarJsrOh1D1 3XLuuXEoSz8Fr/LB8zlHPoLen0FXU+MzqFq/ETSRGVlYi7OjE+Qda7/wkQyvPy70dD5z Y9rw== X-Gm-Message-State: AGi0PuYLT+5aDdOgUogW6QFYDW6BOKWo9F5EXLUXm+qIpKiCKVvsHvwf jjUCc0kXInZtn7brO2Jl4Vk= X-Google-Smtp-Source: APiQypLV6jBL5+FQdod02iabZmkgK3Ya+pjnD7z5Ymo5/qQ8zBi5RtcOJE+OH7YGMaaXnh8SttIm5A== X-Received: by 2002:a05:620a:2141:: with SMTP id m1mr33411040qkm.231.1587052070441; Thu, 16 Apr 2020 08:47:50 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:d576:b2c:87d0:1dec? ([2620:10d:c091:480::8f7f]) by smtp.googlemail.com with ESMTPSA id f130sm3184192qke.22.2020.04.16.08.47.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Apr 2020 08:47:49 -0700 (PDT) To: Jason Merrill From: Nathan Sidwell Subject: [PR94454] specialization hashtable inconsistencies Message-ID: <8a383686-4c6e-b4c9-3bc6-c87b416592ff@acm.org> Date: Thu, 16 Apr 2020 11:47:47 -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=-20.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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: , Cc: Iain Sandoe , GCC Patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" These patches address 3 separate things I discovered in working on pr94454. As mentioned in the bug, we have disagreement between hash value equality and key equality in the specialization table. Once Iain got a reproducible build on gcc110, I came up with pr94454-shim.diff. This (a) causes all specializations to only be hashed by their template. and (b) adds a checking assert to the argument comparator, to assert that if the arguments are equal, the argument's hashes are the same. This triggered the problem, and a bunch of other cases using the existing testsuites. We use comp_template_args not only for the hash table, but for specialization ordering and the like, hence the protection of that checking_assert for some special cases. While we could keep the checking assert, the neutering of the hasher to increase collisions really kills performance -- some of the libstdc++ tests timeout on a non-optimized checking build. I don't think that should be enabled with checking. There doesn't seem to be an obvious existing checking flag to add it to (type_checking is enabled on a checking build). The problem Eric hit in his case was that expression pack expansions were comparing equal, (but hashing differently). Causing us to create two, apparently equal, specializations that would sometimes collide. I'm not sure why we had some randomness in reproducibility. I didn't locate an uninitialized field, which was one of my hypotheses about the cause. This is fixed by pr94454-pack.diff. cp_tree_operand_length says a pack has 1 operand (for mangling), whereas it actually has 3, but only two of which are significant for equality. We must special case that in cp_tree_equal. That new code matches the hasher and the type_pack_expansion case in structural_comp_types. However, I also discovered 2 other problems. The first is that the hasher was not skipping nodes that template_args_equal would. Fixed by replacing the STRIP_NOPS invocation by a bespoke loop. There's also a change to tpl-tpl-parm hashing, which is part of the next problem ... ... we treat tpl-tpl-parms as types. They're not; bound-tpl-tpl-parms are. We can get away with them being type-like. Unfortunately we give the original level==orig_level case a canonical type, but the reduced cases of level PR 94454 - tpl-tpl-parms are not canonicalized types * pt.c (canonical_type_parameter): Assert not a tpl-tpl-parm. (process_template_parm): tpl-tpl-parms are structural. (rewrite_template_parm): Propagate structuralness. diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 0a8ec3198d2..5bc94a85129 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -4382,6 +4402,9 @@ canonical_type_parameter (tree type) { tree list; int idx = TEMPLATE_TYPE_IDX (type); + + gcc_assert (TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM); + if (!canonical_template_parms) vec_alloc (canonical_template_parms, idx + 1); @@ -4564,7 +4587,10 @@ process_template_parm (tree list, location_t parm_loc, tree parm, processing_template_decl, decl, TREE_TYPE (parm)); TEMPLATE_TYPE_PARAMETER_PACK (t) = is_parameter_pack; - TYPE_CANONICAL (t) = canonical_type_parameter (t); + if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM) + SET_TYPE_STRUCTURAL_EQUALITY (t); + else + TYPE_CANONICAL (t) = canonical_type_parameter (t); } DECL_ARTIFICIAL (decl) = 1; SET_DECL_TEMPLATE_PARM_P (decl); @@ -28005,7 +28039,10 @@ rewrite_template_parm (tree olddecl, unsigned index, unsigned level, TEMPLATE_PARM_PARAMETER_PACK (newidx) = TEMPLATE_PARM_PARAMETER_PACK (oldidx); TYPE_STUB_DECL (newtype) = TYPE_NAME (newtype) = newdecl; - TYPE_CANONICAL (newtype) = canonical_type_parameter (newtype); + if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (olddecl))) + SET_TYPE_STRUCTURAL_EQUALITY (newtype); + else + TYPE_CANONICAL (newtype) = canonical_type_parameter (newtype); if (TREE_CODE (olddecl) == TEMPLATE_DECL) {