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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: PR java/20502


GCJ would crash when compiling a .jar file which contains duplicate copies of the same class. This patch changes it to issue a warning, ignore the duplicate class, and not crash.

OK to commit?

Bryce

2005-03-16  Bryce McKinlay  <mckinlay@redhat.com>

	PR java/20502
	* java-tree.h (CLASS_COMPILED_P): Renamed from
	CLASS_FROM_CURRENTLY_COMPILED_P.
	* jcf-parse.c: Use CLASS_COMPILED_P.
	(duplicate_class_warning): New function.
	(parse_class_file): Set CLASS_COMPILED_P. Call duplicate_class_warning
	if it was already set.
	(parse_zip_file_entries): Likewise.
	* class.c (is_compiled_class): Use CLASS_COMPILED_P.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.221
diff -u -r1.221 class.c
--- class.c	4 Mar 2005 15:38:13 -0000	1.221
+++ class.c	17 Mar 2005 01:06:08 -0000
@@ -1927,7 +1929,7 @@
     return 2;
 
   seen_in_zip = (TYPE_JCF (class) && JCF_SEEN_IN_ZIP (TYPE_JCF (class)));
-  if (CLASS_FROM_CURRENTLY_COMPILED_P (class) || seen_in_zip)
+  if (CLASS_COMPILED_P (class) || seen_in_zip)
     {
       /* The class was seen in the current ZIP file and will be
 	 available as a compiled class in the future but may not have
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.228
diff -u -r1.228 java-tree.h
--- java-tree.h	6 Mar 2005 08:42:32 -0000	1.228
+++ java-tree.h	17 Mar 2005 01:06:08 -0000
@@ -1581,8 +1581,9 @@
 /* True of a RECORD_TYPE of a class/interface type (not array type) */
 #define CLASS_P(TYPE) TYPE_LANG_FLAG_4 (TYPE)
 
-/* True if class TYPE was requested (on command line) to be compiled.*/
-#define CLASS_FROM_CURRENTLY_COMPILED_P(TYPE) TYPE_LANG_FLAG_5 (TYPE)
+/* True if class TYPE was requested (on command line) to be compiled, and
+   code has been generated for it. */
+#define CLASS_COMPILED_P(TYPE) TYPE_LANG_FLAG_5 (TYPE)
 
 /* True if class TYPE is currently being laid out. Helps in detection
    of inheritance cycle occurring as a side effect of performing the
Index: jcf-parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-parse.c,v
retrieving revision 1.183
diff -u -r1.183 jcf-parse.c
--- jcf-parse.c	12 Feb 2005 15:21:14 -0000	1.183
+++ jcf-parse.c	17 Mar 2005 01:06:08 -0000
@@ -649,7 +649,7 @@
       tree type = TREE_TYPE (class_decl);
       is_compiled_class
 	= ((TYPE_JCF (type) && JCF_SEEN_IN_ZIP (TYPE_JCF (type)))
-	   || CLASS_FROM_CURRENTLY_COMPILED_P (type));
+	   || CLASS_COMPILED_P (type));
     }
 
   /* If the class is from source code, then it must already be loaded.  */
@@ -823,11 +823,32 @@
 }
 
 static void
+duplicate_class_warning (void)
+{
+  location_t warn_loc;
+#ifdef USE_MAPPED_LOCATION
+  linemap_add (&line_table, LC_RENAME, 0, current_jcf->filename, 0);
+  warn_loc = linemap_line_start (&line_table, 0, 1);
+#else
+  warn_loc.file = current_jcf->filename;
+  warn_loc.line = 0;
+#endif
+  warning ("%Hduplicate class will only be compiled once.", &warn_loc);
+}
+
+static void
 parse_class_file (void)
 {
   tree method;
   location_t save_location = input_location;
 
+  if (CLASS_COMPILED_P (current_class))
+    {
+      /* We've already compiled this class. */
+      duplicate_class_warning ();
+      return;
+    }
+  CLASS_COMPILED_P (current_class) = 1;
   java_layout_seen_class_methods ();
 
   input_location = DECL_SOURCE_LOCATION (TYPE_NAME (current_class));
@@ -1214,7 +1235,6 @@
 	  jcf_parse (current_jcf);
 	  DECL_SOURCE_LOCATION (node) = file_start_location;
 	  TYPE_JCF (current_class) = current_jcf;
-	  CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1;
 	  TREE_TYPE (node) = current_class;
 	}
       else if (magic == (JCF_u4)ZIPMAGIC)
@@ -1236,10 +1256,6 @@
 	  linemap_add (&line_table, LC_LEAVE, false, NULL, 0);
 #endif
 	  parse_zip_file_entries ();
-	  /*
-	  for (each entry)
-	    CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1;
-	  */
 	}
       else
 	{
@@ -1413,6 +1429,14 @@
 		layout_class (current_class);
 		load_inner_classes (current_class);
 	      }
+	      
+	    if (CLASS_COMPILED_P (current_class))
+	      {
+	        /* We've already compiled this class. Warn here to avoid 
+		double-free crash.  */
+		duplicate_class_warning ();
+		break;
+	      }
 
 	    if (TYPE_SIZE (current_class) != error_mark_node)
 	      {
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.530
diff -u -r1.530 parse.y
--- parse.y	10 Mar 2005 18:40:26 -0000	1.530
+++ parse.y	17 Mar 2005 01:06:09 -0000
@@ -3881,11 +3881,11 @@
 #ifdef USE_MAPPED_LOCATION
   {
     tree tmp = maybe_get_identifier (EXPR_FILENAME (cl));
-    CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
+    CLASS_COMPILED_P (TREE_TYPE (decl)) =
       tmp && IS_A_COMMAND_LINE_FILENAME_P (tmp);
   }
 #else
-  CLASS_FROM_CURRENTLY_COMPILED_P (TREE_TYPE (decl)) =
+  CLASS_COMPILED_P (TREE_TYPE (decl)) =
     IS_A_COMMAND_LINE_FILENAME_P (EXPR_WFL_FILENAME_NODE (cl));
 #endif
 

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