diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2009-04-21 17:17:13 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2009-04-21 17:17:13 +0000 |
commit | ca80e52b017482baf0bc3b91ce59af78a86785ba (patch) | |
tree | 4af8030719296e992a9c12adcef79ed4833b2ff8 /gcc/fold-const.c | |
parent | 71b495a2ac3a1c89a2f6a1a789dde32d337ef654 (diff) | |
download | gcc-ca80e52b017482baf0bc3b91ce59af78a86785ba.tar.gz |
c-common.c (c_common_truthvalue_conversion): Use LOCATION to build NE_EXPR operations as well.
* c-common.c (c_common_truthvalue_conversion): Use LOCATION to build
NE_EXPR operations as well.
* c-parser.c (c_parser_condition): Do not set location information on
the condition.
(c_parser_conditional_expression): Likewise.
(c_parser_binary_expression): Set location information on operators.
* c-typeck.c (build_unary_op) <TRUTH_NOT_EXPR>: Reset the location if
TRUTH_NOT_EXPR has been folded.
* fold-const.c (fold_truth_not_expr): Copy location information from
the incoming expression to the outgoing one.
* gimplify.c (shortcut_cond_r): Add locus parameter. Pass it to
recursive calls on the LHS of the operator but pass that of the
operator to recursive calls on the RHS of the operator. Set it
on the COND_EXPR.
(shortcut_cond_expr): Set the locus of the operator on the second
COND_EXPR and that of the expression on the first in degenerate cases.
Pass the locus of the expression to calls to shortcut_cond_r.
Set the locus of the 'then' block on the associated jump, if any.
(gimplify_boolean_expr): Add locus parameter. Set it on the COND_EXPR.
(gimplify_expr) <TRUTH_ANDIF_EXPR>: Pass the locus of the outer
expression to call to gimplify_boolean_expr.
ada/
* gcc-interface/trans.c (gnat_to_gnu): Do not overwrite location info.
From-SVN: r146532
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bd5e97df4a9..ca07cf16720 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3641,7 +3641,7 @@ omit_two_operands (tree type, tree result, tree omitted1, tree omitted2) tree fold_truth_not_expr (tree arg) { - tree type = TREE_TYPE (arg); + tree t, type = TREE_TYPE (arg); enum tree_code code = TREE_CODE (arg); /* If this is a comparison, we can simply invert it, except for @@ -3656,16 +3656,15 @@ fold_truth_not_expr (tree arg) && code != ORDERED_EXPR && code != UNORDERED_EXPR && code != NE_EXPR && code != EQ_EXPR) return NULL_TREE; - else - { - code = invert_tree_comparison (code, - HONOR_NANS (TYPE_MODE (op_type))); - if (code == ERROR_MARK) - return NULL_TREE; - else - return build2 (code, type, - TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1)); - } + + code = invert_tree_comparison (code, HONOR_NANS (TYPE_MODE (op_type))); + if (code == ERROR_MARK) + return NULL_TREE; + + t = build2 (code, type, TREE_OPERAND (arg, 0), TREE_OPERAND (arg, 1)); + if (EXPR_HAS_LOCATION (arg)) + SET_EXPR_LOCATION (t, EXPR_LOCATION (arg)); + return t; } switch (code) @@ -3674,14 +3673,16 @@ fold_truth_not_expr (tree arg) return constant_boolean_node (integer_zerop (arg), type); case TRUTH_AND_EXPR: - return build2 (TRUTH_OR_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0)), - invert_truthvalue (TREE_OPERAND (arg, 1))); + t = build2 (TRUTH_OR_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0)), + invert_truthvalue (TREE_OPERAND (arg, 1))); + break; case TRUTH_OR_EXPR: - return build2 (TRUTH_AND_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0)), - invert_truthvalue (TREE_OPERAND (arg, 1))); + t = build2 (TRUTH_AND_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0)), + invert_truthvalue (TREE_OPERAND (arg, 1))); + break; case TRUTH_XOR_EXPR: /* Here we can invert either operand. We invert the first operand @@ -3690,22 +3691,25 @@ fold_truth_not_expr (tree arg) negation of the second operand. */ if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR) - return build2 (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0), - TREE_OPERAND (TREE_OPERAND (arg, 1), 0)); + t = build2 (TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0), + TREE_OPERAND (TREE_OPERAND (arg, 1), 0)); else - return build2 (TRUTH_XOR_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0)), - TREE_OPERAND (arg, 1)); + t = build2 (TRUTH_XOR_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0)), + TREE_OPERAND (arg, 1)); + break; case TRUTH_ANDIF_EXPR: - return build2 (TRUTH_ORIF_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0)), - invert_truthvalue (TREE_OPERAND (arg, 1))); + t = build2 (TRUTH_ORIF_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0)), + invert_truthvalue (TREE_OPERAND (arg, 1))); + break; case TRUTH_ORIF_EXPR: - return build2 (TRUTH_ANDIF_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0)), - invert_truthvalue (TREE_OPERAND (arg, 1))); + t = build2 (TRUTH_ANDIF_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0)), + invert_truthvalue (TREE_OPERAND (arg, 1))); + break; case TRUTH_NOT_EXPR: return TREE_OPERAND (arg, 0); @@ -3717,47 +3721,61 @@ fold_truth_not_expr (tree arg) /* A COND_EXPR may have a throw as one operand, which then has void type. Just leave void operands as they are. */ - return build3 (COND_EXPR, type, TREE_OPERAND (arg, 0), - VOID_TYPE_P (TREE_TYPE (arg1)) - ? arg1 : invert_truthvalue (arg1), - VOID_TYPE_P (TREE_TYPE (arg2)) - ? arg2 : invert_truthvalue (arg2)); + t = build3 (COND_EXPR, type, TREE_OPERAND (arg, 0), + VOID_TYPE_P (TREE_TYPE (arg1)) + ? arg1 : invert_truthvalue (arg1), + VOID_TYPE_P (TREE_TYPE (arg2)) + ? arg2 : invert_truthvalue (arg2)); + break; } case COMPOUND_EXPR: - return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0), - invert_truthvalue (TREE_OPERAND (arg, 1))); + t = build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg, 0), + invert_truthvalue (TREE_OPERAND (arg, 1))); + break; case NON_LVALUE_EXPR: return invert_truthvalue (TREE_OPERAND (arg, 0)); case NOP_EXPR: if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE) - return build1 (TRUTH_NOT_EXPR, type, arg); + { + t = build1 (TRUTH_NOT_EXPR, type, arg); + break; + } + + /* ... fall through ... */ case CONVERT_EXPR: case FLOAT_EXPR: - return build1 (TREE_CODE (arg), type, - invert_truthvalue (TREE_OPERAND (arg, 0))); + t = build1 (TREE_CODE (arg), type, + invert_truthvalue (TREE_OPERAND (arg, 0))); + break; case BIT_AND_EXPR: if (!integer_onep (TREE_OPERAND (arg, 1))) - break; - return build2 (EQ_EXPR, type, arg, - build_int_cst (type, 0)); + return NULL_TREE; + t = build2 (EQ_EXPR, type, arg, build_int_cst (type, 0)); + break; case SAVE_EXPR: - return build1 (TRUTH_NOT_EXPR, type, arg); + t = build1 (TRUTH_NOT_EXPR, type, arg); + break; case CLEANUP_POINT_EXPR: - return build1 (CLEANUP_POINT_EXPR, type, - invert_truthvalue (TREE_OPERAND (arg, 0))); + t = build1 (CLEANUP_POINT_EXPR, type, + invert_truthvalue (TREE_OPERAND (arg, 0))); + break; default: + t = NULL_TREE; break; } - return NULL_TREE; + if (t && EXPR_HAS_LOCATION (arg)) + SET_EXPR_LOCATION (t, EXPR_LOCATION (arg)); + + return t; } /* Return a simplified tree node for the truth-negation of ARG. This |