From patchwork Thu Sep 21 02:50:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 816645 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-462664-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="Eh33+nff"; 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 3xyLh70JgMz9s83 for ; Thu, 21 Sep 2017 12:50:29 +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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=mE8hal+yqVQn3NJ/XOEP81eaUn54+TMk2uGNMwUk5TiVknZWnB yRpoHucBoe1OOcIutkeMPYoQuREOjVpYfsBmOkiOBddak5auMdC6XQlY8YuwSC24 oeZaCocqM31MYQ1B2wacHwcru0yYaZ/9isDY/O64A3IESb75OQh/RkMgs= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=dFsAA83HqUhQXfMRyfsrzd/Hq04=; b=Eh33+nff0oUduVOYUY/x wqq8BSyr13+8QNmN3tWHm6bZ8T8FaRt9QtqIATJQ5rjxu9QMDjsUOYD9y05zxcj9 TQSIT1SrdbS9rzQUS5lG/hl5GT71Plv9R+eckY5AGwfWI1mXQQfX3ml7cdX1nKW0 w+LFNwEZb4JRiGqjKxeyBL4= Received: (qmail 34298 invoked by alias); 21 Sep 2017 02:50:19 -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 34276 invoked by uid 89); 21 Sep 2017 02:50:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=kicked, territory X-HELO: mail-pg0-f54.google.com Received: from mail-pg0-f54.google.com (HELO mail-pg0-f54.google.com) (74.125.83.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Sep 2017 02:50:17 +0000 Received: by mail-pg0-f54.google.com with SMTP id p5so2774314pgn.7 for ; Wed, 20 Sep 2017 19:50:17 -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:from:subject:message-id:date :user-agent:mime-version:content-language; bh=/ZJezbVQ6fwWtj70Bw51IVF8ViNaun37gl7YCSr8zew=; b=HZEPDgfcNp68WS9MZHkW7cTR/+EGp4gxS5b5pFzTyLzY60T8pOc2ZTvuCd2WjXx5m7 DoWIE6v7BBU3OKcfPjMRngBeZl4iL84gvnZi4QIfhugSqv6ndfB329g/w8d2SO/hYpb8 B9KLXtD0MhviaSkyrQy+hDo0Ki8P63A5qeRc4Q6P5cK7XdEhw+aWTnNgmft+SdsQpstF EUJO26Z6nBNx6zeKiFvlZnlJhfEUVHis8urPYT6rPn4MpytyKhO/xm9msoMySTAQ9i6H s/uOaC7+GoSDEbQ44Kuo/4RWviRNXveIbqbA03Q900Iq+lYCfLC2PJoB1w/iDgzlrXx9 d+Kw== X-Gm-Message-State: AHPjjUj72KlKd5spWdUf0eAMV1MPwnLW8Z+z7x5jyvseHh8//L/VYTLR 4IrRvSFGqX3/2zp3KYGGRKg= X-Google-Smtp-Source: AOwi7QCc9/PkwoFh7L+a3jaF3u7e4Puw2QOQvmjRZedN3RnvoljaVYwme6cYhk9etkHSqzxh4q0S7Q== X-Received: by 10.84.233.70 with SMTP id k6mr4096505plt.138.1505962216148; Wed, 20 Sep 2017 19:50:16 -0700 (PDT) Received: from [10.0.70.63] ([209.92.66.180]) by smtp.googlemail.com with ESMTPSA id 77sm385964pfi.103.2017.09.20.19.50.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 19:50:15 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] class member ordering Message-ID: <510f7c74-6417-20c6-9979-7301ddcbaec7@acm.org> Date: Wed, 20 Sep 2017 19:50:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 This patch makes the class member ordering well defined, in the face of decls with identical locations. We spuriously generate duplicate TYPE_DECLS, which we shouldn't do. But we can also reach this via (at least) template parameter pack expansions. Fixed by using DECL_UID as a more complete ordering than DECL_SOURCE_LOCATION. nathan 2017-09-20 Nathan Sidwell * name-lookup.c (member_name_cmp): Use DECL_UID for final ordering. Index: name-lookup.c =================================================================== --- name-lookup.c (revision 252918) +++ name-lookup.c (working copy) @@ -1434,29 +1434,38 @@ member_name_cmp (const void *a_p, const b = OVL_FUNCTION (b); /* We're in STAT_HACK or USING_DECL territory (or possibly error-land). */ - if (TREE_CODE (a) == TREE_CODE (b)) - /* We can get two TYPE_DECLs or two USING_DECLs. Place in source - order. */ - return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; - - /* If one of them is a TYPE_DECL, it loses. */ - if (TREE_CODE (a) == TYPE_DECL) - return +1; - else if (TREE_CODE (b) == TYPE_DECL) - return -1; - - /* If one of them is a USING_DECL, it loses. */ - if (TREE_CODE (a) == USING_DECL) - return +1; - else if (TREE_CODE (b) == USING_DECL) - return -1; - - /* There are no other cases, as duplicate detection should have - kicked in earlier. However, some erroneous cases get though. - Order by source location. We should really prevent this - happening. */ - gcc_assert (errorcount); - return DECL_SOURCE_LOCATION (a) < DECL_SOURCE_LOCATION (b) ? -1 : +1; + if (TREE_CODE (a) != TREE_CODE (b)) + { + /* If one of them is a TYPE_DECL, it loses. */ + if (TREE_CODE (a) == TYPE_DECL) + return +1; + else if (TREE_CODE (b) == TYPE_DECL) + return -1; + + /* If one of them is a USING_DECL, it loses. */ + if (TREE_CODE (a) == USING_DECL) + return +1; + else if (TREE_CODE (b) == USING_DECL) + return -1; + + /* There are no other cases with different kinds of decls, as + duplicate detection should have kicked in earlier. However, + some erroneous cases get though. */ + gcc_assert (errorcount); + } + + /* Using source location would be the best thing here, but we can + get identically-located decls in the following circumstances: + + 1) duplicate artificial type-decls for the same type. + + 2) pack expansions of using-decls. + + We should not be doing #1, but in either case it doesn't matter + how we order these. Use UID as a proxy for source ordering, so + that identically-located decls still have a well-defined stable + ordering. */ + return DECL_UID (a) < DECL_UID (b) ? -1 : +1; } static struct {