From patchwork Mon Jan 16 09:04:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 136262 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]) by ozlabs.org (Postfix) with SMTP id 7827AB6EEA for ; Mon, 16 Jan 2012 20:04:27 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327309468; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Cc:Subject:In-Reply-To:Message-ID:References:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=r1jYTr2VYeQUjJaXKmoUYNnYsgk=; b=Jb++dGw6WpNzrxA PkMlrLaG4PS8mJPihHfibgf5HvY7C0OTeEz72eIuqPQIH7mZRtw8L7SRejL3C+VG eWDE5u7gfo6IYLG5Yrq4USlYbLFS4CvxK2I/yfGthipaSa60hTCY9Eg61huwPu4C S+kvVk3xA8EmoccPDv+KxhxSS0iE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Cc:Subject:In-Reply-To:Message-ID:References:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=q4jJI3LUsKKGAYEoC8/8me1A90yJNX0ebz15zT1ZORlnc+xWMCM0JKwjaZ+pqh BeJkjLPo9iRNUVbbdnMlqgf2ivxcZRQApfsj8pfkd77IEeVOyE8qODfKZ9rWS/Nu obdgQmzgSsKW9C0oeuON+0+H6E/kHZXjy5Bn/JILp3I1w=; Received: (qmail 3433 invoked by alias); 16 Jan 2012 09:04:21 -0000 Received: (qmail 3421 invoked by uid 22791); 16 Jan 2012 09:04:20 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 16 Jan 2012 09:04:06 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 5DBDE90182; Mon, 16 Jan 2012 10:04:05 +0100 (CET) Date: Mon, 16 Jan 2012 10:04:05 +0100 (CET) From: Richard Guenther To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH][C] Fix PR37985 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 On Fri, 13 Jan 2012, Joseph S. Myers wrote: > On Fri, 13 Jan 2012, Richard Guenther wrote: > > > This fixes PR37985 where since > > http://gcc.gnu.org/ml/gcc-patches/2006-08/msg01041.html we > > mark conversions produced by convert_to_integer with TREE_NO_WARNING. > > This may shadow "real" stmts with no effects, thus we should > > simply strip them again before checking for TREE_SIDE_EFFECTS. > > > > Bootstrap & regtest pending on x86_64-unknown-linux-gnu. > > > > Ok if that passes? > > OK. It FAILs gcc.dg/20040202-1.c (we warn about a folded memcpy). It looks like wrapping things in TREE_NO_WARNING NOP_EXPRs is fragile as soon as you consider multiple warning kinds (thus, of course the patch causing this regression is at fault). OTOH for the regression warning on folded stmts I really wonder why c_process_expr_stmt folds at all before emitting warnings - why intentionally divert from the source AST here? I'm testing the following before giving up on this regression (which solves the gcc.dg/20040202-1.c FAIL at least). Richard. 2012-01-13 Richard Guenther PR c/37985 * c-typeck.c (emit_side_effect_warnings): Strip conversions with TREE_NO_WARNING. (c_process_expr_stmt): Fold the stmt after emitting warnings. * gcc.dg/Wunused-value-4.c: New testcase. Index: gcc/testsuite/gcc.dg/Wunused-value-4.c =================================================================== *** gcc/testsuite/gcc.dg/Wunused-value-4.c (revision 0) --- gcc/testsuite/gcc.dg/Wunused-value-4.c (revision 0) *************** *** 0 **** --- 1,9 ---- + /* PR c/37985 */ + /* { dg-do compile } */ + /* { dg-options "-Wunused-value" } */ + + unsigned char foo(unsigned char a) + { + a >> 2; /* { dg-warning "statement with no effect" } */ + return a; + } Index: gcc/c-typeck.c =================================================================== --- gcc/c-typeck.c (revision 183205) +++ gcc/c-typeck.c (working copy) @@ -9163,6 +9163,10 @@ c_finish_bc_stmt (location_t loc, tree * static void emit_side_effect_warnings (location_t loc, tree expr) { + /* Strip conversions marked with TREE_NO_WARNING. */ + while (TREE_NO_WARNING (expr) && CONVERT_EXPR_P (expr)) + expr = TREE_OPERAND (expr, 0); + if (expr == error_mark_node) ; else if (!TREE_SIDE_EFFECTS (expr)) @@ -9186,8 +9190,6 @@ c_process_expr_stmt (location_t loc, tre if (!expr) return NULL_TREE; - expr = c_fully_fold (expr, false, NULL); - if (warn_sequence_point) verify_sequence_points (expr); @@ -9213,6 +9215,8 @@ c_process_expr_stmt (location_t loc, tre || TREE_CODE (exprv) == ADDR_EXPR) mark_exp_read (exprv); + expr = c_fully_fold (expr, false, NULL); + /* If the expression is not of a type to which we cannot assign a line number, wrap the thing in a no-op NOP_EXPR. */ if (DECL_P (expr) || CONSTANT_CLASS_P (expr))