From patchwork Wed May 20 03:38:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1293961 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=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wyTQ1TvM; 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 49RdlY3GQyz9sT6 for ; Wed, 20 May 2020 13:39:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F2023851C37; Wed, 20 May 2020 03:38:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F2023851C37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589945939; bh=3A1QEP5mBR5EYR9ou8rZqlZqgSnaHVde4PVu/0AhE6k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wyTQ1TvMPBUdAZVb2UgyhqTx135rp+af5wAtXAcFEWeZ6f343F87zxmMOyQ4MsmFp boA6Ief1mEtHyBc5ocgtXKRPNUn03LBjWfy7hUoFF+ssfGe1TznjEOoiY8aHJMP+cS H+jReJLPQOUgLBTubDbhqgqqy1calMCSv1N6ZTfU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id E34AA3858D35 for ; Wed, 20 May 2020 03:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E34AA3858D35 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-w0Vf4yacNNmPo8zSqQjGKg-1; Tue, 19 May 2020 23:38:53 -0400 X-MC-Unique: w0Vf4yacNNmPo8zSqQjGKg-1 Received: by mail-qv1-f70.google.com with SMTP id i6so2237321qvq.17 for ; Tue, 19 May 2020 20:38:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3A1QEP5mBR5EYR9ou8rZqlZqgSnaHVde4PVu/0AhE6k=; b=GP28/RbQWUsBgZuwJRpYRpTW1BGoNWGA2n+iCYWuns8r1z4MlnDwYahk8/7zOUnPze M8zI4Xhv/eUtxEIlwYadTNv/ksAGA0RiOwcuPIL3ETG47kLlDqFTm2Hql5OPQ0CSnsho 2gHeOPmKrvU5kOlugWm3ZBZ9tFStE3SgjloFzn9qVetM3CqcqKRaDOtspdT4lEwbpFAV fjfLi2g9fIWRY5T7qAqigrX/YO5rr8vW+BGsnxb5sHKscLkncWoQJkqau+UjvTmQOIsA 4xEXRpKdYKGn658Uvsy13Rp2Pik0Kdvg346C8T2QPDLVeCDHG9b6iPKCqEDPDIxzsej3 nNDw== X-Gm-Message-State: AOAM530mVoa30nOjt/o/213aN2xBRvgnelH6koYAHxElNRMhYjtxQyL9 PLqMr5VOTOC4wBO2jb11oq1zKDb3IF3IihoTX6aG9q3LYTb2pNHeDIUcXgq7x183USBTaFEk7l9 gA30kKjBWmKR15jTcIA== X-Received: by 2002:aed:34c6:: with SMTP id x64mr3573810qtd.66.1589945932618; Tue, 19 May 2020 20:38:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3XrdlrGcv/QrKdCSBvn9QrXrRs3KEOi3ofIkJ8hPI6ihLtI9yDCtYKvgb97VnSHZAZXZfAg== X-Received: by 2002:aed:34c6:: with SMTP id x64mr3573796qtd.66.1589945932329; Tue, 19 May 2020 20:38:52 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id f127sm1266386qkj.61.2020.05.19.20.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2020 20:38:51 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: spec_hasher and TYPENAME_TYPE resolution [PR95223] Date: Tue, 19 May 2020 23:38:49 -0400 Message-Id: <20200520033849.2928539-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.626.g172e8ff696 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-19.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" After enabling sanitization of the specialization tables, we are triggering one of the hash table sanity checks in the below testcase. The reason is that when looking up the specialization j in the type_specializations table, the sanity check finds that the existing entry j::m> compares equal to j but hashes differently. The discrepancy is due to structural_comptypes looking through TYPENAME_TYPEs (via resolve_typename_type), something which iterative_hash_template_arg doesn't do. So the TYPENAME_TYPE n::m is considered equal to int, but the hashes of these template arguments are different. It seems wrong for the result of a specialization table lookup to depend on the current scope, so this patch makes structural_comptypes avoid calling resolve_typename_type when comparing_specializations. In order for the below testcase to deterministically trigger the sanitization error without this patch, we also need to fix the location of the call to hash_table::verify within hash_table::find_with_hash. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit? gcc/ChangeLog: PR c++/95223 * hash-table.h (hash_table::find_with_hash): Move up the call to hash_table::verify. gcc/cp/ChangeLog: PR c++/95223 * gcc/cp/typeck.c (structural_comptypes): Don't perform context-dependent resolution of TYPENAME_TYPEs when comparing_specializations. gcc/testsuite/ChangeLog: PR c++/95223 * g++.dg/template/typename23.C: New test. --- gcc/cp/typeck.c | 15 +++++++++------ gcc/hash-table.h | 14 +++++++------- gcc/testsuite/g++.dg/template/typename23.C | 10 ++++++++++ 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/typename23.C diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d2e6c907622..0181984bb99 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1256,13 +1256,16 @@ structural_comptypes (tree t1, tree t2, int strict) gcc_assert (TYPE_P (t1) && TYPE_P (t2)); - /* TYPENAME_TYPEs should be resolved if the qualifying scope is the - current instantiation. */ - if (TREE_CODE (t1) == TYPENAME_TYPE) - t1 = resolve_typename_type (t1, /*only_current_p=*/true); + if (!comparing_specializations) + { + /* TYPENAME_TYPEs should be resolved if the qualifying scope is the + current instantiation. */ + if (TREE_CODE (t1) == TYPENAME_TYPE) + t1 = resolve_typename_type (t1, /*only_current_p=*/true); - if (TREE_CODE (t2) == TYPENAME_TYPE) - t2 = resolve_typename_type (t2, /*only_current_p=*/true); + if (TREE_CODE (t2) == TYPENAME_TYPE) + t2 = resolve_typename_type (t2, /*only_current_p=*/true); + } if (TYPE_PTRMEMFUNC_P (t1)) t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1); diff --git a/gcc/hash-table.h b/gcc/hash-table.h index a1423c78112..32f3a634e1e 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -912,6 +912,12 @@ hash_table if (Lazy && m_entries == NULL) m_entries = alloc_entries (size); + +#if CHECKING_P + if (m_sanitize_eq_and_hash) + verify (comparable, hash); +#endif + value_type *entry = &m_entries[index]; if (is_empty (*entry) || (!is_deleted (*entry) && Descriptor::equal (*entry, comparable))) @@ -928,13 +934,7 @@ hash_table entry = &m_entries[index]; if (is_empty (*entry) || (!is_deleted (*entry) && Descriptor::equal (*entry, comparable))) - { -#if CHECKING_P - if (m_sanitize_eq_and_hash) - verify (comparable, hash); -#endif - return *entry; - } + return *entry; } } diff --git a/gcc/testsuite/g++.dg/template/typename23.C b/gcc/testsuite/g++.dg/template/typename23.C new file mode 100644 index 00000000000..d2fb0ca72f5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/typename23.C @@ -0,0 +1,10 @@ +// PR c++/95223 +// { dg-do compile } +// { dg-additional-options "--param=hash-table-verification-limit=10000" } + +template struct j {}; +template struct n { + typedef int m; + j::m> p(); +}; +template j::m> n::p() { return o::f(); }