You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
#include "config.h"
#include "system.h"
#include "timevar.h"
#include "langhooks.h"
#include "ggc.h"
+#include "toplev.h"
\f
/* Nonzero if we are using EH to handle cleanups. */
static int
struct_ptr_eq (const void *a, const void *b)
{
- const void * const * x = a;
- const void * const * y = b;
+ const void * const * x = (const void * const *) a;
+ const void * const * y = (const void * const *) b;
return *x == *y;
}
static hashval_t
struct_ptr_hash (const void *a)
{
- const void * const * x = a;
+ const void * const * x = (const void * const *) a;
return (size_t)*x >> 4;
}
gcc_assert (num >= 0);
gcc_assert (TREE_CODE (t) != RESX_EXPR);
- n = ggc_alloc (sizeof (*n));
+ n = GGC_NEW (struct throw_stmt_node);
n->stmt = t;
n->region_nr = num;
return -2;
n.stmt = t;
- p = htab_find (get_eh_throw_stmt_table (ifun), &n);
+ p = (struct throw_stmt_node *) htab_find (get_eh_throw_stmt_table (ifun),
+ &n);
return (p ? p->region_nr : -1);
}
struct finally_tree_node *n;
void **slot;
- n = xmalloc (sizeof (*n));
+ n = XNEW (struct finally_tree_node);
n->child = child;
n->parent = parent;
do
{
n.child = start;
- p = htab_find (finally_tree, &n);
+ p = (struct finally_tree_node *) htab_find (finally_tree, &n);
if (!p)
return true;
start = p->parent;
{
struct goto_queue_node tmp, *ret;
tmp.stmt = stmt;
- ret = bsearch (&tmp, tf->goto_queue, tf->goto_queue_active,
+ ret = (struct goto_queue_node *)
+ bsearch (&tmp, tf->goto_queue, tf->goto_queue_active,
sizeof (struct goto_queue_node), goto_queue_cmp);
return (ret ? ret->repl_stmt : NULL);
}
size = (size ? size * 2 : 32);
tf->goto_queue_size = size;
tf->goto_queue
- = xrealloc (tf->goto_queue, size * sizeof (struct goto_queue_node));
+ = XRESIZEVEC (struct goto_queue_node, tf->goto_queue, size);
}
q = &tf->goto_queue[active];
else
new = *return_value_p;
- x = build (MODIFY_EXPR, TREE_TYPE (new), new, old);
+ x = build2 (MODIFY_EXPR, TREE_TYPE (new), new, old);
append_to_statement_list (x, &q->repl_stmt);
if (new == result)
x = result;
else
- x = build (MODIFY_EXPR, TREE_TYPE (result), result, new);
+ x = build2 (MODIFY_EXPR, TREE_TYPE (result), result, new);
q->cont_stmt = build1 (RETURN_EXPR, void_type_node, x);
}
save_filt = create_tmp_var (integer_type_node, "save_filt");
i = tsi_start (finally);
- x = build (EXC_PTR_EXPR, ptr_type_node);
- x = build (MODIFY_EXPR, void_type_node, save_eptr, x);
+ x = build0 (EXC_PTR_EXPR, ptr_type_node);
+ x = build2 (MODIFY_EXPR, void_type_node, save_eptr, x);
tsi_link_before (&i, x, TSI_CONTINUE_LINKING);
- x = build (FILTER_EXPR, integer_type_node);
- x = build (MODIFY_EXPR, void_type_node, save_filt, x);
+ x = build0 (FILTER_EXPR, integer_type_node);
+ x = build2 (MODIFY_EXPR, void_type_node, save_filt, x);
tsi_link_before (&i, x, TSI_CONTINUE_LINKING);
i = tsi_last (finally);
- x = build (EXC_PTR_EXPR, ptr_type_node);
- x = build (MODIFY_EXPR, void_type_node, x, save_eptr);
+ x = build0 (EXC_PTR_EXPR, ptr_type_node);
+ x = build2 (MODIFY_EXPR, void_type_node, x, save_eptr);
tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
- x = build (FILTER_EXPR, integer_type_node);
- x = build (MODIFY_EXPR, void_type_node, x, save_filt);
+ x = build0 (FILTER_EXPR, integer_type_node);
+ x = build2 (MODIFY_EXPR, void_type_node, x, save_filt);
tsi_link_after (&i, x, TSI_CONTINUE_LINKING);
x = build_resx (get_eh_region_number (tf->region));
/* Wrap the block with protect_cleanup_actions as the action. */
if (protect_cleanup_actions)
{
- x = build (EH_FILTER_EXPR, void_type_node, NULL, NULL);
+ x = build2 (EH_FILTER_EXPR, void_type_node, NULL, NULL);
append_to_statement_list (protect_cleanup_actions, &EH_FILTER_FAILURE (x));
EH_FILTER_MUST_NOT_THROW (x) = 1;
- finally = build (TRY_CATCH_EXPR, void_type_node, finally, x);
+ finally = build2 (TRY_CATCH_EXPR, void_type_node, finally, x);
lower_eh_filter (outer_state, &finally);
}
else
struct goto_queue_node *q, *qe;
tree return_val = NULL;
int return_index, index;
- struct
+ struct labels_s
{
struct goto_queue_node *q;
tree label;
} *labels;
return_index = VEC_length (tree, tf->dest_array);
- labels = xcalloc (sizeof (*labels), return_index + 1);
+ labels = XCNEWVEC (struct labels_s, return_index + 1);
q = tf->goto_queue;
qe = q + tf->goto_queue_active;
finally_label = create_artificial_label ();
case_label_vec = make_tree_vec (ndests);
- switch_stmt = build (SWITCH_EXPR, integer_type_node, finally_tmp,
- NULL_TREE, case_label_vec);
+ switch_stmt = build3 (SWITCH_EXPR, integer_type_node, finally_tmp,
+ NULL_TREE, case_label_vec);
switch_body = NULL;
last_case = NULL;
last_case_index = 0;
if (tf->may_fallthru)
{
- x = build (MODIFY_EXPR, void_type_node, finally_tmp,
- build_int_cst (NULL_TREE, fallthru_index));
+ x = build2 (MODIFY_EXPR, void_type_node, finally_tmp,
+ build_int_cst (NULL_TREE, fallthru_index));
append_to_statement_list (x, tf->top_p);
if (tf->may_throw)
}
- last_case = build (CASE_LABEL_EXPR, void_type_node,
- build_int_cst (NULL_TREE, fallthru_index), NULL,
- create_artificial_label ());
+ last_case = build3 (CASE_LABEL_EXPR, void_type_node,
+ build_int_cst (NULL_TREE, fallthru_index), NULL,
+ create_artificial_label ());
TREE_VEC_ELT (case_label_vec, last_case_index) = last_case;
last_case_index++;
- x = build (LABEL_EXPR, void_type_node, CASE_LABEL (last_case));
+ x = build1 (LABEL_EXPR, void_type_node, CASE_LABEL (last_case));
append_to_statement_list (x, &switch_body);
x = lower_try_finally_fallthru_label (tf);
x = build1 (LABEL_EXPR, void_type_node, tf->eh_label);
append_to_statement_list (x, tf->top_p);
- x = build (MODIFY_EXPR, void_type_node, finally_tmp,
- build_int_cst (NULL_TREE, eh_index));
+ x = build2 (MODIFY_EXPR, void_type_node, finally_tmp,
+ build_int_cst (NULL_TREE, eh_index));
append_to_statement_list (x, tf->top_p);
- last_case = build (CASE_LABEL_EXPR, void_type_node,
- build_int_cst (NULL_TREE, eh_index), NULL,
- create_artificial_label ());
+ last_case = build3 (CASE_LABEL_EXPR, void_type_node,
+ build_int_cst (NULL_TREE, eh_index), NULL,
+ create_artificial_label ());
TREE_VEC_ELT (case_label_vec, last_case_index) = last_case;
last_case_index++;
- x = build (LABEL_EXPR, void_type_node, CASE_LABEL (last_case));
+ x = build1 (LABEL_EXPR, void_type_node, CASE_LABEL (last_case));
append_to_statement_list (x, &switch_body);
x = build_resx (get_eh_region_number (tf->region));
append_to_statement_list (x, &switch_body);
if (q->index < 0)
{
- mod = build (MODIFY_EXPR, void_type_node, finally_tmp,
- build_int_cst (NULL_TREE, return_index));
+ mod = build2 (MODIFY_EXPR, void_type_node, finally_tmp,
+ build_int_cst (NULL_TREE, return_index));
do_return_redirection (q, finally_label, mod, &return_val);
switch_id = return_index;
}
else
{
- mod = build (MODIFY_EXPR, void_type_node, finally_tmp,
- build_int_cst (NULL_TREE, q->index));
+ mod = build2 (MODIFY_EXPR, void_type_node, finally_tmp,
+ build_int_cst (NULL_TREE, q->index));
do_goto_redirection (q, finally_label, mod);
switch_id = q->index;
}
case_index = j + q->index;
if (!TREE_VEC_ELT (case_label_vec, case_index))
TREE_VEC_ELT (case_label_vec, case_index)
- = build (CASE_LABEL_EXPR, void_type_node,
- build_int_cst (NULL_TREE, switch_id), NULL,
- /* We store the cont_stmt in the
- CASE_LABEL, so that we can recover it
- in the loop below. We don't create
- the new label while walking the
- goto_queue because pointers don't
- offer a stable order. */
- q->cont_stmt);
+ = build3 (CASE_LABEL_EXPR, void_type_node,
+ build_int_cst (NULL_TREE, switch_id), NULL,
+ /* We store the cont_stmt in the
+ CASE_LABEL, so that we can recover it
+ in the loop below. We don't create
+ the new label while walking the
+ goto_queue because pointers don't
+ offer a stable order. */
+ q->cont_stmt);
}
for (j = last_case_index; j < last_case_index + nlabels; j++)
{
label = create_artificial_label ();
CASE_LABEL (last_case) = label;
- x = build (LABEL_EXPR, void_type_node, label);
+ x = build1 (LABEL_EXPR, void_type_node, label);
append_to_statement_list (x, &switch_body);
append_to_statement_list (cont_stmt, &switch_body);
maybe_record_in_goto_queue (state, cont_stmt);
}
}
-static void
+static unsigned int
lower_eh_constructs (void)
{
struct leh_state null_state;
htab_delete (finally_tree);
collect_eh_region_array ();
+ return 0;
}
struct tree_opt_pass pass_lower_eh =
TV_TREE_EH, /* tv_id */
PROP_gimple_lcf, /* properties_required */
PROP_gimple_leh, /* properties_provided */
- PROP_gimple_lcf, /* properties_destroyed */
+ 0, /* properties_destroyed */
0, /* todo_flags_start */
TODO_dump_func, /* todo_flags_finish */
0 /* letter */
tree stmt, lab;
basic_block src, dst;
- stmt = data;
+ stmt = (tree) data;
lab = get_eh_region_tree_label (region);
src = bb_for_stmt (stmt);
basic_block src, dst;
edge e;
- stmt = data;
+ stmt = (tree) data;
lab = get_eh_region_tree_label (region);
src = bb_for_stmt (stmt);
e = find_edge (src, dst);
if (!e)
{
- error ("EH edge %i->%i is missing %i %i.", src->index, dst->index, src, dst);
+ error ("EH edge %i->%i is missing", src->index, dst->index);
mark_eh_edge_found_error = true;
}
else if (!(e->flags & EDGE_EH))
{
- error ("EH edge %i->%i miss EH flag.", src->index, dst->index);
+ error ("EH edge %i->%i miss EH flag", src->index, dst->index);
mark_eh_edge_found_error = true;
}
else if (e->aux)
{
/* ??? might not be mistake. */
- error ("EH edge %i->%i has duplicated regions.", src->index, dst->index);
+ error ("EH edge %i->%i has duplicated regions", src->index, dst->index);
mark_eh_edge_found_error = true;
}
else
{
if ((e->flags & EDGE_EH) && !e->aux)
{
- error ("Unnecesary EH edge %i->%i", bb->index, e->dest->index);
+ error ("unnecessary EH edge %i->%i", bb->index, e->dest->index);
mark_eh_edge_found_error = true;
return true;
}
restart:
switch (code)
{
+ case TARGET_MEM_REF:
+ /* For TARGET_MEM_REFs use the information based on the original
+ reference. */
+ expr = TMR_ORIGINAL (expr);
+ code = TREE_CODE (expr);
+ goto restart;
+
case COMPONENT_REF:
case REALPART_EXPR:
case IMAGPART_EXPR:
goto restart;
case ARRAY_RANGE_REF:
- /* Let us be conservative here for now. We might be checking bounds of
- the access similarly to the case below. */
- if (!TREE_THIS_NOTRAP (expr))
+ base = TREE_OPERAND (expr, 0);
+ if (tree_could_trap_p (base))
return true;
- base = TREE_OPERAND (expr, 0);
- return tree_could_trap_p (base);
+ if (TREE_THIS_NOTRAP (expr))
+ return false;
+
+ return !range_in_array_bounds_p (expr);
case ARRAY_REF:
base = TREE_OPERAND (expr, 0);
tree_can_throw_internal (tree stmt)
{
int region_nr;
+ bool is_resx = false;
if (TREE_CODE (stmt) == RESX_EXPR)
- region_nr = TREE_INT_CST_LOW (TREE_OPERAND (stmt, 0));
+ region_nr = TREE_INT_CST_LOW (TREE_OPERAND (stmt, 0)), is_resx = true;
else
region_nr = lookup_stmt_eh_region (stmt);
if (region_nr < 0)
return false;
- return can_throw_internal_1 (region_nr);
+ return can_throw_internal_1 (region_nr, is_resx);
}
bool
tree_can_throw_external (tree stmt)
{
int region_nr;
+ bool is_resx = false;
if (TREE_CODE (stmt) == RESX_EXPR)
- region_nr = TREE_INT_CST_LOW (TREE_OPERAND (stmt, 0));
+ region_nr = TREE_INT_CST_LOW (TREE_OPERAND (stmt, 0)), is_resx = true;
else
region_nr = lookup_stmt_eh_region (stmt);
if (region_nr < 0)
return tree_could_throw_p (stmt);
else
- return can_throw_external_1 (region_nr);
+ return can_throw_external_1 (region_nr, is_resx);
}
-bool
-maybe_clean_eh_stmt (tree stmt)
+/* Given a statement OLD_STMT and a new statement NEW_STMT that has replaced
+ OLD_STMT in the function, remove OLD_STMT from the EH table and put NEW_STMT
+ in the table if it should be in there. Return TRUE if a replacement was
+ done that my require an EH edge purge. */
+
+bool
+maybe_clean_or_replace_eh_stmt (tree old_stmt, tree new_stmt)
{
- if (!tree_could_throw_p (stmt))
- if (remove_stmt_from_eh_region (stmt))
- return true;
+ int region_nr = lookup_stmt_eh_region (old_stmt);
+
+ if (region_nr >= 0)
+ {
+ bool new_stmt_could_throw = tree_could_throw_p (new_stmt);
+
+ if (new_stmt == old_stmt && new_stmt_could_throw)
+ return false;
+
+ remove_stmt_from_eh_region (old_stmt);
+ if (new_stmt_could_throw)
+ {
+ add_stmt_to_eh_region (new_stmt, region_nr);
+ return false;
+ }
+ else
+ return true;
+ }
+
return false;
}
+#ifdef ENABLE_CHECKING
+static int
+verify_eh_throw_stmt_node (void **slot, void *data ATTRIBUTE_UNUSED)
+{
+ struct throw_stmt_node *node = (struct throw_stmt_node *)*slot;
+
+ gcc_assert (node->stmt->common.ann == NULL);
+ return 1;
+}
+
+void
+verify_eh_throw_table_statements (void)
+{
+ if (!get_eh_throw_stmt_table (cfun))
+ return;
+ htab_traverse (get_eh_throw_stmt_table (cfun),
+ verify_eh_throw_stmt_node,
+ NULL);
+}
+
+#endif