This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

patch for uninit var warnings in java subdir



This patch squelches most of the uninitialized variable warnings in
the Java front end.  In two cases (resolve_qualified_expression_name
and patch_method_invocation) this fixes a real bug.

There are a couple of warnings left - in parse.y; I couldn't figure
out what was going on there, so I left them alone.

OK to install?

zw

1999-04-14 23:32 -0400  Zack Weinberg  <zack@rabi.columbia.edu>

	* class.c (build_utf8_ref): Initialize `field' before use.
	* decl.c (init_decl_processing): Likewise.
	* parse.y (find_in_imports_on_demand): Initialize
	`node_to_use' and `cl' upon declaration.  Simplify `seen_once'
	logic.
	(resolve_qualified_expression_name): Move `field_decl' into
	narrowest possible scope.  Use `decl' instead when reporting
	reference error.
	(patch_method_invocation): Abort on "impossible" situation.
	(patch_assignment): Set lhs_type to NULL_TREE on invalid LHS.
	(patch_binop): Initialize `prom_type' upon declaration.
	(patch_unaryop): Likewise.
	* verify.c (verify_jvm_instructions): Initialize `prevpc' and
	`oldpc' before entering the big loop.  Disentangle logic in
	case OPCODE_lookupswitch.

===================================================================
Index: java/class.c
--- java/class.c	1999/04/05 13:04:22	1.35
+++ java/class.c	1999/04/15 03:31:50
@@ -571,6 +571,7 @@ build_utf8_ref (name)
   ctype = make_node (RECORD_TYPE);
   str_type = build_prim_array_type (unsigned_byte_type_node,
 				    name_len + 1); /* Allow for final '\0'. */
+  field = NULL_TREE;
   PUSH_FIELD (ctype, field, "hash", unsigned_short_type_node);
   PUSH_FIELD (ctype, field, "length", unsigned_short_type_node);
   PUSH_FIELD (ctype, field, "data", str_type);
===================================================================
Index: java/decl.c
--- java/decl.c	1999/04/05 13:04:23	1.26
+++ java/decl.c	1999/04/15 03:31:53
@@ -570,6 +570,7 @@ init_decl_processing ()
   init_expr_processing();
 
   utf8const_type = make_node (RECORD_TYPE);
+  field = NULL_TREE;
   PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
   PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
   FINISH_RECORD (utf8const_type);
===================================================================
Index: java/parse.y
--- java/parse.y	1999/04/12 18:32:22	1.74
+++ java/parse.y	1999/04/15 03:31:59
@@ -5104,9 +5104,9 @@ static int
 find_in_imports_on_demand (class_type)
      tree class_type;
 {
-  tree node, import, node_to_use;
-  int seen_once = -1;
-  tree cl;
+  tree node, import;
+  int seen_once = 0;
+  tree node_to_use = NULL_TREE, cl = NULL_TREE;
 
   for (import = ctxp->import_demand_list; import; import = TREE_CHAIN (import))
     {
@@ -5123,20 +5123,19 @@ find_in_imports_on_demand (class_type)
       node = maybe_get_identifier (id_name);
       if (node && IS_A_CLASSFILE_NAME (node))
 	{
-	  if (seen_once < 0)
+	  if (seen_once == 0)
 	    {
 	      cl = TREE_PURPOSE (import);
-	      seen_once = 1;
 	      node_to_use = node;
 	    }
 	  else
 	    {
-	      seen_once++;
 	      parse_error_context 
 		(import, "Type `%s' also potentially defined in package `%s'",
 		 IDENTIFIER_POINTER (TYPE_NAME (class_type)),
 		 IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))));
 	    }
+	  seen_once++;
 	}
     }
 
@@ -5159,7 +5158,7 @@ find_in_imports_on_demand (class_type)
       return check_pkg_class_access (TYPE_NAME (class_type), cl);
     }
   else
-    return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
+    return (seen_once > 1 ? 1 : 0); /* It's ok not to have found */
 }
 
 static tree
@@ -6423,8 +6422,6 @@ resolve_qualified_expression_name (wfl, 
       /* We resolve and expression name */
       else 
 	{
-	  tree field_decl;
-
 	  /* If there exists an early resolution, use it. That occurs
 	     only once and we know that there are more things to
 	     come. Don't do that when processing something after SUPER
@@ -6454,6 +6451,7 @@ resolve_qualified_expression_name (wfl, 
 	  else
 	    {
 	      int is_static;
+	      tree field_decl;
 	      tree field_decl_type; /* For layout */
 
 	      if (!from_type && !JREFERENCE_TYPE_P (type))
@@ -6462,7 +6460,7 @@ resolve_qualified_expression_name (wfl, 
 		    (qual_wfl, "Attempt to reference field `%s' in `%s %s'",
 		     IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
 		     lang_printable_name (type, 0),
-		     IDENTIFIER_POINTER (DECL_NAME (field_decl)));
+		     IDENTIFIER_POINTER (DECL_NAME (decl)));
 		  return 1;
 		}
 	      
@@ -6838,6 +6836,8 @@ patch_method_invocation (patch, primary,
 		  PATCH_METHOD_RETURN_ERROR ();
 		}
 	    }
+	  else
+	    abort ();
 
 	  /* Class to search is NULL if we're searching the current one */
 	  if (class_to_search)
@@ -8589,6 +8589,7 @@ patch_assignment (node, wfl_op1, wfl_op2
     {
       parse_error_context (wfl_op1, "Invalid left hand side of assignment");
       error_found = 1;
+      lhs_type = NULL_TREE;
     }
 
   rhs_type = TREE_TYPE (rhs);
@@ -9105,7 +9106,7 @@ patch_binop (node, wfl_op1, wfl_op2)
   tree op2 = TREE_OPERAND (node, 1);
   tree op1_type = TREE_TYPE (op1);
   tree op2_type = TREE_TYPE (op2);
-  tree prom_type;
+  tree prom_type = NULL_TREE;
   int code = TREE_CODE (node);
 
   /* If 1, tell the routine that we have to return error_mark_node
@@ -9725,7 +9726,7 @@ patch_unaryop (node, wfl_op)
 {
   tree op = TREE_OPERAND (node, 0);
   tree op_type = TREE_TYPE (op);
-  tree prom_type, value, decl;
+  tree prom_type = NULL_TREE, value, decl;
   int code = TREE_CODE (node);
   int error_found = 0;
 
===================================================================
Index: java/verify.c
--- java/verify.c	1999/04/06 14:28:38	1.14
+++ java/verify.c	1999/04/15 03:31:59
@@ -334,7 +334,7 @@ verify_jvm_instructions (jcf, byte_ops, 
   int op_code;
   int PC;
   int oldpc; /* PC of start of instruction. */
-  int prevpc;  /* If >= 0, PC of previous instruction. */
+  int prevpc = INVALID_PC;  /* If >= 0, PC of previous instruction. */
   const char *message;
   int i;
   register unsigned char *p;
@@ -385,7 +385,9 @@ verify_jvm_instructions (jcf, byte_ops, 
       instruction_bits [handler_pc] |= BCODE_EXCEPTION_TARGET;
     }
 
-  for (PC = 0;;)
+  oldpc = 0;
+  PC = 0;
+  for (;;)
     {
       int index;
       tree type, tmp;
@@ -1004,7 +1006,7 @@ verify_jvm_instructions (jcf, byte_ops, 
 
 	case OPCODE_lookupswitch:
 	  {
-	    jint npairs, last, not_registered = 1;
+	    jint npairs, last, match;
 
 	    pop_type (int_type_node);
 	    while (PC%4)
@@ -1018,13 +1020,14 @@ verify_jvm_instructions (jcf, byte_ops, 
 	    
 	    if (npairs < 0)
 	      VERIFICATION_ERROR ("invalid number of targets in lookupswitch");
+	    npairs--;
+	    last = match = IMMEDIATE_s4;
+	    PUSH_PENDING (lookup_label (oldpc + IMMEDIATE_s4));
 
 	    while (npairs--)
 	      {
-	        int match = IMMEDIATE_s4;
-		if (not_registered)
-		  not_registered = 0;
-		else if (last >= match)
+	        match = IMMEDIATE_s4;
+		if (last >= match)
 		  VERIFICATION_ERROR ("unsorted match value in lookupswitch");
 
 		last = match;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]