PATCH: use gcc_assert, gcc_unreachable in java frontend

Ben Elliston bje@au1.ibm.com
Fri Feb 3 03:27:00 GMT 2006


While debugging the Java frontend, I discovered that it had not been
converted to use gcc_assert() and gcc_unreachable().

Tested on powerpc-linux with a full bootstrap and no regressions when
running make check-target-libjava run.  Okay for the trunk?

Ben

2006-02-03  Ben Elliston  <bje@au.ibm.com>

	* java-gimplify.c: Use gcc_assert and gcc_unreachable throughout.
	* typeck.c: Likewise.
	* verify-impl.c: Likewise.
	* class.c: Likewise.
	* decl.c: Likewise.
	* jcf-parse.c: Likewise.
	* constants.c: Likewise.
	* check-init.c: Likewise.
	* jcf-write.c: Likewise.
	* verify-glue.c: Likewise.
	* mangle.c: Likewise.
	* expr.c: Likewise.
	* lang.c: Likewise.
	* boehm.c: Likewise.

Index: java-gimplify.c
===================================================================
--- java-gimplify.c	(revision 110530)
+++ java-gimplify.c	(working copy)
@@ -146,7 +146,7 @@ java_gimplify_expr (tree *expr_p, tree *
     case CONDITIONAL_EXPR:
     case INSTANCEOF_EXPR:
     case CLASS_LITERAL:
-      abort ();
+      gcc_unreachable ();
 
     default:
       /* Java insists on strict left-to-right evaluation of expressions.
Index: typeck.c
===================================================================
--- typeck.c	(revision 110530)
+++ typeck.c	(working copy)
@@ -55,8 +55,7 @@ set_local_type (int slot, tree type)
   int max_locals = DECL_MAX_LOCALS(current_function_decl);
   int nslots = TYPE_IS_WIDE (type) ? 2 : 1;
 
-  if (slot < 0 || slot + nslots - 1 >= max_locals)
-    abort ();
+  gcc_assert (slot >= 0 && (slot + nslots - 1 < max_locals));
 
   type_map[slot] = type;
   while (--nslots > 0)
@@ -458,9 +457,7 @@ static tree
 parse_signature_type (const unsigned char **ptr, const unsigned char *limit)
 {
   tree type;
-
-  if (*ptr >= limit)
-    abort ();
+  gcc_assert (*ptr < limit);
 
   switch (**ptr)
     {
@@ -484,8 +481,7 @@ parse_signature_type (const unsigned cha
 	const unsigned char *str = start;
 	for ( ; ; str++)
 	  {
-	    if (str >= limit)
-	      abort ();
+	    gcc_assert (str < limit);
 	    if (*str == ';')
 	      break;
 	  }
@@ -494,7 +490,7 @@ parse_signature_type (const unsigned cha
 	break;
       }
     default:
-      abort ();
+      gcc_unreachable ();
     }
   return promote_type (type);
 }
@@ -662,7 +658,7 @@ build_java_signature (tree type)
 	  break;
 	bad_type:
 	default:
-	  abort ();
+	  gcc_unreachable ();
 	}
       TYPE_SIGNATURE (type) = sig;
     }
Index: verify-impl.c
===================================================================
--- verify-impl.c	(revision 110530)
+++ verify-impl.c	(working copy)
@@ -3178,7 +3178,7 @@ collapse_type (type *t)
       return vfy_object_type ();
     }
 
-  abort ();
+  gcc_unreachable ();
 }
 
 static void
@@ -3220,8 +3220,7 @@ verify_instructions (void)
 				   vfy_unsuitable_type ());
 	    }
 	}
-      if (slot != curr->stackdepth)
-	abort ();
+      gcc_assert (slot == curr->stackdepth);
     }
 }
 
Index: class.c
===================================================================
--- class.c	(revision 110530)
+++ class.c	(working copy)
@@ -1014,7 +1014,7 @@ build_class_ref (tree type)
 	      else if (type == void_type_node)
                 prim_class_name = "java.lang.Void";
 	      else
-		abort ();
+		gcc_unreachable ();
 
 	      prim_class = lookup_class (get_identifier (prim_class_name));
 	      /* We wrap the class in a NOP_EXPR, because it is a
@@ -1207,7 +1207,7 @@ get_access_flags_from_decl (tree decl)
 	access_flags |= ACC_INVISIBLE;
       return access_flags;
     }
-  abort ();
+  gcc_unreachable ();
 }
 
 static GTY (()) int alias_labelno = 0;
@@ -2313,8 +2313,7 @@ get_interface_method_index (tree method,
     {
       if (meth == method)
 	return i;
-      if (meth == NULL_TREE)
-	abort ();
+      gcc_assert (meth != NULL_TREE);
     }
 }
 
Index: decl.c
===================================================================
--- decl.c	(revision 110530)
+++ decl.c	(working copy)
@@ -163,8 +163,7 @@ update_aliases (tree decl, int index, in
   tree decl_type = TREE_TYPE (decl);
   tree tmp;
 
-  if (debug_variable_p (decl))
-    abort ();
+  gcc_assert (! debug_variable_p (decl));
 
   for (tmp = TREE_VEC_ELT (decl_map, index); 
        tmp != NULL_TREE; 
@@ -188,8 +187,7 @@ update_aliases (tree decl, int index, in
 		  && TREE_CODE (decl_type) == POINTER_TYPE)))
 	{
 	  tree src = build1 (NOP_EXPR, tmp_type, decl);
-	  if (LOCAL_VAR_OUT_OF_SCOPE_P (tmp))
-	    abort ();
+	  gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (tmp));
 	  java_add_stmt (build2 (MODIFY_EXPR, tmp_type, tmp, src));
 	}
     }
@@ -269,8 +267,7 @@ check_local_unnamed_variable (tree best,
 {
   tree decl_type = TREE_TYPE (decl);
   
-  if (LOCAL_VAR_OUT_OF_SCOPE_P (decl))
-    abort ();
+  gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
 
   /* Use the same decl for all integer types <= 32 bits.  This is
      necessary because sometimes a value is stored as (for example)
@@ -411,9 +408,7 @@ java_replace_reference (tree var_decl, b
 	  int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
 	  tree base_decl = TREE_VEC_ELT (base_decl_map, index); 
 
-	  if (! base_decl)
-	    abort ();
-
+	  gcc_assert (base_decl);
 	  if (! want_lvalue)
 	    base_decl = build1 (NOP_EXPR, decl_type, base_decl);
 
@@ -2010,8 +2005,7 @@ start_java_method (tree fndecl)
     {
       tree parm_name = NULL_TREE, parm_decl;
       tree parm_type = TREE_VALUE (tem);
-      if (i >= DECL_MAX_LOCALS (fndecl))
-	abort ();
+      gcc_assert (i < DECL_MAX_LOCALS (fndecl));
 
       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
       DECL_CONTEXT (parm_decl) = fndecl;
@@ -2277,8 +2271,7 @@ get_stmts (void)
 void
 register_exception_range (struct eh_range *range, int pc, int end_pc)
 {
-  if (current_binding_level->exception_range)
-    abort ();
+  gcc_assert (! current_binding_level->exception_range);
   current_binding_level->exception_range = range;
   current_binding_level->end_pc = end_pc;
   current_binding_level->start_pc = pc;      
Index: jcf-parse.c
===================================================================
--- jcf-parse.c	(revision 110530)
+++ jcf-parse.c	(working copy)
@@ -120,7 +120,7 @@ handle_deprecated (void)
   else
     {
       /* Shouldn't happen.  */
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -285,12 +285,12 @@ set_source_filename (JCF *jcf, int index
 tree
 parse_signature (JCF *jcf, int sig_index)
 {
-  if (sig_index <= 0 || sig_index >= JPOOL_SIZE (jcf)
-      || JPOOL_TAG (jcf, sig_index) != CONSTANT_Utf8)
-    abort ();
-  else
-    return parse_signature_string (JPOOL_UTF_DATA (jcf, sig_index),
-				   JPOOL_UTF_LENGTH (jcf, sig_index));
+  gcc_assert (sig_index > 0
+	      && sig_index < JPOOL_SIZE (jcf)
+	      && JPOOL_TAG (jcf, sig_index) == CONSTANT_Utf8);
+
+  return parse_signature_string (JPOOL_UTF_DATA (jcf, sig_index),
+				 JPOOL_UTF_LENGTH (jcf, sig_index));
 }
 
 tree
@@ -395,10 +395,7 @@ tree
 get_name_constant (JCF *jcf, int index)
 {
   tree name = get_constant (jcf, index);
-
-  if (TREE_CODE (name) != IDENTIFIER_NODE)
-    abort ();
-
+  gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
   return name;
 }
 
@@ -445,10 +442,10 @@ handle_innerclass_attribute (int count, 
 static tree
 give_name_to_class (JCF *jcf, int i)
 {
-  if (i <= 0 || i >= JPOOL_SIZE (jcf)
-      || JPOOL_TAG (jcf, i) != CONSTANT_Class)
-    abort ();
-  else
+  gcc_assert (i > 0
+	      && i < JPOOL_SIZE (jcf)
+	      && JPOOL_TAG (jcf, i) == CONSTANT_Class);
+
     {
       tree package_name = NULL_TREE, tmp;
       tree this_class;
@@ -489,9 +486,9 @@ tree
 get_class_constant (JCF *jcf, int i)
 {
   tree type;
-  if (i <= 0 || i >= JPOOL_SIZE (jcf)
-      || (JPOOL_TAG (jcf, i) & ~CONSTANT_ResolvedFlag) != CONSTANT_Class)
-    abort ();
+  gcc_assert (i > 0
+	      && i < JPOOL_SIZE (jcf)
+	      && (JPOOL_TAG (jcf, i) & ~CONSTANT_ResolvedFlag) == CONSTANT_Class);
 
   if (JPOOL_TAG (jcf, i) != CONSTANT_ResolvedClass)
     {
@@ -1421,12 +1418,9 @@ parse_zip_file_entries (void)
 	    
 	    CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1;
 
-	    if (TYPE_DUMMY (class))
-	      {
-		/* This is a dummy class, and now we're compiling it
-		   for real.  */
-		abort ();
-	      }
+	    /* This is a dummy class, and now we're compiling it for
+	       real.  */
+	    gcc_assert (! TYPE_DUMMY (class));
 
 	    /* This is for a corner case where we have a superclass
 	       but no superclass fields.  
@@ -1501,7 +1495,7 @@ parse_zip_file_entries (void)
 	  break;
 
 	default:
-	  abort ();
+	  gcc_unreachable ();
 	}
     }
 }
Index: constants.c
===================================================================
--- constants.c	(revision 110530)
+++ constants.c	(working copy)
@@ -313,8 +313,7 @@ write_constant_pool (CPool *cpool, unsig
 	}
     }
 
-  if (ptr != buffer + length)
-    abort ();
+  gcc_assert (ptr == buffer + length);
 }
 
 static GTY(()) tree tag_nodes[13];
Index: check-init.c
===================================================================
--- check-init.c	(revision 110530)
+++ check-init.c	(working copy)
@@ -672,8 +672,7 @@ check_init (tree exp, words before)
 	DECLARE_BUFFERS(when_true, 2);
 	words when_false = when_true + num_current_words;
 #ifdef ENABLE_JC1_CHECKING
-	if (TREE_CODE (alt->block) != LOOP_EXPR)
-	  abort ();
+	gcc_assert (TREE_CODE (alt->block) == LOOP_EXPR);
 #endif
 	check_bool_init (TREE_OPERAND (exp, 0), before, when_false, when_true);
 	done_alternative (when_true, alt);
Index: jcf-write.c
===================================================================
--- jcf-write.c	(revision 110530)
+++ jcf-write.c	(working copy)
@@ -80,7 +80,7 @@ const char *jcf_write_base_directory = N
 /* Macro to call each time we pop I words from the JVM stack. */
 
 #define NOTE_POP(I) \
-  do { state->code_SP -= (I); if (state->code_SP < 0) abort(); } while (0)
+  do { state->code_SP -= (I); gcc_assert (state->code_SP >= 0); } while (0)
 
 /* A chunk or segment of a .class file. */
 
@@ -356,10 +356,8 @@ static int CHECK_PUT (void *, struct jcf
 static int
 CHECK_PUT (void *ptr, struct jcf_partial *state, int i)
 {
-  if ((unsigned char *) ptr < state->chunk->data
-      || (unsigned char *) ptr + i > state->chunk->data + state->chunk->size)
-    abort ();
-
+  gcc_assert ((unsigned char *) ptr >= state->chunk->data
+	      && (unsigned char *) ptr + i <= state->chunk->data + state->chunk->size);
   return 0;
 }
 #else
@@ -406,9 +404,7 @@ static int CHECK_OP (struct jcf_partial 
 static int
 CHECK_OP (struct jcf_partial *state)
 {
-  if (state->bytecode.ptr > state->bytecode.limit)
-    abort ();
-
+  gcc_assert (state->bytecode.ptr <= state->bytecode.limit);
   return 0;
 }
 #else
@@ -609,15 +605,13 @@ maybe_free_localvar (tree decl, struct j
 
   info->end_label = end_label;
 
-  if (info->decl != decl)
-    abort ();
+  gcc_assert (info->decl == decl);
   if (! really)
     return;
   ptr[0] = NULL;
   if (wide)
     {
-      if (ptr[1] !=  (struct localvar_info *)(~0))
-	abort ();
+      gcc_assert (ptr[1] == (struct localvar_info *) (~0));
       ptr[1] = NULL;
     }
 }
@@ -667,7 +661,7 @@ get_access_flags (tree decl)
 	flags |= ACC_STRICT;
     }
   else
-    abort ();
+    gcc_unreachable ();
 
   if (TREE_CODE (decl) == FUNCTION_DECL)
     {
@@ -827,7 +821,7 @@ find_constant_index (tree value, struct 
     return find_string_constant (&state->cpool, value);
 
   else
-    abort ();
+    gcc_unreachable ();
 }
 
 /* Push 64-bit long constant on VM stack.
@@ -902,7 +896,7 @@ adjust_typed_op (tree type, int max)
     default:
       break;
     }
-  abort ();
+  gcc_unreachable ();
 }
 
 static void
@@ -942,7 +936,7 @@ emit_dup (int size, int offset, struct j
   else if (offset == 2)
     kind = size == 1 ? OPCODE_dup_x2 : OPCODE_dup2_x2;
   else
-    abort();
+    gcc_unreachable ();
   OP1 (kind);
   NOTE_PUSH (size);
 }
@@ -1134,8 +1128,7 @@ generate_bytecode_conditional (tree exp,
 	generate_bytecode_conditional (TREE_OPERAND (exp, 2),
 				       true_label, false_label,
 				       true_branch_first, state);
-	if (state->code_SP != save_SP_after)
-	  abort ();
+	gcc_assert (state->code_SP == save_SP_after);
       }
       break;
     case TRUTH_NOT_EXPR:
@@ -1243,7 +1236,8 @@ generate_bytecode_conditional (tree exp,
 	    {
 	    case EQ_EXPR:  op = OPCODE_if_acmpeq;  break;
 	    case NE_EXPR:  op = OPCODE_if_acmpne;  break;
-	    default:  abort();
+	    default:
+	      gcc_unreachable ();
 	    }
 	  if (integer_zerop (exp1) || integer_zerop (exp0))
 	    {
@@ -1333,8 +1327,7 @@ generate_bytecode_conditional (tree exp,
 	}
       break;
     }
-  if (save_SP != state->code_SP)
-    abort ();
+  gcc_assert (save_SP == state->code_SP);
 }
 
 /* Call pending cleanups i.e. those for surrounding TRY_FINALLY_EXPRs.
@@ -1496,8 +1489,7 @@ generate_bytecode_insns (tree exp, int t
       if (target == IGNORE_TARGET) ; /* do nothing */
       else if (TREE_CODE (type) == POINTER_TYPE)
 	{
-	  if (! integer_zerop (exp))
-	    abort();
+	  gcc_assert (integer_zerop (exp));
 	  RESERVE(1);
 	  OP1 (OPCODE_aconst_null);
 	  NOTE_PUSH (1);
@@ -1834,7 +1826,7 @@ generate_bytecode_insns (tree exp, int t
       if (exp == NULL_TREE)
 	exp = build_java_empty_stmt ();
       else if (TREE_CODE (exp) != MODIFY_EXPR) 
-	abort ();
+	gcc_unreachable ();
       else
 	exp = TREE_OPERAND (exp, 1);
       generate_bytecode_return (exp, state);
@@ -1848,8 +1840,7 @@ generate_bytecode_insns (tree exp, int t
 	end_label->u.labeled_block = exp;
 	if (LABELED_BLOCK_BODY (exp))
 	  generate_bytecode_insns (LABELED_BLOCK_BODY (exp), target, state);
-	if (state->labeled_blocks != end_label)
-	  abort();
+	gcc_assert (state->labeled_blocks == end_label);
 	state->labeled_blocks = end_label->next;
 	define_jcf_label (end_label, state);
       }
@@ -1957,7 +1948,7 @@ generate_bytecode_insns (tree exp, int t
 	  offset = 0;
 	}
       else
-	abort ();
+	gcc_unreachable ();
 
       if (target != IGNORE_TARGET && post_op)
 	emit_dup (size, offset, state);
@@ -2081,7 +2072,7 @@ generate_bytecode_insns (tree exp, int t
 		NOTE_PUSH (TYPE_IS_WIDE (TREE_TYPE (lhs)) ? 2 : 1);
 	      }
 	    else
-	      abort ();
+	      gcc_unreachable ();
 
 	    /* This function correctly handles the case where the LHS
 	       of a binary expression is NULL_TREE.  */
@@ -2127,7 +2118,7 @@ generate_bytecode_insns (tree exp, int t
 	  NOTE_POP (TYPE_IS_WIDE (TREE_TYPE (exp)) ? 4 : 3);
 	}
       else
-	abort ();
+	gcc_unreachable ();
       break;
     case PLUS_EXPR:
       jopcode = OPCODE_iadd;
@@ -2313,8 +2304,7 @@ generate_bytecode_insns (tree exp, int t
 	struct jcf_block *end_label;  /* End of try clause. */
 	struct jcf_block *finished_label = gen_jcf_label (state);
 	tree clause = TREE_OPERAND (exp, 1);
-	if (target != IGNORE_TARGET)
-	  abort ();
+	gcc_assert (target == IGNORE_TARGET);
 	generate_bytecode_insns (try_clause, IGNORE_TARGET, state);
 	end_label = get_jcf_label_here (state);
 	if (end_label == start_label)
@@ -2369,8 +2359,7 @@ generate_bytecode_insns (tree exp, int t
 
 	if (CAN_COMPLETE_NORMALLY (finally))
 	  {
-	    if (state->labeled_blocks != finally_label)
-	      abort();
+	    gcc_assert (state->labeled_blocks == finally_label);
 	    state->labeled_blocks = finally_label->next;
 	  }
 	end_label = get_jcf_label_here (state);
@@ -2517,8 +2506,7 @@ generate_bytecode_insns (tree exp, int t
 	tree op0 = TREE_OPERAND (exp, 0);
 	tree op1 = TREE_OPERAND (exp, 1);
 	tree x;
-	if (TREE_SIDE_EFFECTS (op0) || TREE_SIDE_EFFECTS (op1))
-	  abort ();
+	gcc_assert (! TREE_SIDE_EFFECTS (op0) && ! TREE_SIDE_EFFECTS (op1));
 	x = build3 (COND_EXPR, TREE_TYPE (exp), 
 		    build2 (code, boolean_type_node, op0, op1), 
 		    op0, op1);	  
@@ -2645,9 +2633,7 @@ generate_bytecode_insns (tree exp, int t
 	    OP2 (index);
 	    if (interface)
 	      {
-		if (nargs <= 0)
-		  abort ();
-
+		gcc_assert (nargs > 0);
 		OP1 (nargs);
 		OP1 (0);
 	      }
@@ -2863,8 +2849,7 @@ perform_relocations (struct jcf_partial 
 	      *--new_ptr = - reloc->kind;
 	    }
 	}
-      if (new_ptr != chunk->data)
-	abort ();
+      gcc_assert (new_ptr == chunk->data);
     }
   state->code_length = pc;
 }
@@ -3125,8 +3110,7 @@ generate_classfile (tree clas, struct jc
 	  generate_bytecode_insns (body, IGNORE_TARGET, state);
 	  if (CAN_COMPLETE_NORMALLY (body))
 	    {
-	      if (TREE_CODE (TREE_TYPE (type)) != VOID_TYPE)
-		abort();
+	      gcc_assert (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE);
 	      RESERVE (1);
 	      OP1 (OPCODE_return);
 	    }
Index: verify-glue.c
===================================================================
--- verify-glue.c	(revision 110530)
+++ verify-glue.c	(working copy)
@@ -252,8 +252,7 @@ char
 vfy_get_primitive_char (vfy_jclass klass)
 {
   tree sig;
-  if (! vfy_is_primitive (klass))
-    abort ();
+  gcc_assert (vfy_is_primitive (klass));
   sig = build_java_signature (klass);
   return (IDENTIFIER_POINTER (sig))[0];
 }
@@ -296,8 +295,7 @@ vfy_jclass
 vfy_get_component_type (vfy_jclass klass)
 {
   vfy_jclass k;
-  if (! vfy_is_array (klass))
-    abort ();
+  gcc_assert (vfy_is_array (klass));
   k = TYPE_ARRAY_ELEMENT (klass);
   if (TREE_CODE (k) == POINTER_TYPE)
     k = TREE_TYPE (k);
Index: mangle.c
===================================================================
--- mangle.c	(revision 110530)
+++ mangle.c	(working copy)
@@ -280,7 +280,7 @@ mangle_type (tree type)
       break;
     bad_type:
     default:
-      abort ();
+      gcc_unreachable ();
     }
 }
 
@@ -397,8 +397,7 @@ mangle_record_type (tree type, int for_p
 #define ADD_N() \
   do { obstack_1grow (mangle_obstack, 'N'); nadded_p = 1; } while (0)
 
-  if (TREE_CODE (type) != RECORD_TYPE)
-    abort ();
+  gcc_assert (TREE_CODE (type) == RECORD_TYPE);
 
   if (!TYPE_PACKAGE_LIST (type))
     set_type_package_list (type);
@@ -450,8 +449,7 @@ mangle_pointer_type (tree type)
   /* This didn't work. We start by mangling the pointed-to type */
   pointer_type = type;
   type = TREE_TYPE (type);
-  if (TREE_CODE (type) != RECORD_TYPE)
-    abort ();
+  gcc_assert (TREE_CODE (type) == RECORD_TYPE);
   
   obstack_1grow (mangle_obstack, 'P');
   if (mangle_record_type (type, /* for_pointer = */ 1))
@@ -473,8 +471,7 @@ mangle_array_type (tree p_type)
   int match;
 
   type = TREE_TYPE (p_type);
-  if (!type)
-    abort ();
+  gcc_assert (type);
 
   elt_type = TYPE_ARRAY_ELEMENT (type);
 
Index: expr.c
===================================================================
--- expr.c	(revision 110530)
+++ expr.c	(working copy)
@@ -273,8 +273,7 @@ push_type_0 (tree type)
 void
 push_type (tree type)
 {
-  if (! push_type_0 (type))
-    abort ();
+  gcc_assert (push_type_0 (type));
 }
 
 static void
@@ -606,15 +605,13 @@ java_stack_pop (int count)
     {
       tree type, val;
 
-      if (stack_pointer == 0)
-	abort ();
+      gcc_assert (stack_pointer != 0);
 
       type = stack_type_map[stack_pointer - 1];
       if (type == TYPE_SECOND)
 	{
 	  count--;
-	  if (stack_pointer == 1 || count <= 0)
-	    abort ();
+	  gcc_assert (stack_pointer != 1 && count > 0);
 
 	  type = stack_type_map[stack_pointer - 2];
 	}
@@ -632,13 +629,12 @@ java_stack_swap (void)
   tree temp;
   tree decl1, decl2;
 
-  if (stack_pointer < 2
-      || (type1 = stack_type_map[stack_pointer - 1]) == TYPE_UNKNOWN
-      || (type2 = stack_type_map[stack_pointer - 2]) == TYPE_UNKNOWN
-      || type1 == TYPE_SECOND || type2 == TYPE_SECOND
-      || TYPE_IS_WIDE (type1) || TYPE_IS_WIDE (type2))
-    /* Bad stack swap.  */
-    abort ();
+  /* Bad stack swap.  */
+  gcc_assert (stack_pointer >= 2
+	      && (type1 = stack_type_map[stack_pointer - 1]) != TYPE_UNKNOWN
+	      && (type2 = stack_type_map[stack_pointer - 2]) != TYPE_UNKNOWN
+	      && (type1 != TYPE_SECOND && type2 != TYPE_SECOND)
+	      && (! TYPE_IS_WIDE (type1) && ! TYPE_IS_WIDE (type2)));
 
   flush_quick_stack ();
   decl1 = find_stack_slot (stack_pointer - 1, type1);
@@ -678,18 +674,16 @@ java_stack_dup (int size, int offset)
       type = stack_type_map [src_index];
       if (type == TYPE_SECOND)
 	{
-	  if (src_index <= low_index)
-	    /* Dup operation splits 64-bit number.  */
-	    abort ();
+	  /* Dup operation splits 64-bit number.  */
+	  gcc_assert (src_index > low_index);
 
 	  stack_type_map[dst_index] = type;
 	  src_index--;  dst_index--;
 	  type = stack_type_map[src_index];
-	  if (! TYPE_IS_WIDE (type))
-	    abort ();
+	  gcc_assert (TYPE_IS_WIDE (type));
 	}
-      else if (TYPE_IS_WIDE (type))
-	abort ();
+      else
+	gcc_assert (! TYPE_IS_WIDE (type));
 
       if (src_index != dst_index)
 	{
@@ -785,7 +779,7 @@ encode_newarray_type (tree type)
   else if (type == long_type_node)
     return 11;
   else
-    abort ();
+    gcc_unreachable ();
 }
 
 /* Build a call to _Jv_ThrowBadArrayIndex(), the
@@ -942,17 +936,15 @@ build_java_arraystore_check (tree array,
     }
   else
     {
-      if (! is_array_type_p (array_type_p))
-	abort ();
+      gcc_assert (is_array_type_p (array_type_p));
 
       /* Get the TYPE_DECL for ARRAY's element type. */
       element_type
 	= TYPE_NAME (TREE_TYPE (TREE_TYPE (TREE_TYPE (array_type_p))));
     }
 
-  if (TREE_CODE (element_type) != TYPE_DECL   
-      || TREE_CODE (object_type) != TYPE_DECL)
-    abort ();
+  gcc_assert (TREE_CODE (element_type) == TYPE_DECL
+	      && TREE_CODE (object_type) == TYPE_DECL);
 
   if (!flag_store_check)
     return build1 (NOP_EXPR, array_type_p, array);
@@ -1235,7 +1227,7 @@ expand_java_pushc (int ival, tree type)
       value = build_real (type, x);
     }
   else
-    abort ();
+    gcc_unreachable ();
 
   push_value (value);
 }
@@ -1492,9 +1484,7 @@ build_java_soft_divmod (enum tree_code o
 	}
     }
 
-  if (! call)
-    abort ();
-		  
+  gcc_assert (call);
   call = build3 (CALL_EXPR, type,
 		 build_address_of (call),
 		 tree_cons (NULL_TREE, arg1,
@@ -1890,7 +1880,7 @@ pop_arguments (tree arg_types)
 	arg = convert (integer_type_node, arg);
       return tree_cons (NULL_TREE, arg, tail);
     }
-  abort ();
+  gcc_unreachable ();
 }
 
 /* Attach to PTR (a block) the declaration found in ENTRY. */
@@ -2151,8 +2141,7 @@ build_invokevirtual (tree dtable, tree m
 
   if (flag_indirect_dispatch)
     {
-      if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
-	abort ();
+      gcc_assert (! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))));
 
       otable_index 
 	= build_int_cst (NULL_TREE, get_symbol_table_index 
@@ -2205,8 +2194,7 @@ build_invokeinterface (tree dtable, tree
 		   lookup_field (&dtable_type, class_ident), NULL_TREE);
 
   interface = DECL_CONTEXT (method);
-  if (! CLASS_INTERFACE (TYPE_NAME (interface)))
-    abort ();
+  gcc_assert (CLASS_INTERFACE (TYPE_NAME (interface)));
   layout_class_methods (interface);
   
   if (flag_indirect_dispatch)
@@ -2447,8 +2435,7 @@ build_jni_stub (tree method)
   int from_class = ! CLASS_FROM_SOURCE_P (klass);
   klass = build_class_ref (klass);
 
-  if (! METHOD_NATIVE (method) || ! flag_jni)
-    abort ();
+  gcc_assert (METHOD_NATIVE (method) && flag_jni);
 
   DECL_ARTIFICIAL (method) = 1;
   DECL_EXTERNAL (method) = 0;
@@ -2602,8 +2589,7 @@ build_jni_stub (tree method)
   if (res_var != NULL_TREE)
     {
       tree drt;
-      if (! DECL_RESULT (method))
-	abort ();
+      gcc_assert (DECL_RESULT (method));
       /* Make sure we copy the result variable to the actual
 	 result.  We use the type of the DECL_RESULT because it
 	 might be different from the return type of the function:
@@ -3482,8 +3468,7 @@ force_evaluation_order (tree node)
 	return node;
 
       /* Not having a list of arguments here is an error. */ 
-      if (TREE_CODE (arg) != TREE_LIST)
-        abort ();
+      gcc_assert (TREE_CODE (arg) == TREE_LIST);
 
       /* This reverses the evaluation order. This is a desired effect. */
       for (cmp = NULL_TREE; arg; arg = TREE_CHAIN (arg))
Index: lang.c
===================================================================
--- lang.c	(revision 110530)
+++ lang.c	(working copy)
@@ -335,7 +335,7 @@ java_handle_option (size_t scode, const 
     default:
       if (cl_options[code].flags & CL_Java)
 	break;
-      abort();
+      gcc_unreachable ();
     }
 
   return 1;
@@ -781,8 +781,7 @@ merge_init_test_initialization (void **e
   /* See if we have remapped this declaration.  If we haven't there's
      a bug in the inliner.  */
   n = splay_tree_lookup (decl_map, (splay_tree_key) ite->value);
-  if (! n)
-    abort ();
+  gcc_assert (n);
 
   /* Create a new entry for the class and its remapped boolean
      variable.  If we already have a mapping for this class we've
Index: boehm.c
===================================================================
--- boehm.c	(revision 110530)
+++ boehm.c	(working copy)
@@ -101,8 +101,7 @@ mark_reference_fields (tree field,
 
 	  /* If this reference slot appears to overlay a slot we think
 	     we already covered, then we are doomed.  */
-	  if (offset <= *last_view_index)
-	    abort ();
+	  gcc_assert (offset > *last_view_index);
 
 	  count = offset * BITS_PER_UNIT / POINTER_SIZE;
 	  size_words = size_bytes * BITS_PER_UNIT / POINTER_SIZE;



More information about the Java mailing list