Commit b66906a8 by Roger Sayle Committed by Roger Sayle

re PR fortran/12632 ([g77 only] -fbounds-check ICE)


	PR fortran/12632
	* fold-const.c (fold) <COND_EXPR>: Don't fold a constant condition,
	if the type of the selected branch doesn't match its' parent.

	* com.c (ffecom_subscript_check_): Take as an extra argument the
	(possibly NULL) decl of the array.  Don't create unnecessary tree
	nodes if the array index is known to be safe at compile-time.
	If the array index is unsafe, force the array decl into memory to
	avoid RTL expansion problems.
	(ffecom_array_ref_): Update calls to ffecom_subscript_check_.
	(ffecom_char_args_x_): Likewise.

	* g77.dg/12632.f: New test case.

From-SVN: r75203
parent 68deab91
2003-12-29 Roger Sayle <roger@eyesopen.com>
PR fortran/12632
* fold-const.c (fold) <COND_EXPR>: Don't fold a constant condition,
if the type of the selected branch doesn't match its' parent.
2003-12-29 Jan Hubicka <jh@suse.cz> 2003-12-29 Jan Hubicka <jh@suse.cz>
* coverage.c (read_counts_file): Better error messages; cause corrupted * coverage.c (read_counts_file): Better error messages; cause corrupted
......
2003-12-29 Roger Sayle <roger@eyesopen.com>
PR fortran/12632
* com.c (ffecom_subscript_check_): Take as an extra argument the
(possibly NULL) decl of the array. Don't create unnecessary tree
nodes if the array index is known to be safe at compile-time.
If the array index is unsafe, force the array decl into memory to
avoid RTL expansion problems.
(ffecom_array_ref_): Update calls to ffecom_subscript_check_.
(ffecom_char_args_x_): Likewise.
2003-12-06 Kelley Cook <kcook@gcc.gnu.org> 2003-12-06 Kelley Cook <kcook@gcc.gnu.org>
* Make-lang.in (G77_CROSS_NAME): Delete. * Make-lang.in (G77_CROSS_NAME): Delete.
......
...@@ -638,15 +638,16 @@ static GTY(()) tree shadowed_labels; ...@@ -638,15 +638,16 @@ static GTY(()) tree shadowed_labels;
/* Return the subscript expression, modified to do range-checking. /* Return the subscript expression, modified to do range-checking.
`array' is the array to be checked against. `array' is the array type to be checked against.
`element' is the subscript expression to check. `element' is the subscript expression to check.
`dim' is the dimension number (starting at 0). `dim' is the dimension number (starting at 0).
`total_dims' is the total number of dimensions (0 for CHARACTER substring). `total_dims' is the total number of dimensions (0 for CHARACTER substring).
`item' is the array decl or NULL_TREE.
*/ */
static tree static tree
ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims, ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims,
const char *array_name) const char *array_name, tree item)
{ {
tree low = TYPE_MIN_VALUE (TYPE_DOMAIN (array)); tree low = TYPE_MIN_VALUE (TYPE_DOMAIN (array));
tree high = TYPE_MAX_VALUE (TYPE_DOMAIN (array)); tree high = TYPE_MAX_VALUE (TYPE_DOMAIN (array));
...@@ -713,6 +714,10 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims, ...@@ -713,6 +714,10 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims,
} }
} }
/* If the array index is safe at compile-time, return element. */
if (integer_nonzerop (cond))
return element;
{ {
int len; int len;
char *proc; char *proc;
...@@ -807,13 +812,10 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims, ...@@ -807,13 +812,10 @@ ffecom_subscript_check_ (tree array, tree element, int dim, int total_dims,
TREE_SIDE_EFFECTS (die) = 1; TREE_SIDE_EFFECTS (die) = 1;
die = convert (void_type_node, die); die = convert (void_type_node, die);
element = ffecom_3 (COND_EXPR, if (integer_zerop (cond) && item)
TREE_TYPE (element), ffe_mark_addressable (item);
cond,
element,
die);
return element; return ffecom_3 (COND_EXPR, TREE_TYPE (element), cond, element, die);
} }
/* Return the computed element of an array reference. /* Return the computed element of an array reference.
...@@ -899,7 +901,7 @@ ffecom_arrayref_ (tree item, ffebld expr, int want_ptr) ...@@ -899,7 +901,7 @@ ffecom_arrayref_ (tree item, ffebld expr, int want_ptr)
element = ffecom_expr_ (dims[i], NULL, NULL, NULL, FALSE, TRUE); element = ffecom_expr_ (dims[i], NULL, NULL, NULL, FALSE, TRUE);
if (flag_bounds_check) if (flag_bounds_check)
element = ffecom_subscript_check_ (array, element, i, total_dims, element = ffecom_subscript_check_ (array, element, i, total_dims,
array_name); array_name, item);
if (element == error_mark_node) if (element == error_mark_node)
return element; return element;
...@@ -945,7 +947,7 @@ ffecom_arrayref_ (tree item, ffebld expr, int want_ptr) ...@@ -945,7 +947,7 @@ ffecom_arrayref_ (tree item, ffebld expr, int want_ptr)
element = ffecom_expr_ (dims[i], NULL, NULL, NULL, FALSE, TRUE); element = ffecom_expr_ (dims[i], NULL, NULL, NULL, FALSE, TRUE);
if (flag_bounds_check) if (flag_bounds_check)
element = ffecom_subscript_check_ (array, element, i, total_dims, element = ffecom_subscript_check_ (array, element, i, total_dims,
array_name); array_name, item);
if (element == error_mark_node) if (element == error_mark_node)
return element; return element;
...@@ -2037,7 +2039,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null) ...@@ -2037,7 +2039,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null)
end_tree = ffecom_expr (end); end_tree = ffecom_expr (end);
if (flag_bounds_check) if (flag_bounds_check)
end_tree = ffecom_subscript_check_ (array, end_tree, 1, 0, end_tree = ffecom_subscript_check_ (array, end_tree, 1, 0,
char_name); char_name, NULL_TREE);
end_tree = convert (ffecom_f2c_ftnlen_type_node, end_tree = convert (ffecom_f2c_ftnlen_type_node,
end_tree); end_tree);
...@@ -2055,7 +2057,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null) ...@@ -2055,7 +2057,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null)
start_tree = ffecom_expr (start); start_tree = ffecom_expr (start);
if (flag_bounds_check) if (flag_bounds_check)
start_tree = ffecom_subscript_check_ (array, start_tree, 0, 0, start_tree = ffecom_subscript_check_ (array, start_tree, 0, 0,
char_name); char_name, NULL_TREE);
start_tree = convert (ffecom_f2c_ftnlen_type_node, start_tree = convert (ffecom_f2c_ftnlen_type_node,
start_tree); start_tree);
...@@ -2088,7 +2090,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null) ...@@ -2088,7 +2090,7 @@ ffecom_char_args_x_ (tree *xitem, tree *length, ffebld expr, bool with_null)
end_tree = ffecom_expr (end); end_tree = ffecom_expr (end);
if (flag_bounds_check) if (flag_bounds_check)
end_tree = ffecom_subscript_check_ (array, end_tree, 1, 0, end_tree = ffecom_subscript_check_ (array, end_tree, 1, 0,
char_name); char_name, NULL_TREE);
end_tree = convert (ffecom_f2c_ftnlen_type_node, end_tree = convert (ffecom_f2c_ftnlen_type_node,
end_tree); end_tree);
......
...@@ -7864,9 +7864,16 @@ fold (tree expr) ...@@ -7864,9 +7864,16 @@ fold (tree expr)
/* Pedantic ANSI C says that a conditional expression is never an lvalue, /* Pedantic ANSI C says that a conditional expression is never an lvalue,
so all simple results must be passed through pedantic_non_lvalue. */ so all simple results must be passed through pedantic_non_lvalue. */
if (TREE_CODE (arg0) == INTEGER_CST) if (TREE_CODE (arg0) == INTEGER_CST)
return pedantic_non_lvalue {
(TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1))); tem = TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1));
else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0)) /* Only optimize constant conditions when the selected branch
has the same type as the COND_EXPR. This avoids optimizing
away "c ? x : throw", where the throw has a void type. */
if (TREE_TYPE (tem) == TREE_TYPE (t))
return pedantic_non_lvalue (tem);
return t;
}
if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0))
return pedantic_omit_one_operand (type, arg1, arg0); return pedantic_omit_one_operand (type, arg1, arg0);
/* If we have A op B ? A : C, we may be able to convert this to a /* If we have A op B ? A : C, we may be able to convert this to a
......
2003-12-29 Roger Sayle <roger@eyesopen.com>
PR fortran/12632
* g77.dg/12632.f: New test case.
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> 2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13289 PR c++/13289
......
C { dg-do compile }
C { dg-options "-fbounds-check" }
INTEGER I(1)
I(2) = 0 ! { dg-error "out of defined range" "out of defined range" }
END
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment