From patchwork Thu Mar 24 14:38:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 88206 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 87E58B6F84 for ; Fri, 25 Mar 2011 01:42:57 +1100 (EST) Received: (qmail 3136 invoked by alias); 24 Mar 2011 14:42:56 -0000 Received: (qmail 3126 invoked by uid 22791); 24 Mar 2011 14:42:55 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Mar 2011 14:42:48 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 286BF290008 for ; Thu, 24 Mar 2011 15:42:47 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bLk8Tl-i235y for ; Thu, 24 Mar 2011 15:42:44 +0100 (CET) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 17FBECB02A6 for ; Thu, 24 Mar 2011 15:42:44 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Preserve source location in folder Date: Thu, 24 Mar 2011 15:38:15 +0100 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201103241538.15273.ebotcazou@adacore.com> 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 Hi, when fold_ternary_loc is attempting to make the tree prettier, e.g. by swapping the arguments of a COND_EXPR, it does: tem = fold_truth_not_expr (loc, arg0); Now LOC is the location that will be put on the whole expression and there is no reason it should override the location of ARG0, if any, when inverting it. The attached patch only ensures that - this gives more precise coverage info. Bootstrapped/regtested on x86_64-suse-linux, OK for the mainline? 2011-03-24 Eric Botcazou * fold-const.c (fold_ternary_loc): Preserve the location (if any) of the argument in calls to fold_truth_not_expr. Index: fold-const.c =================================================================== --- fold-const.c (revision 171345) +++ fold-const.c (working copy) @@ -13327,7 +13327,10 @@ fold_ternary_loc (location_t loc, enum t TREE_OPERAND (arg0, 1)) && !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (op2)))) { - tem = fold_truth_not_expr (loc, arg0); + location_t loc0 = EXPR_LOCATION (arg0); + if (loc0 == UNKNOWN_LOCATION) + loc0 = loc; + tem = fold_truth_not_expr (loc0, arg0); if (tem && COMPARISON_CLASS_P (tem)) { tem = fold_cond_expr_with_comparison (loc, type, tem, op2, op1); @@ -13341,10 +13344,13 @@ fold_ternary_loc (location_t loc, enum t if (truth_value_p (TREE_CODE (arg0)) && tree_swap_operands_p (op1, op2, false)) { + location_t loc0 = EXPR_LOCATION (arg0); + if (loc0 == UNKNOWN_LOCATION) + loc0 = loc; /* See if this can be inverted. If it can't, possibly because it was a floating-point inequality comparison, don't do anything. */ - tem = fold_truth_not_expr (loc, arg0); + tem = fold_truth_not_expr (loc0, arg0); if (tem) return fold_build3_loc (loc, code, type, tem, op2, op1); } @@ -13489,8 +13495,11 @@ fold_ternary_loc (location_t loc, enum t && truth_value_p (TREE_CODE (arg0)) && truth_value_p (TREE_CODE (arg1))) { + location_t loc0 = EXPR_LOCATION (arg0); + if (loc0 == UNKNOWN_LOCATION) + loc0 = loc; /* Only perform transformation if ARG0 is easily inverted. */ - tem = fold_truth_not_expr (loc, arg0); + tem = fold_truth_not_expr (loc0, arg0); if (tem) return fold_build2_loc (loc, TRUTH_ORIF_EXPR, type, fold_convert_loc (loc, type, tem), @@ -13502,8 +13511,11 @@ fold_ternary_loc (location_t loc, enum t && truth_value_p (TREE_CODE (arg0)) && truth_value_p (TREE_CODE (op2))) { + location_t loc0 = EXPR_LOCATION (arg0); + if (loc0 == UNKNOWN_LOCATION) + loc0 = loc; /* Only perform transformation if ARG0 is easily inverted. */ - tem = fold_truth_not_expr (loc, arg0); + tem = fold_truth_not_expr (loc0, arg0); if (tem) return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type, fold_convert_loc (loc, type, tem),