From patchwork Mon Feb 8 15:25:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 580326 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 18B53140B93 for ; Tue, 9 Feb 2016 02:26:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=OQBlkYDv; 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=iDGb5kT0E3FI6LfU6 ssLWu10Jax71xBcT3k9zApdxhj+TM+S1lmJek7wW2a5kraj+bwgJC3olDB4PFIWm rS0oHes++WlQTIOYis9IR3AGOwlozHOcwbM47YqwcaRsuywiGP0GCd3UGxQgTe/t AJ3TtsP7PL3rth2JkEJHZcXgog= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=s/oOM6ZQYLVss6AFVOzeoCu lYUE=; b=OQBlkYDvA7PsIMaUFtrzC+OvwYd8LYULoDXcdIjZv2iZy/pW9jtmzJm WsjXAoLyHP8NH7rgRP6Awk/MHmHKSn8G1D4Z8+xgeKedfZl/hNJMOo/2XbUNmDPF hH1PGyN0vzNcKeUedH+/FtsxMpwUvAyo0cpnGbzGX8UHQV6LFSIc= Received: (qmail 110696 invoked by alias); 8 Feb 2016 15:26: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 110684 invoked by uid 89); 8 Feb 2016 15:26:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=21PM, 21pm, DECL_INITIAL, decl_initial 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, 08 Feb 2016 15:26:06 +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 (Postfix) with ESMTPS id 214BB31D8A2 for ; Mon, 8 Feb 2016 15:26:05 +0000 (UTC) Received: from redhat.com (ovpn-204-23.brq.redhat.com [10.40.204.23]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u18FQ08R022764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 8 Feb 2016 10:26:02 -0500 Date: Mon, 8 Feb 2016 16:25:59 +0100 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: C++ PATCH for c++/69688 (bogus error with -Wsign-compare) Message-ID: <20160208152559.GA3289@redhat.com> References: <20160205223243.GA3321@redhat.com> <56B523E5.6040500@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <56B523E5.6040500@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) On Fri, Feb 05, 2016 at 05:36:21PM -0500, Jason Merrill wrote: > On 02/05/2016 05:32 PM, Marek Polacek wrote: > > if (TREE_CODE (type) == ERROR_MARK) > > return NULL_TREE; > > > >+ /* Here, DECL may change value; purge caches. */ > >+ clear_fold_cache (); > >+ clear_cv_cache (); > >+ > > if (MAYBE_CLASS_TYPE_P (type)) > > This should happen after computing the value to be stored, not before. Also, > could you combine those two functions into one? There's no reason for > callers such as this to need to call two different functions. Okay. So like this? Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-02-08 Marek Polacek PR c++/69688 * constexpr.c (clear_cv_and_fold_caches): Renamed from clear_cv_cache. Call clear_fold_cache. * cp-tree.h: Adjust declaration. * decl.c (finish_enum_value_list): Call clear_cv_and_fold_caches rather than clear_cv_cache and clear_fold_cache. * typeck2.c (store_init_value): Call clear_cv_and_fold_caches. * g++.dg/init/const12.C: New test. Marek diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index 05f6843..85fc64e 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -4098,12 +4098,13 @@ maybe_constant_value (tree t, tree decl) return ret; } -/* Dispose of the whole CV_CACHE. */ +/* Dispose of the whole CV_CACHE and FOLD_CACHE. */ void -clear_cv_cache (void) +clear_cv_and_fold_caches (void) { gt_cleare_cache (cv_cache); + clear_fold_cache (); } /* Like maybe_constant_value but first fully instantiate the argument. diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h index 0aeee57..a67e9b6 100644 --- gcc/cp/cp-tree.h +++ gcc/cp/cp-tree.h @@ -6920,7 +6920,7 @@ extern bool var_in_constexpr_fn (tree); extern void explain_invalid_constexpr_fn (tree); extern vec cx_error_context (void); extern tree fold_sizeof_expr (tree); -extern void clear_cv_cache (void); +extern void clear_cv_and_fold_caches (void); /* In c-family/cilk.c */ extern bool cilk_valid_spawn (tree); diff --git gcc/cp/decl.c gcc/cp/decl.c index 2c337bc..11f7ce6 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -13414,8 +13414,7 @@ finish_enum_value_list (tree enumtype) /* Each enumerator now has the type of its enumeration. Clear the cache so that this change in types doesn't confuse us later on. */ - clear_cv_cache (); - clear_fold_cache (); + clear_cv_and_fold_caches (); } /* Finishes the enum type. This is called only the first time an diff --git gcc/cp/typeck2.c gcc/cp/typeck2.c index 419faa2..2a76c96 100644 --- gcc/cp/typeck2.c +++ gcc/cp/typeck2.c @@ -837,6 +837,9 @@ store_init_value (tree decl, tree init, vec** cleanups, int flags) /* Handle aggregate NSDMI in non-constant initializers, too. */ value = replace_placeholders (value, decl); + /* DECL may change value; purge caches. */ + clear_cv_and_fold_caches (); + /* If the initializer is not a constant, fill in DECL_INITIAL with the bits that are constant, and then return an expression that will perform the dynamic initialization. */ diff --git gcc/testsuite/g++.dg/init/const12.C gcc/testsuite/g++.dg/init/const12.C index e69de29..2f6f9b2 100644 --- gcc/testsuite/g++.dg/init/const12.C +++ gcc/testsuite/g++.dg/init/const12.C @@ -0,0 +1,20 @@ +// PR c++/69688 +// { dg-do compile } +// { dg-options "-Wsign-compare" } + +struct S +{ + static const int s; + static const char c[]; + static wchar_t w[]; + + S () + { + for (int i = 0; i < s; i++) + w[i] = 0; + } +}; + +const char S::c[] = "x"; +const int S::s = sizeof (S::c) - 1; +wchar_t S::w[S::s];