From patchwork Mon Aug 21 17:15:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 804113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-460658-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fSMqPwdj"; dkim-atps=neutral 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 3xbgML5MTQz9sRW for ; Tue, 22 Aug 2017 03:16:11 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=G11uL8hUG7xTT7iIRhpiDQ50iNquKUUmp54u2dzU2oXjVZ2BlC P1IWkObhTrw0VrO7EUD3oiSz70Ay3QnEsSscafIcrjJi/KNVJi6ne8YxQmroxvGQ lQDi0fAXJ94qZYQmWZaGc4ASPmJLkJGWHAP6pRwaUC0vcp4q7vlwbWtF8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=M3iQBUhiYnZqxmhMWw2+aNtCmvc=; b=fSMqPwdjDRH1ecnvS/WW ESbwq9LtrrujEaT6FvEIk/TdjslbYCSvB4SoLrNTE9GEB/QLMA0pNLHCs9F+bwbm 81bZsPj6zbvcFWk0+dKx6MEPIRN76cslDA4goTQChrMNRvOBr/YlqfwRkZbD/MDk weAflXn9RyYbbzTs4HnCneg= Received: (qmail 125752 invoked by alias); 21 Aug 2017 17:16:02 -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 124711 invoked by uid 89); 21 Aug 2017 17:15:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=ilk X-HELO: mail-yw0-f179.google.com Received: from mail-yw0-f179.google.com (HELO mail-yw0-f179.google.com) (209.85.161.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 Aug 2017 17:15:37 +0000 Received: by mail-yw0-f179.google.com with SMTP id h127so26561275ywf.0 for ; Mon, 21 Aug 2017 10:15:35 -0700 (PDT) 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=lNR3wjIqWYfnfujjbwFcsHd9de0aAUxnqmlzhb0QPUI=; b=Jn+cLD3X4ff9R9uUVkB3LhElGlsVRkFhBy03gYWjK+U2tIJ6I7TMNZvcd/WUAPDN9i w0WxBSVL+NyMfPNmiXgL/dg0b3k5S9O0av8TdyVk//eVk53tMyux18KGTSgXwkzwBTTg xscwGTBTudvo9VdLI1B4fZR+NfhCSKhYW/vLiEYzglkB2HnI5PyQJL10YMFD1pyZbAk3 5JJRhegGQ8ZmQHbNT3e5X6TfdItbbtR+tYwvuLIQu9r0ZxePSyCMUFCPPIQH05ii4U8o lBfE1mpGoibUhx4wcKpkDjGiHXki5VG5sRpU292LemSg2atX37HQr1FqfJVj6GEhmdHA 6t3g== X-Gm-Message-State: AHYfb5gzcV+y20XBLpx9W4yA06n/Mwb/us0dLJSvuGIFDNv5qHuBN1NL YaOYDjgVi1cvkA== X-Received: by 10.37.201.69 with SMTP id z66mr15469045ybf.216.1503335734167; Mon, 21 Aug 2017 10:15:34 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:59fa]) by smtp.googlemail.com with ESMTPSA id r24sm4740889ywa.16.2017.08.21.10.15.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Aug 2017 10:15:33 -0700 (PDT) To: GCC Patches Cc: David Malcolm From: Nathan Sidwell Subject: [C++ PATCH] class member lookup Message-ID: <4ad6f482-3d1b-cc3f-58a8-d841260bf1b2@acm.org> Date: Mon, 21 Aug 2017 13:15:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 This small patch adds asserts that we never get to look for a field in a non-class. I'm moving this code around on the name-lookup branch, but as Jakub found & fixed a previous suprise of this ilk, I thought I'd put this straight on trunk to get wider exposure of the invariant. I also noticed that fuzzy lookup no longer needed to look at METHOD_VEC, as member fns are on TYPE_FIELDS now. David, FWIW it looks like that lookup could be less twisty if fuzzy_lookup_fields was a static member fn taking a void *? nathan 2017-08-21 Nathan Sidwell * search.c (lookup_field_1): Assert TYPE is a class and VFIELD isn't special. (lookup_field_fuzzy_info::fuzzy_lookup_fnfields): Delete. (lookup_field_fuzzy_r): Adjust. Index: search.c =================================================================== --- search.c (revision 251221) +++ search.c (working copy) @@ -371,18 +371,7 @@ lookup_field_1 (tree type, tree name, bo { tree field; - gcc_assert (identifier_p (name)); - - if (TREE_CODE (type) == TEMPLATE_TYPE_PARM - || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM - || TREE_CODE (type) == TYPENAME_TYPE) - /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and - BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all; - instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously, - the code often worked even when we treated the index as a list - of fields!) - The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */ - return NULL_TREE; + gcc_assert (identifier_p (name) && RECORD_OR_UNION_TYPE_P (type)); if (CLASSTYPE_SORTED_FIELDS (type)) { @@ -474,13 +463,11 @@ lookup_field_1 (tree type, tree name, bo && (!want_type || DECL_DECLARES_TYPE_P (decl))) return decl; } - /* Not found. */ - if (name == vptr_identifier) - { - /* Give the user what s/he thinks s/he wants. */ - if (TYPE_POLYMORPHIC_P (type)) - return TYPE_VFIELD (type); - } + + /* We used to special-case vptr_identifier. Make sure it's not + special any more. */ + gcc_assert (name != vptr_identifier || !TYPE_VFIELD (type)); + return NULL_TREE; } @@ -1374,7 +1361,6 @@ class lookup_field_fuzzy_info lookup_field_fuzzy_info (bool want_type_p) : m_want_type_p (want_type_p), m_candidates () {} - void fuzzy_lookup_fnfields (tree type); void fuzzy_lookup_field (tree type); /* If true, we are looking for types, not data members. */ @@ -1383,27 +1369,6 @@ class lookup_field_fuzzy_info auto_vec m_candidates; }; -/* Locate all methods within TYPE, append them to m_candidates. */ - -void -lookup_field_fuzzy_info::fuzzy_lookup_fnfields (tree type) -{ - vec *method_vec; - tree fn; - size_t i; - - if (!CLASS_TYPE_P (type)) - return; - - method_vec = CLASSTYPE_METHOD_VEC (type); - if (!method_vec) - return; - - for (i = 0; vec_safe_iterate (method_vec, i, &fn); ++i) - if (fn) - m_candidates.safe_push (OVL_NAME (fn)); -} - /* Locate all fields within TYPE, append them to m_candidates. */ void @@ -1432,11 +1397,6 @@ lookup_field_fuzzy_r (tree binfo, void * lookup_field_fuzzy_info *lffi = (lookup_field_fuzzy_info *) data; tree type = BINFO_TYPE (binfo); - /* First, look for functions. */ - if (!lffi->m_want_type_p) - lffi->fuzzy_lookup_fnfields (type); - - /* Look for data member and types. */ lffi->fuzzy_lookup_field (type); return NULL_TREE;