From patchwork Tue Mar 20 15:54:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 888290 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-475038-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="rt3/xzla"; 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 405HYy60Vhz9s0n for ; Wed, 21 Mar 2018 02:54:45 +1100 (AEDT) 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=p8iEVPUKfNpJ/tXJOIlvS19g/0QreBg95Tb7NTh1NNNSh4Vr9+ awc5Wbq0yQ5s3Y+DieLcfEul7e3TE4Ir7fgmYcqg/AegcZ7XiJ3bB21iJQ8oeOpa BoseHHvQUAhpiK49EbEvutIH1eGKK2APtssG2kOgkujhPPLcF90Ks+IOM= 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=W7KXtQIRx2AV7j4NLMoLVdfY1uI=; b=rt3/xzla6vOKqxFD1vgq mS7gljWq4hVAqmz13ER/3znUHcDXDhkeHva7avxxWlZ5NWsrx9VxCEGYXRizA19o UPMkSA5ac2ivwl46ppdAjpeeAE4EVcIuZOK2od332SHTDQp5/SZMmh8srYw0oYyx xBctddCzDOvtFkE5uZ/tI9c= Received: (qmail 69020 invoked by alias); 20 Mar 2018 15:54:39 -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 68642 invoked by uid 89); 20 Mar 2018 15:54:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=templates X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Mar 2018 15:54:36 +0000 Received: by mail-yw0-f173.google.com with SMTP id y23so678425ywy.4 for ; Tue, 20 Mar 2018 08:54:36 -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=LY89OtZnEuwizIVVBAK6kSlXRE83v1mHHO6U0le2Ki4=; b=PuvsMh4hDKFGz9Q8+0BrkEVNyFCNxanRRWWEt4YluEAbpA81fLnzDrQEIenwGu5yq0 jfjTq8VAYUHb9uPvOhKfl0lmwh4aKXyaGcY+3f+qcfQ1udXMNZYxSvbDHUFaZGaeHwVD DdneFYC3fB3ct/z0gtW+rwBtCsJ/SjGJYb16zTxEdMqB7aNW2lNMsRSyDzYOElg0Mec1 5kxKMksDxYCq7QVYdmpEJMEdF5eisXRFks8wfJEoVlkf7thpWK7GpaOMZo1e5MTjfuRT k6MqXXXSUTzEexiI8LoklUJM686ohe9CjjLq3MKFPFV6A/Xxsr2CSdhS+Eg9PCVIJ1vb TYUQ== X-Gm-Message-State: AElRT7H6v+vfOPIkLezb6e1Z+WiQAoxOZEDSeR5OlV31ZdbZ2NnixFVm wrxERWGMUWE7/pdIRVIkAWo= X-Google-Smtp-Source: AG47ELvTzaKgD1NUt3Lk6yDDCzZ9L3RUVArLGeTo4l7hAz23KK5QHaKhgXkIzU2HwxOlqJMg+1FXMg== X-Received: by 10.13.213.193 with SMTP id x184mr9621072ywd.157.1521561275041; Tue, 20 Mar 2018 08:54:35 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:ec9e]) by smtp.googlemail.com with ESMTPSA id i11sm712290ywb.57.2018.03.20.08.54.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Mar 2018 08:54:34 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [PR c++/84970] lookup marking Message-ID: <104ba059-2270-d992-c2f5-94588d7ecdf2@acm.org> Date: Tue, 20 Mar 2018 11:54:32 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 This is another case of lookups escaping into template bodies, without being marked. In this case an initializer list. in the non-template case, we try and recycle these lookup nodes immediately. But for templates we have to mark lookups, so we don't try and mutate them via the binding. When the lookup involved via a using directive we can detect the marking failure. nathan 2018-03-20 Nathan Sidwell PR c++/84970 * cp-tree.h (lookup_list_keep): Declare. * tree.c (lookup_list_keep): New, broken out of ... (build_min): ... here. Call it. * decl.c (cp_finish_decl): Call lookup_list_keep. PR c++/84970 * g++.dg/lookup/pr84970.C: New. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 258676) +++ cp/cp-tree.h (working copy) @@ -7012,6 +7012,7 @@ extern tree lookup_add (tree fns, tre extern tree lookup_maybe_add (tree fns, tree lookup, bool deduping); extern void lookup_keep (tree lookup, bool keep); +extern void lookup_list_keep (tree list, bool keep); extern int is_overloaded_fn (tree) ATTRIBUTE_PURE; extern bool really_overloaded_fn (tree) ATTRIBUTE_PURE; extern tree dependent_name (tree); Index: cp/decl.c =================================================================== --- cp/decl.c (revision 258676) +++ cp/decl.c (working copy) @@ -7034,7 +7034,11 @@ cp_finish_decl (tree decl, tree init, bo } if (init) - DECL_INITIAL (decl) = init; + { + if (TREE_CODE (init) == TREE_LIST) + lookup_list_keep (init, true); + DECL_INITIAL (decl) = init; + } if (dep_init) { retrofit_lang_decl (decl); Index: cp/tree.c =================================================================== --- cp/tree.c (revision 258676) +++ cp/tree.c (working copy) @@ -2436,6 +2436,20 @@ lookup_keep (tree lookup, bool keep) ovl_used (lookup); } +/* LIST is a TREE_LIST whose TREE_VALUEs may be OVERLOADS that need + keeping, or may be ignored. */ + +void +lookup_list_keep (tree list, bool keep) +{ + for (; list; list = TREE_CHAIN (list)) + { + tree v = TREE_VALUE (list); + if (TREE_CODE (v) == OVERLOAD) + lookup_keep (v, keep); + } +} + /* Returns nonzero if X is an expression for a (possibly overloaded) function. If "f" is a function or function template, "f", "c->f", "c.f", "C::f", and "f" will all be considered possibly @@ -3315,9 +3329,7 @@ build_min (enum tree_code code, tree tt, if (code == CAST_EXPR) /* The single operand is a TREE_LIST, which we have to check. */ - for (tree v = TREE_OPERAND (t, 0); v; v = TREE_CHAIN (v)) - if (TREE_CODE (TREE_VALUE (v)) == OVERLOAD) - lookup_keep (TREE_VALUE (v), true); + lookup_list_keep (TREE_OPERAND (t, 0), true); return t; } Index: testsuite/g++.dg/lookup/pr84970.C =================================================================== --- testsuite/g++.dg/lookup/pr84970.C (revision 0) +++ testsuite/g++.dg/lookup/pr84970.C (working copy) @@ -0,0 +1,21 @@ +// PR c++/84970 ICE with deferred initializer + +namespace bob { + void a(); +} +using namespace bob; + +void a (int); + +template +void *x (b) +{ + void (*c)(b) (a); + + return (void *)c; +} + +void d () { + x (1); +} +