diff options
author | Kai Tietz <ktietz@redhat.com> | 2011-05-12 20:19:07 +0200 |
---|---|---|
committer | Kai Tietz <ktietz@gcc.gnu.org> | 2011-05-12 20:19:07 +0200 |
commit | 1d15f620aa4e68f6298491d52ca8cc8d496457a6 (patch) | |
tree | adcc70e35c9e266924a73609b2a5e907b5c51dd0 /gcc/gimplify.c | |
parent | c2b5fc8de6a06b34a60f90bb37c46e27dc67d347 (diff) | |
download | gcc-1d15f620aa4e68f6298491d52ca8cc8d496457a6.zip gcc-1d15f620aa4e68f6298491d52ca8cc8d496457a6.tar.gz gcc-1d15f620aa4e68f6298491d52ca8cc8d496457a6.tar.bz2 |
gimplify.c (gimple_boolify): Re-boolify expression arguments even if expression type is of kind BOOLEAN_TYPE.
2011-05-12 Kai Tietz <ktietz@redhat.com>
* gimplify.c (gimple_boolify): Re-boolify expression
arguments even if expression type is of kind BOOLEAN_TYPE.
(gimplify_boolean_expr): Removed.
(gimplify_expr): Boolify truth opcodes AND, ANDIF, OR, ORIF,
and XOR. Additional take care that we keep expression's type.
* tree-cfg.c (verify_gimple_assign_binary): Adjust check for type
of TRUTH_AND|OR|XOR_EXPR.
From-SVN: r173711
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r-- | gcc/gimplify.c | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 700aa23..c54d3b5 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2824,9 +2824,6 @@ gimple_boolify (tree expr) } } - if (TREE_CODE (type) == BOOLEAN_TYPE) - return expr; - switch (TREE_CODE (expr)) { case TRUTH_AND_EXPR: @@ -2851,6 +2848,8 @@ gimple_boolify (tree expr) default: /* Other expressions that get here must have boolean values, but might need to be converted to the appropriate mode. */ + if (TREE_CODE (type) == BOOLEAN_TYPE) + return expr; return fold_convert_loc (loc, boolean_type_node, expr); } } @@ -4695,31 +4694,6 @@ gimplify_scalar_mode_aggregate_compare (tree *expr_p) return GS_OK; } -/* Gimplify TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR expressions. EXPR_P - points to the expression to gimplify. - - Expressions of the form 'a && b' are gimplified to: - - a && b ? true : false - - LOCUS is the source location to be put on the generated COND_EXPR. - gimplify_cond_expr will do the rest. */ - -static enum gimplify_status -gimplify_boolean_expr (tree *expr_p, location_t locus) -{ - /* Preserve the original type of the expression. */ - tree type = TREE_TYPE (*expr_p); - - *expr_p = build3 (COND_EXPR, type, *expr_p, - fold_convert_loc (locus, type, boolean_true_node), - fold_convert_loc (locus, type, boolean_false_node)); - - SET_EXPR_LOCATION (*expr_p, locus); - - return GS_OK; -} - /* Gimplify an expression sequence. This function gimplifies each expression and rewrites the original expression with the last expression of the sequence in GIMPLE form. @@ -6762,9 +6736,22 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case TRUTH_ANDIF_EXPR: case TRUTH_ORIF_EXPR: - /* Pass the source location of the outer expression. */ - ret = gimplify_boolean_expr (expr_p, saved_location); - break; + { + /* Preserve the original type of the expression and the + source location of the outer expression. */ + tree org_type = TREE_TYPE (*expr_p); + *expr_p = gimple_boolify (*expr_p); + *expr_p = build3_loc (saved_location, COND_EXPR, + org_type, *expr_p, + fold_convert_loc + (saved_location, + org_type, boolean_true_node), + fold_convert_loc + (saved_location, + org_type, boolean_false_node)); + ret = GS_OK; + break; + } case TRUTH_NOT_EXPR: if (TREE_CODE (TREE_TYPE (*expr_p)) != BOOLEAN_TYPE) @@ -7203,6 +7190,23 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: case TRUTH_XOR_EXPR: + { + tree org_type = TREE_TYPE (*expr_p); + + *expr_p = gimple_boolify (*expr_p); + + /* This shouldn't happen, but due fold-const (and here especially + fold_truth_not_expr) happily uses operand type and doesn't + automatically uses boolean_type as result, we need to keep + orignal type. */ + if (TREE_CODE (org_type) != BOOLEAN_TYPE) + { + *expr_p = fold_convert (org_type, *expr_p); + ret = GS_OK; + break; + } + } + /* Classified as tcc_expression. */ goto expr_2; |