This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[treelang] abort -> gcc_assert/gcc_unreachable.
- From: ja2morri at csclub dot uwaterloo dot ca (James A. Morrison)
- To: gcc-patches at gcc dot gnu dot org
- Date: 02 Oct 2004 12:04:57 -0400
- Subject: [treelang] abort -> gcc_assert/gcc_unreachable.
Hi,
This patch changes all but one abort in the treelang frontend to be
either gcc_asserts or gcc_unreachable. This patch is bootstrapping and
regtesting in combination with the previous patch and the next patch.
I'll commit it once the testing is done both with
--enable-mapped-location and --disable-mapped-location.
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
2004-10-02 James A. Morrison <phython@gcc.gnu.org>
* parse.y: Use gcc_assert and gcc_unreachable instead of abort.
* tree1.c: Likewise.
* treetree.c: Likewise.
diff -upr comments/gcc/treelang/parse.y aborts/gcc/treelang/parse.y
--- comments/gcc/treelang/parse.y 2004-10-01 10:51:45.494404112 -0400
+++ aborts/gcc/treelang/parse.y 2004-10-01 10:53:22.530652360 -0400
@@ -197,8 +197,7 @@ storage typename NAME init_opt SEMICOLON
if (VAR_INIT (prod))
{
- if (! ((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code)
- abort ();
+ gcc_assert (((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code);
if (STORAGE_CLASS (prod) == EXTERNAL_REFERENCE_STORAGE)
{
fprintf (stderr, "%s:%i:%i: External reference variables may not have initial value\n",
@@ -217,8 +216,7 @@ storage typename NAME init_opt SEMICOLON
VAR_INIT (prod) ?
((struct prod_token_parm_item*)VAR_INIT (prod))->tp.pro.code : NULL,
tok->tp.tok.location);
- if (!prod->tp.pro.code)
- abort ();
+ gcc_assert (prod->tp.pro.code);
}
;
@@ -287,7 +285,7 @@ storage typename NAME LEFT_PARENTHESIS p
break;
default:
- abort ();
+ gcc_unreachable ();
}
type = EXPRESSION_TYPE (prod);
/* Create a parameter list in a non-front end specific format. */
@@ -295,16 +293,15 @@ storage typename NAME LEFT_PARENTHESIS p
this_parm;
this_parm = this_parm->tp.pro.next)
{
- if (this_parm->category != production_category)
- abort ();
+ gcc_assert (this_parm->category == production_category);
+
this_parm_var = VARIABLE (this_parm);
- if (!this_parm_var)
- abort ();
- if (this_parm_var->category != production_category)
- abort ();
+
+ gcc_assert (this_parm_var);
+ gcc_assert (this_parm_var->category == production_category);
+
this_parms = my_malloc (sizeof (struct prod_token_parm_item));
- if (!this_parm_var->tp.pro.main_token)
- abort ();
+ gcc_assert (this_parm_var->tp.pro.main_token);
this_parms->tp.par.variable_name =
this_parm_var->tp.pro.main_token->tp.tok.chars;
@@ -353,22 +350,21 @@ NAME LEFT_BRACE {
errorcount++;
YYERROR;
}
- if (!proto->tp.pro.code)
- abort ();
- tree_code_create_function_initial
- (proto->tp.pro.code, tok->tp.tok.location,
- FIRST_PARMS (current_function));
+ gcc_assert (proto->tp.pro.code);
+ tree_code_create_function_initial (proto->tp.pro.code, tok->tp.tok.location,
+ FIRST_PARMS (current_function));
+
+#ifdef ENABLE_CHECKING
/* Check all the parameters have code. */
for (this_parm = PARAMETERS (proto);
this_parm;
this_parm = this_parm->tp.pro.next)
{
- if (! (struct prod_token_parm_item*)VARIABLE (this_parm))
- abort ();
- if (! (( (struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code))
- abort ();
+ gcc_assert ((struct prod_token_parm_item*)VARIABLE (this_parm));
+ gcc_assert ((( (struct prod_token_parm_item*)VARIABLE (this_parm))->tp.pro.code));
}
+#endif
}
variable_defs_opt statements_opt RIGHT_BRACE {
struct prod_token_parm_item* tok;
@@ -555,12 +551,12 @@ tl_RETURN expression_opt {
/* Check same type. */
if (check_type_match (NUMERIC_TYPE (type_prod), $2))
{
- if (!type_prod->tp.pro.code)
- abort ();
- if (!exp->tp.pro.code)
- abort ();
+ gcc_assert (type_prod->tp.pro.code);
+ gcc_assert (exp->tp.pro.code);
+
/* Generate the code. */
- tree_code_generate_return (type_prod->tp.pro.code, exp->tp.pro.code);
+ tree_code_generate_return (type_prod->tp.pro.code,
+ exp->tp.pro.code);
}
}
}
@@ -573,8 +569,7 @@ expression_opt:
|expression {
struct prod_token_parm_item *exp;
exp = $1;
- if (!exp->tp.pro.code)
- abort ();
+ gcc_assert (exp->tp.pro.code);
$$ = $1;
}
@@ -680,20 +675,19 @@ NAME LEFT_PARENTHESIS expressions_with_c
for (exp_proto = PARAMETERS (proto), exp = PARAMETERS (prod);
exp_proto;
exp = exp->tp.pro.next, exp_proto = exp_proto->tp.pro.next)
- {
- if (!exp)
- abort ();
- if (!exp_proto)
- abort ();
- if (!exp->tp.pro.code)
- abort ();
- var = VARIABLE (exp_proto);
- if (!var)
- abort ();
- if (!var->tp.pro.code)
- abort ();
- parms = tree_code_add_parameter (parms, var->tp.pro.code, exp->tp.pro.code);
- }
+ {
+ gcc_assert (exp);
+ gcc_assert (exp_proto);
+ gcc_assert (exp->tp.pro.code);
+
+ var = VARIABLE (exp_proto);
+
+ gcc_assert (var);
+ gcc_assert (var->tp.pro.code);
+
+ parms = tree_code_add_parameter (parms, var->tp.pro.code,
+ exp->tp.pro.code);
+ }
type = tree_code_get_type (NUMERIC_TYPE (prod));
prod->tp.pro.code = tree_code_get_expression (EXP_FUNCTION_INVOCATION, type,
proto->tp.pro.code, parms,
@@ -826,8 +820,7 @@ reverse_prod_list (struct prod_token_par
while (current)
{
- if (current->category != production_category)
- abort ();
+ gcc_assert (current->category == production_category);
next = current->tp.pro.next;
current->tp.pro.next = prev;
prev = current;
@@ -888,18 +881,14 @@ check_type_match (int type_num, struct p
return 1;
case VOID_TYPE:
- abort ();
-
default:
- abort ();
+ gcc_unreachable ();
}
break;
case VOID_TYPE:
- abort ();
-
default:
- abort ();
+ gcc_unreachable ();
}
}
@@ -943,8 +932,7 @@ make_plus_expression (struct prod_token_
NUMERIC_TYPE (prod) = type_code;
type = tree_code_get_type (type_code);
- if (!type)
- abort ();
+ gcc_assert (type);
OP1 (prod) = op1;
OP2 (prod) = op2;
@@ -982,7 +970,7 @@ set_storage (struct prod_token_parm_item
break;
default:
- abort ();
+ gcc_unreachable ();
}
}
diff -upr comments/gcc/treelang/tree1.c aborts/gcc/treelang/tree1.c
--- comments/gcc/treelang/tree1.c 2004-10-01 10:03:52.782122760 -0400
+++ aborts/gcc/treelang/tree1.c 2004-10-01 10:16:50.620873296 -0400
@@ -104,9 +104,6 @@ treelang_handle_option (size_t scode, co
switch (code)
{
- default:
- abort();
-
case OPT_v:
if (!version_done)
{
@@ -129,6 +126,10 @@ treelang_handle_option (size_t scode, co
case OPT_flexer_trace:
option_lexer_trace = value;
break;
+
+ default:
+ gcc_unreachable ();
+
}
return 1;
@@ -294,7 +295,7 @@ sanity_check (struct prod_token_parm_ite
break;
default:
- abort ();
+ gcc_unreachable ();
}
}
diff -upr comments/gcc/treelang/treetree.c aborts/gcc/treelang/treetree.c
--- comments/gcc/treelang/treetree.c 2004-10-01 10:50:43.943761232 -0400
+++ aborts/gcc/treelang/treetree.c 2004-10-01 10:22:51.772969832 -0400
@@ -245,7 +248,7 @@ tree_code_get_type (int type_num)
return void_type_node;
default:
- abort ();
+ gcc_unreachable ();
}
}
@@ -330,8 +333,7 @@ tree_code_create_function_prototype (uns
id = get_identifier ((const char*)chars);
for (parm = parms; parm; parm = parm->tp.par.next)
{
- if (parm->category != parameter_category)
- abort ();
+ gcc_assert (parm->category == parameter_category);
type_node = tree_code_get_type (parm->type);
type_list = tree_cons (NULL_TREE, type_node, type_list);
}
@@ -375,7 +377,7 @@ tree_code_create_function_prototype (uns
case AUTOMATIC_STORAGE:
default:
- abort ();
+ gcc_unreachable ();
}
/* Process declaration of function defined elsewhere. */
@@ -403,8 +405,7 @@ tree_code_create_function_initial (tree
struct prod_token_parm_item* parm;
fn_decl = prev_saved;
- if (!fn_decl)
- abort ();
+ gcc_assert (fn_decl);
/* Output message if not -quiet. */
announce_function (fn_decl);
@@ -437,10 +438,8 @@ tree_code_create_function_initial (tree
/* Some languages have different nominal and real types. */
DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
- if (!DECL_ARG_TYPE (parm_decl))
- abort ();
- if (!fn_decl)
- abort ();
+ gcc_assert (DECL_ARG_TYPE (parm_decl));
+ gcc_assert (fn_decl);
DECL_CONTEXT (parm_decl) = fn_decl;
DECL_SOURCE_LOCATION (parm_decl) = loc;
parm_list = chainon (parm_decl, parm_list);
@@ -458,12 +457,10 @@ tree_code_create_function_initial (tree
param_decl = TREE_CHAIN (param_decl),
this_parm = this_parm->tp.par.next)
{
- if (!this_parm)
- abort (); /* Too few. */
+ gcc_assert (this_parm); /* Too few. */
*this_parm->tp.par.where_to_put_var_tree = param_decl;
}
- if (this_parm)
- abort (); /* Too many. */
+ gcc_assert (!this_parm); /* Too many. */
/* Create a new level at the start of the function. */
@@ -541,8 +538,7 @@ tree_code_create_variable (unsigned int
var_type = tree_code_get_type (expression_type);
/* 2. Build the name. */
- if (chars[length] != 0)
- abort (); /* Should be null terminated. */
+ gcc_assert (chars[length] == 0); /* Should be null terminated. */
var_id = get_identifier ((const char*)chars);
@@ -555,8 +551,7 @@ tree_code_create_variable (unsigned int
else
DECL_INITIAL (var_decl) = NULL_TREE;
- if (TYPE_SIZE (var_type) == 0)
- abort (); /* Did not calculate size. */
+ gcc_assert (TYPE_SIZE (var_type) != 0); /* Did not calculate size. */
DECL_CONTEXT (var_decl) = current_function_decl;
@@ -586,7 +581,7 @@ tree_code_create_variable (unsigned int
break;
default:
- abort ();
+ gcc_unreachable ();
}
/* This should really only be set if the variable is used. */
@@ -611,13 +606,12 @@ tree_code_generate_return (tree type, tr
tree setret;
tree param;
+#ifdef ENABLE_CHECKING
for (param = DECL_ARGUMENTS (current_function_decl);
param;
param = TREE_CHAIN (param))
- {
- if (DECL_CONTEXT (param) != current_function_decl)
- abort ();
- }
+ gcc_assert (DECL_CONTEXT (param) == current_function_decl);
+#endif
if (exp && TREE_TYPE (TREE_TYPE (current_function_decl)) != void_type_node)
{
@@ -692,12 +686,10 @@ tree_code_get_expression (unsigned int e
switch (exp_type)
{
case EXP_ASSIGN:
- if (!op1 || !op2)
- abort ();
+ gcc_assert (op1 && op2);
operator = MODIFY_EXPR;
ret1 = fold (build2 (operator, void_type_node, op1,
fold (build1 (CONVERT_EXPR, TREE_TYPE (op1), op2))));
-
break;
case EXP_PLUS:
@@ -714,8 +706,7 @@ tree_code_get_expression (unsigned int e
/* Expand a binary expression. Ensure the operands are the right type. */
binary_expression:
- if (!op1 || !op2)
- abort ();
+ gcc_assert (op1 && op2);
ret1 = fold (build2 (operator, type,
fold (build1 (CONVERT_EXPR, type, op1)),
fold (build1 (CONVERT_EXPR, type, op2))));
@@ -725,8 +716,7 @@ tree_code_get_expression (unsigned int e
decl for the variable. If the TYPE is different than the
variable type, convert it. */
case EXP_REFERENCE:
- if (!op1)
- abort ();
+ gcc_assert (op1);
if (type == TREE_TYPE (op1))
ret1 = op1;
else
@@ -734,9 +724,7 @@ tree_code_get_expression (unsigned int e
break;
case EXP_FUNCTION_INVOCATION:
- if (!op1 || !op2)
- abort ();
-
+ gcc_assert (op1 && op2);
{
tree fun_ptr;
fun_ptr = fold (build1 (ADDR_EXPR,
@@ -746,7 +734,7 @@ tree_code_get_expression (unsigned int e
break;
default:
- abort ();
+ gcc_unreachable ();
}
return ret1;