diff mbox

Preserve source location in folder

Message ID 201103241538.15273.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou March 24, 2011, 2:38 p.m. UTC
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  <ebotcazou@adacore.com>

	* fold-const.c (fold_ternary_loc): Preserve the location (if any) of
	the argument in calls to fold_truth_not_expr.

Comments

Richard Biener March 24, 2011, 2:53 p.m. UTC | #1
On Thu, Mar 24, 2011 at 3:38 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> 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?

Ok.

(I shortly thought about a PREFER_OVER_UNKNOWN_LOCATION
(maybe_unknown, loc) macro, but well ...)

Thanks,
Richard.

>
> 2011-03-24  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * fold-const.c (fold_ternary_loc): Preserve the location (if any) of
>        the argument in calls to fold_truth_not_expr.
>
>
> --
> Eric Botcazou
>
diff mbox

Patch

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),