From patchwork Mon May 18 17:11:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 473529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 D76EA14012C for ; Tue, 19 May 2015 03:11:15 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=CbRgtgf8; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=myKRoxOQJdn6hNsTKrUH5gs5ZHXW6qWHCPN6sPyU2JOkGr SVjaxFZ6aia1j6XB16lHZPcLUBHpR1UQ2zm0fzn6vE3PCDcBBgip/l6Bvt8N9Ife vFKqrIUw5kSpYWgcpHtwAKbwQ5o7CB8NaRrxqhvBRIz0c8G3uqieMZzQ4cnDI= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=dUm67SbqY1EmfSrkIYAJ8e2MJyw=; b=CbRgtgf8dHjF1sZhb+MO xCCQwirK/Xl/marA91YvQ6uLP+Q67IwXrrcc7nVZHn0P/v+yy6Bm9YuyARx9dUAv DschWv0ylxKkmkDBz1bxV0wA7mfeLJAWkpvcf/42+QR0TENUYhqyO8q3nMTo+k+Z XcR+t1wRRIw2rT1BIHdQrPg= Received: (qmail 2653 invoked by alias); 18 May 2015 17:11:08 -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 2644 invoked by uid 89); 18 May 2015 17:11:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 18 May 2015 17:11:07 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4IHB6sI028334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 18 May 2015 13:11:06 -0400 Received: from [10.10.116.16] ([10.10.116.16]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4IHB5Ih022199 for ; Mon, 18 May 2015 13:11:05 -0400 Message-ID: <555A1D24.7040504@redhat.com> Date: Mon, 18 May 2015 13:11:00 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for bugs in strip_typedefs* While looking at a bug report caused by failure to strip all typedefs, I came across a few latent bugs in the strip_typedefs functions. First, if we're going to return a TREE_LIST unchanged we need to copy the pointer before we change the input variable. Second, if we have a decltype with no typedefs in the argument, we still need to handle a typedef to that decltype. Third, when we strip the operands of a TRAIT_EXPR we want to update the operands of the copy, not the original. Tested x86_64-pc-linux-gnu, applying to trunk and 5. commit a5bfb34605c5ea629db6ff6db76cdaed0f675670 Author: Jason Merrill Date: Fri May 15 15:28:54 2015 -0400 * tree.c (strip_typedefs_expr) [TRAIT_EXPR]: Fix typo. (strip_typedefs) [DECLTYPE_TYPE]: Fix typedef of decltype. [TREE_LIST]: Fix no-change case. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index ec9be8c..eebb415 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1265,6 +1265,7 @@ strip_typedefs (tree t, bool *remove_attributes) { bool changed = false; vec *vec = make_tree_vector (); + tree r = t; for (; t; t = TREE_CHAIN (t)) { gcc_assert (!TREE_PURPOSE (t)); @@ -1273,7 +1274,6 @@ strip_typedefs (tree t, bool *remove_attributes) changed = true; vec_safe_push (vec, elt); } - tree r = t; if (changed) r = build_tree_list_vec (vec); release_tree_vector (vec); @@ -1411,7 +1411,7 @@ strip_typedefs (tree t, bool *remove_attributes) result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t), remove_attributes); if (result == DECLTYPE_TYPE_EXPR (t)) - return t; + result = NULL_TREE; else result = (finish_decltype_type (result, @@ -1496,8 +1496,8 @@ strip_typedefs_expr (tree t, bool *remove_attributes) && type2 == TRAIT_EXPR_TYPE2 (t)) return t; r = copy_node (t); - TRAIT_EXPR_TYPE1 (t) = type1; - TRAIT_EXPR_TYPE2 (t) = type2; + TRAIT_EXPR_TYPE1 (r) = type1; + TRAIT_EXPR_TYPE2 (r) = type2; return r; }